xo-alloc2 xo-object2 : refactor to build on osx

This commit is contained in:
Roland Conybeare 2026-01-12 01:03:49 -05:00
commit cbf6abb539
16 changed files with 182 additions and 100 deletions

View file

@ -8,6 +8,7 @@
#include <xo/indentlog/scope.hpp>
#include <xo/indentlog/print/tostr.hpp>
#include <sys/mman.h>
#include <unistd.h> // for ::getpagesize() on osx
namespace xo {
using xo::print::operator<<;

View file

@ -7,6 +7,7 @@
#include "print.hpp"
#include <xo/indentlog/print/tag.hpp>
#include <catch2/catch.hpp>
#include <unistd.h> // for getpagesize() on osx
namespace xo {
using xo::mm::DCircularBuffer;

View file

@ -6,7 +6,6 @@
#pragma once
#include <xo/gc/GCObject.hpp>
//#include "xo/alloc2/gcobject/RGCObject.hpp"
#include <xo/facet/obj.hpp>
#include <xo/indentlog/print/ppindentinfo.hpp>
@ -14,6 +13,8 @@ namespace xo {
namespace scm {
// TODO: consider renaming to DCons
// See also ListOps in ListOps.hpp
//
struct DList {
using size_type = std::size_t;
using AGCObject = xo::mm::AGCObject;
@ -23,28 +24,6 @@ namespace xo {
DList(xo::obj<AGCObject> h,
DList * r) : head_{h}, rest_{r} {}
template <typename AConsFacet = AGCObject>
static obj<AConsFacet,DList> nil();
/** shortcut for
* cons(mm, cdr, cdr.data())
**/
template <typename AConsFacet = AGCObject, typename ACdrFacet = AGCObject>
static obj<AConsFacet,DList> cons(obj<AAllocator> mm,
obj<AGCObject> car,
obj<ACdrFacet,DList> cdr);
/** list with one element @p e1, allocated from @p mm **/
template <typename AListFacet = AGCObject>
static obj<AListFacet,DList> list(obj<AAllocator> mm,
obj<AGCObject> e1);
/** list with two element @p e1, @p e2, allocated from @p mm **/
template <typename AListFacet = AGCObject>
static obj<AListFacet,DList> list(obj<AAllocator> mm,
obj<AGCObject> e1,
obj<AGCObject> e2);
/** sentinel for null list **/
static DList * _nil();
@ -84,39 +63,6 @@ namespace xo {
DList * rest_ = nullptr;
};
template <typename AConsFacet>
obj<AConsFacet,DList>
DList::nil()
{
return obj<AConsFacet,DList>(DList::_nil());
}
template <typename AConsFacet, typename ACdrFacet>
obj<AConsFacet,DList>
DList::cons(obj<AAllocator> mm,
obj<AGCObject> car,
obj<ACdrFacet,DList> cdr)
{
return obj<AConsFacet,DList>(DList::_cons(mm, car, cdr.data()));
}
template <typename AListFacet>
obj<AListFacet,DList>
DList::list(obj<AAllocator> mm,
obj<AGCObject> e1)
{
return cons(mm, e1, nil());
}
template <typename AListFacet>
obj<AListFacet,DList>
DList::list(obj<AAllocator> mm,
obj<AGCObject> e1,
obj<AGCObject> e2)
{
return cons(mm, e1, list(mm, e2));
}
} /*namespace scm*/
} /*namespace xo*/

View file

@ -9,10 +9,11 @@
#include <xo/gc/Collector.hpp>
#include <xo/gc/detail/AGCObject.hpp>
#include <xo/gc/detail/IGCObject_Xfer.hpp>
#include "DList.hpp"
//#include "DList.hpp" // circular
namespace xo {
namespace scm { struct IGCObject_DList; }
namespace scm { struct DList; }
namespace facet {
template <>

View file

@ -0,0 +1,84 @@
/** @file ListOps.hpp
*
* @author Roland Conybeare, Jan 2026
**/
#pragma once
#include "IGCObject_DList.hpp"
#include "DList.hpp"
namespace xo {
namespace scm {
/** @brief list functions
*
* note: separate from DList, to avoid problems with deps needed
* to compile functions that return obj<AGCObject,DList>
**/
struct ListOps {
using AGCObject = xo::mm::AGCObject;
using AAllocator = xo::mm::AAllocator;
template <typename AConsFacet = AGCObject>
static obj<AConsFacet,DList> nil();
/** shortcut for
* cons(mm, cdr, cdr.data())
**/
template <typename AConsFacet = AGCObject, typename ACdrFacet = AGCObject>
static obj<AConsFacet,DList> cons(obj<AAllocator> mm,
obj<AGCObject> car,
obj<ACdrFacet,DList> cdr);
/** list with one element @p e1, allocated from @p mm **/
template <typename AListFacet = AGCObject>
static obj<AListFacet,DList> list(obj<AAllocator> mm,
obj<AGCObject> e1);
/** list with two element @p e1, @p e2, allocated from @p mm **/
template <typename AListFacet = AGCObject>
static obj<AListFacet,DList> list(obj<AAllocator> mm,
obj<AGCObject> e1,
obj<AGCObject> e2);
};
template <typename AConsFacet>
obj<AConsFacet,DList>
ListOps::nil()
{
return obj<AConsFacet,DList>(DList::_nil());
}
template <typename AConsFacet, typename ACdrFacet>
obj<AConsFacet,DList>
ListOps::cons(obj<AAllocator> mm,
obj<AGCObject> car,
obj<ACdrFacet,DList> cdr)
{
return obj<AConsFacet,DList>(DList::_cons(mm, car, cdr.data()));
}
template <typename AListFacet>
obj<AListFacet,DList>
ListOps::list(obj<AAllocator> mm,
obj<AGCObject> e1)
{
// clang 15 doesn't like nil() here.
return cons(mm, e1, nil());
}
template <typename AListFacet>
obj<AListFacet,DList>
ListOps::list(obj<AAllocator> mm,
obj<AGCObject> e1,
obj<AGCObject> e2)
{
return cons(mm, e1, list(mm, e2));
}
} /*namespace scm*/
} /*namespace xo*/
/* end ListOps.hpp */

View file

@ -0,0 +1,17 @@
/** @file object2_register_facets.hpp
*
* @author Roland Conybeare, Jan 2026
**/
#pragma once
#include <xo/gc/Collector.hpp>
namespace xo {
namespace scm {
/** Register object2 (facet,impl) combinations with FacetRegistry **/
bool object2_register_facets();
}
}
/* end object2_register_facets.hpp */

View file

@ -9,13 +9,8 @@
namespace xo {
namespace scm {
/** Register all object2/ gc-aware types with @p gc.
* Return true iff all types register successfully.
**/
bool object2_register_types(obj<xo::mm::ACollector> gc);
/** Register object2 (facet,impl) combinations with FacetRegistry **/
bool object2_register_facets();
bool object2_register_types(obj<xo::mm::ACollector> gc);
}
}

View file

@ -14,6 +14,7 @@ set(SELF_SRCS
DFloat.cpp
DInteger.cpp
object2_register_types.cpp
object2_register_facets.cpp
)
xo_add_shared_library4(${SELF_LIB} ${PROJECT_NAME}Targets ${PROJECT_VERSION} 1 ${SELF_SRCS})

View file

@ -141,7 +141,6 @@ namespace xo {
return false;
}
}
} /*namespace scm*/
} /*namespace xo*/

View file

@ -4,6 +4,7 @@
**/
#include "IGCObject_DList.hpp"
#include "DList.hpp"
#include <xo/indentlog/scope.hpp>
namespace xo {
@ -46,7 +47,6 @@ namespace xo {
return shallow_size(src);
}
} /*namespace scm*/
} /*namespace xo*/

View file

@ -25,4 +25,4 @@ namespace xo {
} /*namespace scm*/
} /*namespace xo*/
/* end IPrintable_DList.cpp */
/* end IPrintable_DList.cpp */

View file

@ -11,6 +11,7 @@
* [idl/ISequence_DList.json5]
**/
#include "IGCObject_DList.hpp" // apparently need this with clang 15
#include "ISequence_DList.hpp"
namespace xo {
@ -37,4 +38,4 @@ namespace xo {
} /*namespace scm*/
} /*namespace xo*/
/* end ISequence_DList.cpp */
/* end ISequence_DList.cpp */

View file

@ -0,0 +1,57 @@
/** @file object2_register_facets.cpp
*
* @author Roland Conybeare, Jan 2026
**/
#include "object2_register_facets.hpp"
#include <xo/object2/IGCObject_DList.hpp>
#include <xo/object2/IGCObject_DFloat.hpp>
#include <xo/object2/IGCObject_DInteger.hpp>
#include <xo/object2/IPrintable_DList.hpp>
#include <xo/object2/IPrintable_DFloat.hpp>
#include <xo/object2/IPrintable_DInteger.hpp>
#include <xo/printable2/detail/APrintable.hpp>
#include <xo/alloc2/alloc/AAllocator.hpp>
#include <xo/facet/FacetRegistry.hpp>
#include <xo/indentlog/scope.hpp>
namespace xo {
using xo::print::APrintable;
using xo::mm::AAllocator;
using xo::mm::AGCObject;
using xo::scm::DList;
using xo::scm::DFloat;
using xo::facet::FacetRegistry;
using xo::facet::typeseq;
namespace scm {
bool
object2_register_facets()
{
scope log(XO_DEBUG(true));
FacetRegistry::register_impl<AGCObject, DList>();
FacetRegistry::register_impl<APrintable, DList>();
FacetRegistry::register_impl<AGCObject, DFloat>();
FacetRegistry::register_impl<APrintable, DFloat>();
FacetRegistry::register_impl<AGCObject, DInteger>();
FacetRegistry::register_impl<APrintable, DInteger>();
log && log(xtag("DList.tseq", typeseq::id<DList>()));
log && log(xtag("DFloat.tseq", typeseq::id<DFloat>()));
log && log(xtag("DInteger.tseq", typeseq::id<DInteger>()));
log && log(xtag("AAllocator.tseq", typeseq::id<AAllocator>()));
log && log(xtag("APrintable.tseq", typeseq::id<APrintable>()));
log && log(xtag("AGCObject.tseq", typeseq::id<AGCObject>()));
return true;
}
} /*namespace scm*/
} /*namespace xo*/
/* end object2_register_facets.cpp */

View file

@ -17,18 +17,17 @@
#include <xo/indentlog/scope.hpp>
namespace xo {
using xo::print::APrintable;
using xo::mm::AAllocator;
// using xo::print::APrintable;
// using xo::mm::AAllocator;
using xo::mm::ACollector;
using xo::mm::AGCObject;
using xo::mm::IGCObject_Any;
using xo::facet::FacetRegistry;
// using xo::mm::IGCObject_Any;
// using xo::facet::FacetRegistry;
using xo::facet::impl_for;
using xo::facet::typeseq;
using xo::scope;
namespace scm {
bool
object2_register_types(obj<ACollector> gc)
{
@ -42,31 +41,6 @@ namespace xo {
return ok;
}
bool
object2_register_facets()
{
scope log(XO_DEBUG(true));
FacetRegistry::register_impl<AGCObject, DList>();
FacetRegistry::register_impl<APrintable, DList>();
FacetRegistry::register_impl<AGCObject, DFloat>();
// FacetRegistry::register_impl<APrintable, DFloat>();
FacetRegistry::register_impl<AGCObject, DInteger>();
FacetRegistry::register_impl<APrintable, DInteger>();
log && log(xtag("DList.tseq", typeseq::id<DList>()));
log && log(xtag("DFloat.tseq", typeseq::id<DFloat>()));
log && log(xtag("DInteger.tseq", typeseq::id<DInteger>()));
log && log(xtag("AAllocator.tseq", typeseq::id<AAllocator>()));
log && log(xtag("APrintable.tseq", typeseq::id<APrintable>()));
log && log(xtag("AGCObject.tseq", typeseq::id<AGCObject>()));
return true;
}
}
} /*namespace xo*/

View file

@ -3,8 +3,10 @@
* @author Roland Conybeare, Jan 2026
**/
#include "ListOps.hpp"
#include "DList.hpp"
#include "object2_register_types.hpp"
#include "object2_register_facets.hpp"
#include <xo/object2/DList.hpp>
#include <xo/object2/IGCObject_DList.hpp>
@ -30,6 +32,7 @@
namespace ut {
using xo::scm::object2_register_types;
using xo::scm::object2_register_facets;
using xo::scm::ListOps;
using xo::scm::DList;
using xo::scm::DInteger;
using xo::mm::AAllocator;
@ -107,14 +110,14 @@ namespace ut {
bool ok = object2_register_types(c_o);
REQUIRE(ok);
auto l0_o = DList::nil();
auto l0_o = ListOps::nil();
c_o.add_gc_root(&l0_o);
for(int ip1 = tc.list_.size(); ip1 > 0; --ip1) {
auto xi_o = DInteger::box<AGCObject>(gc_o, tc.list_[ip1 - 1]);
l0_o = DList::cons(gc_o, xi_o, l0_o);
l0_o = ListOps::cons(gc_o, xi_o, l0_o);
}
// TODO: log_streambuf using DArena

View file

@ -3,6 +3,7 @@
* @author Roland Conybeare, Dec 2025
**/
#include "ListOps.hpp"
#include "DFloat.hpp"
#include "DList.hpp"
#include "object2_register_types.hpp"
@ -26,6 +27,7 @@
namespace ut {
using xo::scm::object2_register_types;
using xo::scm::ListOps;
using xo::scm::DList;
using xo::scm::DFloat;
using xo::mm::AAllocator;
@ -173,7 +175,7 @@ namespace ut {
//DList * l0 = DList::list(gc_o, x0_o);
//auto l0_o = with_facet<AGCObject>::mkobj(l0);
auto l0_o = DList::list(gc_o, x0_o);
auto l0_o = ListOps::list(gc_o, x0_o);
c_o.add_gc_root(&l0_o);
REQUIRE(to_0->allocated() == (sizeof(AllocHeader) + sizeof(DFloat)
+ sizeof(AllocHeader) + sizeof(DList)));