From 5a141e09acfe0e72668d4a37e948bb996ff4e3a1 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Wed, 11 Mar 2026 07:49:14 -0500 Subject: [PATCH] xo-reader2 stack: expand symbol table to store typedefs + typedef utest + misc qol policy choices --- CMakeLists.txt | 44 ++++-- cmake/xo_expression2Config.cmake.in | 1 + idl/IGCObject_DTypename.json5 | 18 +++ idl/IPrintable_DTypename.json5 | 16 ++ include/xo/expression2/DGlobalSymtab.hpp | 46 ++++-- include/xo/expression2/DLambdaExpr.hpp | 2 +- include/xo/expression2/DLocalSymtab.hpp | 55 ++++--- include/xo/expression2/DSequenceExpr.hpp | 4 +- include/xo/expression2/DTypename.hpp | 77 +++++++++ include/xo/expression2/DVariable.hpp | 2 +- include/xo/expression2/TypeRef.hpp | 25 ++- include/xo/expression2/Typename.hpp | 12 ++ .../typename/IGCObject_DTypename.hpp | 65 ++++++++ .../typename/IPrintable_DTypename.hpp | 62 ++++++++ src/expression2/CMakeLists.txt | 5 + src/expression2/DApplyExpr.cpp | 7 + src/expression2/DConstant.cpp | 5 +- src/expression2/DGlobalSymtab.cpp | 120 +++++++++++--- src/expression2/DIfElseExpr.cpp | 8 +- src/expression2/DLambdaExpr.cpp | 10 +- src/expression2/DLocalSymtab.cpp | 146 +++++++++++------- src/expression2/DSequenceExpr.cpp | 18 ++- src/expression2/DTypename.cpp | 89 +++++++++++ src/expression2/DVariable.cpp | 7 +- src/expression2/IGCObject_DTypename.cpp | 39 +++++ src/expression2/IPrintable_DTypename.cpp | 28 ++++ src/expression2/TypeRef.cpp | 44 ++++++ .../expression2_register_facets.cpp | 14 +- .../expression2_register_types.cpp | 22 +-- 29 files changed, 841 insertions(+), 150 deletions(-) create mode 100644 idl/IGCObject_DTypename.json5 create mode 100644 idl/IPrintable_DTypename.json5 create mode 100644 include/xo/expression2/DTypename.hpp create mode 100644 include/xo/expression2/Typename.hpp create mode 100644 include/xo/expression2/typename/IGCObject_DTypename.hpp create mode 100644 include/xo/expression2/typename/IPrintable_DTypename.hpp create mode 100644 src/expression2/DTypename.cpp create mode 100644 src/expression2/IGCObject_DTypename.cpp create mode 100644 src/expression2/IPrintable_DTypename.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 92652b90..1af09c58 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,7 +47,7 @@ xo_add_genfacetimpl( # note: manual target; generated code committed to git xo_add_genfacetimpl( TARGET xo-expression2-facetimpl-gcobject-localsymtab - FACET_PKG xo_gc + FACET_PKG xo_alloc2 FACET GCObject REPR LocalSymtab INPUT idl/IGCObject_DLocalSymtab.json5 @@ -82,7 +82,7 @@ xo_add_genfacetimpl( # note: manual target; generated code committed to git xo_add_genfacetimpl( TARGET xo-expression2-facetimpl-gcobject-globalsymtab - FACET_PKG xo_gc + FACET_PKG xo_alloc2 FACET GCObject REPR GlobalSymtab INPUT idl/IGCObject_DGlobalSymtab.json5 @@ -128,7 +128,7 @@ xo_add_genfacetimpl( # note: manual target; generated code committed to git xo_add_genfacetimpl( TARGET xo-expression2-facetimpl-gcobject-constant - FACET_PKG xo_gc + FACET_PKG xo_alloc2 FACET GCObject REPR Constant INPUT idl/IGCObject_DConstant.json5 @@ -163,7 +163,7 @@ xo_add_genfacetimpl( # note: manual target; generated code committed to git xo_add_genfacetimpl( TARGET xo-expression2-facetimpl-gcobject-variable - FACET_PKG xo_gc + FACET_PKG xo_alloc2 FACET GCObject REPR Variable INPUT idl/IGCObject_DVariable.json5 @@ -184,6 +184,30 @@ xo_add_genfacetimpl( # ---------------------------------------------------------------- +# note: manual target; generated code committed to git +xo_add_genfacetimpl( + TARGET xo-expression2-facetimpl-gcobject-typename + FACET_PKG xo_alloc2 + FACET GCObject + REPR Typename + INPUT idl/IGCObject_DTypename.json5 + OUTPUT_HPP_DIR include/xo/expression2 + OUTPUT_IMPL_SUBDIR typename +) + +# note: manual target; generated code committed to git +xo_add_genfacetimpl( + TARGET xo-expression2-facetimpl-printable-typename + FACET_PKG xo_printable2 + FACET Printable + REPR Typename + INPUT idl/IPrintable_DTypename.json5 + OUTPUT_HPP_DIR include/xo/expression2 + OUTPUT_IMPL_SUBDIR typename +) + +# ---------------------------------------------------------------- + # note: manual target; generated code committed to git xo_add_genfacetimpl( TARGET xo-expression2-facetimpl-expression-varref @@ -198,7 +222,7 @@ xo_add_genfacetimpl( # note: manual target; generated code committed to git xo_add_genfacetimpl( TARGET xo-expression2-facetimpl-gcobject-varref - FACET_PKG xo_gc + FACET_PKG xo_alloc2 FACET GCObject REPR VarRef INPUT idl/IGCObject_DVarRef.json5 @@ -233,7 +257,7 @@ xo_add_genfacetimpl( # note: manual target; generated code committed to git xo_add_genfacetimpl( TARGET xo-expression2-facetimpl-gcobject-defineexpr - FACET_PKG xo_gc + FACET_PKG xo_alloc2 FACET GCObject REPR DefineExpr INPUT idl/IGCObject_DDefineExpr.json5 @@ -268,7 +292,7 @@ xo_add_genfacetimpl( # note: manual target; generated code committed to git xo_add_genfacetimpl( TARGET xo-expression2-facetimpl-gcobject-applyexpr - FACET_PKG xo_gc + FACET_PKG xo_alloc2 FACET GCObject REPR ApplyExpr INPUT idl/IGCObject_DApplyExpr.json5 @@ -303,7 +327,7 @@ xo_add_genfacetimpl( # note: manual target; generated code committed to git xo_add_genfacetimpl( TARGET xo-expression2-facetimpl-gcobject-lambdaexpr - FACET_PKG xo_gc + FACET_PKG xo_alloc2 FACET GCObject REPR LambdaExpr INPUT idl/IGCObject_DLambdaExpr.json5 @@ -338,7 +362,7 @@ xo_add_genfacetimpl( # note: manual target; generated code committed to git xo_add_genfacetimpl( TARGET xo-expression2-facetimpl-gcobject-ifelseexpr - FACET_PKG xo_gc + FACET_PKG xo_alloc2 FACET GCObject REPR IfElseExpr INPUT idl/IGCObject_DIfElseExpr.json5 @@ -373,7 +397,7 @@ xo_add_genfacetimpl( # note: manual target; generated code committed to git xo_add_genfacetimpl( TARGET xo-expression2-facetimpl-gcobject-sequenceexpr - FACET_PKG xo_gc + FACET_PKG xo_alloc2 FACET GCObject REPR SequenceExpr INPUT idl/IGCObject_DSequenceExpr.json5 diff --git a/cmake/xo_expression2Config.cmake.in b/cmake/xo_expression2Config.cmake.in index ca2e2ccb..c237d261 100644 --- a/cmake/xo_expression2Config.cmake.in +++ b/cmake/xo_expression2Config.cmake.in @@ -6,6 +6,7 @@ include(CMakeFindDependencyMacro) # must coordinate with xo_dependency() calls # in CMakeLists.txt # +find_dependency(xo_type) find_dependency(xo_gc) find_dependency(reflect) find_dependency(xo_procedure2) diff --git a/idl/IGCObject_DTypename.json5 b/idl/IGCObject_DTypename.json5 new file mode 100644 index 00000000..ae99ef9a --- /dev/null +++ b/idl/IGCObject_DTypename.json5 @@ -0,0 +1,18 @@ +{ + mode: "implementation", + output_cpp_dir: "src/expression2", + output_hpp_dir: "include/xo/expression2", + output_impl_subdir: "typename", + includes: [ +// "", +// "" + ], + local_types: [ ], + namespace1: "xo", + namespace2: "scm", + facet_idl: "idl/GCObject.json5", + brief: "provide AGCObject interface for DTypename", + using_doxygen: true, + repr: "DTypename", + doc: [ "implement AGCObject for DTypename" ], +} diff --git a/idl/IPrintable_DTypename.json5 b/idl/IPrintable_DTypename.json5 new file mode 100644 index 00000000..d11d8993 --- /dev/null +++ b/idl/IPrintable_DTypename.json5 @@ -0,0 +1,16 @@ +{ + mode: "implementation", + output_cpp_dir: "src/expression2", + output_hpp_dir: "include/xo/expression2", + output_impl_subdir: "typename", + includes: [ "", + "" ], + local_types: [ ], + namespace1: "xo", + namespace2: "scm", + facet_idl: "idl/Printable.json5", + brief: "provide APrintable interface for DTypename", + using_doxygen: true, + repr: "DTypename", + doc: [ "implement APrintable for DTypename" ], +} diff --git a/include/xo/expression2/DGlobalSymtab.hpp b/include/xo/expression2/DGlobalSymtab.hpp index 5cd03fb2..5fe1edb3 100644 --- a/include/xo/expression2/DGlobalSymtab.hpp +++ b/include/xo/expression2/DGlobalSymtab.hpp @@ -7,6 +7,7 @@ #include "Binding.hpp" #include "DVariable.hpp" +#include "DTypename.hpp" #include #include #include @@ -38,16 +39,18 @@ namespace xo { /** @defgroup scm-globalsymtab-ctors constructors **/ ///@{ - DGlobalSymtab(dp map, DArray * vars); + DGlobalSymtab(dp var_map, DArray * vars, + dp type_map, DArray * types); /** create instance. * Use memory from @p fixed_mm for @ref map_. * Use memory from @p mm for DGlobalSymtab instance. - * Hashmap configured per @p cfg. + * Hashmap for variables per @p var_cfg; for types per @p type_cfg. **/ static dp make(obj mm, obj fixed_mm, - const ArenaHashMapConfig & cfg); + const ArenaHashMapConfig & var_cfg, + const ArenaHashMapConfig & type_cfg); /** non-trivial destructor for @ref map_ **/ ~DGlobalSymtab() = default; @@ -56,8 +59,8 @@ namespace xo { /** @defgroup scm-globalsymtab-access-methods access methods **/ ///@{ - size_type size() const noexcept { return map_->size(); } - size_type capacity() const noexcept { return map_->capacity(); } + size_type n_vars() const noexcept { return var_map_->size(); } + size_type var_capacity() const noexcept { return var_map_->capacity(); } /** visit symtab-owned memory pools; call visitor(info) for each **/ void visit_pools(const MemorySizeVisitor & visitor) const; @@ -65,6 +68,9 @@ namespace xo { /** lookup global symbol with name @p sym **/ DVariable * lookup_variable(const DUniqueString * sym) const noexcept; + /** lookup global typename with name @p sym **/ + DTypename * lookup_typename(const DUniqueString * sym) const noexcept; + ///@} /** @defgroup scm-globalsymtab-general-methods general methods **/ ///@{ @@ -76,6 +82,13 @@ namespace xo { void upsert_variable(obj mm, DVariable * var); + /** update this symtab to associate typename @p type with @c type->name(). + * If there was a previous type with the same name, replace it with + * @p type. + **/ + void upsert_typename(obj mm, + DTypename * type); + ///@} /** @defgroup scm-globalsymtab-symboltable-facet symboltable facet **/ ///@{ @@ -104,20 +117,31 @@ namespace xo { ///@} private: - /** map symbols -> bindings. - * Minor point: storing offsets instead of Variables allows us to omit - * iterating over map elements during GC. Possible savings if map_ slots - * sparsely populated. + /** map variable symbol -> index into @ref vars_. + * Minor point: storing offsets instead of Variables allows us to: + * omit hash-map iteration during GC. + * Savings when map_ slots sparsely populated. **/ - dp map_; + dp var_map_; /** array of variables. * When S is a unique-string for a global symbol, then: - * 1. map_[S] is unique global index i(S) for S. + * 1. var_map_[S] is unique global index i(S) for S. * 2. vars_[i(S)] is variable-expr var(S) for S * 3. var(S)->name == S **/ DArray * vars_ = nullptr; + + /** map type name -> index values into @ref types_ **/ + dp type_map_; + + /** array of types. + * When T is a unique-string for a globally-defined type, then: + * 1. type_map_[T] is unique global index i(T) for T. + * 2. types_[i(T)] is type type(T) for T + * 3. type(T)->name == T + **/ + DArray * types_ = nullptr; }; } /*namespace scm*/ diff --git a/include/xo/expression2/DLambdaExpr.hpp b/include/xo/expression2/DLambdaExpr.hpp index 30ed2b74..a7de8044 100644 --- a/include/xo/expression2/DLambdaExpr.hpp +++ b/include/xo/expression2/DLambdaExpr.hpp @@ -62,7 +62,7 @@ namespace xo { ///@{ DLocalSymtab * local_symtab() const noexcept { return local_symtab_; } - size_type n_args() const noexcept { return local_symtab_->size(); } + size_type n_args() const noexcept { return local_symtab_->n_vars(); } obj body_expr() const noexcept { return body_expr_; } // get_free_variables() diff --git a/include/xo/expression2/DLocalSymtab.hpp b/include/xo/expression2/DLocalSymtab.hpp index f4073226..6e459035 100644 --- a/include/xo/expression2/DLocalSymtab.hpp +++ b/include/xo/expression2/DLocalSymtab.hpp @@ -8,9 +8,7 @@ #include "Binding.hpp" #include "DVariable.hpp" #include "DUniqueString.hpp" -//#include "exprtype.hpp" -//#include -//#include +#include namespace xo { namespace scm { @@ -19,14 +17,11 @@ namespace xo { **/ struct DLocalSymtab { public: -// using TaggedPtr = xo::reflect::TaggedPtr; -// using TypeDescr = xo::reflect::TypeDescr; -// using AGCObject = xo::mm::AGCObject; -// using typeseq = xo::reflect::typeseq; - + using DArray = xo::scm::DArray; using ppindentinfo = xo::print::ppindentinfo; using ACollector = xo::mm::ACollector; using AAllocator = xo::mm::AAllocator; + using AGCObject = xo::mm::AGCObject; /* note: uint16_t would be fine too */ using size_type = std::uint32_t; @@ -46,32 +41,31 @@ namespace xo { /** @defgroup scm-lambdaexpr-constructors **/ ///@{ - /** empty instance with parent @p p and capacity for @p n slots. - * Caller must ensure that slots_[0..n) are actually addressable + /** empty instance with parent @p p, using arrays @p vars for variables + * and @p types for type definitions. **/ - DLocalSymtab(DLocalSymtab * p, size_type n); + DLocalSymtab(DLocalSymtab * p, DArray * nv, DArray * nt); /** scaffold empty symtab instance, - * with capacity for @p n slots, using memory from allocator @p mm + * capacity for @p nv vars and @p nt types, + * using memory from allocator @p mm. + * Symtab chains to parent @p p. **/ static DLocalSymtab * _make_empty(obj mm, DLocalSymtab * p, - size_type n); + size_type nv, + size_type nt); ///@} /** @defgroup scm-lambdaexpr-methods **/ ///@{ DLocalSymtab * parent() const noexcept { return parent_; } - size_type capacity() const noexcept { return capacity_; } - size_type size() const noexcept { return size_; } + //size_type capacity() const noexcept { return capacity_; } + size_type n_vars() const noexcept { return vars_->size(); } + size_type n_types() const noexcept { return types_->size(); } - DVariable * lookup_var(Binding ix) noexcept { - assert(ix.i_link() == 0); - assert(ix.j_slot() < static_cast(size_)); - - return slots_[ix.j_slot()].var_; - } + DVariable * lookup_var(Binding ix) noexcept; /** increase slot size (provided below capacity) to append * binding for one local variable. Local variable will be allocated @@ -81,6 +75,14 @@ namespace xo { const DUniqueString * name, TypeRef typeref); + /** increase slot size (provided below capacity) to append + * binding for one local type. Local type will be allocated + * from @p mm, named @p name, with type described by @p type. + **/ + void append_type(obj mm, + const DUniqueString * name, + obj type); + ///@} /** @defgroup xo-localsymtab-symboltable-facet symboltable facet**/ ///@{ @@ -110,12 +112,23 @@ namespace xo { private: /** parent symbol table from scoping surrounding this one **/ DLocalSymtab * parent_ = nullptr; + /** variables owned by (declared in) this symbol table + * vars_[i] is convertible to obj + **/ + DArray * vars_ = nullptr; + /** types owned by (defined in) this symbol table + * types_[i] is convertible to obj + **/ + DArray * types_ = nullptr; + +#ifdef OBSOLETE /** actual range of slots_[] array. Can use indices in [0,..,n) **/ size_type capacity_ = 0; /** number of slots in use **/ size_type size_ = 0; /** memory for names and bindings **/ Slot slots_[]; +#endif }; } /*namespace scm*/ } /*namespace xo*/ diff --git a/include/xo/expression2/DSequenceExpr.hpp b/include/xo/expression2/DSequenceExpr.hpp index c5bb6f16..39fa79d0 100644 --- a/include/xo/expression2/DSequenceExpr.hpp +++ b/include/xo/expression2/DSequenceExpr.hpp @@ -29,8 +29,8 @@ namespace xo { using ppindentinfo = xo::print::ppindentinfo; public: - DSequenceExpr() = default; - DSequenceExpr(DArray * xv) : expr_v_{xv} {} + DSequenceExpr() ; + DSequenceExpr(DArray * xv); /** create empty sequence using memory from @p mm **/ static obj make_empty(obj mm); diff --git a/include/xo/expression2/DTypename.hpp b/include/xo/expression2/DTypename.hpp new file mode 100644 index 00000000..1d9d0629 --- /dev/null +++ b/include/xo/expression2/DTypename.hpp @@ -0,0 +1,77 @@ +/** @file DTypename.hpp + * + * @author Roland Conybeare, Mar 2026 + **/ + +#pragma once + +#include "DUniqueString.hpp" +#include +#include +#include + +namespace xo { + namespace scm { + + /** @class DTypename + * @brief Container for a named type + * + * Represents the result of syntax like + * 1. deftype Foo :: i64; + * 2. deftype FooAlias :: Foo; + **/ + class DTypename { + public: + using ppindentinfo = xo::print::ppindentinfo; + using ACollector = xo::mm::ACollector; + using AAllocator = xo::mm::AAllocator; + using AGCObject = xo::mm::AGCObject; + + public: + DTypename(const DUniqueString * name, + obj type); + + /** create instance + * @p mm memory allocator + * @p name type name + * @p type type definition + **/ + static DTypename * _make(obj mm, + const DUniqueString * name, + obj type); + /** create fop for new instance **/ + static obj make(obj mm, + const DUniqueString * name, + obj type); + + const DUniqueString * name() const noexcept { return name_; } + obj type() const noexcept { return type_; } + + void assign_name(const DUniqueString * name) { this->name_ = name; } + + + /** @defgroup scm-typename-gcobject-facet **/ + ///@{ + + size_t shallow_size() const noexcept; + DTypename * shallow_copy(obj mm) const noexcept; + size_t forward_children(obj gc) noexcept; + + ///@} + /** @defgroup scm-typename-printable-facet **/ + ///@{ + + bool pretty(const ppindentinfo & ppii) const; + + ///@} + + private: + /** symbol name **/ + const DUniqueString * name_ = nullptr; + /** type defintion. Everything but the name **/ + obj type_; + }; + } /*namespace scm*/ +} /*namespace xo*/ + +/* end DTypename.hpp */ diff --git a/include/xo/expression2/DVariable.hpp b/include/xo/expression2/DVariable.hpp index 29253097..329cf088 100644 --- a/include/xo/expression2/DVariable.hpp +++ b/include/xo/expression2/DVariable.hpp @@ -76,7 +76,7 @@ namespace xo { private: /** symbol name **/ - const DUniqueString * name_; + const DUniqueString * name_ = nullptr; /** variable value always has type consistent * with this description **/ diff --git a/include/xo/expression2/TypeRef.hpp b/include/xo/expression2/TypeRef.hpp index eecb438d..1342b4df 100644 --- a/include/xo/expression2/TypeRef.hpp +++ b/include/xo/expression2/TypeRef.hpp @@ -5,7 +5,9 @@ #pragma once +#include #include +#include #include #include @@ -23,17 +25,28 @@ namespace xo { using TypeDescr = xo::reflect::TypeDescr; using type_var = flatstring<20>; using prefix_type = flatstring<8>; + using ACollector = xo::mm::ACollector; using ppindentinfo = xo::print::ppindentinfo; public: TypeRef() = default; - TypeRef(const type_var & id, TypeDescr td); + TypeRef(const type_var & id, obj type); /** trivial typeref, where already resolved. * Require: @p td non-null **/ static TypeRef resolved(TypeDescr td); + /** trivial typeref, where already resolved **/ + static TypeRef resolved(obj type); + + /** if @p type is non-null + * -> type already resolved + * else + * -> generate unique typevar name, starting with @p prefix + **/ + static TypeRef dwim(prefix_type prefix, obj type); + /** if @p td is non-null * -> type is already resolved * @@ -59,9 +72,19 @@ namespace xo { /** pretty-printer support **/ bool pretty(const ppindentinfo & ppii) const; + /** gc support **/ + void forward_children(obj gc) noexcept; + + private: + TypeRef(const type_var & id, TypeDescr td); + private: /** unique (probably generated) name for type at this location **/ type_var id_; + + /** Type, when resolved **/ + obj type_; + /** Description for concrete type, once resolved. * May be null when this TypeRef created, * but expected to be immutable once established. diff --git a/include/xo/expression2/Typename.hpp b/include/xo/expression2/Typename.hpp new file mode 100644 index 00000000..69c90bab --- /dev/null +++ b/include/xo/expression2/Typename.hpp @@ -0,0 +1,12 @@ +/** @file Typename.hpp + * + * @author Roland Conybeare, Mar 2026 + **/ + +#pragma once + +#include "DTypename.hpp" +#include "typename/IGCObject_DTypename.hpp" +#include "typename/IPrintable_DTypename.hpp" + +/* end Typename.hpp */ diff --git a/include/xo/expression2/typename/IGCObject_DTypename.hpp b/include/xo/expression2/typename/IGCObject_DTypename.hpp new file mode 100644 index 00000000..f01740d4 --- /dev/null +++ b/include/xo/expression2/typename/IGCObject_DTypename.hpp @@ -0,0 +1,65 @@ +/** @file IGCObject_DTypename.hpp + * + * Generated automagically from ingredients: + * 1. code generator: + * [xo-facet/codegen/genfacet] + * arguments: + * --input [idl/IGCObject_DTypename.json5] + * 2. jinja2 template for abstract facet .hpp file: + * [iface_facet_repr.hpp.j2] + * 3. idl for facet methods + * [idl/IGCObject_DTypename.json5] + **/ + +#pragma once + +#include "GCObject.hpp" +#include "DTypename.hpp" + +namespace xo { namespace scm { class IGCObject_DTypename; } } + +namespace xo { + namespace facet { + template <> + struct FacetImplementation + { + using ImplType = xo::mm::IGCObject_Xfer + ; + }; + } +} + +namespace xo { + namespace scm { + /** @class IGCObject_DTypename + **/ + class IGCObject_DTypename { + public: + /** @defgroup scm-gcobject-dtypename-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-dtypename-methods **/ + ///@{ + // const methods + /** memory consumption for this instance **/ + static size_type shallow_size(const DTypename & self) noexcept; + /** copy instance using allocator **/ + static Opaque shallow_copy(const DTypename & self, obj mm) noexcept; + + // non-const methods + /** during GC: forward immdiate children **/ + static size_type forward_children(DTypename & self, obj gc) noexcept; + ///@} + }; + + } /*namespace scm*/ +} /*namespace xo*/ + +/* end */ \ No newline at end of file diff --git a/include/xo/expression2/typename/IPrintable_DTypename.hpp b/include/xo/expression2/typename/IPrintable_DTypename.hpp new file mode 100644 index 00000000..88504191 --- /dev/null +++ b/include/xo/expression2/typename/IPrintable_DTypename.hpp @@ -0,0 +1,62 @@ +/** @file IPrintable_DTypename.hpp + * + * Generated automagically from ingredients: + * 1. code generator: + * [xo-facet/codegen/genfacet] + * arguments: + * --input [idl/IPrintable_DTypename.json5] + * 2. jinja2 template for abstract facet .hpp file: + * [iface_facet_repr.hpp.j2] + * 3. idl for facet methods + * [idl/IPrintable_DTypename.json5] + **/ + +#pragma once + +#include "Printable.hpp" +#include +#include +#include "DTypename.hpp" + +namespace xo { namespace scm { class IPrintable_DTypename; } } + +namespace xo { + namespace facet { + template <> + struct FacetImplementation + { + using ImplType = xo::print::IPrintable_Xfer + ; + }; + } +} + +namespace xo { + namespace scm { + /** @class IPrintable_DTypename + **/ + class IPrintable_DTypename { + public: + /** @defgroup scm-printable-dtypename-type-traits **/ + ///@{ + using ppindentinfo = xo::print::APrintable::ppindentinfo; + using Copaque = xo::print::APrintable::Copaque; + using Opaque = xo::print::APrintable::Opaque; + ///@} + /** @defgroup scm-printable-dtypename-methods **/ + ///@{ + // const methods + /** Pretty-printing support for this object. +See [xo-indentlog/xo/indentlog/pretty.hpp] **/ + static bool pretty(const DTypename & self, const ppindentinfo & ppii); + + // 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 d5bf81f4..42b491fc 100644 --- a/src/expression2/CMakeLists.txt +++ b/src/expression2/CMakeLists.txt @@ -63,11 +63,16 @@ set(SELF_SRCS IGCObject_DGlobalSymtab.cpp IPrintable_DGlobalSymtab.cpp + DTypename.cpp + IGCObject_DTypename.cpp + IPrintable_DTypename.cpp + ) xo_add_shared_library4(${SELF_LIB} ${PROJECT_NAME}Targets ${PROJECT_VERSION} 1 ${SELF_SRCS}) # note: deps here must also appear in cmake/xo_expression2Config.cmake.in xo_dependency(${SELF_LIB} xo_gc) +xo_dependency(${SELF_LIB} xo_type) xo_dependency(${SELF_LIB} reflect) xo_dependency(${SELF_LIB} xo_procedure2) xo_dependency(${SELF_LIB} xo_printable2) diff --git a/src/expression2/DApplyExpr.cpp b/src/expression2/DApplyExpr.cpp index d4e1fa55..784e4473 100644 --- a/src/expression2/DApplyExpr.cpp +++ b/src/expression2/DApplyExpr.cpp @@ -129,6 +129,13 @@ namespace xo { std::size_t DApplyExpr::forward_children(obj gc) noexcept { + typeref_.forward_children(gc); + + { + obj fn_gco = fn_.to_facet(); + gc.forward_inplace(fn_gco.iface(), (void **)&fn_.data_); + } + for (size_type i = 0; i < n_args_; ++i) { obj & arg = args_[i]; diff --git a/src/expression2/DConstant.cpp b/src/expression2/DConstant.cpp index f1f560be..53ab045e 100644 --- a/src/expression2/DConstant.cpp +++ b/src/expression2/DConstant.cpp @@ -91,7 +91,10 @@ namespace xo { std::size_t DConstant::forward_children(obj gc) noexcept { - gc.forward_inplace(value_.iface(), (void **)&(value_.data_)); + typeref_.forward_children(gc); + + gc.forward_inplace(&value_); + //gc.forward_inplace(value_.iface(), (void **)&(value_.data_)); return shallow_size(); } diff --git a/src/expression2/DGlobalSymtab.cpp b/src/expression2/DGlobalSymtab.cpp index 95db6b26..d7f52228 100644 --- a/src/expression2/DGlobalSymtab.cpp +++ b/src/expression2/DGlobalSymtab.cpp @@ -4,6 +4,8 @@ **/ #include "DGlobalSymtab.hpp" +#include "Typename.hpp" +#include "Binding.hpp" #include "DUniqueString.hpp" #include #include @@ -18,25 +20,40 @@ namespace xo { namespace scm { - DGlobalSymtab::DGlobalSymtab(dp map, - DArray * vars) - : map_{std::move(map)}, vars_{vars} + DGlobalSymtab::DGlobalSymtab(dp var_map, + DArray * vars, + dp type_map, + DArray * types) + : var_map_{std::move(var_map)}, vars_{vars}, + type_map_{std::move(type_map)}, types_{types} { } dp DGlobalSymtab::make(obj mm, obj aux_mm, - const ArenaHashMapConfig & cfg) + const ArenaHashMapConfig & var_cfg, + const ArenaHashMapConfig & type_cfg) { - auto map = dp::make(aux_mm, cfg); - assert(map); + /* note: using aux_mm for DArenaHashMap superstructure. + * {variable, type} storage allocated from mm. + */ + + auto var_map = dp::make(aux_mm, var_cfg); + assert(var_map); /* choosing same capacity for hash, vars */ - DArray * vars = DArray::empty(mm, map->capacity()); + DArray * vars = DArray::empty(mm, var_map->capacity()); assert(vars); - auto symtab = dp::make(mm, std::move(map), vars); + auto type_map = dp::make(aux_mm, type_cfg); + assert(type_map); + + DArray * types = DArray::empty(mm, type_map->capacity()); + + auto symtab = dp::make(mm, + std::move(var_map), vars, + std::move(type_map), types); assert(symtab); return symtab; @@ -45,8 +62,10 @@ namespace xo { void DGlobalSymtab::visit_pools(const MemorySizeVisitor & visitor) const { - if (map_) - map_->visit_pools(visitor); + if (var_map_) + var_map_->visit_pools(visitor); + if (type_map_) + type_map_->visit_pools(visitor); } DVariable * @@ -58,11 +77,11 @@ namespace xo { return nullptr; auto var_gco = obj::from((*vars_)[existing.j_slot()]); - auto var = var_gco.to_facet(); - assert(var.data()); + //auto var = var_gco.to_facet(); + //assert(var.data()); - return var.data(); + return var_gco.data(); } void @@ -93,6 +112,7 @@ namespace xo { // stash new definition (possibly has different type), // replacing previous one // + log && log("STUB: need write barrier"); (*vars_)[existing->path().j_slot()] = obj(var); } else { log && log("variable is new"); @@ -123,12 +143,70 @@ namespace xo { var->assign_path(binding); // need slot# in .map_ for this unique symbol - (*map_)[var->name()] = binding.j_slot(); + (*var_map_)[var->name()] = binding.j_slot(); vars_->push_back(obj(var)); } } + DTypename * + DGlobalSymtab::lookup_typename(const DUniqueString * sym) const noexcept + { + auto ix = type_map_->find(sym); + + if (ix == type_map_->end()) + return nullptr; + + Binding::slot_type i_slot = ix->second; + + auto tname_gco = obj::from((*types_)[i_slot]); + + return tname_gco.data(); + } + + void + DGlobalSymtab::upsert_typename(obj mm, + DTypename * tname) + { + scope log(XO_DEBUG(true), + std::string_view(*tname->name())); + + auto ix = type_map_->find(tname->name()); + + if (ix == type_map_->end()) { + log && log("typename is new"); + + DArray::size_type n = types_->size(); + + /** make sure types_ has room **/ + if (n == types_->capacity()) { + // DArray is out of room. + // Reallocate with more capacity + DArray * types_2x = DArray::copy(mm, types_, types_->capacity() * 2); + + if (!types_2x) { + assert(false); + + // in any case, we can't make progress + return; + } + + log && log("STUB: need write barrier"); + this->types_ = types_2x; + } + + (*type_map_)[tname->name()] = n; + + log && log("STUB: need write barrier"); + types_->push_back(obj(tname)); + } else { + Binding::slot_type i_slot = ix->second; + + log && log("STUB: need write barrier"); + (*types_)[i_slot] = obj(tname); + } + } + #ifdef NOT_USING // don't know if we need this path DVariable * DGlobalSymtab::establish_variable(obj mm, @@ -154,9 +232,9 @@ namespace xo { scope log(XO_DEBUG(true), std::string_view(*sym)); - auto ix = map_->find(sym); + auto ix = var_map_->find(sym); - if (ix == map_->end()) + if (ix == var_map_->end()) return Binding::null(); return Binding::global(ix->second); @@ -185,7 +263,8 @@ namespace xo { if (copy_mem) { DGlobalSymtab * self = const_cast(this); - return new (copy_mem) DGlobalSymtab(std::move(self->map_), vars_); + return new (copy_mem) DGlobalSymtab(std::move(self->var_map_), vars_, + std::move(self->type_map_), types_); } return nullptr; @@ -197,6 +276,7 @@ namespace xo { // map_ doesn't contain any gc-owned data, can skip gc.forward_inplace(&vars_); + gc.forward_inplace(&types_); return this->shallow_size(); } @@ -209,8 +289,10 @@ namespace xo { return ppii.pps()->pretty_struct (ppii, "DGlobalSymtab", - refrtag("nsym", vars_->size()), - refrtag("capacity", vars_->capacity())); + refrtag("nvar", vars_->size()), + refrtag("var_capacity", vars_->capacity()), + refrtag("ntype", types_->size()), + refrtag("type_capacity", types_->capacity())); } } /*namespace scm*/ diff --git a/src/expression2/DIfElseExpr.cpp b/src/expression2/DIfElseExpr.cpp index 649a2482..0db04f7e 100644 --- a/src/expression2/DIfElseExpr.cpp +++ b/src/expression2/DIfElseExpr.cpp @@ -102,17 +102,19 @@ namespace xo { std::size_t DIfElseExpr::forward_children(obj gc) noexcept { + typeref_.forward_children(gc); + // GC needs to locate AGCObject iface for each member. { - auto gco = FacetRegistry::instance().variant(test_); + auto gco = test_.to_facet(); gc.forward_inplace(gco.iface(), (void **)&(test_.data_)); } { - auto gco = FacetRegistry::instance().variant(when_true_); + auto gco = when_true_.to_facet(); gc.forward_inplace(gco.iface(), (void **)&(when_true_.data_)); } { - auto gco = FacetRegistry::instance().variant(when_false_); + auto gco = when_false_.to_facet(); gc.forward_inplace(gco.iface(), (void **)&(when_false_.data_)); } diff --git a/src/expression2/DLambdaExpr.cpp b/src/expression2/DLambdaExpr.cpp index 56d55c03..a45c1e32 100644 --- a/src/expression2/DLambdaExpr.cpp +++ b/src/expression2/DLambdaExpr.cpp @@ -95,7 +95,7 @@ namespace xo { std::vector arg_td_v; { - DLocalSymtab::size_type z = symtab->size(); + DLocalSymtab::size_type z = symtab->n_vars(); arg_td_v.reserve(z); @@ -152,7 +152,10 @@ namespace xo { std::size_t DLambdaExpr::forward_children(obj gc) noexcept { + typeref_.forward_children(gc); + { + //gc.forward_inplace(&name_); // doesn't compile for const ptr auto iface = xo::facet::impl_for(); gc.forward_inplace(&iface, (void **)(&name_)); } @@ -160,8 +163,9 @@ namespace xo { // type_name_str_ { - auto iface = xo::facet::impl_for(); - gc.forward_inplace(&iface, (void **)(&local_symtab_)); + gc.forward_inplace(&local_symtab_); + //auto iface = xo::facet::impl_for(); + //gc.forward_inplace(&iface, (void **)(&local_symtab_)); } { diff --git a/src/expression2/DLocalSymtab.cpp b/src/expression2/DLocalSymtab.cpp index cf9c8459..539d5d78 100644 --- a/src/expression2/DLocalSymtab.cpp +++ b/src/expression2/DLocalSymtab.cpp @@ -5,38 +5,52 @@ #include "LocalSymtab.hpp" #include "Variable.hpp" +#include "Typename.hpp" #include "DUniqueString.hpp" +#include #include +#include #include namespace xo { using xo::mm::AGCObject; using xo::print::APrintable; - using xo::facet::typeseq; + //using xo::facet::typeseq; using xo::print::ppstate; namespace scm { DLocalSymtab::DLocalSymtab(DLocalSymtab * p, - size_type n) : parent_{p}, - capacity_{n}, - size_{0} + DArray * vars, DArray * types) + : parent_{p}, vars_{vars}, types_{types} { - for (size_type i = 0; i < n; ++i) { - void * mem = &slots_[i]; - new (mem) Slot(); - } } DLocalSymtab * DLocalSymtab::_make_empty(obj mm, DLocalSymtab * p, - size_type n) + size_type nv, + size_type nt) { - void * mem = mm.alloc(typeseq::id(), - sizeof(DLocalSymtab) + (n * sizeof(Slot))); + void * mem = mm.alloc_for(); - return new (mem) DLocalSymtab(p, n); + DArray * vars = DArray::empty(mm, nv); + DArray * types = DArray::empty(mm, nt); + + return new (mem) DLocalSymtab(p, vars, types); + } + + DVariable * + DLocalSymtab::lookup_var(Binding ix) noexcept + { + assert(ix.i_link() == 0); + assert(ix.j_slot() < static_cast(vars_->size())); + + auto var = obj::from((*vars_)[ix.j_slot()]); + + assert(var); + + return var.data(); } Binding @@ -46,32 +60,50 @@ namespace xo { { assert(name); - if (size_ >= capacity_ || !name) { + if (vars_->size() >= vars_->capacity() || !name) { assert(false); return Binding::null(); } else { - size_type i_slot = (this->size_)++; - Binding binding = Binding::local(i_slot); - DVariable * var = DVariable::make(mm, name, typeref, binding); + //size_type i_slot = (this->size_)++; + Binding binding = Binding::local(vars_->size()); - this->slots_[i_slot] = Slot(var); + DVariable * var = DVariable::make(mm, name, typeref, binding); + vars_->push_back(obj(var)); return binding; } } + void + DLocalSymtab::append_type(obj mm, + const DUniqueString * name, + obj type) + { + assert(name); + + if (types_->size() >= types_->capacity() || !name) { + assert(false); + } else { + obj tname = DTypename::make(mm, name, type); + + types_->push_back(tname); + } + } + Binding DLocalSymtab::lookup_binding(const DUniqueString * sym) const noexcept { assert(sym); if (sym) { - for (size_type i = 0; i < size_; ++i) { - const Slot & slot = slots_[i]; + for (size_type i = 0, n = vars_->size(); i < n; ++i) { + auto var_i = obj::from((*vars_)[i]); - if (*sym == *(slot.var_->name())) - return slot.var_->path(); + assert(var_i); + + if (*sym == *(var_i->name())) + return var_i->path(); } } @@ -83,39 +115,21 @@ namespace xo { std::size_t DLocalSymtab::shallow_size() const noexcept { - return (sizeof(DLocalSymtab) + (capacity_ * sizeof(Slot))); + return sizeof(DLocalSymtab); } 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; + return mm.std_copy_for(this); } 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_))); - } + gc.forward_inplace(&parent_); + gc.forward_inplace(&vars_); + gc.forward_inplace(&types_); return shallow_size(); } @@ -127,45 +141,69 @@ namespace xo { { ppstate * pps = ppii.pps(); + (void)pps; + if (ppii.upto()) { /* perhaps print on one line */ if (!pps->print_upto("print_upto(xrefrtag("size", size_))) + + if (!pps->print_upto(xrefrtag("nvars", vars_->size()))) return false; - for (size_type i = 0; i < size_; ++i) { + for (size_type i = 0, n = vars_->size(); i arg_pr(const_cast(slots_[i].var_)); + obj arg_pr = (*vars_)[i].to_facet(); if (!pps->print_upto(xrefrtag(buf, arg_pr))) return false; } + if (!pps->print_upto(xrefrtag("ntypes", types_->size()))) + return false; + + for (size_type i = 0, n = types_->size(); i < n; ++i) { + char buf[32]; + snprintf(buf, sizeof(buf), "[%u]", i); + + obj type_pr = (*types_)[i].to_facet(); + + if (!pps->print_upto(xrefrtag(buf, type_pr))) + return false; + } + pps->write(">"); return true; } else { /* with line breaks */ pps->write("newline_pretty_tag(ppii.ci1(), "size", size_); + pps->newline_pretty_tag(ppii.ci1(), "nvars", vars_->size()); - for (size_type i = 0; i < size_; ++i) { + for (size_type i = 0, n = vars_->size(); i < n; ++i) { char buf[32]; snprintf(buf, sizeof(buf), "[%u]", i); - assert(slots_[i].var_); - - obj arg_pr(const_cast(slots_[i].var_)); + obj arg_pr = (*vars_)[i].to_facet(); pps->newline_pretty_tag(ppii.ci1(), buf, arg_pr); } + pps->newline_pretty_tag(ppii.ci1(), "ntypes", types_->size()); + + for (size_type i = 0, n = types_->size(); i < n; ++i) { + char buf[32]; + snprintf(buf, sizeof(buf), "[%u]", i); + + obj type_pr = (*types_)[i].to_facet(); + + pps->newline_pretty_tag(ppii.ci1(), buf, type_pr); + } + pps->write(">"); + return false; } } diff --git a/src/expression2/DSequenceExpr.cpp b/src/expression2/DSequenceExpr.cpp index fdc73b8e..141d4946 100644 --- a/src/expression2/DSequenceExpr.cpp +++ b/src/expression2/DSequenceExpr.cpp @@ -22,6 +22,12 @@ namespace xo { namespace scm { + DSequenceExpr::DSequenceExpr() = default; + + DSequenceExpr::DSequenceExpr(DArray * xv) + : expr_v_{xv} + {} + obj DSequenceExpr::make_empty(obj mm) { @@ -127,13 +133,13 @@ namespace xo { std::size_t DSequenceExpr::forward_children(obj gc) noexcept { - // WARNING. - // if this proves problematic, - // may resort to obj for expr_v_ member + typeref_.forward_children(gc); - auto iface = facet::impl_for(); - - gc.forward_inplace(&iface, (void**)&expr_v_); + { + //auto iface = facet::impl_for(); + //gc.forward_inplace(&iface, (void**)&expr_v_); + gc.forward_inplace(&expr_v_); + } return this->shallow_size(); } diff --git a/src/expression2/DTypename.cpp b/src/expression2/DTypename.cpp new file mode 100644 index 00000000..fd62336b --- /dev/null +++ b/src/expression2/DTypename.cpp @@ -0,0 +1,89 @@ +/** @file DTypename.cpp + * + * @author Roland Conybeare, Jan 2026 + **/ + +#include "Typename.hpp" +#include +#include +#include +#include +#include + +namespace xo { + using xo::mm::ACollector; + using xo::mm::AGCObject; + using xo::print::APrintable; + + namespace scm { + + DTypename * + DTypename::_make(obj mm, + const DUniqueString * name, + obj type) + { + void * mem = mm.alloc_for(); + + return new (mem) DTypename(name, type); + } + + obj + DTypename::make(obj mm, + const DUniqueString * name, + obj type) + { + return obj(_make(mm, name, type)); + } + + DTypename::DTypename(const DUniqueString * name, + obj type) + : name_{name}, type_{type} + {} + + size_t + DTypename::shallow_size() const noexcept + { + return sizeof(DTypename); + } + + DTypename * + DTypename::shallow_copy(obj mm) const noexcept + { + return mm.std_copy_for(this); + } + + size_t + DTypename::forward_children(obj gc) noexcept + { + gc.forward_inplace(const_cast(&name_)); + { + auto e = type_.to_facet(); + gc.forward_inplace(e.iface(), (void **)&(type_.data_)); + } + + return shallow_size(); + } + + bool + DTypename::pretty(const ppindentinfo & ppii) const + { + using xo::print::quot; + + auto name = (name_ + ? std::string_view(*name_) + : std::string_view("")); + + auto type_pr = type_.to_facet(); + + return ppii.pps()->pretty_struct + (ppii, + "DTypename" + , refrtag("name", quot(name)) + , refrtag("type", type_pr) + ); + } + + } /*namespace scm*/ +} /*namespace xo*/ + +/* end DTypename.cpp */ diff --git a/src/expression2/DVariable.cpp b/src/expression2/DVariable.cpp index 8fc201a5..092eb715 100644 --- a/src/expression2/DVariable.cpp +++ b/src/expression2/DVariable.cpp @@ -57,12 +57,9 @@ namespace xo { } size_t - DVariable::forward_children(obj) noexcept + DVariable::forward_children(obj gc) noexcept { - // nothing to collect. - // - DUniqueString never in GC space - // - TypeDescr not in GC space - // - path only integers + typeref_.forward_children(gc); return shallow_size(); } diff --git a/src/expression2/IGCObject_DTypename.cpp b/src/expression2/IGCObject_DTypename.cpp new file mode 100644 index 00000000..2b898fbf --- /dev/null +++ b/src/expression2/IGCObject_DTypename.cpp @@ -0,0 +1,39 @@ +/** @file IGCObject_DTypename.cpp + * + * Generated automagically from ingredients: + * 1. code generator: + * [xo-facet/codegen/genfacet] + * arguments: + * --input [idl/IGCObject_DTypename.json5] + * 2. jinja2 template for abstract facet .hpp file: + * [iface_facet_any.hpp.j2] + * 3. idl for facet methods + * [idl/IGCObject_DTypename.json5] +**/ + +#include "typename/IGCObject_DTypename.hpp" + +namespace xo { + namespace scm { + auto + IGCObject_DTypename::shallow_size(const DTypename & self) noexcept -> size_type + { + return self.shallow_size(); + } + + auto + IGCObject_DTypename::shallow_copy(const DTypename & self, obj mm) noexcept -> Opaque + { + return self.shallow_copy(mm); + } + + auto + IGCObject_DTypename::forward_children(DTypename & self, obj gc) noexcept -> size_type + { + return self.forward_children(gc); + } + + } /*namespace scm*/ +} /*namespace xo*/ + +/* end IGCObject_DTypename.cpp */ diff --git a/src/expression2/IPrintable_DTypename.cpp b/src/expression2/IPrintable_DTypename.cpp new file mode 100644 index 00000000..8d753b0e --- /dev/null +++ b/src/expression2/IPrintable_DTypename.cpp @@ -0,0 +1,28 @@ +/** @file IPrintable_DTypename.cpp + * + * Generated automagically from ingredients: + * 1. code generator: + * [xo-facet/codegen/genfacet] + * arguments: + * --input [idl/IPrintable_DTypename.json5] + * 2. jinja2 template for abstract facet .hpp file: + * [iface_facet_any.hpp.j2] + * 3. idl for facet methods + * [idl/IPrintable_DTypename.json5] +**/ + +#include "typename/IPrintable_DTypename.hpp" + +namespace xo { + namespace scm { + auto + IPrintable_DTypename::pretty(const DTypename & self, const ppindentinfo & ppii) -> bool + { + return self.pretty(ppii); + } + + + } /*namespace scm*/ +} /*namespace xo*/ + +/* end IPrintable_DTypename.cpp */ diff --git a/src/expression2/TypeRef.cpp b/src/expression2/TypeRef.cpp index 5ff1d258..4040cf13 100644 --- a/src/expression2/TypeRef.cpp +++ b/src/expression2/TypeRef.cpp @@ -4,16 +4,34 @@ **/ #include "TypeRef.hpp" +#include +#include #include #include #include namespace xo { + using xo::mm::AGCObject; + using xo::facet::FacetRegistry; + namespace scm { + TypeRef::TypeRef(const type_var & id, obj type) + : id_{id}, type_{type} + {} + TypeRef::TypeRef(const type_var & id, TypeDescr td) : id_{id}, td_{td} {} + TypeRef + TypeRef::resolved(obj type) + { + assert(type); + + type_var null; + return TypeRef(null, type); + } + TypeRef TypeRef::resolved(TypeDescr td) { @@ -23,6 +41,23 @@ namespace xo { return TypeRef(null, td); } + TypeRef + TypeRef::dwim(prefix_type prefix, obj type) + { + if (type) { + /* type already resolved + * -> we don't need a type variable name + */ + return TypeRef::resolved(type); + } else { + /* type is not resolved yet. + * -> give it a unique name, + * to seed unification + */ + return TypeRef(generate_unique(prefix), type); + } + } + TypeRef TypeRef::dwim(prefix_type prefix, TypeDescr td) { @@ -65,6 +100,15 @@ namespace xo { return (td_ != nullptr); } + void + TypeRef::forward_children(obj gc) noexcept + { + { + auto e = FacetRegistry::instance().variant(type_); + gc.forward_inplace(e.iface(), (void **)&(type_.data_)); + } + } + bool TypeRef::pretty(const ppindentinfo & ppii) const { diff --git a/src/expression2/expression2_register_facets.cpp b/src/expression2/expression2_register_facets.cpp index 3cd9413d..1e68c771 100644 --- a/src/expression2/expression2_register_facets.cpp +++ b/src/expression2/expression2_register_facets.cpp @@ -5,11 +5,13 @@ #include "expression2_register_facets.hpp" -#include -#include -#include +//#include +//#include +//#include #include +#include +#include #include #include #include @@ -83,6 +85,11 @@ namespace xo { FacetRegistry::register_impl(); FacetRegistry::register_impl(); + // Typename + + FacetRegistry::register_impl(); + FacetRegistry::register_impl(); + // SymbolTable // +- LocalSymtab // \- GlobalSymtab @@ -103,6 +110,7 @@ namespace xo { log && log(xtag("DUniqueString.tseq", typeseq::id())); log && log(xtag("DDefineExpr.tseq", typeseq::id())); log && log(xtag("DVariable.tseq", typeseq::id())); + log && log(xtag("DTypename.tseq", typeseq::id())); log && log(xtag("DVarRef.tseq", typeseq::id())); log && log(xtag("DConstant.tseq", typeseq::id())); log && log(xtag("DApplyExpr.tseq", typeseq::id())); diff --git a/src/expression2/expression2_register_types.cpp b/src/expression2/expression2_register_types.cpp index 7a64eb1f..c62ea264 100644 --- a/src/expression2/expression2_register_types.cpp +++ b/src/expression2/expression2_register_types.cpp @@ -5,14 +5,17 @@ #include "expression2_register_types.hpp" +#include "DefineExpr.hpp" #include "Constant.hpp" -//#include "detail/IGCObject_DConstant.hpp" -#include "detail/IGCObject_DVariable.hpp" +#include "Variable.hpp" +#include "Typename.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 "LambdaExpr.hpp" +#include "IfElseExpr.hpp" +#include "SequenceExpr.hpp" +#include "LocalSymtab.hpp" +#include "GlobalSymtab.hpp" //#include "detail/IGCObject_DLocalSymtab.hpp" // when avail //#include "detail/IGCObject_DUniqueString.hpp" @@ -24,7 +27,6 @@ namespace xo { using xo::mm::ACollector; using xo::mm::AGCObject; using xo::facet::impl_for; - using xo::facet::typeseq; using xo::scope; namespace scm { @@ -37,13 +39,15 @@ namespace xo { 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()); + 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()); 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()); + ok &= gc.install_type(impl_for()); return ok; }