xo-alloc + xo-allocutil: refactor to shrink dep surface area

This commit is contained in:
Roland Conybeare 2025-12-01 01:20:49 -05:00
commit 540b43d971
34 changed files with 479 additions and 323 deletions

View file

@ -5,7 +5,7 @@
#pragma once
#include "xo/alloc/IAlloc.hpp"
#include "xo/allocutil/IAlloc.hpp"
#include <cstdint>
namespace xo {

View file

@ -23,7 +23,7 @@ namespace xo {
/** create instance holding integer value @p x **/
static gp<Integer> make(IAlloc * mm, int_type x);
/** downcast from @p x iff x is actually an Integer. Otherwise nullptr **/
static gp<Integer> from(gp<Object> x);
static gp<Integer> from(gp<IObject> x);
int_type value() const { return value_; }

View file

@ -18,7 +18,7 @@ namespace xo {
static gp<List> nil;
/** @return non-null iff @p x is actually a List cell (or nil) **/
static gp<List> from(gp<Object> x);
static gp<List> from(gp<IObject> x);
/** @return list with first element @p car, and tail @p cdr **/
static gp<List> cons(gp<Object> car, gp<List> cdr);
@ -44,7 +44,7 @@ namespace xo {
/** @return first element in list; synonym for @ref head **/
gp<Object> car() const { return head_; }
/** @return remainder of list after first element; synonym for @ref rest **/
gp<Object> cdr() const { return rest_; }
gp<List> cdr() const { return rest_; }
/** @return number of top-level elements in this list **/
std::size_t size() const;
@ -58,7 +58,7 @@ namespace xo {
virtual TaggedPtr self_tp() const final override;
virtual void display(std::ostream & os) const final override;
virtual std::size_t _shallow_size() const final override;
virtual Object * _shallow_copy(gc::IAlloc * gc) const final override;
virtual IObject * _shallow_copy(gc::IAlloc * gc) const final override;
virtual std::size_t _forward_children(gc::IAlloc * gc) final override;
private:

View file

@ -5,7 +5,7 @@
#include "xo/alloc/Object.hpp"
#include "ObjectConversion.hpp"
#include "xo/alloc/IAlloc.hpp"
#include "xo/allocutil/IAlloc.hpp"
#include "xo/indentlog/print/tag.hpp"
namespace xo {

View file

@ -23,7 +23,7 @@ namespace xo {
}
gp<Integer>
Integer::from(gp<Object> x) {
Integer::from(gp<IObject> x) {
return gp<Integer>::from(x);
}

View file

@ -21,7 +21,7 @@ namespace xo {
List::nil = new List(nullptr, nullptr);
gp<List>
List::from(gp<Object> x) {
List::from(gp<IObject> x) {
return dynamic_cast<List *>(x.ptr());
}
@ -99,7 +99,7 @@ namespace xo {
return sizeof(List);
}
Object *
IObject *
List::_shallow_copy(gc::IAlloc * gc) const
{
assert(!(this->is_nil()));

View file

@ -59,10 +59,10 @@ namespace xo {
Object::mm = gc.get();
gp<List> l = List::list(Integer::make(gc.get(), 1));
gc->add_gc_root(reinterpret_cast<Object**>(l.ptr_address()));
gc->add_gc_root(reinterpret_cast<IObject**>(l.ptr_address()));
gp<List> l2 = List::list(Integer::make(gc.get(), 10));
gc->add_gc_root(reinterpret_cast<Object**>(l2.ptr_address()));
gc->add_gc_root(reinterpret_cast<IObject**>(l2.ptr_address()));
{
REQUIRE(l->size() == 1);
@ -447,7 +447,7 @@ namespace xo {
REQUIRE(root_v_.size() == r_);
for (auto & root : root_v_)
gc->add_gc_root(root.ptr_address());
gc->add_gc_root(reinterpret_cast<IObject**>(root.ptr_address()));
}
void RandomMutationModel::generate_random_mutations(xoshiro256ss * p_rgen)
@ -495,7 +495,7 @@ namespace xo {
if (w2_.at(j)->_is_forwarded()) {
/* w2[i] survived GC */
w2_[j] = w2_[j]->_destination();
w2_[j] = Object::from(w2_[j]->_destination());
REQUIRE(w2_[j].ptr());
} else {
/* w2[j] is garbage, replace */

View file

@ -124,7 +124,7 @@ namespace xo {
REQUIRE(l1->size() == v.size());
root_v[i] = l1;
gc->add_gc_root(reinterpret_cast<Object **>(root_v[i].ptr_address()));
gc->add_gc_root(reinterpret_cast<IObject **>(root_v[i].ptr_address()));
REQUIRE(gc->allocated() % sizeof(std::uintptr_t) == 0);
REQUIRE(gc->allocated() == expected_alloc_z);
@ -285,7 +285,7 @@ namespace xo {
//REQUIRE(l1->size() == v.size()); // lwill loop forever
root_v[i] = l1;
gc->add_gc_root(reinterpret_cast<Object **>(root_v[i].ptr_address()));
gc->add_gc_root(reinterpret_cast<IObject **>(root_v[i].ptr_address()));
REQUIRE(gc->allocated() % sizeof(std::uintptr_t) == 0);
REQUIRE(gc->allocated() == expected_alloc_z);

View file

@ -145,7 +145,7 @@ namespace xo {
xtag("alloc_z", alloc_z));
log && log(xtag("expected_alloc_z", expected_alloc_z));
gc->add_gc_root(reinterpret_cast<Object **>(sv[i].ptr_address()));
gc->add_gc_root(reinterpret_cast<IObject **>(sv[i].ptr_address()));
REQUIRE(gc->allocated() % sizeof(std::uintptr_t) == 0);
REQUIRE(gc->allocated() == expected_alloc_z);