From 0d3470c5413a8fd45e796156c5747a65094a7563 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Mon, 29 Dec 2025 14:32:52 -0500 Subject: [PATCH] xo-gc xo-object2 xo-facet: builds w/ ISequence,Dlist --- CMakeLists.txt | 10 ++++ idl/ISequence_DList.json5 | 12 +++++ idl/Sequence.json5 | 2 + include/xo/object2/DList.hpp | 14 +++++- include/xo/object2/IGCObject_DFloat.hpp | 1 + include/xo/object2/IGCObject_DInteger.hpp | 1 + include/xo/object2/IGCObject_DList.hpp | 13 +++++ include/xo/object2/ISequence_DList.hpp | 61 +++++++++++++++++++++++ src/object2/CMakeLists.txt | 3 ++ src/object2/DList.cpp | 54 ++++++++++++++++++++ src/object2/IGCObject_DList.cpp | 9 +++- src/object2/ISequence_DList.cpp | 40 +++++++++++++++ 12 files changed, 216 insertions(+), 4 deletions(-) create mode 100644 idl/ISequence_DList.json5 create mode 100644 include/xo/object2/ISequence_DList.hpp create mode 100644 src/object2/DList.cpp create mode 100644 src/object2/ISequence_DList.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 7fcc980..4dabb20 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,6 +27,16 @@ xo_add_genfacet( OUTPUT_CPP_DIR src/object2 ) +xo_add_genfacetimpl( + TARGET xo-object2-facetimpl-sequence-list + FACET Sequence + REPR List + INPUT idl/ISequence_DList.json5 + OUTPUT_HPP_DIR include/xo/object2 + OUTPUT_IMPL_SUBDIR sequence + OUTPUT_CPP_DIR src/object2 +) + # ---------------------------------------------------------------- # must complete definition of expression lib before configuring examples diff --git a/idl/ISequence_DList.json5 b/idl/ISequence_DList.json5 new file mode 100644 index 0000000..30c0b26 --- /dev/null +++ b/idl/ISequence_DList.json5 @@ -0,0 +1,12 @@ +{ + mode: "implementation", + includes: [], + namespace1: "xo", + namespace2: "scm", + facet_idl: "idl/Sequence.json5", + brief: "provide ASequence interface for DList state", + using_doxygen: true, + repr: "DList", + doc: [ "doc for something or other" + ], +} \ No newline at end of file diff --git a/idl/Sequence.json5 b/idl/Sequence.json5 index 433d3ca..2ee1a20 100644 --- a/idl/Sequence.json5 +++ b/idl/Sequence.json5 @@ -1,8 +1,10 @@ { + mode: "facet", includes: [""], namespace1: "xo", namespace2: "scm", facet: "Sequence", + detail_subdir: "sequence", brief: "an ordered collection of variants", using_doxygen: true, doc: [ diff --git a/include/xo/object2/DList.hpp b/include/xo/object2/DList.hpp index 9710def..79cc84f 100644 --- a/include/xo/object2/DList.hpp +++ b/include/xo/object2/DList.hpp @@ -11,13 +11,23 @@ namespace xo { namespace scm { struct DList { + using size_type = std::size_t; using AGCObject = xo::mm::AGCObject; DList(xo::obj h, - xo::obj r) : head_{h}, rest_{r} {} + DList * r) : head_{h}, rest_{r} {} + + /** DList length is at least 1 **/ + bool is_empty() const noexcept { return false; }; + /** DList models a finite sequence **/ + bool is_finite() const noexcept { return true; }; + /** return number of elements in this DList **/ + size_type size() const noexcept; + /** return element at 0-based index @p ix **/ + obj at(size_type ix) const; obj head_; - obj rest_; + DList * rest_ = nullptr; }; } /*namespace scm*/ diff --git a/include/xo/object2/IGCObject_DFloat.hpp b/include/xo/object2/IGCObject_DFloat.hpp index a6c5c17..3ccf40d 100644 --- a/include/xo/object2/IGCObject_DFloat.hpp +++ b/include/xo/object2/IGCObject_DFloat.hpp @@ -5,6 +5,7 @@ #pragma once +#include #include #include #include diff --git a/include/xo/object2/IGCObject_DInteger.hpp b/include/xo/object2/IGCObject_DInteger.hpp index 1f1f220..c53a79f 100644 --- a/include/xo/object2/IGCObject_DInteger.hpp +++ b/include/xo/object2/IGCObject_DInteger.hpp @@ -5,6 +5,7 @@ #pragma once +#include #include "xo/alloc2/alloc/AAllocator.hpp" #include #include diff --git a/include/xo/object2/IGCObject_DList.hpp b/include/xo/object2/IGCObject_DList.hpp index 8ba91a6..c469d17 100644 --- a/include/xo/object2/IGCObject_DList.hpp +++ b/include/xo/object2/IGCObject_DList.hpp @@ -13,6 +13,19 @@ #include "DList.hpp" namespace xo { + namespace scm { struct IGCObject_DList; } + + namespace facet { + template <> + struct FacetImplementation + { + using ImplType = xo::mm::IGCObject_Xfer + ; + }; + } + namespace scm { /* changes here coordinate with: * IGCObject_XFer diff --git a/include/xo/object2/ISequence_DList.hpp b/include/xo/object2/ISequence_DList.hpp new file mode 100644 index 0000000..5f67a3f --- /dev/null +++ b/include/xo/object2/ISequence_DList.hpp @@ -0,0 +1,61 @@ +/** @file ISequence_DList.hpp + * + * Generated automagically from ingredients: + * 1. code generator: + * [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet] + * arguments: + * --input [idl/ISequence_DList.json5] + * 2. jinja2 template for abstract facet .hpp file: + * [iface_facet_any.hpp.j2] + * 3. idl for facet methods + * [idl/ISequence_DList.json5] + **/ + +#pragma once + +#include "Sequence.hpp" +#include "sequence/ISequence_Xfer.hpp" +#include "DList.hpp" + +namespace xo { namespace scm { class ISequence_DList; } } + +namespace xo { + namespace facet { + template <> + struct FacetImplementation + { + using ImplType = xo::scm::ISequence_Xfer + ; + }; + } +} + +namespace xo { + namespace scm { + /** @class ISequence_DList + **/ + class ISequence_DList { + public: + /** @defgroup scm-sequence-dlist-type-traits **/ + ///@{ + using size_type = ASequence::size_type; + using AGCObject = ASequence::AGCObject; + ///@} + /** @defgroup scm-sequence-dlist-methods **/ + ///@{ + /** true iff sequence is empty **/ + static bool is_empty(const DList & self) noexcept; + /** true iff sequence is finite **/ + static bool is_finite(const DList & self) noexcept; + /** return element @p index of this sequence **/ + static obj at(const DList & self, size_type index); + + ///@} + }; + + } /*namespace scm*/ +} /*namespace xo*/ + +/* end */ \ No newline at end of file diff --git a/src/object2/CMakeLists.txt b/src/object2/CMakeLists.txt index d7df723..dd76874 100644 --- a/src/object2/CMakeLists.txt +++ b/src/object2/CMakeLists.txt @@ -6,9 +6,12 @@ set(SELF_SRCS IGCObject_DInteger.cpp IGCObject_DList.cpp ISequence_Any.cpp + ISequence_DList.cpp + DList.cpp ) xo_add_shared_library4(${SELF_LIB} ${PROJECT_NAME}Targets ${PROJECT_VERSION} 1 ${SELF_SRCS}) # note: deps here must also appear in cmake/xo_alloc2Config.cmake.in xo_dependency(${SELF_LIB} xo_gc) #xo_dependency(${SELF_LIB} indentlog) +#add_dependencies(${SELF_LIB} xo-object2-facetimpl-sequence-list) diff --git a/src/object2/DList.cpp b/src/object2/DList.cpp new file mode 100644 index 0000000..2377d18 --- /dev/null +++ b/src/object2/DList.cpp @@ -0,0 +1,54 @@ +/** @file DList.cpp + * + * @author Roland Conybeare, Dec 2025 + **/ + +#include "DList.hpp" +#include + +namespace xo { + namespace scm { + auto + DList::size() const noexcept -> size_type + { + const DList * l = this; + + size_type z = 0; + + while (l) { + ++z; + l = l->rest_; + } + + return z; + } + + auto + DList::at(size_type index) const -> obj + { + size_type ix = index; + const DList * l = this; + + while (l->rest_ && (ix > 0)) { + --ix; + l = l->rest_; + } + + if (ix > 0) { + assert(l == nullptr); + + throw std::runtime_error + (tostr("DList::at: out-of-range index where [0..z) expected", + xtag("index", index), + xtag("z", this->size()))); + } + + assert(l); + + return l->head_; + } + + } /*namespace scm*/ +} /*namespace xo*/ + +/* end DList.cpp */ diff --git a/src/object2/IGCObject_DList.cpp b/src/object2/IGCObject_DList.cpp index 104358e..d4355a2 100644 --- a/src/object2/IGCObject_DList.cpp +++ b/src/object2/IGCObject_DList.cpp @@ -6,7 +6,9 @@ #include "IGCObject_DList.hpp" namespace xo { + using xo::mm::AGCObject; using xo::mm::AAllocator; + using xo::facet::with_facet; using xo::facet::obj; using std::size_t; @@ -33,8 +35,11 @@ namespace xo { IGCObject_DList::forward_children(DList & src, obj gc) noexcept { - gc.forward_inplace(&src.head_); - gc.forward_inplace(&src.rest_); + gc.forward_inplace(src.head_.iface(), (void **)&(src.head_.data_)); + + //auto rest = with_facet::mkobj(src.rest_); + xo::facet::FacetImplementation::ImplType iface; + gc.forward_inplace(&iface, (void **)(&src.rest_)); return shallow_size(src); } diff --git a/src/object2/ISequence_DList.cpp b/src/object2/ISequence_DList.cpp new file mode 100644 index 0000000..22d5bde --- /dev/null +++ b/src/object2/ISequence_DList.cpp @@ -0,0 +1,40 @@ +/** @file ISequence_DList.cpp + * + * Generated automagically from ingredients: + * 1. code generator: + * [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet] + * arguments: + * --input [idl/ISequence_DList.json5] + * 2. jinja2 template for abstract facet .hpp file: + * [iface_facet_any.hpp.j2] + * 3. idl for facet methods + * [idl/ISequence_DList.json5] +**/ + +#include "ISequence_DList.hpp" + +namespace xo { + namespace scm { + auto + ISequence_DList::is_empty(const DList & self) noexcept -> bool + { + return self.is_empty(); + } + + auto + ISequence_DList::is_finite(const DList & self) noexcept -> bool + { + return self.is_finite(); + } + + auto + ISequence_DList::at(const DList & self, size_type index) -> obj + { + return self.at(index); + } + + + } /*namespace scm*/ +} /*namespace xo*/ + +/* end ISequence_DList.cpp */ \ No newline at end of file