xo-interpreter2: + DVsmRcx. runtime context for vsm

This commit is contained in:
Roland Conybeare 2026-02-12 16:05:22 -05:00
commit c60a2506fc
6 changed files with 113 additions and 4 deletions

View file

@ -1,2 +1,36 @@
/** @file DVsmRcx.hpp
n*
*
* @author Roland Conybeare, Feb 2026
**/
#pragma once
#include <xo/alloc2/Allocator.hpp>
namespace xo {
namespace scm {
// see xo-interpreter/ VirtualSchematikaMachine.hpp
class VirtualSchematikaMachine;
/** @brief Runtime context for schematika interpreter
*
* Provides allocator
**/
class DVsmRcx {
public:
using AAllocator = xo::mm::AAllocator;
public:
DVsmRcx(VirtualSchematikaMachine * vsm);
obj<AAllocator> allocator() const noexcept;
private:
/** schematika interpreter **/
VirtualSchematikaMachine * vsm_ = nullptr;;
};
} /*namespace scm*/
} /*namespace xo*/
/* end DVsmRcx.hpp */

View file

@ -70,6 +70,9 @@ namespace xo {
public:
VirtualSchematikaMachine(const VsmConfig & config);
/** allocator for schematika data **/
obj<AAllocator> allocator() const noexcept;
/** visit vsm-owned memory pools; call visitor(info) for each **/
void visit_pools(const MemorySizeVisitor & visitor) const;

View file

@ -25,10 +25,9 @@ set(SELF_SRCS
IPrintable_DLocalEnv.cpp
DLocalEnv.cpp
DVsmRcx.cpp
VsmInstr.cpp
#IExpression_Any.cpp
)
xo_add_shared_library4(${SELF_LIB} ${PROJECT_NAME}Targets ${PROJECT_VERSION} 1 ${SELF_SRCS})

View file

@ -0,0 +1,25 @@
/** @file DVsmRcx.cpp
*
* @author Roland Conybeare, Feb 2026
**/
#include "DVsmRcx.hpp"
#include "VirtualSchematikaMachine.hpp"
namespace xo {
using xo::mm::AAllocator;
namespace scm {
DVsmRcx::DVsmRcx(VirtualSchematikaMachine * vsm) : vsm_{vsm} {}
obj<AAllocator>
DVsmRcx::allocator() const noexcept
{
return vsm_->allocator();
}
} /*namespace scm*/
} /*namespace xo*/
/* end DVsmRcx.cpp */

View file

@ -24,6 +24,7 @@ namespace xo {
using xo::print::ppstate_standalone;
using xo::mm::AGCObject;
//using xo::mm::MemorySizeInfo; // not used yet
using xo::mm::AAllocator;
using xo::mm::DX1Collector;
using xo::facet::FacetRegistry;
using std::cout;
@ -42,6 +43,12 @@ namespace xo {
// TODO: allocate global_env
}
obj<AAllocator>
VirtualSchematikaMachine::allocator() const noexcept
{
return mm_.to_op();
}
void
VirtualSchematikaMachine::visit_pools(const MemorySizeVisitor & visitor) const
{

View file

@ -225,6 +225,47 @@ namespace xo {
vsm.visit_pools(visitor);
}
#ifdef NOT_YET
TEST_CASE("VirtualSchematikaMachine-apply2", "[interpreter2][VSM]")
{
scope log(XO_DEBUG(true));
VsmConfig cfg;
VirtualSchematikaMachine vsm(cfg);
bool eof_flag = false;
vsm.begin_interactive_session();
VsmResultExt res
= vsm.read_eval_print(span_type::from_cstr
("(lambda (x : i64, y : i64) { x * y; })(13, 15);"),
eof_flag);
REQUIRE(res.is_value());
REQUIRE(res.value());
log && log(xtag("res.tseq", res.value()->_typeseq()));
auto x = obj<AGCObject,DClosure>::from(*res.value());
REQUIRE(x);
//REQUIRE(x.data()->value() == 1.570796325);
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);
}
#endif
} /*namespace ut*/
} /*namespace xo*/