diff --git a/CMakeLists.txt b/CMakeLists.txt index 63ff9fad..ae1bb8c2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,6 +34,30 @@ xo_add_genfacet( # ---------------------------------------------------------------- +xo_add_genfacetimpl( + TARGET xo-expression2-facetimpl-symboltable-localsymtab + FACET_PKG xo_expression2 + FACET SymbolTable + REPR LocalSymtab + INPUT idl/ISymbolTable_DLocalSymtab.json5 + OUTPUT_HPP_DIR include/xo/expression2 + OUTPUT_IMPL_SUBDIR symtab + OUTPUT_CPP_DIR src/expression2 +) + +xo_add_genfacetimpl( + TARGET xo-expression2-facetimpl-printable-localsymtab + FACET_PKG xo_printable2 + FACET Printable + REPR LocalSymtab + INPUT idl/IPrintable_DLocalSymtab.json5 + OUTPUT_HPP_DIR include/xo/expression2 + OUTPUT_IMPL_SUBDIR symtab + OUTPUT_CPP_DIR src/expression2 +) + +# ---------------------------------------------------------------- + # note: manual target; generated code committed to git xo_add_genfacet( TARGET xo-expression2-facet-expression diff --git a/idl/IPrintable_DLocalSymtab.json5 b/idl/IPrintable_DLocalSymtab.json5 new file mode 100644 index 00000000..3f17e64e --- /dev/null +++ b/idl/IPrintable_DLocalSymtab.json5 @@ -0,0 +1,13 @@ +{ + mode: "implementation", + includes: [ "", + "" ], + local_types: [ ], + namespace1: "xo", + namespace2: "scm", + facet_idl: "idl/Printable.json5", + brief: "provide APrintable interface for DLocalSymtab", + using_doxygen: true, + repr: "DLocalSymtab", + doc: [ "implement APrintable for DLocalSymtab" ], +} diff --git a/idl/ISymbolTable_DLocalSymtab.json5 b/idl/ISymbolTable_DLocalSymtab.json5 new file mode 100644 index 00000000..026c0ed1 --- /dev/null +++ b/idl/ISymbolTable_DLocalSymtab.json5 @@ -0,0 +1,12 @@ +{ + mode: "implementation", + includes: [ ], + local_types: [ ], + namespace1: "xo", + namespace2: "scm", + facet_idl: "idl/SymbolTable.json5", + brief: "provide ASymbolTable interface for DLocalSymtab", + using_doxygen: true, + repr: "DLocalSymtab", + doc: [ "implement ASymbolTable for DLocalSymtab" ], +} diff --git a/include/xo/expression2/Binding.hpp b/include/xo/expression2/Binding.hpp index e97cc715..6dffb16b 100644 --- a/include/xo/expression2/Binding.hpp +++ b/include/xo/expression2/Binding.hpp @@ -25,6 +25,7 @@ namespace xo { static Binding local(int32_t j_slot) { return Binding(0, j_slot); } bool is_global() const { return i_link_ == s_link_global; } + bool is_local() const { return (i_link_ == 0) && (j_slot_ >= 0); } int32_t i_link() const noexcept { return i_link_; } int32_t j_slot() const noexcept { return j_slot_; } diff --git a/include/xo/expression2/DLocalSymtab.hpp b/include/xo/expression2/DLocalSymtab.hpp index 9eada176..01d9aa85 100644 --- a/include/xo/expression2/DLocalSymtab.hpp +++ b/include/xo/expression2/DLocalSymtab.hpp @@ -45,20 +45,23 @@ namespace xo { /** @defgroup scm-lambdaexpr-constructors **/ ///@{ - /** empty instance with capacity for n slots. + /** empty instance with parent @p p and capacity for @p n slots. * Caller must ensure that slots_[0..n) are actually addressable **/ - DLocalSymtab(size_type n); + DLocalSymtab(DLocalSymtab * p, size_type n); /** scaffold empty symtab instance, * with capacity for @p n slots, using memory from allocator @p mm **/ - static DLocalSymtab * _make_empty(obj mm, size_type n); + static DLocalSymtab * _make_empty(obj mm, + DLocalSymtab * p, + size_type n); ///@} /** @defgroup scm-lambdaexpr-methods **/ ///@{ + DLocalSymtab * parent() const noexcept { return parent_; } size_type capacity() const noexcept { return capacity_; } size_type size() const noexcept { return size_; } @@ -96,6 +99,8 @@ namespace xo { ///@} private: + /** parent symbol table from scoping surrounding this one **/ + DLocalSymtab * parent_ = nullptr; /** actual range of slots_[] array. Can use inices in [0,..,n) **/ size_type capacity_ = 0; /** number of slots in use **/ diff --git a/include/xo/expression2/detail/IExpression_DIfElseExpr.hpp b/include/xo/expression2/detail/IExpression_DIfElseExpr.hpp index 03500a39..7d726dde 100644 --- a/include/xo/expression2/detail/IExpression_DIfElseExpr.hpp +++ b/include/xo/expression2/detail/IExpression_DIfElseExpr.hpp @@ -2,7 +2,7 @@ * * Generated automagically from ingredients: * 1. code generator: - * [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet] + * [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet] * arguments: * --input [idl/IExpression_DIfElseExpr.json5] * 2. jinja2 template for abstract facet .hpp file: diff --git a/include/xo/expression2/detail/IGCObject_DVariable.hpp b/include/xo/expression2/detail/IGCObject_DVariable.hpp index aee612ea..24dc591f 100644 --- a/include/xo/expression2/detail/IGCObject_DVariable.hpp +++ b/include/xo/expression2/detail/IGCObject_DVariable.hpp @@ -2,7 +2,7 @@ * * Generated automagically from ingredients: * 1. code generator: - * [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet] + * [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet] * arguments: * --input [idl/IGCObject_DVariable.json5] * 2. jinja2 template for abstract facet .hpp file: diff --git a/include/xo/expression2/detail/IPrintable_DIfElseExpr.hpp b/include/xo/expression2/detail/IPrintable_DIfElseExpr.hpp index e9cf67ff..fcf80fd5 100644 --- a/include/xo/expression2/detail/IPrintable_DIfElseExpr.hpp +++ b/include/xo/expression2/detail/IPrintable_DIfElseExpr.hpp @@ -2,7 +2,7 @@ * * Generated automagically from ingredients: * 1. code generator: - * [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet] + * [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet] * arguments: * --input [idl/IPrintable_DIfElseExpr.json5] * 2. jinja2 template for abstract facet .hpp file: diff --git a/include/xo/expression2/symtab/IPrintable_DLocalSymtab.hpp b/include/xo/expression2/symtab/IPrintable_DLocalSymtab.hpp new file mode 100644 index 00000000..c013e937 --- /dev/null +++ b/include/xo/expression2/symtab/IPrintable_DLocalSymtab.hpp @@ -0,0 +1,62 @@ +/** @file IPrintable_DLocalSymtab.hpp + * + * Generated automagically from ingredients: + * 1. code generator: + * [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet] + * arguments: + * --input [idl/IPrintable_DLocalSymtab.json5] + * 2. jinja2 template for abstract facet .hpp file: + * [iface_facet_repr.hpp.j2] + * 3. idl for facet methods + * [idl/IPrintable_DLocalSymtab.json5] + **/ + +#pragma once + +#include "Printable.hpp" +#include +#include +#include "DLocalSymtab.hpp" + +namespace xo { namespace scm { class IPrintable_DLocalSymtab; } } + +namespace xo { + namespace facet { + template <> + struct FacetImplementation + { + using ImplType = xo::print::IPrintable_Xfer + ; + }; + } +} + +namespace xo { + namespace scm { + /** @class IPrintable_DLocalSymtab + **/ + class IPrintable_DLocalSymtab { + public: + /** @defgroup scm-printable-dlocalsymtab-type-traits **/ + ///@{ + using ppindentinfo = xo::print::APrintable::ppindentinfo; + using Copaque = xo::print::APrintable::Copaque; + using Opaque = xo::print::APrintable::Opaque; + ///@} + /** @defgroup scm-printable-dlocalsymtab-methods **/ + ///@{ + // const methods + /** Pretty-printing support for this object. +See [xo-indentlog/xo/indentlog/pretty.hpp] **/ + static bool pretty(const DLocalSymtab & self, const ppindentinfo & ppii); + + // non-const methods + ///@} + }; + + } /*namespace scm*/ +} /*namespace xo*/ + +/* end */ \ No newline at end of file diff --git a/include/xo/expression2/symtab/ISymbolTable_DLocalSymtab.hpp b/include/xo/expression2/symtab/ISymbolTable_DLocalSymtab.hpp new file mode 100644 index 00000000..72f409dd --- /dev/null +++ b/include/xo/expression2/symtab/ISymbolTable_DLocalSymtab.hpp @@ -0,0 +1,60 @@ +/** @file ISymbolTable_DLocalSymtab.hpp + * + * Generated automagically from ingredients: + * 1. code generator: + * [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet] + * arguments: + * --input [idl/ISymbolTable_DLocalSymtab.json5] + * 2. jinja2 template for abstract facet .hpp file: + * [iface_facet_repr.hpp.j2] + * 3. idl for facet methods + * [idl/ISymbolTable_DLocalSymtab.json5] + **/ + +#pragma once + +#include "SymbolTable.hpp" +#include "DLocalSymtab.hpp" + +namespace xo { namespace scm { class ISymbolTable_DLocalSymtab; } } + +namespace xo { + namespace facet { + template <> + struct FacetImplementation + { + using ImplType = xo::scm::ISymbolTable_Xfer + ; + }; + } +} + +namespace xo { + namespace scm { + /** @class ISymbolTable_DLocalSymtab + **/ + class ISymbolTable_DLocalSymtab { + public: + /** @defgroup scm-symboltable-dlocalsymtab-type-traits **/ + ///@{ + using Copaque = xo::scm::ASymbolTable::Copaque; + using Opaque = xo::scm::ASymbolTable::Opaque; + ///@} + /** @defgroup scm-symboltable-dlocalsymtab-methods **/ + ///@{ + // const methods + /** true iff this is toplevel (global) symbol table. **/ + static bool is_global_symtab(const DLocalSymtab & self) noexcept; + /** report ingredients needed to address variable at runtime. **/ + static Binding lookup_binding(const DLocalSymtab & self, const DUniqueString * sym) noexcept; + + // non-const methods + ///@} + }; + + } /*namespace scm*/ +} /*namespace xo*/ + +/* end */ \ No newline at end of file diff --git a/src/expression2/CMakeLists.txt b/src/expression2/CMakeLists.txt index 03bd8230..8e6565c4 100644 --- a/src/expression2/CMakeLists.txt +++ b/src/expression2/CMakeLists.txt @@ -39,6 +39,9 @@ set(SELF_SRCS ISymbolTable_Any.cpp + ISymbolTable_DLocalSymtab.cpp + IPrintable_DLocalSymtab.cpp + StringTable.cpp DUniqueString.cpp diff --git a/src/expression2/DLocalSymtab.cpp b/src/expression2/DLocalSymtab.cpp index c38096ff..85631d34 100644 --- a/src/expression2/DLocalSymtab.cpp +++ b/src/expression2/DLocalSymtab.cpp @@ -5,14 +5,21 @@ #include "DLocalSymtab.hpp" #include "DUniqueString.hpp" +#include +#include #include namespace xo { + using xo::print::APrintable; using xo::facet::typeseq; + using xo::print::ppstate; namespace scm { - DLocalSymtab::DLocalSymtab(size_type n) : capacity_{n}, size_{0} + DLocalSymtab::DLocalSymtab(DLocalSymtab * p, + size_type n) : parent_{p}, + capacity_{n}, + size_{0} { for (size_type i = 0; i < n; ++i) { void * mem = &slots_[i]; @@ -21,12 +28,14 @@ namespace xo { } DLocalSymtab * - DLocalSymtab::_make_empty(obj mm, size_type n) + DLocalSymtab::_make_empty(obj mm, + DLocalSymtab * p, + size_type n) { void * mem = mm.alloc(typeseq::id(), sizeof(DLocalSymtab) + (n * sizeof(Slot))); - return new (mem) DLocalSymtab(n); + return new (mem) DLocalSymtab(p, n); } Binding @@ -68,6 +77,53 @@ namespace xo { return Binding(); } + bool + DLocalSymtab::pretty(const ppindentinfo & ppii) const + { + ppstate * pps = ppii.pps(); + + if (ppii.upto()) { + /* perhaps print on one line */ + if (!pps->print_upto("print_upto(xrefrtag("size", size_))) + return false; + + for (size_type i = 0; i < size_; ++i) { + char buf[32]; + snprintf(buf, sizeof(buf), "[%u]", i); + + assert(slots_[i].var_); + + obj arg_pr(const_cast(slots_[i].var_)); + + if (!pps->print_upto(xrefrtag(buf, arg_pr))) + return false; + } + + pps->write(">"); + return true; + } else { + /* with line breaks */ + + pps->write("newline_pretty_tag(ppii.ci1(), "size", size_); + + for (size_type i = 0; i < size_; ++i) { + char buf[32]; + snprintf(buf, sizeof(buf), "[%u]", i); + + assert(slots_[i].var_); + + obj arg_pr(const_cast(slots_[i].var_)); + + pps->newline_pretty_tag(ppii.ci1(), buf, arg_pr); + } + + pps->write(">"); + return false; + } + } } /*namespace scm*/ } /*namespace xo*/ diff --git a/src/expression2/IExpression_DIfElseExpr.cpp b/src/expression2/IExpression_DIfElseExpr.cpp index 78680310..d913eaf0 100644 --- a/src/expression2/IExpression_DIfElseExpr.cpp +++ b/src/expression2/IExpression_DIfElseExpr.cpp @@ -2,7 +2,7 @@ * * Generated automagically from ingredients: * 1. code generator: - * [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet] + * [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet] * arguments: * --input [idl/IExpression_DIfElseExpr.json5] * 2. jinja2 template for abstract facet .hpp file: diff --git a/src/expression2/IGCObject_DVariable.cpp b/src/expression2/IGCObject_DVariable.cpp index 8735b286..4af0f906 100644 --- a/src/expression2/IGCObject_DVariable.cpp +++ b/src/expression2/IGCObject_DVariable.cpp @@ -2,7 +2,7 @@ * * Generated automagically from ingredients: * 1. code generator: - * [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet] + * [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet] * arguments: * --input [idl/IGCObject_DVariable.json5] * 2. jinja2 template for abstract facet .hpp file: diff --git a/src/expression2/IPrintable_DIfElseExpr.cpp b/src/expression2/IPrintable_DIfElseExpr.cpp index ec68b9fc..a75cd6a4 100644 --- a/src/expression2/IPrintable_DIfElseExpr.cpp +++ b/src/expression2/IPrintable_DIfElseExpr.cpp @@ -2,7 +2,7 @@ * * Generated automagically from ingredients: * 1. code generator: - * [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet] + * [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet] * arguments: * --input [idl/IPrintable_DIfElseExpr.json5] * 2. jinja2 template for abstract facet .hpp file: diff --git a/src/expression2/IPrintable_DLocalSymtab.cpp b/src/expression2/IPrintable_DLocalSymtab.cpp new file mode 100644 index 00000000..dbd4887b --- /dev/null +++ b/src/expression2/IPrintable_DLocalSymtab.cpp @@ -0,0 +1,28 @@ +/** @file IPrintable_DLocalSymtab.cpp + * + * Generated automagically from ingredients: + * 1. code generator: + * [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet] + * arguments: + * --input [idl/IPrintable_DLocalSymtab.json5] + * 2. jinja2 template for abstract facet .hpp file: + * [iface_facet_any.hpp.j2] + * 3. idl for facet methods + * [idl/IPrintable_DLocalSymtab.json5] +**/ + +#include "symtab/IPrintable_DLocalSymtab.hpp" + +namespace xo { + namespace scm { + auto + IPrintable_DLocalSymtab::pretty(const DLocalSymtab & self, const ppindentinfo & ppii) -> bool + { + return self.pretty(ppii); + } + + + } /*namespace scm*/ +} /*namespace xo*/ + +/* end IPrintable_DLocalSymtab.cpp */ \ No newline at end of file diff --git a/src/expression2/ISymbolTable_DLocalSymtab.cpp b/src/expression2/ISymbolTable_DLocalSymtab.cpp new file mode 100644 index 00000000..778cfdf4 --- /dev/null +++ b/src/expression2/ISymbolTable_DLocalSymtab.cpp @@ -0,0 +1,34 @@ +/** @file ISymbolTable_DLocalSymtab.cpp + * + * Generated automagically from ingredients: + * 1. code generator: + * [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet] + * arguments: + * --input [idl/ISymbolTable_DLocalSymtab.json5] + * 2. jinja2 template for abstract facet .hpp file: + * [iface_facet_any.hpp.j2] + * 3. idl for facet methods + * [idl/ISymbolTable_DLocalSymtab.json5] +**/ + +#include "symtab/ISymbolTable_DLocalSymtab.hpp" + +namespace xo { + namespace scm { + auto + ISymbolTable_DLocalSymtab::is_global_symtab(const DLocalSymtab & self) noexcept -> bool + { + return self.is_global_symtab(); + } + + auto + ISymbolTable_DLocalSymtab::lookup_binding(const DLocalSymtab & self, const DUniqueString * sym) noexcept -> Binding + { + return self.lookup_binding(sym); + } + + + } /*namespace scm*/ +} /*namespace xo*/ + +/* end ISymbolTable_DLocalSymtab.cpp */ \ No newline at end of file diff --git a/src/expression2/expression2_register_facets.cpp b/src/expression2/expression2_register_facets.cpp index a6bd50e5..06ccc7d5 100644 --- a/src/expression2/expression2_register_facets.cpp +++ b/src/expression2/expression2_register_facets.cpp @@ -27,6 +27,9 @@ #include #include +#include +#include + #include #include #include @@ -74,6 +77,9 @@ namespace xo { FacetRegistry::register_impl(); FacetRegistry::register_impl(); + FacetRegistry::register_impl(); + FacetRegistry::register_impl(); + log && log(xtag("DUniqueString.tseq", typeseq::id())); log && log(xtag("DDefineExpr.tseq", typeseq::id())); log && log(xtag("DVariable.tseq", typeseq::id())); @@ -82,7 +88,10 @@ namespace xo { log && log(xtag("DLambdaExpr.tseq", typeseq::id())); log && log(xtag("DIfElseExpr.tseq", typeseq::id())); + log && log(xtag("DLocalSymtab.tseq", typeseq::id())); + log && log(xtag("AExpression.tqseq", typeseq::id())); + log && log(xtag("ASymbolTable.tseq", typeseq::id())); return true; }