From a6a0e8a8ea71ab3141956548c33a369ad6d07c11 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Sat, 17 Jan 2026 01:24:04 -0500 Subject: [PATCH] xo-expression2: + IExpression_DVariable --- xo-expression2/CMakeLists.txt | 12 ++++ xo-expression2/idl/Expression.json5 | 5 +- .../idl/IExpression_DConstant.json5 | 1 + .../idl/IExpression_DVariable.json5 | 12 ++++ .../include/xo/expression2/DLocalSymtab.hpp | 49 +++++++------- .../include/xo/expression2/Expression.hpp | 1 + .../xo/expression2/detail/AExpression.hpp | 6 +- .../xo/expression2/detail/IExpression_Any.hpp | 2 +- .../detail/IExpression_DVariable.hpp | 66 +++++++++++++++++++ .../xo/expression2/detail/RExpression.hpp | 10 ++- xo-expression2/src/expression2/CMakeLists.txt | 1 + .../src/expression2/IExpression_Any.cpp | 9 +++ .../src/expression2/IExpression_DVariable.cpp | 45 +++++++++++++ 13 files changed, 187 insertions(+), 32 deletions(-) create mode 100644 xo-expression2/idl/IExpression_DVariable.json5 create mode 100644 xo-expression2/include/xo/expression2/detail/IExpression_DVariable.hpp create mode 100644 xo-expression2/src/expression2/IExpression_DVariable.cpp diff --git a/xo-expression2/CMakeLists.txt b/xo-expression2/CMakeLists.txt index a0aad4e9..28982fba 100644 --- a/xo-expression2/CMakeLists.txt +++ b/xo-expression2/CMakeLists.txt @@ -54,6 +54,18 @@ xo_add_genfacetimpl( OUTPUT_CPP_DIR src/expression2 ) +# note: manual target; generated code committed to git +xo_add_genfacetimpl( + TARGET xo-expression2-facetimpl-expression-variable + FACET_PKG xo_expression2 + FACET Expression + REPR Variable + INPUT idl/IExpression_DVariable.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-gcobject-uniquestring diff --git a/xo-expression2/idl/Expression.json5 b/xo-expression2/idl/Expression.json5 index f156dffe..f2f7d44a 100644 --- a/xo-expression2/idl/Expression.json5 +++ b/xo-expression2/idl/Expression.json5 @@ -3,9 +3,12 @@ includes: [ "\"TypeRef.hpp\"", "\"exprtype.hpp\"", ""], - + // extra includes in Expression.hpp, if any + user_hpp_includes: [], namespace1: "xo", namespace2: "scm", + // text after includes, before AExpression + pretext: [ "// {pretext} here" ], facet: "Expression", detail_subdir: "detail", brief: "a schematika expression", diff --git a/xo-expression2/idl/IExpression_DConstant.json5 b/xo-expression2/idl/IExpression_DConstant.json5 index 89842432..d7628f81 100644 --- a/xo-expression2/idl/IExpression_DConstant.json5 +++ b/xo-expression2/idl/IExpression_DConstant.json5 @@ -1,6 +1,7 @@ { mode: "implementation", includes: [ "\"Expression.hpp\"" ], + local_types: [ ], namespace1: "xo", namespace2: "scm", facet_idl: "idl/Expression.json5", diff --git a/xo-expression2/idl/IExpression_DVariable.json5 b/xo-expression2/idl/IExpression_DVariable.json5 new file mode 100644 index 00000000..6e7993d3 --- /dev/null +++ b/xo-expression2/idl/IExpression_DVariable.json5 @@ -0,0 +1,12 @@ +{ + mode: "implementation", + includes: [ "\"Expression.hpp\"" ], + local_types: [ ], + namespace1: "xo", + namespace2: "scm", + facet_idl: "idl/Expression.json5", + brief: "provide AExpression interface for DVariable state", + using_doxygen: true, + repr: "DVariable", + doc: ["doc for IExpression+DVariable" ], +} diff --git a/xo-expression2/include/xo/expression2/DLocalSymtab.hpp b/xo-expression2/include/xo/expression2/DLocalSymtab.hpp index b8d583bf..b60b6570 100644 --- a/xo-expression2/include/xo/expression2/DLocalSymtab.hpp +++ b/xo-expression2/include/xo/expression2/DLocalSymtab.hpp @@ -5,48 +5,45 @@ #pragma once -#include "TypeRef.hpp" -#include "exprtype.hpp" -#include -#include +#include "Binding.hpp" +#include "DUniqueString.hpp" +//#include "exprtype.hpp" +//#include +//#include namespace xo { namespace scm { /** @class DLocalSymtab - * @brief Schematika expression respresenting a literal constant + * @brief symbol table for a local stack frame **/ struct DLocalSymtab { public: - using TaggedPtr = xo::reflect::TaggedPtr; - using TypeDescr = xo::reflect::TypeDescr; - using AGCObject = xo::mm::AGCObject; - using typeseq = xo::reflect::typeseq; +// using TaggedPtr = xo::reflect::TaggedPtr; +// using TypeDescr = xo::reflect::TypeDescr; +// using AGCObject = xo::mm::AGCObject; +// using typeseq = xo::reflect::typeseq; + + struct Slot { + // obj var_; + Binding binding_; + }; public: - explicit DLocalSymtab(obj value) noexcept; +// explicit DLocalSymtab(obj value) noexcept; - bool is_resolved() const noexcept { return typeref_.is_resolved(); } + /** @defgroup xo-expression2-symboltable-facet symboltable facet**/ + ///@{ - exprtype extype() const noexcept { return exprtype::constant; } - TypeDescr value_td() const noexcept { return typeref_.td(); } - TaggedPtr value_tp() const noexcept { return TaggedPtr(typeref_.td(), value_.data()); } + /** true for global symbol table **/ + bool is_global_symtab() const noexcept { return false; } - TypeRef typeref() const noexcept { return typeref_; } - TypeDescr valuetype() const noexcept { return typeref_.td(); } - obj value() const noexcept { return value_; } + /** lookup binding for variable @p sym **/ + Binding lookup_binding(const DUniqueString * sym) const noexcept; - void assign_valuetype(TypeDescr td) noexcept { typeref_.resolve(td); } + ///@} private: - static TypeDescr _lookup_td(typeseq tseq); - private: - /** type for value of this expression - * or unification breadcrumb before unification - **/ - TypeRef typeref_; - /** literal value **/ - obj value_; }; } /*namespace scm*/ } /*namespace xo*/ diff --git a/xo-expression2/include/xo/expression2/Expression.hpp b/xo-expression2/include/xo/expression2/Expression.hpp index c6960c07..60e8a402 100644 --- a/xo-expression2/include/xo/expression2/Expression.hpp +++ b/xo-expression2/include/xo/expression2/Expression.hpp @@ -18,4 +18,5 @@ #include "detail/IExpression_Xfer.hpp" #include "detail/RExpression.hpp" + /* end Expression.hpp */ \ No newline at end of file diff --git a/xo-expression2/include/xo/expression2/detail/AExpression.hpp b/xo-expression2/include/xo/expression2/detail/AExpression.hpp index 18b7823f..10375114 100644 --- a/xo-expression2/include/xo/expression2/detail/AExpression.hpp +++ b/xo-expression2/include/xo/expression2/detail/AExpression.hpp @@ -21,6 +21,8 @@ #include #include +// {pretext} here + namespace xo { namespace scm { @@ -37,6 +39,8 @@ public: // types /** integer identifying a type **/ using typeseq = xo::facet::typeseq; + using Copaque = const void *; + using Opaque = void *; /** struct describing a type **/ using TypeDescr = xo::reflect::TypeDescr; ///@} @@ -75,4 +79,4 @@ using IExpression_ImplType = xo::facet::FacetImplType; } /*namespace scm*/ } /*namespace xo*/ -/* */ +/* AExpression.hpp */ \ No newline at end of file diff --git a/xo-expression2/include/xo/expression2/detail/IExpression_Any.hpp b/xo-expression2/include/xo/expression2/detail/IExpression_Any.hpp index e76cc3a6..c92c2c4a 100644 --- a/xo-expression2/include/xo/expression2/detail/IExpression_Any.hpp +++ b/xo-expression2/include/xo/expression2/detail/IExpression_Any.hpp @@ -61,7 +61,7 @@ namespace scm { [[noreturn]] TypeDescr valuetype(Copaque) const noexcept override { _fatal(); } // nonconst methods - [[noreturn]] void assign_valuetype(Opaque, TypeDescr) noexcept override { _fatal(); } + [[noreturn]] void assign_valuetype(Opaque, TypeDescr) noexcept override; ///@} diff --git a/xo-expression2/include/xo/expression2/detail/IExpression_DVariable.hpp b/xo-expression2/include/xo/expression2/detail/IExpression_DVariable.hpp new file mode 100644 index 00000000..95b1becb --- /dev/null +++ b/xo-expression2/include/xo/expression2/detail/IExpression_DVariable.hpp @@ -0,0 +1,66 @@ +/** @file IExpression_DVariable.hpp + * + * Generated automagically from ingredients: + * 1. code generator: + * [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet] + * arguments: + * --input [idl/IExpression_DVariable.json5] + * 2. jinja2 template for abstract facet .hpp file: + * [iface_facet_repr.hpp.j2] + * 3. idl for facet methods + * [idl/IExpression_DVariable.json5] + **/ + +#pragma once + +#include "Expression.hpp" +#include "Expression.hpp" +#include "DVariable.hpp" + +namespace xo { namespace scm { class IExpression_DVariable; } } + +namespace xo { + namespace facet { + template <> + struct FacetImplementation + { + using ImplType = xo::scm::IExpression_Xfer + ; + }; + } +} + +namespace xo { + namespace scm { + /** @class IExpression_DVariable + **/ + class IExpression_DVariable { + public: + /** @defgroup scm-expression-dvariable-type-traits **/ + ///@{ + using TypeDescr = xo::scm::AExpression::TypeDescr; + using Copaque = xo::scm::AExpression::Copaque; + using Opaque = xo::scm::AExpression::Opaque; + ///@} + /** @defgroup scm-expression-dvariable-methods **/ + ///@{ + // const methods + /** expression type (constant | apply | ..) **/ + static exprtype extype(const DVariable & self) noexcept; + /** placeholder for type giving possible values for this expression **/ + static TypeRef typeref(const DVariable & self) noexcept; + /** type giving possible values for this expression. Maybe null before typecheck **/ + static TypeDescr valuetype(const DVariable & self) noexcept; + + // non-const methods + /** assing to valuetype member. Useful when scaffolding expressions **/ + static void assign_valuetype(DVariable & self, TypeDescr td) noexcept; + ///@} + }; + + } /*namespace scm*/ +} /*namespace xo*/ + +/* end */ \ No newline at end of file diff --git a/xo-expression2/include/xo/expression2/detail/RExpression.hpp b/xo-expression2/include/xo/expression2/detail/RExpression.hpp index 9afd711f..caf69fe0 100644 --- a/xo-expression2/include/xo/expression2/detail/RExpression.hpp +++ b/xo-expression2/include/xo/expression2/detail/RExpression.hpp @@ -38,6 +38,9 @@ public: ///@{ RExpression() {} RExpression(Object::DataPtr data) : Object{std::move(data)} {} + RExpression(const AExpression * iface, void * data) + requires std::is_same_v + : Object(iface, data) {} ///@} /** @defgroup scm-expression-router-methods **/ @@ -55,9 +58,10 @@ public: return O::iface()->valuetype(O::data()); } - // non-const methods - // << do something for non-const methods >> - // + // non-const methods (still const in router!) + void assign_valuetype(TypeDescr td) noexcept { + return O::iface()->assign_valuetype(O::data(), td); + } ///@} /** @defgroup scm-expression-member-vars **/ diff --git a/xo-expression2/src/expression2/CMakeLists.txt b/xo-expression2/src/expression2/CMakeLists.txt index e7de9253..9194bfa5 100644 --- a/xo-expression2/src/expression2/CMakeLists.txt +++ b/xo-expression2/src/expression2/CMakeLists.txt @@ -11,6 +11,7 @@ set(SELF_SRCS IExpression_Any.cpp IExpression_DConstant.cpp + IExpression_DVariable.cpp ISymbolTable_Any.cpp diff --git a/xo-expression2/src/expression2/IExpression_Any.cpp b/xo-expression2/src/expression2/IExpression_Any.cpp index a27a68bc..7f60e5af 100644 --- a/xo-expression2/src/expression2/IExpression_Any.cpp +++ b/xo-expression2/src/expression2/IExpression_Any.cpp @@ -32,6 +32,15 @@ bool IExpression_Any::_valid = valid_facet_implementation(); +// nonconst methods + +auto +IExpression_Any::assign_valuetype(Opaque, TypeDescr) noexcept -> void +{ + _fatal(); +} + + } /*namespace scm*/ } /*namespace xo*/ diff --git a/xo-expression2/src/expression2/IExpression_DVariable.cpp b/xo-expression2/src/expression2/IExpression_DVariable.cpp new file mode 100644 index 00000000..ca657c36 --- /dev/null +++ b/xo-expression2/src/expression2/IExpression_DVariable.cpp @@ -0,0 +1,45 @@ +/** @file IExpression_DVariable.cpp + * + * Generated automagically from ingredients: + * 1. code generator: + * [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet] + * arguments: + * --input [idl/IExpression_DVariable.json5] + * 2. jinja2 template for abstract facet .hpp file: + * [iface_facet_any.hpp.j2] + * 3. idl for facet methods + * [idl/IExpression_DVariable.json5] +**/ + +#include "detail/IExpression_DVariable.hpp" + +namespace xo { + namespace scm { + auto + IExpression_DVariable::extype(const DVariable & self) noexcept -> exprtype + { + return self.extype(); + } + + auto + IExpression_DVariable::typeref(const DVariable & self) noexcept -> TypeRef + { + return self.typeref(); + } + + auto + IExpression_DVariable::valuetype(const DVariable & self) noexcept -> TypeDescr + { + return self.valuetype(); + } + + auto + IExpression_DVariable::assign_valuetype(DVariable & self, TypeDescr td) noexcept -> void + { + self.assign_valuetype(td); + } + + } /*namespace scm*/ +} /*namespace xo*/ + +/* end IExpression_DVariable.cpp */ \ No newline at end of file