xo-interpreter2: refactor to setup vsm utest + repl

This commit is contained in:
Roland Conybeare 2026-02-02 10:53:28 -05:00
commit 7028fa49f8
12 changed files with 133 additions and 43 deletions

View file

@ -27,6 +27,9 @@ namespace xo {
RAllocator() {}
RAllocator(Object::DataPtr data) : Object{std::move(data)} {}
RAllocator(const AAllocator * iface, void * data)
requires std::is_same_v<typename Object::DataType, xo::facet::DVariantPlaceholder>
: Object(iface, data) {}
typeseq _typeseq() const noexcept { return O::iface()->_typeseq(); }
void _drop() const noexcept { O::iface()->_drop(O::data()); }

View file

@ -47,7 +47,7 @@ namespace ut {
using xo::mm::ACollector;
using xo::mm::AGCObject;
using xo::mm::DX1Collector;
using xo::mm::CollectorConfig;
using xo::mm::X1CollectorConfig;
using xo::mm::ArenaConfig;
using xo::print::APrintable;
using xo::print::ppstate_standalone;
@ -71,7 +71,7 @@ namespace ut {
{
REQUIRE(s_init.evidence());
CollectorConfig cfg{
X1CollectorConfig cfg{
.name_ = "dapplyexpr_make2_test",
.arena_config_ = ArenaConfig{
.size_ = 8192,
@ -111,7 +111,7 @@ namespace ut {
{
REQUIRE(s_init.evidence());
CollectorConfig cfg{
X1CollectorConfig cfg{
.name_ = "dapplyexpr_extype_test",
.arena_config_ = ArenaConfig{
.size_ = 8192,
@ -146,7 +146,7 @@ namespace ut {
{
REQUIRE(s_init.evidence());
CollectorConfig cfg{
X1CollectorConfig cfg{
.name_ = "dapplyexpr_n_args_test",
.arena_config_ = ArenaConfig{
.size_ = 8192,
@ -181,7 +181,7 @@ namespace ut {
{
REQUIRE(s_init.evidence());
CollectorConfig cfg{
X1CollectorConfig cfg{
.name_ = "dapplyexpr_fn_test",
.arena_config_ = ArenaConfig{
.size_ = 8192,
@ -219,7 +219,7 @@ namespace ut {
{
REQUIRE(s_init.evidence());
CollectorConfig cfg{
X1CollectorConfig cfg{
.name_ = "dapplyexpr_arg_test",
.arena_config_ = ArenaConfig{
.size_ = 8192,
@ -263,7 +263,7 @@ namespace ut {
REQUIRE(s_init.evidence());
CollectorConfig cfg{
X1CollectorConfig cfg{
.name_ = "dapplyexpr_pretty_test",
.arena_config_ = ArenaConfig{
.size_ = 8192,

View file

@ -39,7 +39,7 @@ namespace ut {
using xo::mm::ACollector;
using xo::mm::AGCObject;
using xo::mm::DX1Collector;
using xo::mm::CollectorConfig;
using xo::mm::X1CollectorConfig;
using xo::mm::ArenaConfig;
using xo::print::APrintable;
using xo::print::ppstate_standalone;
@ -66,7 +66,7 @@ namespace ut {
{
REQUIRE(s_init.evidence());
CollectorConfig cfg{
X1CollectorConfig cfg{
.name_ = "dconstant_float_test",
.arena_config_ = ArenaConfig{
.size_ = 8192,
@ -105,7 +105,7 @@ namespace ut {
{
REQUIRE(s_init.evidence());
CollectorConfig cfg{
X1CollectorConfig cfg{
.name_ = "dconstant_int_test",
.arena_config_ = ArenaConfig{
.size_ = 8192,
@ -146,7 +146,7 @@ namespace ut {
REQUIRE(s_init.evidence());
CollectorConfig cfg{
X1CollectorConfig cfg{
.name_ = "dconstant_pp_float_test",
.arena_config_ = ArenaConfig{
.size_ = 8192,
@ -190,7 +190,7 @@ namespace ut {
REQUIRE(s_init.evidence());
CollectorConfig cfg{
X1CollectorConfig cfg{
.name_ = "dconstant_pp_int_test",
.arena_config_ = ArenaConfig{
.size_ = 8192,

View file

@ -44,7 +44,7 @@ namespace ut {
using xo::mm::ACollector;
using xo::mm::AGCObject;
using xo::mm::DX1Collector;
using xo::mm::CollectorConfig;
using xo::mm::X1CollectorConfig;
using xo::mm::ArenaConfig;
using xo::print::APrintable;
using xo::print::ppstate_standalone;
@ -68,7 +68,7 @@ namespace ut {
{
REQUIRE(s_init.evidence());
CollectorConfig cfg{
X1CollectorConfig cfg{
.name_ = "ddefineexpr_make_test",
.arena_config_ = ArenaConfig{
.size_ = 8192,
@ -103,7 +103,7 @@ namespace ut {
{
REQUIRE(s_init.evidence());
CollectorConfig cfg{
X1CollectorConfig cfg{
.name_ = "ddefineexpr_lhs_test",
.arena_config_ = ArenaConfig{
.size_ = 8192,
@ -138,7 +138,7 @@ namespace ut {
{
REQUIRE(s_init.evidence());
CollectorConfig cfg{
X1CollectorConfig cfg{
.name_ = "ddefineexpr_rhs_test",
.arena_config_ = ArenaConfig{
.size_ = 8192,
@ -174,7 +174,7 @@ namespace ut {
{
REQUIRE(s_init.evidence());
CollectorConfig cfg{
X1CollectorConfig cfg{
.name_ = "ddefineexpr_name_test",
.arena_config_ = ArenaConfig{
.size_ = 8192,
@ -207,7 +207,7 @@ namespace ut {
{
REQUIRE(s_init.evidence());
CollectorConfig cfg{
X1CollectorConfig cfg{
.name_ = "ddefineexpr_extype_test",
.arena_config_ = ArenaConfig{
.size_ = 8192,
@ -239,7 +239,7 @@ namespace ut {
{
REQUIRE(s_init.evidence());
CollectorConfig cfg{
X1CollectorConfig cfg{
.name_ = "ddefineexpr_valuetype_test",
.arena_config_ = ArenaConfig{
.size_ = 8192,
@ -273,7 +273,7 @@ namespace ut {
REQUIRE(s_init.evidence());
CollectorConfig cfg{
X1CollectorConfig cfg{
.name_ = "ddefineexpr_pretty_test",
.arena_config_ = ArenaConfig{
.size_ = 8192,

View file

@ -42,15 +42,15 @@ namespace ut {
using xo::mm::ACollector;
using xo::mm::AGCObject;
using xo::mm::DX1Collector;
using xo::mm::CollectorConfig;
using xo::mm::X1CollectorConfig;
using xo::mm::ArenaConfig;
using xo::print::APrintable;
using xo::print::ppstate_standalone;
using xo::print::ppconfig;
using xo::facet::FacetRegistry;
//using xo::facet::FacetRegistry;
using xo::facet::with_facet;
using xo::facet::obj;
using xo::reflect::Reflect;
//using xo::reflect::Reflect;
using xo::InitEvidence;
using xo::InitSubsys;
using xo::scope;
@ -66,7 +66,7 @@ namespace ut {
{
REQUIRE(s_init.evidence());
CollectorConfig cfg{
X1CollectorConfig cfg{
.name_ = "difelseexpr_make_test",
.arena_config_ = ArenaConfig{
.size_ = 8192,
@ -107,7 +107,7 @@ namespace ut {
{
REQUIRE(s_init.evidence());
CollectorConfig cfg{
X1CollectorConfig cfg{
.name_ = "difelseexpr_test_test",
.arena_config_ = ArenaConfig{
.size_ = 8192,
@ -145,7 +145,7 @@ namespace ut {
{
REQUIRE(s_init.evidence());
CollectorConfig cfg{
X1CollectorConfig cfg{
.name_ = "difelseexpr_when_true_test",
.arena_config_ = ArenaConfig{
.size_ = 8192,
@ -183,7 +183,7 @@ namespace ut {
{
REQUIRE(s_init.evidence());
CollectorConfig cfg{
X1CollectorConfig cfg{
.name_ = "difelseexpr_when_false_test",
.arena_config_ = ArenaConfig{
.size_ = 8192,
@ -221,7 +221,7 @@ namespace ut {
{
REQUIRE(s_init.evidence());
CollectorConfig cfg{
X1CollectorConfig cfg{
.name_ = "difelseexpr_extype_test",
.arena_config_ = ArenaConfig{
.size_ = 8192,
@ -256,7 +256,7 @@ namespace ut {
{
REQUIRE(s_init.evidence());
CollectorConfig cfg{
X1CollectorConfig cfg{
.name_ = "difelseexpr_valuetype_test",
.arena_config_ = ArenaConfig{
.size_ = 8192,
@ -296,7 +296,7 @@ namespace ut {
REQUIRE(s_init.evidence());
CollectorConfig cfg{
X1CollectorConfig cfg{
.name_ = "difelseexpr_pretty_test",
.arena_config_ = ArenaConfig{
.size_ = 8192,

View file

@ -37,7 +37,7 @@ namespace ut {
using xo::mm::AAllocator;
using xo::mm::ACollector;
using xo::mm::DX1Collector;
using xo::mm::CollectorConfig;
using xo::mm::X1CollectorConfig;
using xo::mm::ArenaConfig;
using xo::print::APrintable;
using xo::print::ppstate_standalone;
@ -61,7 +61,7 @@ namespace ut {
{
REQUIRE(s_init.evidence());
CollectorConfig cfg{
X1CollectorConfig cfg{
.name_ = "dvariable_make_test",
.arena_config_ = ArenaConfig{
.size_ = 8192,
@ -92,7 +92,7 @@ namespace ut {
{
REQUIRE(s_init.evidence());
CollectorConfig cfg{
X1CollectorConfig cfg{
.name_ = "dvariable_extype_test",
.arena_config_ = ArenaConfig{
.size_ = 8192,
@ -122,7 +122,7 @@ namespace ut {
{
REQUIRE(s_init.evidence());
CollectorConfig cfg{
X1CollectorConfig cfg{
.name_ = "dvariable_valuetype_test",
.arena_config_ = ArenaConfig{
.size_ = 8192,
@ -152,7 +152,7 @@ namespace ut {
{
REQUIRE(s_init.evidence());
CollectorConfig cfg{
X1CollectorConfig cfg{
.name_ = "dvariable_name_test",
.arena_config_ = ArenaConfig{
.size_ = 8192,
@ -185,7 +185,7 @@ namespace ut {
REQUIRE(s_init.evidence());
CollectorConfig cfg{
X1CollectorConfig cfg{
.name_ = "dvariable_pretty_test",
.arena_config_ = ArenaConfig{
.size_ = 8192,

View file

@ -46,7 +46,7 @@ namespace xo {
box(box<AFacet, DOther> && other)
requires (std::is_same_v<DRepr, DVariantPlaceholder>
|| std::is_same_v<DRepr, DOther>)
: obj<AFacet,DRepr>()
: RoutingType<AFacet,OObject<AFacet,DRepr>>()
{
/* replacing .iface_ along w/ .data_ */
this->from_obj(other);
@ -55,8 +55,10 @@ namespace xo {
}
/** explicit conversion to obj<AFacet,DRepr> **/
obj<AFacet, DRepr> to_op() const noexcept { return obj<AFacet, DRepr>(this->iface(), this->data()); }
obj<AFacet, DRepr> to_op() const noexcept {
return obj<AFacet, DRepr>(this->iface(), this->data());
}
/** Take ownership from unowned object **/
template <typename DOther>
box & adopt(const obj<AFacet, DOther> & other)
@ -65,11 +67,11 @@ namespace xo {
{
/* replace .iface_ along w/ .data_ */
this->from_obj(other);
return *this;
}
~box() {
~box() {
auto p = this->data();
this->_drop();
::operator delete(p);

View file

@ -14,6 +14,23 @@
namespace xo {
namespace scm {
/** similar to @ref xo::scm::ReaderResult **/
struct VsmResult {
using AGCObject = xo::mm::AGCObject;
using span_type = xo::mm::span<const char>;
bool is_tk_error() const { return tk_error_.is_error(); }
/** result of evaluating first expression encountered in input **/
obj<AGCObject> value_;
/** unconsumed portion of input span **/
span_type remaining_input_;
/** {src_function, error_description, input_state, error_pos} **/
TokenizerError tk_error_;
};
/** @class VirtualSchematikaMachine
* @brief virtual machine for schematika
**/
@ -23,10 +40,17 @@ namespace xo {
using Stack = void *;
using AAllocator = xo::mm::AAllocator;
using AGCObject = xo::mm::AGCObject;
using span_type = xo::mm::span<const char>;
public:
VirtualSchematikaMachine(const VsmConfig & config);
/** consume input @p input_cstr **/
VsmResult read_eval_print(span_type input_span, bool eof);
/** evaluate expression @p expr **/
std::pair<obj<AGCObject>, TokenizerError> eval(obj<AExpression> expr);
/** borrow calling thread to run indefinitely,
* until halt instruction
**/

View file

@ -10,11 +10,13 @@
namespace xo {
namespace scm {
/** Configuration for virtual schematika machine
/** Configuration for virtual schematika machine
**/
struct VsmConfig {
using X1CollectorConfig = xo::mm::X1CollectorConfig;
VsmConfig() = default;
/** reader configuration **/
ReaderConfig rdr_config_;
/** Configuration for allocator/collector.

View file

@ -8,10 +8,18 @@
#include <xo/expression2/DConstant.hpp>
#include <xo/gc/DX1Collector.hpp>
#include <xo/gc/detail/IAllocator_DX1Collector.hpp>
#include <xo/printable2/Printable.hpp>
#include <xo/facet/FacetRegistry.hpp>
#include <cassert>
namespace xo {
using xo::print::APrintable;
using xo::print::ppconfig;
using xo::print::ppstate_standalone;
using xo::mm::AGCObject;
using xo::mm::DX1Collector;
using xo::facet::FacetRegistry;
using std::cout;
namespace scm {
@ -21,6 +29,52 @@ namespace xo {
reader_{config.rdr_config_, mm_.to_op()}
{}
VsmResult
VirtualSchematikaMachine::read_eval_print(span_type input, bool eof)
{
if (input.empty()) {
return VsmResult();
}
auto [expr, remaining, error1]
= reader_.read_expr(input, eof);
if (!expr) {
return {
.remaining_input_ = remaining,
.tk_error_ = error1
};
}
auto [value, error2] = this->eval(expr);
if (!value) {
return {
.remaining_input_ = remaining,
.tk_error_ = error2
};
}
obj<APrintable> value_pr
= FacetRegistry::instance().variant<APrintable,AGCObject>(value);
// pretty_toplevel(value_pr, &cout, ppconfig());
ppconfig ppc;
ppstate_standalone pps(&cout, 0, &ppc);
pps.prettyn(value_pr);
return { .remaining_input_ = remaining };
}
std::pair<obj<AGCObject>, TokenizerError>
VirtualSchematikaMachine::eval(obj<AExpression> expr)
{
(void)expr;
assert(false);
return std::make_pair(obj<AGCObject>(), TokenizerError());
}
void
VirtualSchematikaMachine::run()
{

View file

@ -20,6 +20,9 @@
#include <catch2/catch.hpp>
namespace xo {
using xo::scm::VirtualSchematikaMachine;
using xo::scm::VsmConfig;
#ifdef NOT_YET
using xo::scm::SchematikaParser;
using xo::scm::ASyntaxStateMachine;
@ -42,6 +45,8 @@ namespace xo {
namespace ut {
TEST_CASE("VirtualSchematikaMachine-ctor", "[interpreter2][VSM]")
{
VirtualSchematikaMachine vsm(VsmConfig);
#ifdef NOT_YET
ArenaConfig config;
config.name_ = "test-arena";

View file

@ -41,7 +41,7 @@ namespace xo {
size_t max_stringtable_cap_ = 64*1024;
/** debug flag for schematika_reader **/
bool reader_debug_flag_ = false;;
bool reader_debug_flag_ = false;
};
} /*namespace scm*/