From cbf6abb539fd9294f147230f0bfa5d4125b5e200 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Mon, 12 Jan 2026 01:03:49 -0500 Subject: [PATCH] xo-alloc2 xo-object2 : refactor to build on osx --- xo-arena/src/arena/DCircularBuffer.cpp | 1 + xo-arena/utest/DCircularBuffer.test.cpp | 1 + xo-object2/include/xo/object2/DList.hpp | 58 +------------ .../include/xo/object2/IGCObject_DList.hpp | 3 +- xo-object2/include/xo/object2/ListOps.hpp | 84 +++++++++++++++++++ .../xo/object2/object2_register_facets.hpp | 17 ++++ .../xo/object2/object2_register_types.hpp | 7 +- xo-object2/src/object2/CMakeLists.txt | 1 + xo-object2/src/object2/DList.cpp | 1 - xo-object2/src/object2/IGCObject_DList.cpp | 2 +- xo-object2/src/object2/IPrintable_DList.cpp | 2 +- xo-object2/src/object2/ISequence_DList.cpp | 3 +- .../src/object2/object2_register_facets.cpp | 57 +++++++++++++ .../src/object2/object2_register_types.cpp | 34 +------- xo-object2/utest/Printable.test.cpp | 7 +- xo-object2/utest/X1Collector.test.cpp | 4 +- 16 files changed, 182 insertions(+), 100 deletions(-) create mode 100644 xo-object2/include/xo/object2/ListOps.hpp create mode 100644 xo-object2/include/xo/object2/object2_register_facets.hpp create mode 100644 xo-object2/src/object2/object2_register_facets.cpp diff --git a/xo-arena/src/arena/DCircularBuffer.cpp b/xo-arena/src/arena/DCircularBuffer.cpp index e00aaaf7..2a415c49 100644 --- a/xo-arena/src/arena/DCircularBuffer.cpp +++ b/xo-arena/src/arena/DCircularBuffer.cpp @@ -8,6 +8,7 @@ #include #include #include +#include // for ::getpagesize() on osx namespace xo { using xo::print::operator<<; diff --git a/xo-arena/utest/DCircularBuffer.test.cpp b/xo-arena/utest/DCircularBuffer.test.cpp index 2d8df93d..ea5a01be 100644 --- a/xo-arena/utest/DCircularBuffer.test.cpp +++ b/xo-arena/utest/DCircularBuffer.test.cpp @@ -7,6 +7,7 @@ #include "print.hpp" #include #include +#include // for getpagesize() on osx namespace xo { using xo::mm::DCircularBuffer; diff --git a/xo-object2/include/xo/object2/DList.hpp b/xo-object2/include/xo/object2/DList.hpp index b023f0d3..d20fadca 100644 --- a/xo-object2/include/xo/object2/DList.hpp +++ b/xo-object2/include/xo/object2/DList.hpp @@ -6,7 +6,6 @@ #pragma once #include -//#include "xo/alloc2/gcobject/RGCObject.hpp" #include #include @@ -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 h, DList * r) : head_{h}, rest_{r} {} - template - static obj nil(); - - /** shortcut for - * cons(mm, cdr, cdr.data()) - **/ - template - static obj cons(obj mm, - obj car, - obj cdr); - - /** list with one element @p e1, allocated from @p mm **/ - template - static obj list(obj mm, - obj e1); - - /** list with two element @p e1, @p e2, allocated from @p mm **/ - template - static obj list(obj mm, - obj e1, - obj e2); - /** sentinel for null list **/ static DList * _nil(); @@ -84,39 +63,6 @@ namespace xo { DList * rest_ = nullptr; }; - template - obj - DList::nil() - { - return obj(DList::_nil()); - } - - template - obj - DList::cons(obj mm, - obj car, - obj cdr) - { - return obj(DList::_cons(mm, car, cdr.data())); - } - - template - obj - DList::list(obj mm, - obj e1) - { - return cons(mm, e1, nil()); - } - - template - obj - DList::list(obj mm, - obj e1, - obj e2) - { - return cons(mm, e1, list(mm, e2)); - } - } /*namespace scm*/ } /*namespace xo*/ diff --git a/xo-object2/include/xo/object2/IGCObject_DList.hpp b/xo-object2/include/xo/object2/IGCObject_DList.hpp index 3d61a71d..eba4a7d1 100644 --- a/xo-object2/include/xo/object2/IGCObject_DList.hpp +++ b/xo-object2/include/xo/object2/IGCObject_DList.hpp @@ -9,10 +9,11 @@ #include #include #include -#include "DList.hpp" +//#include "DList.hpp" // circular namespace xo { namespace scm { struct IGCObject_DList; } + namespace scm { struct DList; } namespace facet { template <> diff --git a/xo-object2/include/xo/object2/ListOps.hpp b/xo-object2/include/xo/object2/ListOps.hpp new file mode 100644 index 00000000..90041cac --- /dev/null +++ b/xo-object2/include/xo/object2/ListOps.hpp @@ -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 + **/ + struct ListOps { + using AGCObject = xo::mm::AGCObject; + using AAllocator = xo::mm::AAllocator; + + template + static obj nil(); + + /** shortcut for + * cons(mm, cdr, cdr.data()) + **/ + template + static obj cons(obj mm, + obj car, + obj cdr); + + /** list with one element @p e1, allocated from @p mm **/ + template + static obj list(obj mm, + obj e1); + + /** list with two element @p e1, @p e2, allocated from @p mm **/ + template + static obj list(obj mm, + obj e1, + obj e2); + + }; + + template + obj + ListOps::nil() + { + return obj(DList::_nil()); + } + + template + obj + ListOps::cons(obj mm, + obj car, + obj cdr) + { + return obj(DList::_cons(mm, car, cdr.data())); + } + + template + obj + ListOps::list(obj mm, + obj e1) + { + // clang 15 doesn't like nil() here. + + return cons(mm, e1, nil()); + } + + template + obj + ListOps::list(obj mm, + obj e1, + obj e2) + { + return cons(mm, e1, list(mm, e2)); + } + + } /*namespace scm*/ +} /*namespace xo*/ + +/* end ListOps.hpp */ diff --git a/xo-object2/include/xo/object2/object2_register_facets.hpp b/xo-object2/include/xo/object2/object2_register_facets.hpp new file mode 100644 index 00000000..e419b794 --- /dev/null +++ b/xo-object2/include/xo/object2/object2_register_facets.hpp @@ -0,0 +1,17 @@ +/** @file object2_register_facets.hpp + * + * @author Roland Conybeare, Jan 2026 + **/ + +#pragma once + +#include + +namespace xo { + namespace scm { + /** Register object2 (facet,impl) combinations with FacetRegistry **/ + bool object2_register_facets(); + } +} + +/* end object2_register_facets.hpp */ diff --git a/xo-object2/include/xo/object2/object2_register_types.hpp b/xo-object2/include/xo/object2/object2_register_types.hpp index 110779cb..5c61692d 100644 --- a/xo-object2/include/xo/object2/object2_register_types.hpp +++ b/xo-object2/include/xo/object2/object2_register_types.hpp @@ -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 gc); - /** Register object2 (facet,impl) combinations with FacetRegistry **/ - bool object2_register_facets(); + bool object2_register_types(obj gc); } } diff --git a/xo-object2/src/object2/CMakeLists.txt b/xo-object2/src/object2/CMakeLists.txt index d784e881..fc4c2d8e 100644 --- a/xo-object2/src/object2/CMakeLists.txt +++ b/xo-object2/src/object2/CMakeLists.txt @@ -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}) diff --git a/xo-object2/src/object2/DList.cpp b/xo-object2/src/object2/DList.cpp index 934fa503..b43d1a9f 100644 --- a/xo-object2/src/object2/DList.cpp +++ b/xo-object2/src/object2/DList.cpp @@ -141,7 +141,6 @@ namespace xo { return false; } } - } /*namespace scm*/ } /*namespace xo*/ diff --git a/xo-object2/src/object2/IGCObject_DList.cpp b/xo-object2/src/object2/IGCObject_DList.cpp index af7353f3..4266075d 100644 --- a/xo-object2/src/object2/IGCObject_DList.cpp +++ b/xo-object2/src/object2/IGCObject_DList.cpp @@ -4,6 +4,7 @@ **/ #include "IGCObject_DList.hpp" +#include "DList.hpp" #include namespace xo { @@ -46,7 +47,6 @@ namespace xo { return shallow_size(src); } - } /*namespace scm*/ } /*namespace xo*/ diff --git a/xo-object2/src/object2/IPrintable_DList.cpp b/xo-object2/src/object2/IPrintable_DList.cpp index 880af691..19e5a875 100644 --- a/xo-object2/src/object2/IPrintable_DList.cpp +++ b/xo-object2/src/object2/IPrintable_DList.cpp @@ -25,4 +25,4 @@ namespace xo { } /*namespace scm*/ } /*namespace xo*/ -/* end IPrintable_DList.cpp */ \ No newline at end of file +/* end IPrintable_DList.cpp */ diff --git a/xo-object2/src/object2/ISequence_DList.cpp b/xo-object2/src/object2/ISequence_DList.cpp index 22d5bde5..71dcf744 100644 --- a/xo-object2/src/object2/ISequence_DList.cpp +++ b/xo-object2/src/object2/ISequence_DList.cpp @@ -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 */ \ No newline at end of file +/* end ISequence_DList.cpp */ diff --git a/xo-object2/src/object2/object2_register_facets.cpp b/xo-object2/src/object2/object2_register_facets.cpp new file mode 100644 index 00000000..210fb7c0 --- /dev/null +++ b/xo-object2/src/object2/object2_register_facets.cpp @@ -0,0 +1,57 @@ +/** @file object2_register_facets.cpp + * + * @author Roland Conybeare, Jan 2026 + **/ + +#include "object2_register_facets.hpp" +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include + +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(); + FacetRegistry::register_impl(); + + FacetRegistry::register_impl(); + FacetRegistry::register_impl(); + + FacetRegistry::register_impl(); + FacetRegistry::register_impl(); + + log && log(xtag("DList.tseq", typeseq::id())); + log && log(xtag("DFloat.tseq", typeseq::id())); + log && log(xtag("DInteger.tseq", typeseq::id())); + + log && log(xtag("AAllocator.tseq", typeseq::id())); + log && log(xtag("APrintable.tseq", typeseq::id())); + log && log(xtag("AGCObject.tseq", typeseq::id())); + + return true; + } + } /*namespace scm*/ +} /*namespace xo*/ + +/* end object2_register_facets.cpp */ diff --git a/xo-object2/src/object2/object2_register_types.cpp b/xo-object2/src/object2/object2_register_types.cpp index 131b8cfc..909d28ab 100644 --- a/xo-object2/src/object2/object2_register_types.cpp +++ b/xo-object2/src/object2/object2_register_types.cpp @@ -17,18 +17,17 @@ #include 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 gc) { @@ -42,31 +41,6 @@ namespace xo { return ok; } - - bool - object2_register_facets() - { - scope log(XO_DEBUG(true)); - - FacetRegistry::register_impl(); - FacetRegistry::register_impl(); - - FacetRegistry::register_impl(); -// FacetRegistry::register_impl(); - - FacetRegistry::register_impl(); - FacetRegistry::register_impl(); - - log && log(xtag("DList.tseq", typeseq::id())); - log && log(xtag("DFloat.tseq", typeseq::id())); - log && log(xtag("DInteger.tseq", typeseq::id())); - - log && log(xtag("AAllocator.tseq", typeseq::id())); - log && log(xtag("APrintable.tseq", typeseq::id())); - log && log(xtag("AGCObject.tseq", typeseq::id())); - - return true; - } } } /*namespace xo*/ diff --git a/xo-object2/utest/Printable.test.cpp b/xo-object2/utest/Printable.test.cpp index e84d52a6..47bfcf1b 100644 --- a/xo-object2/utest/Printable.test.cpp +++ b/xo-object2/utest/Printable.test.cpp @@ -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 #include @@ -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(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 diff --git a/xo-object2/utest/X1Collector.test.cpp b/xo-object2/utest/X1Collector.test.cpp index 1536ebfd..2ad93810 100644 --- a/xo-object2/utest/X1Collector.test.cpp +++ b/xo-object2/utest/X1Collector.test.cpp @@ -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::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)));