xo-object: generative GC utest + reinstate coverage build

This commit is contained in:
Roland Conybeare 2025-08-06 09:30:37 -05:00
commit e80304a09b
18 changed files with 625 additions and 28 deletions

View file

@ -19,15 +19,29 @@ namespace xo {
return s_boolean_v[static_cast<std::size_t>(x)];
}
gp<Boolean>
Boolean::true_obj()
{
return boolean_obj(true);
}
gp<Boolean>
Boolean::false_obj()
{
return boolean_obj(false);
}
std::size_t
Boolean::_shallow_size() const
{
return sizeof(Boolean);
}
// LCOV_EXCL_START
Object *
Boolean::_shallow_copy() const
{
/* Boolean instances not created in GC-owned space,
* so GC will not traverse them.
*
@ -38,14 +52,18 @@ namespace xo {
assert(false);
return nullptr;
}
}
// LCOV_EXCL_STOP
// LCOV_EXCL_START
std::size_t
Boolean::_forward_children()
{
assert(false);
return 0;
}
// LCOV_EXCL_STOP
}
} /*namespace xo*/

View file

@ -16,6 +16,11 @@ namespace xo {
gp<List>
List::nil = new List(nullptr, nullptr);
gp<List>
List::from(gp<Object> x) {
return dynamic_cast<List *>(x.ptr());
}
gp<List>
List::cons(gp<Object> car, gp<List> cdr) {
return new (MMPtr(mm)) List(car, cdr);

View file

@ -12,14 +12,14 @@
namespace xo {
namespace obj {
String::String(Owner owner, std::size_t z, char * s)
String::String(owner owner, std::size_t z, char * s)
: owner_{owner}, z_chars_{z}, chars_{s}
{}
String::String(gc::IAlloc * mm, Owner owner, std::size_t z, char * s, bool copy)
String::String(gc::IAlloc * mm, owner owner, std::size_t z, char * s)
: owner_{owner}, z_chars_{z}
{
if (copy) {
if (owner_ == owner::unique) {
chars_ = reinterpret_cast<char *>(mm->alloc(z));
assert(chars_);
@ -35,6 +35,14 @@ namespace xo {
return dynamic_cast<String*>(x.ptr());
}
gp<String>
String::share(const char * s) {
const char * chars = s ? s : "";
std::size_t z = 1 + ::strlen(chars);
return new (MMPtr(mm)) String(mm, owner::shared, z, const_cast<char *>(chars));
}
gp<String>
String::copy(const char * s) {
return copy(Object::mm, s);
@ -47,13 +55,13 @@ namespace xo {
const char * chars = s ? s : "";
// const-cast ok since chars copied with Owner::unique
return new (MMPtr(mm)) String(mm, Owner::unique, z, const_cast<char *>(chars), true /*copy*/);
return new (MMPtr(mm)) String(mm, owner::unique, z, const_cast<char *>(chars));
}
gp<String>
String::allocate(std::size_t z)
{
return new (MMPtr(Object::mm)) String(mm, Owner::unique, z, const_cast<char *>(""), true /*copy*/);
return new (MMPtr(Object::mm)) String(mm, owner::unique, z, const_cast<char *>(""));
}
gp<String>
@ -63,10 +71,11 @@ namespace xo {
std::size_t z2 = s2->length();
std::size_t z = z1 + z2;
gp<String> retval = allocate(z);
// +1 for null terminator
gp<String> retval = allocate(z+1);
strlcpy(retval->chars_, s1->chars_, z1);
strlcpy(retval->chars_ + z1, s2->chars_, z2);
strlcpy(retval->chars_, s1->chars_, z1+1);
strlcpy(retval->chars_ + z1, s2->chars_, z2+1);
return retval;
}
@ -87,7 +96,7 @@ namespace xo {
*/
std::size_t retval = gc::IAlloc::with_padding(sizeof(String));
if (owner_ == Owner::unique)
if (owner_ == owner::unique)
retval += gc::IAlloc::with_padding(z_chars_);
return retval;
@ -109,7 +118,7 @@ namespace xo {
//
gp<String> copy = new (cpof) String(owner_, z_chars_, chars_);
if (owner_ == Owner::unique) {
if (owner_ == owner::unique) {
std::byte * mem = reinterpret_cast<std::byte *>(chars_);
copy->chars_ = reinterpret_cast<char *>(Object::mm->alloc_gc_copy(z_chars_, mem));