From 6f87a2324af7d8cf664b9e8d6c16863037033270 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Sat, 7 Feb 2026 23:14:48 -0500 Subject: [PATCH] xo-interpreter: vsm work on environments [WIP] --- .../include/xo/interpreter2/DGlobalEnv.hpp | 29 +++++++++++++++++++ .../include/xo/interpreter2/DLocalEnv.hpp | 2 +- .../include/xo/interpreter2/DVsmRcx.hpp | 2 ++ .../interpreter2/VirtualSchematikaMachine.hpp | 13 +++++++++ .../interpreter2/VirtualSchematikaMachine.cpp | 28 +++++++++++++++++- 5 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 xo-interpreter2/include/xo/interpreter2/DGlobalEnv.hpp create mode 100644 xo-interpreter2/include/xo/interpreter2/DVsmRcx.hpp diff --git a/xo-interpreter2/include/xo/interpreter2/DGlobalEnv.hpp b/xo-interpreter2/include/xo/interpreter2/DGlobalEnv.hpp new file mode 100644 index 00000000..d0ab0827 --- /dev/null +++ b/xo-interpreter2/include/xo/interpreter2/DGlobalEnv.hpp @@ -0,0 +1,29 @@ +/** @file DGlobalEnv.hpp + * + * @author Roland Conybeare, Feb 2026 + **/ + +#pragma once + +#include +#include + +namespace xo { + namespace scm { + + + /** @brief runtime bindings for global variabels + **/ + class DGlobalEnv { + public: + DGLobalEnv() = default; + + private: + // absurd O(n) implementation for now + // replace with gc-aware hashtable, when available. + + /** globals. Slots in @ref global_v_ are numbered in DLocalSymtab **/ + DArray * global_v_ = nullptr; + }; + } +} diff --git a/xo-interpreter2/include/xo/interpreter2/DLocalEnv.hpp b/xo-interpreter2/include/xo/interpreter2/DLocalEnv.hpp index fec8148d..0291c748 100644 --- a/xo-interpreter2/include/xo/interpreter2/DLocalEnv.hpp +++ b/xo-interpreter2/include/xo/interpreter2/DLocalEnv.hpp @@ -11,7 +11,7 @@ namespace xo { namespace scm { - /** @brief bindings for arguments to a lambda + /** @brief runtime bindings for arguments to a lambda **/ class DLocalEnv { public: diff --git a/xo-interpreter2/include/xo/interpreter2/DVsmRcx.hpp b/xo-interpreter2/include/xo/interpreter2/DVsmRcx.hpp new file mode 100644 index 00000000..3506206e --- /dev/null +++ b/xo-interpreter2/include/xo/interpreter2/DVsmRcx.hpp @@ -0,0 +1,2 @@ +/** @file DVsmRcx.hpp +n* diff --git a/xo-interpreter2/include/xo/interpreter2/VirtualSchematikaMachine.hpp b/xo-interpreter2/include/xo/interpreter2/VirtualSchematikaMachine.hpp index d06deb26..7a209bf1 100644 --- a/xo-interpreter2/include/xo/interpreter2/VirtualSchematikaMachine.hpp +++ b/xo-interpreter2/include/xo/interpreter2/VirtualSchematikaMachine.hpp @@ -194,6 +194,9 @@ namespace xo { // for VM stack. Only works for code that doesn't rely on fancy // lexical scoping + // consider separate allocator for reader (i.e. program code) + // and data (program execution) + /** reader: text -> expression **/ SchematikaReader reader_; @@ -206,6 +209,16 @@ namespace xo { /** expression register **/ obj expr_; + /** environment pointer. Provides bindings + * for surrounding lexical scope at this point + * in execution + **/ + DLocalEnv * local_env_ = nullptr; + /** environment pointer. Maintains bindings + * for global variables. + **/ + DGlobalEnv * global_env_ = nullptr; + /** function to call **/ obj fn_; /** evaluated argument list **/ diff --git a/xo-interpreter2/src/interpreter2/VirtualSchematikaMachine.cpp b/xo-interpreter2/src/interpreter2/VirtualSchematikaMachine.cpp index 1395209a..767ef784 100644 --- a/xo-interpreter2/src/interpreter2/VirtualSchematikaMachine.cpp +++ b/xo-interpreter2/src/interpreter2/VirtualSchematikaMachine.cpp @@ -36,7 +36,9 @@ namespace xo { mm_(box(new DX1Collector(config.x1_config_))), rcx_(box(new DSimpleRcx(mm_.to_op()))), reader_{config.rdr_config_, mm_.to_op()} - {} + { + // TODO: allocate global_env + } void VirtualSchematikaMachine::visit_pools(const MemorySizeVisitor & visitor) const @@ -202,6 +204,30 @@ namespace xo { void VirtualSchematikaMachine::_do_eval_lambda_op() { + // assuming bump allocator + // + // +----------- DArray---------+ +-------------DLocalEnv-----------+ +-----DClosure-------+ + // | .cap |.size | .elts_[]... |h| .parent x | .symtab x | .args x |h| .lambda x | .env x | + // +------+------+-------------+ +---------|-+---------|-+-------|-+ +---------|-+------|-+ + // ^ ^ | | | | | + // \-----------------------------|---------|-----------|---------/ | | + // | | | | | + // \---------|-----------|-----------------------|--------/ + // | | | + // <--------------------------------------/ | | + // | | + // v v + // DLocalSymtab DLambdaExpr + // + // DClosure runtime procedure (created below) + // DArray bound non-local variables (established by VSM) + // DLocalEnv local environment (copy ref from VSM state) + // h alloc header + // DLocalSymtab local symbol table (created by parser) + // DLambdaExpr lambda expression (created by parser) + + DArray * args = + // not implemented assert(false); }