From 93b613e8feb7f7ed8db1a49fba2743d95cb02a61 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Thu, 12 Mar 2026 20:26:08 -0500 Subject: [PATCH] xo-interpreter2 stack: refactor + bugfix operator expr --- CMakeLists.txt | 18 --- idl/IGCObject_DGlobalEnv.json5 | 18 --- idl/IPrintable_DGlobalEnv.json5 | 16 -- include/xo/interpreter2/DGlobalEnv.hpp | 94 ------------ include/xo/interpreter2/GlobalEnv.hpp | 12 -- .../interpreter2/env/IGCObject_DGlobalEnv.hpp | 67 -------- .../env/IPrintable_DGlobalEnv.hpp | 62 -------- src/interpreter2/CMakeLists.txt | 4 - src/interpreter2/DGlobalEnv.cpp | 145 ------------------ src/interpreter2/IGCObject_DGlobalEnv.cpp | 39 ----- src/interpreter2/IPrintable_DGlobalEnv.cpp | 28 ---- src/interpreter2/init_interpreter2.cpp | 2 + .../interpreter2_register_facets.cpp | 7 +- src/skrepl/skreplxx.cpp | 18 ++- 14 files changed, 15 insertions(+), 515 deletions(-) delete mode 100644 idl/IGCObject_DGlobalEnv.json5 delete mode 100644 idl/IPrintable_DGlobalEnv.json5 delete mode 100644 include/xo/interpreter2/DGlobalEnv.hpp delete mode 100644 include/xo/interpreter2/GlobalEnv.hpp delete mode 100644 include/xo/interpreter2/env/IGCObject_DGlobalEnv.hpp delete mode 100644 include/xo/interpreter2/env/IPrintable_DGlobalEnv.hpp delete mode 100644 src/interpreter2/DGlobalEnv.cpp delete mode 100644 src/interpreter2/IGCObject_DGlobalEnv.cpp delete mode 100644 src/interpreter2/IPrintable_DGlobalEnv.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 229bf176..f325441b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -161,24 +161,6 @@ xo_add_genfacetimpl( # ---------------------------------------------------------------- -# note: manual target; generated code committed to git -xo_add_genfacetimpl( - TARGET xo-interpreter2-facetimpl-gcobject-globalenv - FACET_PKG xo_alloc2 -# REPR GlobalEnv - INPUT idl/IGCObject_DGlobalEnv.json5 -) - -# note: manual target; generated code committed to git -xo_add_genfacetimpl( - TARGET xo-interpreter2-facetimpl-printable-globalenv - FACET_PKG xo_printable2 -# REPR GlobalEnv - INPUT idl/IPrintable_DGlobalEnv.json5 -) - -# ---------------------------------------------------------------- - # note: manual target; generated code committed to git xo_add_genfacetimpl( TARGET xo-interpreter2-facetimpl-gcobject-localenv diff --git a/idl/IGCObject_DGlobalEnv.json5 b/idl/IGCObject_DGlobalEnv.json5 deleted file mode 100644 index 9ce50388..00000000 --- a/idl/IGCObject_DGlobalEnv.json5 +++ /dev/null @@ -1,18 +0,0 @@ -{ - mode: "implementation", - output_cpp_dir: "src/interpreter2", - output_hpp_dir: "include/xo/interpreter2", - output_impl_subdir: "env", - includes: [ - "", - "" - ], - local_types: [ ], - namespace1: "xo", - namespace2: "scm", - facet_idl: "idl/GCObject.json5", - brief: "provide AGCObject interface for GlobalEnv", - using_doxygen: true, - repr: "DGlobalEnv", - doc: [ "implement AGCObject for DGlobalEnv" ], -} diff --git a/idl/IPrintable_DGlobalEnv.json5 b/idl/IPrintable_DGlobalEnv.json5 deleted file mode 100644 index 541146ae..00000000 --- a/idl/IPrintable_DGlobalEnv.json5 +++ /dev/null @@ -1,16 +0,0 @@ -{ - mode: "implementation", - output_cpp_dir: "src/interpreter2", - output_hpp_dir: "include/xo/interpreter2", - output_impl_subdir: "env", - includes: [ "", - "" ], - local_types: [ ], - namespace1: "xo", - namespace2: "scm", - facet_idl: "idl/Printable.json5", - brief: "provide APrintable interface for DGlobalEnv", - using_doxygen: true, - repr: "DGlobalEnv", - doc: [ "implement APrintable for DGlobalEnv" ], -} diff --git a/include/xo/interpreter2/DGlobalEnv.hpp b/include/xo/interpreter2/DGlobalEnv.hpp deleted file mode 100644 index da7f8536..00000000 --- a/include/xo/interpreter2/DGlobalEnv.hpp +++ /dev/null @@ -1,94 +0,0 @@ -/** @file DGlobalEnv.hpp - * - * @author Roland Conybeare, Feb 2026 - **/ - -#pragma once - -#include -#include - -namespace xo { - namespace scm { - - /** @brief runtime bindings for global variabels - * - * Implementation here uses a DArenaHashMap to hold pairs. - * The hash map has its own memory outside GC space. - * Keys are DUniqueStrings, also outside GC space. - * Values are regular gc-aware objects, generally will be in GC space. - * - * We need collector to traverse all the values in a global env - * on each cycle. Arrange that by having DGlobalEnv itself - * in GC space. - * - **/ - class DGlobalEnv { - public: - using TypeDescr = xo::reflect::TypeDescr; - using ACollector = xo::mm::ACollector; - using AAllocator = xo::mm::AAllocator; - using AGCObject = xo::mm::AGCObject; - using MemorySizeVisitor = xo::mm::MemorySizeVisitor; - using ppindentinfo = xo::print::ppindentinfo; - using size_type = std::uint32_t; - - public: - /** @defgroup scm-globalenv-ctors constructors **/ - ///@{ - - DGlobalEnv(DGlobalSymtab * symtab, DArray * values); - - static DGlobalEnv * _make(obj mm, - DGlobalSymtab * symtab); - - - ///@} - /** @defgroup scm-globalenv-methods methods **/ - ///@{ - - /** symbol-table size. Is the number of distinct global variables **/ - size_type n_vars() const noexcept { return symtab_->n_vars(); } - - /** lookup current value associated with binding @p ix **/ - obj lookup_value(Binding ix) const noexcept; - - /** assign value associated with binding @p to @p x. - * If need to expand size of this env, use memory from @p mm - **/ - void assign_value(obj mm, Binding ix, obj x); - - /** create/establish global for symbol @p sym with resolved type @p td - * and associate with @p value. - **/ - DVariable * _upsert_value(obj mm, - const DUniqueString * sym, - TypeDescr td, - obj value); - - ///@} - /** @defgroup scm-globalenv-gcobject-facet **/ - ///@{ - - std::size_t shallow_size() const noexcept; - DGlobalEnv * shallow_copy(obj mm) const noexcept; - std::size_t forward_children(obj gc) noexcept; - - ///@} - /** @defgroup scm-globalenv-printable-facet **/ - ///@{ - - bool pretty(const ppindentinfo & ppii) const; - - ///@} - - private: - - /** symbol table assigns a unique index for each symbol **/ - DGlobalSymtab * symtab_; - - /** value for a symbol S will be in values_[symtab->lookup_binding(S)] **/ - DArray * values_ = nullptr; - }; - } -} diff --git a/include/xo/interpreter2/GlobalEnv.hpp b/include/xo/interpreter2/GlobalEnv.hpp deleted file mode 100644 index 94bafc42..00000000 --- a/include/xo/interpreter2/GlobalEnv.hpp +++ /dev/null @@ -1,12 +0,0 @@ -/** @file GlobalEnv.hpp - * - * @author Roland Conybeare, Feb 2026 - **/ - -#pragma once - -#include "DGlobalEnv.hpp" -#include "env/IGCObject_DGlobalEnv.hpp" -#include "env/IPrintable_DGlobalEnv.hpp" - -/* end GlobalEnv.hpp */ diff --git a/include/xo/interpreter2/env/IGCObject_DGlobalEnv.hpp b/include/xo/interpreter2/env/IGCObject_DGlobalEnv.hpp deleted file mode 100644 index a2fcb5f6..00000000 --- a/include/xo/interpreter2/env/IGCObject_DGlobalEnv.hpp +++ /dev/null @@ -1,67 +0,0 @@ -/** @file IGCObject_DGlobalEnv.hpp - * - * Generated automagically from ingredients: - * 1. code generator: - * [xo-facet/codegen/genfacet] - * arguments: - * --input [idl/IGCObject_DGlobalEnv.json5] - * 2. jinja2 template for abstract facet .hpp file: - * [iface_facet_repr.hpp.j2] - * 3. idl for facet methods - * [idl/IGCObject_DGlobalEnv.json5] - **/ - -#pragma once - -#include "GCObject.hpp" -#include -#include -#include "DGlobalEnv.hpp" - -namespace xo { namespace scm { class IGCObject_DGlobalEnv; } } - -namespace xo { - namespace facet { - template <> - struct FacetImplementation - { - using ImplType = xo::mm::IGCObject_Xfer - ; - }; - } -} - -namespace xo { - namespace scm { - /** @class IGCObject_DGlobalEnv - **/ - class IGCObject_DGlobalEnv { - public: - /** @defgroup scm-gcobject-dglobalenv-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-dglobalenv-methods **/ - ///@{ - // const methods - /** memory consumption for this instance **/ - static size_type shallow_size(const DGlobalEnv & self) noexcept; - /** copy instance using allocator **/ - static Opaque shallow_copy(const DGlobalEnv & self, obj mm) noexcept; - - // non-const methods - /** during GC: forward immdiate children **/ - static size_type forward_children(DGlobalEnv & self, obj gc) noexcept; - ///@} - }; - - } /*namespace scm*/ -} /*namespace xo*/ - -/* end */ \ No newline at end of file diff --git a/include/xo/interpreter2/env/IPrintable_DGlobalEnv.hpp b/include/xo/interpreter2/env/IPrintable_DGlobalEnv.hpp deleted file mode 100644 index 6efcd963..00000000 --- a/include/xo/interpreter2/env/IPrintable_DGlobalEnv.hpp +++ /dev/null @@ -1,62 +0,0 @@ -/** @file IPrintable_DGlobalEnv.hpp - * - * Generated automagically from ingredients: - * 1. code generator: - * [xo-facet/codegen/genfacet] - * arguments: - * --input [idl/IPrintable_DGlobalEnv.json5] - * 2. jinja2 template for abstract facet .hpp file: - * [iface_facet_repr.hpp.j2] - * 3. idl for facet methods - * [idl/IPrintable_DGlobalEnv.json5] - **/ - -#pragma once - -#include "Printable.hpp" -#include -#include -#include "DGlobalEnv.hpp" - -namespace xo { namespace scm { class IPrintable_DGlobalEnv; } } - -namespace xo { - namespace facet { - template <> - struct FacetImplementation - { - using ImplType = xo::print::IPrintable_Xfer - ; - }; - } -} - -namespace xo { - namespace scm { - /** @class IPrintable_DGlobalEnv - **/ - class IPrintable_DGlobalEnv { - public: - /** @defgroup scm-printable-dglobalenv-type-traits **/ - ///@{ - using ppindentinfo = xo::print::APrintable::ppindentinfo; - using Copaque = xo::print::APrintable::Copaque; - using Opaque = xo::print::APrintable::Opaque; - ///@} - /** @defgroup scm-printable-dglobalenv-methods **/ - ///@{ - // const methods - /** Pretty-printing support for this object. -See [xo-indentlog/xo/indentlog/pretty.hpp] **/ - static bool pretty(const DGlobalEnv & self, const ppindentinfo & ppii); - - // non-const methods - ///@} - }; - - } /*namespace scm*/ -} /*namespace xo*/ - -/* end */ \ No newline at end of file diff --git a/src/interpreter2/CMakeLists.txt b/src/interpreter2/CMakeLists.txt index c15ddef6..27927606 100644 --- a/src/interpreter2/CMakeLists.txt +++ b/src/interpreter2/CMakeLists.txt @@ -36,10 +36,6 @@ set(SELF_SRCS IGCObject_DClosure.cpp IPrintable_DClosure.cpp - DGlobalEnv.cpp - IGCObject_DGlobalEnv.cpp - IPrintable_DGlobalEnv.cpp - DLocalEnv.cpp IGCObject_DLocalEnv.cpp IPrintable_DLocalEnv.cpp diff --git a/src/interpreter2/DGlobalEnv.cpp b/src/interpreter2/DGlobalEnv.cpp deleted file mode 100644 index fcc92efa..00000000 --- a/src/interpreter2/DGlobalEnv.cpp +++ /dev/null @@ -1,145 +0,0 @@ -/** @file DGlobalEnv.cpp - * - * @author Roland Conybeare, Feb 2026 -**/ - -#include "GlobalEnv.hpp" -#include -#include - -namespace xo { - using xo::mm::AAllocator; - using xo::mm::AGCObject; - - namespace scm { - - DGlobalEnv::DGlobalEnv(DGlobalSymtab * symtab, DArray * values) - : symtab_{symtab}, values_{values} - {} - - DGlobalEnv * - DGlobalEnv::_make(obj mm, - DGlobalSymtab * symtab) - { - DArray * values = DArray::empty(mm, symtab->var_capacity()); - - void * mem = mm.alloc_for(); - - return new (mem) DGlobalEnv(symtab, values); - } - - obj - DGlobalEnv::lookup_value(Binding ix) const noexcept - { - if (!ix.is_global()) { - assert(false); - return obj(); - } - - if (ix.j_slot() >= static_cast(values_->size())) { - assert(false); - return obj(); - } - - return (*values_)[ix.j_slot()]; - } - - void - DGlobalEnv::assign_value(obj mm, Binding ix, obj x) - { - scope log(XO_DEBUG(true), - xtag("ix.j_slot", ix.j_slot()), - xtag("values.cap", values_->capacity())); - - assert(ix.is_global()); - - if (ix.j_slot() >= static_cast(values_->size())) { - // Control will come here in interpreter as new definitions are introduced. - // After seeing - // def foo = 1.2345; - // introducing new symbol foo: - // GlobalSymtab extends to include foo without this GlobalEnv - // knowing about it. - - if (ix.j_slot() + 1 > static_cast(values_->capacity())) { - // realloc global array for more size - - size_t cap_2x = 2 * values_->capacity(); - - while (cap_2x < static_cast(ix.j_slot() + 1)) - cap_2x = 2 * cap_2x; - - DArray * values_2x = DArray::copy(mm, values_, cap_2x); - assert(values_2x); - - if (values_2x) { - log && log("STUB: need write barrier for GC (also in GlobalSymtab!)"); - this->values_ = values_2x; - } else { - return; - } - } - - /** expand size sot that j_slot is valid **/ - values_->resize(ix.j_slot() + 1); - } - - log && log("STUB: need write barrier for GC here"); - (*values_)[ix.j_slot()] = x; - } - - DVariable * - DGlobalEnv::_upsert_value(obj mm, - const DUniqueString * sym, - TypeDescr td, - obj value) - { - DVariable * var - = DVariable::make(mm, sym, TypeRef::resolved(td)); - - assert(var); - - symtab_->upsert_variable(mm, var); - this->assign_value(mm, var->path(), value); - - return var; - } - - // ----- AGCObject facet ----- - - std::size_t - DGlobalEnv::shallow_size() const noexcept - { - return sizeof(*this); - } - - DGlobalEnv * - DGlobalEnv::shallow_copy(obj mm) const noexcept - { - return mm.std_copy_for(this); - } - - std::size_t - DGlobalEnv::forward_children(obj gc) noexcept - { - gc.forward_inplace(&symtab_); - gc.forward_inplace(&values_); - - return this->shallow_size(); - } - - // ----- APrintable facet ----- - - bool - DGlobalEnv::pretty(const ppindentinfo & ppii) const - { - return ppii.pps()->pretty_struct - (ppii, - "DGlobalEnv", - refrtag("n_vars", symtab_->n_vars())); - } - - } /*namespace scm*/ -} /*namespace xo*/ - -/* end DGlobalEnv.cpp */ diff --git a/src/interpreter2/IGCObject_DGlobalEnv.cpp b/src/interpreter2/IGCObject_DGlobalEnv.cpp deleted file mode 100644 index 76606d6f..00000000 --- a/src/interpreter2/IGCObject_DGlobalEnv.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/** @file IGCObject_DGlobalEnv.cpp - * - * Generated automagically from ingredients: - * 1. code generator: - * [xo-facet/codegen/genfacet] - * arguments: - * --input [idl/IGCObject_DGlobalEnv.json5] - * 2. jinja2 template for abstract facet .hpp file: - * [iface_facet_any.hpp.j2] - * 3. idl for facet methods - * [idl/IGCObject_DGlobalEnv.json5] -**/ - -#include "env/IGCObject_DGlobalEnv.hpp" - -namespace xo { - namespace scm { - auto - IGCObject_DGlobalEnv::shallow_size(const DGlobalEnv & self) noexcept -> size_type - { - return self.shallow_size(); - } - - auto - IGCObject_DGlobalEnv::shallow_copy(const DGlobalEnv & self, obj mm) noexcept -> Opaque - { - return self.shallow_copy(mm); - } - - auto - IGCObject_DGlobalEnv::forward_children(DGlobalEnv & self, obj gc) noexcept -> size_type - { - return self.forward_children(gc); - } - - } /*namespace scm*/ -} /*namespace xo*/ - -/* end IGCObject_DGlobalEnv.cpp */ diff --git a/src/interpreter2/IPrintable_DGlobalEnv.cpp b/src/interpreter2/IPrintable_DGlobalEnv.cpp deleted file mode 100644 index 84fc561c..00000000 --- a/src/interpreter2/IPrintable_DGlobalEnv.cpp +++ /dev/null @@ -1,28 +0,0 @@ -/** @file IPrintable_DGlobalEnv.cpp - * - * Generated automagically from ingredients: - * 1. code generator: - * [xo-facet/codegen/genfacet] - * arguments: - * --input [idl/IPrintable_DGlobalEnv.json5] - * 2. jinja2 template for abstract facet .hpp file: - * [iface_facet_any.hpp.j2] - * 3. idl for facet methods - * [idl/IPrintable_DGlobalEnv.json5] -**/ - -#include "env/IPrintable_DGlobalEnv.hpp" - -namespace xo { - namespace scm { - auto - IPrintable_DGlobalEnv::pretty(const DGlobalEnv & self, const ppindentinfo & ppii) -> bool - { - return self.pretty(ppii); - } - - - } /*namespace scm*/ -} /*namespace xo*/ - -/* end IPrintable_DGlobalEnv.cpp */ diff --git a/src/interpreter2/init_interpreter2.cpp b/src/interpreter2/init_interpreter2.cpp index 73a6a5c2..6302be0c 100644 --- a/src/interpreter2/init_interpreter2.cpp +++ b/src/interpreter2/init_interpreter2.cpp @@ -27,6 +27,8 @@ namespace xo { InitEvidence InitSubsys::require() { + scope log(XO_DEBUG(true)); + InitEvidence retval; /* direct subsystem deps for xo-interpreter2/ */ diff --git a/src/interpreter2/interpreter2_register_facets.cpp b/src/interpreter2/interpreter2_register_facets.cpp index 22c9bfb9..24801f66 100644 --- a/src/interpreter2/interpreter2_register_facets.cpp +++ b/src/interpreter2/interpreter2_register_facets.cpp @@ -63,12 +63,7 @@ namespace xo { FacetRegistry::register_impl(); FacetRegistry::register_impl(); - // GlobalEnv - - FacetRegistry::register_impl(); - FacetRegistry::register_impl(); - - // LocalEnv + // LocalEnv (see xo-reader2/ for GlobalEnv) FacetRegistry::register_impl(); FacetRegistry::register_impl(); diff --git a/src/skrepl/skreplxx.cpp b/src/skrepl/skreplxx.cpp index 3362b823..e3d5564e 100644 --- a/src/skrepl/skreplxx.cpp +++ b/src/skrepl/skreplxx.cpp @@ -110,13 +110,15 @@ namespace xo { //using X1CollectorConfig = xo::mm::X1CollectorConfig; //using DArena = xo::mm::DArena; //using ArenaConfig = xo::mm::ArenaConfig; + using VsmConfig = xo::scm::VsmConfig; using Replxx = replxx::Replxx; using span_type = VirtualSchematikaMachine::span_type; App(const AppConfig & cfg = AppConfig()) : repl_config_{cfg.repl_config_}, app_arena_{cfg.app_arena_config_}, - vsm_{cfg.vsm_config_, obj(&app_arena_)} + vsm_config_{cfg.vsm_config_} + //vsm_{cfg.vsm_config_, obj(&app_arena_)} { this->interactive_ = isatty(STDIN_FILENO); @@ -148,7 +150,8 @@ namespace xo { /** arena with same lifetime as this application **/ DArena app_arena_; /** schematika virtual machine **/ - VirtualSchematikaMachine vsm_; + VsmConfig vsm_config_; + std::unique_ptr vsm_; }; void @@ -162,13 +165,16 @@ namespace xo { void App::_init() { - // window to contorl size of registries ends as soon as we init other subsystems + // window to control size of registries ends as soon as we init other subsystems TypeRegistry::instance(1024); FacetRegistry::instance(1024); InitEvidence init_evidence_ = (InitSubsys::require()); Subsystem::initialize_all(); + + vsm_.reset(new VirtualSchematikaMachine(vsm_config_, + obj(&app_arena_))); } void @@ -176,7 +182,7 @@ namespace xo { { welcome(cerr); - vsm_.begin_interactive_session(); + vsm_->begin_interactive_session(); } void @@ -186,7 +192,7 @@ namespace xo { span_type input; // outer loop: fetch one line of interactive input - while (replxx_getline(interactive_, vsm_.is_at_toplevel(), rx_, &input)) { + while (replxx_getline(interactive_, vsm_->is_at_toplevel(), rx_, &input)) { // inner loop: consume up to one expression at a time. while (!input.empty() && this->_read_eval_print(&input, false /*eof*/)) @@ -218,7 +224,7 @@ namespace xo { if (!p_input || p_input->empty()) return true; - VsmResultExt res = vsm_.read_eval_print(*p_input, eof); + VsmResultExt res = vsm_->read_eval_print(*p_input, eof); *p_input = res.remaining_;