From 0f7dccc1931176e15ff9d327972972c60f5858ee Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Sat, 31 Jan 2026 18:28:25 -0500 Subject: [PATCH] xo-reader2 xo-expression2: + DSequenceSsm ++ utest --- CMakeLists.txt | 24 +++++++ idl/IGCObject_DConstant.json5 | 15 +++++ idl/IGCObject_DIfElseExpr.json5 | 15 +++++ include/xo/expression2/DConstant.hpp | 12 +++- include/xo/expression2/DIfElseExpr.hpp | 10 +++ .../detail/IGCObject_DConstant.hpp | 67 +++++++++++++++++++ .../detail/IGCObject_DIfElseExpr.hpp | 67 +++++++++++++++++++ src/expression2/CMakeLists.txt | 2 + src/expression2/DConstant.cpp | 25 +++++++ src/expression2/DIfElseExpr.cpp | 41 ++++++++++++ src/expression2/IGCObject_DConstant.cpp | 39 +++++++++++ src/expression2/IGCObject_DIfElseExpr.cpp | 39 +++++++++++ .../expression2_register_facets.cpp | 11 ++- .../expression2_register_types.cpp | 21 +++++- 14 files changed, 384 insertions(+), 4 deletions(-) create mode 100644 idl/IGCObject_DConstant.json5 create mode 100644 idl/IGCObject_DIfElseExpr.json5 create mode 100644 include/xo/expression2/detail/IGCObject_DConstant.hpp create mode 100644 include/xo/expression2/detail/IGCObject_DIfElseExpr.hpp create mode 100644 src/expression2/IGCObject_DConstant.cpp create mode 100644 src/expression2/IGCObject_DIfElseExpr.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 7cc83f11..a9060ce1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -82,6 +82,18 @@ xo_add_genfacetimpl( OUTPUT_CPP_DIR src/expression2 ) +# note: manual target; generated code committed to git +xo_add_genfacetimpl( + TARGET xo-expression2-facetimpl-gcobject-constant + FACET_PKG xo_gc + FACET GCObject + REPR Constant + INPUT idl/IGCObject_DConstant.json5 + OUTPUT_HPP_DIR include/xo/expression2 + OUTPUT_IMPL_SUBDIR detail + OUTPUT_CPP_DIR src/expression2 +) + # note: manual target; generated code committed to git xo_add_genfacetimpl( TARGET xo-expression2-facetimpl-printable-constant @@ -224,6 +236,18 @@ xo_add_genfacetimpl( OUTPUT_CPP_DIR src/expression2 ) +# note: manual target; generated code committed to git +xo_add_genfacetimpl( + TARGET xo-expression2-facetimpl-gcobject-ifelseexpr + FACET_PKG xo_gc + FACET GCObject + REPR IfElseExpr + INPUT idl/IGCObject_DIfElseExpr.json5 + OUTPUT_HPP_DIR include/xo/expression2 + OUTPUT_IMPL_SUBDIR detail + OUTPUT_CPP_DIR src/expression2 +) + # note: manual target; generated code committed to git xo_add_genfacetimpl( TARGET xo-expression2-facetimpl-printable-ifelseexpr diff --git a/idl/IGCObject_DConstant.json5 b/idl/IGCObject_DConstant.json5 new file mode 100644 index 00000000..f67c5b52 --- /dev/null +++ b/idl/IGCObject_DConstant.json5 @@ -0,0 +1,15 @@ +{ + mode: "implementation", + includes: [ + "", + "" + ], + local_types: [ ], + namespace1: "xo", + namespace2: "scm", + facet_idl: "idl/GCObject.json5", + brief: "provide AGCObject interface for DConstant", + using_doxygen: true, + repr: "DConstant", + doc: [ "implement AGCObject for DConstant" ], +} diff --git a/idl/IGCObject_DIfElseExpr.json5 b/idl/IGCObject_DIfElseExpr.json5 new file mode 100644 index 00000000..1c5d0661 --- /dev/null +++ b/idl/IGCObject_DIfElseExpr.json5 @@ -0,0 +1,15 @@ +{ + mode: "implementation", + includes: [ + "", + "" + ], + local_types: [ ], + namespace1: "xo", + namespace2: "scm", + facet_idl: "idl/GCObject.json5", + brief: "provide AGCObject interface for DIfElseExpr", + using_doxygen: true, + repr: "DIfElseExpr", + doc: [ "implement AGCObject for DIfElseExpr" ], +} diff --git a/include/xo/expression2/DConstant.hpp b/include/xo/expression2/DConstant.hpp index 1046176a..0c57f924 100644 --- a/include/xo/expression2/DConstant.hpp +++ b/include/xo/expression2/DConstant.hpp @@ -8,8 +8,9 @@ #include "Expression.hpp" #include "TypeRef.hpp" #include "exprtype.hpp" -#include +#include #include +#include namespace xo { namespace scm { @@ -20,6 +21,7 @@ namespace xo { public: using TaggedPtr = xo::reflect::TaggedPtr; using TypeDescr = xo::reflect::TypeDescr; + using ACollector = xo::mm::ACollector; using AAllocator = xo::mm::AAllocator; using AGCObject = xo::mm::AGCObject; using typeseq = xo::reflect::typeseq; @@ -56,6 +58,14 @@ namespace xo { TypeDescr valuetype() const noexcept { return typeref_.td(); } void assign_valuetype(TypeDescr td) noexcept { typeref_.resolve(td); } + ///@} + /** @defgroup scm-constant-gcobject-facet **/ + ///@{ + + size_t shallow_size() const noexcept; + DConstant * shallow_copy(obj mm) const noexcept; + size_t forward_children(obj gc) noexcept; + ///@} /** @defgroup scm-constant-printable-facet **/ ///@{ diff --git a/include/xo/expression2/DIfElseExpr.hpp b/include/xo/expression2/DIfElseExpr.hpp index 8222834a..3b7b07e2 100644 --- a/include/xo/expression2/DIfElseExpr.hpp +++ b/include/xo/expression2/DIfElseExpr.hpp @@ -8,6 +8,7 @@ #include "Expression.hpp" #include "TypeRef.hpp" #include "exprtype.hpp" +#include #include //#include #include @@ -21,6 +22,7 @@ namespace xo { **/ class DIfElseExpr { public: + using ACollector = xo::mm::ACollector; using AAllocator = xo::mm::AAllocator; using TypeDescr = xo::reflect::TypeDescr; using ppindentinfo = xo::print::ppindentinfo; @@ -93,6 +95,14 @@ namespace xo { bool pretty(const ppindentinfo & ppii) const; ///@} + /** @defgroup scm-ifelseexpr-gcobject-facet **/ + ///@{ + + std::size_t shallow_size() const noexcept; + DIfElseExpr * shallow_copy(obj mm) const noexcept; + std::size_t forward_children(obj gc) noexcept; + + ///@} #ifdef NOT_YET virtual std::set get_free_variables() const override { diff --git a/include/xo/expression2/detail/IGCObject_DConstant.hpp b/include/xo/expression2/detail/IGCObject_DConstant.hpp new file mode 100644 index 00000000..871f9c91 --- /dev/null +++ b/include/xo/expression2/detail/IGCObject_DConstant.hpp @@ -0,0 +1,67 @@ +/** @file IGCObject_DConstant.hpp + * + * Generated automagically from ingredients: + * 1. code generator: + * [xo-facet/codegen/genfacet] + * arguments: + * --input [idl/IGCObject_DConstant.json5] + * 2. jinja2 template for abstract facet .hpp file: + * [iface_facet_repr.hpp.j2] + * 3. idl for facet methods + * [idl/IGCObject_DConstant.json5] + **/ + +#pragma once + +#include "GCObject.hpp" +#include +#include +#include "DConstant.hpp" + +namespace xo { namespace scm { class IGCObject_DConstant; } } + +namespace xo { + namespace facet { + template <> + struct FacetImplementation + { + using ImplType = xo::mm::IGCObject_Xfer + ; + }; + } +} + +namespace xo { + namespace scm { + /** @class IGCObject_DConstant + **/ + class IGCObject_DConstant { + public: + /** @defgroup scm-gcobject-dconstant-type-traits **/ + ///@{ + using size_type = xo::mm::AGCObject::size_type; + using AAllocator = xo::mm::AGCObject::AAllocator; + using ACollector = xo::mm::AGCObject::ACollector; + using Copaque = xo::mm::AGCObject::Copaque; + using Opaque = xo::mm::AGCObject::Opaque; + ///@} + /** @defgroup scm-gcobject-dconstant-methods **/ + ///@{ + // const methods + /** memory consumption for this instance **/ + static size_type shallow_size(const DConstant & self) noexcept; + /** copy instance using allocator **/ + static Opaque shallow_copy(const DConstant & self, obj mm) noexcept; + + // non-const methods + /** during GC: forward immdiate children **/ + static size_type forward_children(DConstant & self, obj gc) noexcept; + ///@} + }; + + } /*namespace scm*/ +} /*namespace xo*/ + +/* end */ \ No newline at end of file diff --git a/include/xo/expression2/detail/IGCObject_DIfElseExpr.hpp b/include/xo/expression2/detail/IGCObject_DIfElseExpr.hpp new file mode 100644 index 00000000..6a47d9b8 --- /dev/null +++ b/include/xo/expression2/detail/IGCObject_DIfElseExpr.hpp @@ -0,0 +1,67 @@ +/** @file IGCObject_DIfElseExpr.hpp + * + * Generated automagically from ingredients: + * 1. code generator: + * [xo-facet/codegen/genfacet] + * arguments: + * --input [idl/IGCObject_DIfElseExpr.json5] + * 2. jinja2 template for abstract facet .hpp file: + * [iface_facet_repr.hpp.j2] + * 3. idl for facet methods + * [idl/IGCObject_DIfElseExpr.json5] + **/ + +#pragma once + +#include "GCObject.hpp" +#include +#include +#include "DIfElseExpr.hpp" + +namespace xo { namespace scm { class IGCObject_DIfElseExpr; } } + +namespace xo { + namespace facet { + template <> + struct FacetImplementation + { + using ImplType = xo::mm::IGCObject_Xfer + ; + }; + } +} + +namespace xo { + namespace scm { + /** @class IGCObject_DIfElseExpr + **/ + class IGCObject_DIfElseExpr { + public: + /** @defgroup scm-gcobject-difelseexpr-type-traits **/ + ///@{ + using size_type = xo::mm::AGCObject::size_type; + using AAllocator = xo::mm::AGCObject::AAllocator; + using ACollector = xo::mm::AGCObject::ACollector; + using Copaque = xo::mm::AGCObject::Copaque; + using Opaque = xo::mm::AGCObject::Opaque; + ///@} + /** @defgroup scm-gcobject-difelseexpr-methods **/ + ///@{ + // const methods + /** memory consumption for this instance **/ + static size_type shallow_size(const DIfElseExpr & self) noexcept; + /** copy instance using allocator **/ + static Opaque shallow_copy(const DIfElseExpr & self, obj mm) noexcept; + + // non-const methods + /** during GC: forward immdiate children **/ + static size_type forward_children(DIfElseExpr & self, obj gc) noexcept; + ///@} + }; + + } /*namespace scm*/ +} /*namespace xo*/ + +/* end */ \ No newline at end of file diff --git a/src/expression2/CMakeLists.txt b/src/expression2/CMakeLists.txt index 4f929fa4..4f3d63c1 100644 --- a/src/expression2/CMakeLists.txt +++ b/src/expression2/CMakeLists.txt @@ -17,6 +17,7 @@ set(SELF_SRCS IExpression_Any.cpp IExpression_DConstant.cpp + IGCObject_DConstant.cpp IPrintable_DConstant.cpp IExpression_DVariable.cpp @@ -33,6 +34,7 @@ set(SELF_SRCS IPrintable_DLambdaExpr.cpp IExpression_DIfElseExpr.cpp + IGCObject_DIfElseExpr.cpp IPrintable_DIfElseExpr.cpp IExpression_DSequenceExpr.cpp diff --git a/src/expression2/DConstant.cpp b/src/expression2/DConstant.cpp index f03fe625..f1f560be 100644 --- a/src/expression2/DConstant.cpp +++ b/src/expression2/DConstant.cpp @@ -71,6 +71,31 @@ namespace xo { return nullptr; } + std::size_t + DConstant::shallow_size() const noexcept + { + return sizeof(DConstant); + } + + DConstant * + DConstant::shallow_copy(obj mm) const noexcept + { + DConstant * copy = (DConstant *)mm.alloc_copy((std::byte *)this); + + if (copy) + *copy = *this; + + return copy; + } + + std::size_t + DConstant::forward_children(obj gc) noexcept + { + gc.forward_inplace(value_.iface(), (void **)&(value_.data_)); + + return shallow_size(); + } + bool DConstant::pretty(const ppindentinfo & ppii) const { diff --git a/src/expression2/DIfElseExpr.cpp b/src/expression2/DIfElseExpr.cpp index d858dfab..e1d5e70e 100644 --- a/src/expression2/DIfElseExpr.cpp +++ b/src/expression2/DIfElseExpr.cpp @@ -5,11 +5,13 @@ #include "DIfElseExpr.hpp" #include "detail/IExpression_DIfElseExpr.hpp" +#include #include #include #include namespace xo { + using xo::mm::AGCObject; using xo::print::APrintable; using xo::reflect::typeseq; using xo::facet::FacetRegistry; @@ -120,6 +122,45 @@ namespace xo { } } + // GCObject facet + + std::size_t + DIfElseExpr::shallow_size() const noexcept + { + return sizeof(DIfElseExpr); + } + + DIfElseExpr * + DIfElseExpr::shallow_copy(obj mm) const noexcept + { + DIfElseExpr * copy = (DIfElseExpr *)mm.alloc_copy((std::byte *)this); + + if (copy) + *copy = *this; + + return copy; + } + + std::size_t + DIfElseExpr::forward_children(obj gc) noexcept + { + // GC needs to locate AGCObject iface for each member. + { + auto gco = FacetRegistry::instance().variant(test_); + gc.forward_inplace(gco.iface(), (void **)&(test_.data_)); + } + { + auto gco = FacetRegistry::instance().variant(when_true_); + gc.forward_inplace(gco.iface(), (void **)&(when_true_.data_)); + } + { + auto gco = FacetRegistry::instance().variant(when_false_); + gc.forward_inplace(gco.iface(), (void **)&(when_false_.data_)); + } + + return shallow_size(); + } + // ---------------------------------------------------------------- #ifdef NOPE diff --git a/src/expression2/IGCObject_DConstant.cpp b/src/expression2/IGCObject_DConstant.cpp new file mode 100644 index 00000000..ea3be262 --- /dev/null +++ b/src/expression2/IGCObject_DConstant.cpp @@ -0,0 +1,39 @@ +/** @file IGCObject_DConstant.cpp + * + * Generated automagically from ingredients: + * 1. code generator: + * [xo-facet/codegen/genfacet] + * arguments: + * --input [idl/IGCObject_DConstant.json5] + * 2. jinja2 template for abstract facet .hpp file: + * [iface_facet_any.hpp.j2] + * 3. idl for facet methods + * [idl/IGCObject_DConstant.json5] +**/ + +#include "detail/IGCObject_DConstant.hpp" + +namespace xo { + namespace scm { + auto + IGCObject_DConstant::shallow_size(const DConstant & self) noexcept -> size_type + { + return self.shallow_size(); + } + + auto + IGCObject_DConstant::shallow_copy(const DConstant & self, obj mm) noexcept -> Opaque + { + return self.shallow_copy(mm); + } + + auto + IGCObject_DConstant::forward_children(DConstant & self, obj gc) noexcept -> size_type + { + return self.forward_children(gc); + } + + } /*namespace scm*/ +} /*namespace xo*/ + +/* end IGCObject_DConstant.cpp */ diff --git a/src/expression2/IGCObject_DIfElseExpr.cpp b/src/expression2/IGCObject_DIfElseExpr.cpp new file mode 100644 index 00000000..8a0f03d5 --- /dev/null +++ b/src/expression2/IGCObject_DIfElseExpr.cpp @@ -0,0 +1,39 @@ +/** @file IGCObject_DIfElseExpr.cpp + * + * Generated automagically from ingredients: + * 1. code generator: + * [xo-facet/codegen/genfacet] + * arguments: + * --input [idl/IGCObject_DIfElseExpr.json5] + * 2. jinja2 template for abstract facet .hpp file: + * [iface_facet_any.hpp.j2] + * 3. idl for facet methods + * [idl/IGCObject_DIfElseExpr.json5] +**/ + +#include "detail/IGCObject_DIfElseExpr.hpp" + +namespace xo { + namespace scm { + auto + IGCObject_DIfElseExpr::shallow_size(const DIfElseExpr & self) noexcept -> size_type + { + return self.shallow_size(); + } + + auto + IGCObject_DIfElseExpr::shallow_copy(const DIfElseExpr & self, obj mm) noexcept -> Opaque + { + return self.shallow_copy(mm); + } + + auto + IGCObject_DIfElseExpr::forward_children(DIfElseExpr & self, obj gc) noexcept -> size_type + { + return self.forward_children(gc); + } + + } /*namespace scm*/ +} /*namespace xo*/ + +/* end IGCObject_DIfElseExpr.cpp */ diff --git a/src/expression2/expression2_register_facets.cpp b/src/expression2/expression2_register_facets.cpp index 8109293a..26869d50 100644 --- a/src/expression2/expression2_register_facets.cpp +++ b/src/expression2/expression2_register_facets.cpp @@ -9,6 +9,7 @@ #include #include +//#include #include #include @@ -16,15 +17,19 @@ #include #include +#include #include #include +//#include #include #include +//#include #include #include +#include #include #include @@ -32,6 +37,7 @@ #include #include +//#include #include #include @@ -60,9 +66,11 @@ namespace xo { // +- DefineExpr // +- ApplyExpr // +- LambdaExpr - // \- IfElseExpr + // +- IfElseExpr + // \- SequenceExpr FacetRegistry::register_impl(); + FacetRegistry::register_impl(); FacetRegistry::register_impl(); FacetRegistry::register_impl(); @@ -79,6 +87,7 @@ namespace xo { FacetRegistry::register_impl(); FacetRegistry::register_impl(); + FacetRegistry::register_impl(); FacetRegistry::register_impl(); FacetRegistry::register_impl(); diff --git a/src/expression2/expression2_register_types.cpp b/src/expression2/expression2_register_types.cpp index 2b8aadcf..b3dd21f8 100644 --- a/src/expression2/expression2_register_types.cpp +++ b/src/expression2/expression2_register_types.cpp @@ -5,11 +5,18 @@ #include "expression2_register_types.hpp" +#include "detail/IGCObject_DConstant.hpp" +#include "detail/IGCObject_DVariable.hpp" +//#include "detail/IGCObject_DDefineExpr.hpp" // when avail +//#include "detail/IGCObject_DApplyExpr.hpp" // when avail +//#include "detail/IGCObject_DLambdaExpr.hpp" // when avail +#include "detail/IGCObject_DIfElseExpr.hpp" +#include "detail/IGCObject_DSequenceExpr.hpp" +//#include "detail/IGCObject_DLocalSymtab.hpp" // when avail #include "detail/IGCObject_DUniqueString.hpp" -//#include "detail/IPrintable_DUniqueString.hpp" +//#include "detail/IPrintable_DUniqueString.hpp" // when avail -//#include #include namespace xo { @@ -27,6 +34,16 @@ namespace xo { bool ok = true; + ok &= gc.install_type(impl_for()); + ok &= gc.install_type(impl_for()); + //ok &= gc.install_type(impl_for()); // when avail + //ok &= gc.install_type(impl_for()); // when avail + //ok &= gc.install_type(impl_for()); // when avail + ok &= gc.install_type(impl_for()); + ok &= gc.install_type(impl_for()); + + //ok &= gc.install_type(impl_for()); // when avail + ok &= gc.install_type(impl_for()); return ok;