diff --git a/include/xo/expression2/DLambdaExpr.hpp b/include/xo/expression2/DLambdaExpr.hpp index 2a0cc2c3..b21a37ce 100644 --- a/include/xo/expression2/DLambdaExpr.hpp +++ b/include/xo/expression2/DLambdaExpr.hpp @@ -20,6 +20,7 @@ namespace xo { **/ class DLambdaExpr { public: + using ACollector = xo::mm::ACollector; using AAllocator = xo::mm::AAllocator; using TypeDescr = xo::reflect::TypeDescr; using ppindentinfo = xo::print::ppindentinfo; @@ -78,6 +79,14 @@ namespace xo { TypeDescr valuetype() const noexcept; void assign_valuetype(TypeDescr td) noexcept; + ///@} + /** @defgroup scm-lambdaexpr-gcobject-facet **/ + ///@{ + + std::size_t shallow_size() const noexcept; + DLambdaExpr * shallow_copy(obj mm) const noexcept; + std::size_t forward_children(obj gc) noexcept; + ///@} /** @defgroup scm-lambdaexpr-printable-facet **/ ///@{ @@ -95,7 +104,7 @@ namespace xo { /** name for this lambda (generated if necessary) **/ const DUniqueString * name_ = nullptr; -#ifdef NOT_YET +#ifdef NOT_YET // when enabled, need to visit forward_children() /** e.g. * i64(f64,string) * for function of two arguments with types (f64, string) respectively, diff --git a/include/xo/expression2/IfElseExpr.hpp b/include/xo/expression2/IfElseExpr.hpp new file mode 100644 index 00000000..901062b2 --- /dev/null +++ b/include/xo/expression2/IfElseExpr.hpp @@ -0,0 +1,13 @@ +/** @file IfElseExpr.hpp + * + * @author Roland Conybeare, Feb 2026 + **/ + +#pragma once + +#include "DIfElseExpr.hpp" +#include "detail/IExpression_DIfElseExpr.hpp" +#include "detail/IGCObject_DIfElseExpr.hpp" +#include "detail/IPrintable_DIfElseExpr.hpp" + +/* end IfElseExpr.hpp */ diff --git a/include/xo/expression2/UniqueString.hpp b/include/xo/expression2/UniqueString.hpp new file mode 100644 index 00000000..90cd1cd2 --- /dev/null +++ b/include/xo/expression2/UniqueString.hpp @@ -0,0 +1,12 @@ +/** @file UniqueString.hpp + * + * @author Roland Conybeare, Feb 2026 + **/ + +#pragma once + +#include "DUniqueString.hpp" +#include "detail/IGCObject_DUniqueString.hpp" +#include "detail/IPrintable_DUniqueString.hpp" + +/* end UniqueString.hpp */ diff --git a/src/expression2/CMakeLists.txt b/src/expression2/CMakeLists.txt index 45b5a06e..749910e4 100644 --- a/src/expression2/CMakeLists.txt +++ b/src/expression2/CMakeLists.txt @@ -10,15 +10,13 @@ set(SELF_SRCS DVariable.cpp DVarRef.cpp DDefineExpr.cpp - DLambdaExpr.cpp DApplyExpr.cpp - DIfElseExpr.cpp - DSequenceExpr.cpp TypeRef.cpp Binding.cpp IExpression_Any.cpp + ISymbolTable_Any.cpp IExpression_DConstant.cpp IGCObject_DConstant.cpp @@ -39,25 +37,28 @@ set(SELF_SRCS IGCObject_DApplyExpr.cpp IPrintable_DApplyExpr.cpp + DLambdaExpr.cpp IExpression_DLambdaExpr.cpp + IGCObject_DLambdaExpr.cpp IPrintable_DLambdaExpr.cpp + DIfElseExpr.cpp IExpression_DIfElseExpr.cpp IGCObject_DIfElseExpr.cpp IPrintable_DIfElseExpr.cpp + DSequenceExpr.cpp IExpression_DSequenceExpr.cpp IGCObject_DSequenceExpr.cpp IPrintable_DSequenceExpr.cpp DLocalSymtab.cpp - DGlobalSymtab.cpp - - ISymbolTable_Any.cpp - ISymbolTable_DLocalSymtab.cpp + IGCObject_DLocalSymtab.cpp IPrintable_DLocalSymtab.cpp + DGlobalSymtab.cpp + StringTable.cpp DUniqueString.cpp diff --git a/src/expression2/DIfElseExpr.cpp b/src/expression2/DIfElseExpr.cpp index 631be466..6a0b053c 100644 --- a/src/expression2/DIfElseExpr.cpp +++ b/src/expression2/DIfElseExpr.cpp @@ -80,32 +80,6 @@ namespace xo { typeref_.resolve(td); } - bool - DIfElseExpr::pretty(const ppindentinfo & ppii) const - { - auto test - = FacetRegistry::instance().try_variant(test_); - auto when_true - = FacetRegistry::instance().try_variant(when_true_); - auto when_false - = FacetRegistry::instance().try_variant(when_false_); - - bool test_present = test; - bool when_true_present = when_true; - bool when_false_present = when_false; - - return ppii.pps()->pretty_struct - (ppii, - "DIfElseExpr", - refrtag("typeref", typeref_), - refrtag("test", test, test_present), - refrtag("when_true", when_true, when_true_present), - refrtag("when_false", when_false, when_false_present)); - } - // GCObject facet std::size_t @@ -145,6 +119,34 @@ namespace xo { return shallow_size(); } + // ----- printable facet ----- + + bool + DIfElseExpr::pretty(const ppindentinfo & ppii) const + { + auto test + = FacetRegistry::instance().try_variant(test_); + auto when_true + = FacetRegistry::instance().try_variant(when_true_); + auto when_false + = FacetRegistry::instance().try_variant(when_false_); + + bool test_present = test; + bool when_true_present = when_true; + bool when_false_present = when_false; + + return ppii.pps()->pretty_struct + (ppii, + "DIfElseExpr", + refrtag("typeref", typeref_), + refrtag("test", test, test_present), + refrtag("when_true", when_true, when_true_present), + refrtag("when_false", when_false, when_false_present)); + } + // ---------------------------------------------------------------- #ifdef NOPE diff --git a/src/expression2/DLambdaExpr.cpp b/src/expression2/DLambdaExpr.cpp index 080e49b5..56d55c03 100644 --- a/src/expression2/DLambdaExpr.cpp +++ b/src/expression2/DLambdaExpr.cpp @@ -3,16 +3,16 @@ * @author Roland Conybeare, Jan 2026 **/ -#include "DLambdaExpr.hpp" -#include "detail/IExpression_DLambdaExpr.hpp" -#include "DLocalSymtab.hpp" -#include "symtab/IPrintable_DLocalSymtab.hpp" +#include "LambdaExpr.hpp" +#include "LocalSymtab.hpp" +#include "UniqueString.hpp" #include #include #include #include namespace xo { + using xo::mm::AGCObject; using xo::print::APrintable; using xo::facet::FacetRegistry; using xo::reflect::TypeDescr; @@ -134,6 +134,49 @@ namespace xo { typeref_.resolve(td); } + std::size_t + DLambdaExpr::shallow_size() const noexcept { + return sizeof(DLambdaExpr); + } + + DLambdaExpr * + DLambdaExpr::shallow_copy(obj mm) const noexcept { + DLambdaExpr * copy = (DLambdaExpr *)mm.alloc_copy((std::byte *)this); + + if (copy) { + *copy = *this; + } + + return copy; + } + + std::size_t + DLambdaExpr::forward_children(obj gc) noexcept { + { + auto iface = xo::facet::impl_for(); + gc.forward_inplace(&iface, (void **)(&name_)); + } + + // type_name_str_ + + { + auto iface = xo::facet::impl_for(); + gc.forward_inplace(&iface, (void **)(&local_symtab_)); + } + + { + auto iface = body_expr_.to_facet().iface(); + gc.forward_inplace(iface, (void **)(&body_expr_)); + } + + // xxx free_var_set + // xxx captured_var_set + // xxx layer_var_map + // xxx nested_lambda_map + + return shallow_size(); + } + bool DLambdaExpr::pretty(const ppindentinfo & ppii) const { diff --git a/src/expression2/DLocalSymtab.cpp b/src/expression2/DLocalSymtab.cpp index 85631d34..cf9c8459 100644 --- a/src/expression2/DLocalSymtab.cpp +++ b/src/expression2/DLocalSymtab.cpp @@ -3,13 +3,14 @@ * @author Roland Conybeare, Jan 2026 **/ -#include "DLocalSymtab.hpp" +#include "LocalSymtab.hpp" +#include "Variable.hpp" #include "DUniqueString.hpp" -#include #include #include namespace xo { + using xo::mm::AGCObject; using xo::print::APrintable; using xo::facet::typeseq; using xo::print::ppstate; @@ -77,6 +78,50 @@ namespace xo { return Binding(); } + // ----- gcobject facet ----- + + std::size_t + DLocalSymtab::shallow_size() const noexcept + { + return (sizeof(DLocalSymtab) + (capacity_ * sizeof(Slot))); + } + + DLocalSymtab * + DLocalSymtab::shallow_copy(obj mm) const noexcept + { + DLocalSymtab * copy = (DLocalSymtab *)mm.alloc_copy((std::byte *)this); + + if (copy) { + *copy = *this; + + ::memcpy((void*)&(copy->slots_[0]), + (void*)&(slots_[0]), + capacity_ * sizeof(Slot)); + } + + return copy; + } + + std::size_t + DLocalSymtab::forward_children(obj gc) noexcept + { + { + auto iface + = xo::facet::impl_for(); + gc.forward_inplace(&iface, (void **)(&parent_)); + } + + auto iface + = xo::facet::impl_for(); + for (size_type i = 0; i < size_; ++i) { + gc.forward_inplace(&iface, (void **)(&(slots_[i].var_))); + } + + return shallow_size(); + } + + // ----- printable facet ----- + bool DLocalSymtab::pretty(const ppindentinfo & ppii) const { diff --git a/src/expression2/expression2_register_facets.cpp b/src/expression2/expression2_register_facets.cpp index 67944a08..16bfac2a 100644 --- a/src/expression2/expression2_register_facets.cpp +++ b/src/expression2/expression2_register_facets.cpp @@ -17,28 +17,16 @@ #include #include - -#include -#include -#include - +#include #include - -#include -//#include -#include - -#include -#include -#include +#include +#include #include #include #include -#include -//#include -#include +#include #include #include @@ -70,6 +58,10 @@ namespace xo { // +- IfElseExpr // \- SequenceExpr + // SymbolTable + // +- LocalSymtab + // \- GlobalSymtab + FacetRegistry::register_impl(); FacetRegistry::register_impl(); FacetRegistry::register_impl(); @@ -91,7 +83,7 @@ namespace xo { FacetRegistry::register_impl(); FacetRegistry::register_impl(); - //FacetRegistry::register_impl(); + FacetRegistry::register_impl(); FacetRegistry::register_impl(); FacetRegistry::register_impl(); @@ -103,7 +95,7 @@ namespace xo { FacetRegistry::register_impl(); FacetRegistry::register_impl(); - //FacetRegistry::register_impl(); + FacetRegistry::register_impl(); FacetRegistry::register_impl(); log && log(xtag("DUniqueString.tseq", typeseq::id()));