xo-interpreter2: work on global symtab [WIP]

This commit is contained in:
Roland Conybeare 2026-02-13 20:46:53 -05:00
commit f5afee2f54
2 changed files with 65 additions and 6 deletions

View file

@ -6,26 +6,43 @@
#pragma once
#include <xo/expression2/DGlobalSymtab.hpp>
#include <xo/object2/DList.hpp>
#include <xo/object2/DArray.hpp>
namespace xo {
namespace scm {
/** @brief runtime bindings for global variabels
*
* Implementation here uses a DArenaHashMap to hold <key,value> 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 MemorySizeVisitor = xo::mm::MemorySizeVisitor;
public:
DGlobalEnv() = default;
/** visit env-owned memory pools; call visitor(info) for each **/
void visit_pools(const MemorySizeVisitor & visitor) const;
protected: // temporary, to appease compiler
// 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;
/** 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;
};
}
}

View file

@ -202,7 +202,8 @@ namespace xo {
{
const auto & testname = Catch::getResultCapture().getCurrentTestName();
scope log(XO_DEBUG(true), xtag("test", testname));
constexpr bool c_debug_flag = false;
scope log(XO_DEBUG(c_debug_flag), xtag("test", testname));
VsmConfig cfg;
VirtualSchematikaMachine vsm(cfg);
@ -237,11 +238,52 @@ namespace xo {
vsm.visit_pools(visitor);
}
TEST_CASE("VirtualSchematikaMachine-if", "[interpreter2][VSM]")
{
const auto & testname = Catch::getResultCapture().getCurrentTestName();
constexpr bool c_debug_flag = true;
scope log(XO_DEBUG(c_debug_flag), xtag("test", testname));
VsmConfig cfg;
VirtualSchematikaMachine vsm(cfg);
bool eof_flag = false;
vsm.begin_interactive_session();
VsmResultExt res = vsm.read_eval_print(span_type::from_cstr("if 123 == 123 then \"equal\" else \"notequal\";"), eof_flag);
REQUIRE(res.is_value());
REQUIRE(res.value());
log && log(xtag("res.tseq", res.value()->_typeseq()));
auto x = obj<AGCObject,DBoolean>::from(*res.value());
REQUIRE(x);
REQUIRE(x.data()->value() == true);
REQUIRE(res.remaining_.size() == 1);
REQUIRE(*res.remaining_.lo() == '\n');
auto visitor = [&log](const MemorySizeInfo & info) {
log && log(xtag("resource", info.resource_name_),
xtag("used", info.used_),
xtag("alloc", info.allocated_),
xtag("commit", info.committed_),
xtag("resv", info.reserved_));
};
FacetRegistry::instance().visit_pools(visitor);
vsm.visit_pools(visitor);
}
TEST_CASE("VirtualSchematikaMachine-lambda1", "[interpreter2][VSM]")
{
const auto & testname = Catch::getResultCapture().getCurrentTestName();
scope log(XO_DEBUG(false), xtag("test", testname));
constexpr bool c_debug_flag = false;
scope log(XO_DEBUG(c_debug_flag), xtag("test", testname));
VsmConfig cfg;
VirtualSchematikaMachine vsm(cfg);