From a10c7dcab2412f205fa4d287a75eea83497e8dcf Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Sun, 1 Feb 2026 22:12:28 -0500 Subject: [PATCH] xo-interpreter2: work towards utest w/ vsm+reader [WIP] --- CMakeLists.txt | 2 +- .../interpreter2/VirtualSchematikaMachine.hpp | 14 ++++- include/xo/interpreter2/VsmConfig.hpp | 28 +++++++++ include/xo/interpreter2/init_interpreter2.hpp | 21 +++++++ src/interpreter2/CMakeLists.txt | 3 +- src/interpreter2/VirtualSchematikaMachine.cpp | 9 ++- src/interpreter2/init_interpreter2.cpp | 50 +++++++++++++++ utest/CMakeLists.txt | 11 ++++ utest/VirtualSchematikaMachine.test.cpp | 63 +++++++++++++++++++ utest/interpreter2_utest_main.cpp | 27 ++++++++ 10 files changed, 224 insertions(+), 4 deletions(-) create mode 100644 include/xo/interpreter2/VsmConfig.hpp create mode 100644 include/xo/interpreter2/init_interpreter2.hpp create mode 100644 src/interpreter2/init_interpreter2.cpp create mode 100644 utest/CMakeLists.txt create mode 100644 utest/VirtualSchematikaMachine.test.cpp create mode 100644 utest/interpreter2_utest_main.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index ac944a36..466e1a1c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,7 +21,7 @@ add_definitions(${PROJECT_CXX_FLAGS}) # output targets add_subdirectory(src/interpreter2) -#add_subdirectory(utest) +add_subdirectory(utest) xo_export_cmake_config(${PROJECT_NAME} ${PROJECT_VERSION} ${PROJECT_NAME}Targets) diff --git a/include/xo/interpreter2/VirtualSchematikaMachine.hpp b/include/xo/interpreter2/VirtualSchematikaMachine.hpp index 0f58f2c4..6e1595da 100644 --- a/include/xo/interpreter2/VirtualSchematikaMachine.hpp +++ b/include/xo/interpreter2/VirtualSchematikaMachine.hpp @@ -5,9 +5,12 @@ #pragma once +#include "VsmConfig.hpp" #include "VsmInstr.hpp" +#include #include #include +#include namespace xo { namespace scm { @@ -18,10 +21,11 @@ namespace xo { public: // will be DArenaVector> probably using Stack = void *; + using AAllocator = xo::mm::AAllocator; using AGCObject = xo::mm::AGCObject; public: - VirtualSchematikaMachine(); + VirtualSchematikaMachine(const VsmConfig & config); /** borrow calling thread to run indefinitely, * until halt instruction @@ -93,6 +97,14 @@ namespace xo { * value_ */ + /** configuration **/ + VsmConfig config_; + + box mm_; + + /** reader: text -> expression **/ + SchematikaReader reader_; + /** program counter **/ VsmInstr pc_ = VsmInstr::halt(); diff --git a/include/xo/interpreter2/VsmConfig.hpp b/include/xo/interpreter2/VsmConfig.hpp new file mode 100644 index 00000000..5071c020 --- /dev/null +++ b/include/xo/interpreter2/VsmConfig.hpp @@ -0,0 +1,28 @@ +/** @file VsmConfig.hpp +* + * @author Roland Conybeare, Jan 2026 + **/ + +#pragma once + +#include +#include + +namespace xo { + namespace scm { + /** Configuration for virtual schematika machine + **/ + struct VsmConfig { + using X1CollectorConfig = xo::mm::X1CollectorConfig; + + /** reader configuration **/ + ReaderConfig rdr_config_; + /** Configuration for allocator/collector. + * TODO: may want to make CollectorConfig polymorphic + **/ + X1CollectorConfig x1_config_ = X1CollectorConfig().with_size(4*1024*1024); + }; + } /*namespace scm*/ +} /*namespace xo*/ + +/* end VsmConfig.hpp */ diff --git a/include/xo/interpreter2/init_interpreter2.hpp b/include/xo/interpreter2/init_interpreter2.hpp new file mode 100644 index 00000000..87e93438 --- /dev/null +++ b/include/xo/interpreter2/init_interpreter2.hpp @@ -0,0 +1,21 @@ +/** @file init_interpreter2.hpp + * + * @author Roland Conybeare, Jan 2026 + **/ + +#pragma once + +#include + +namespace xo { + /* tag to represent the xo-interpreter2/ subsystem within ordered initialization */ + enum S_interpreter2_tag {}; + + template <> + struct InitSubsys { + static void init(); + static InitEvidence require(); + }; +} /*namespace xo*/ + +/* end init_interpreter2.hpp */ diff --git a/src/interpreter2/CMakeLists.txt b/src/interpreter2/CMakeLists.txt index 15d06fdf..7d9cd250 100644 --- a/src/interpreter2/CMakeLists.txt +++ b/src/interpreter2/CMakeLists.txt @@ -2,6 +2,7 @@ set(SELF_LIB xo_interpreter2) set(SELF_SRCS + init_interpreter2.cpp VirtualSchematikaMachine.cpp #IExpression_Any.cpp #interpreter2_register_facets.cpp @@ -9,7 +10,7 @@ set(SELF_SRCS xo_add_shared_library4(${SELF_LIB} ${PROJECT_NAME}Targets ${PROJECT_VERSION} 1 ${SELF_SRCS}) # note: deps here must also appear in cmake/xo_interpreter2Config.cmake.in -xo_dependency(${SELF_LIB} xo_expression2) +xo_dependency(${SELF_LIB} xo_reader2) xo_dependency(${SELF_LIB} xo_gc) #xo_dependency(${SELF_LIB} reflect) #xo_dependency(${SELF_LIB} xo_printable2) diff --git a/src/interpreter2/VirtualSchematikaMachine.cpp b/src/interpreter2/VirtualSchematikaMachine.cpp index 02ed023a..f7e8259e 100644 --- a/src/interpreter2/VirtualSchematikaMachine.cpp +++ b/src/interpreter2/VirtualSchematikaMachine.cpp @@ -6,12 +6,19 @@ #include "VirtualSchematikaMachine.hpp" #include #include +#include +#include #include namespace xo { + using xo::mm::DX1Collector; + namespace scm { - VirtualSchematikaMachine::VirtualSchematikaMachine() + VirtualSchematikaMachine::VirtualSchematikaMachine(const VsmConfig & config) + : config_{config}, + mm_(box(new DX1Collector(config.x1_config_))), + reader_{config.rdr_config_, mm_.to_op()} {} void diff --git a/src/interpreter2/init_interpreter2.cpp b/src/interpreter2/init_interpreter2.cpp new file mode 100644 index 00000000..b0e8a71c --- /dev/null +++ b/src/interpreter2/init_interpreter2.cpp @@ -0,0 +1,50 @@ +/** @file init_interpreter2.cpp + * + * @author Roland Conybeare, Jan 2026 + **/ + +#include "init_interpreter2.hpp" + +#ifdef NOT_YET +#include "interpreter2_register_facets.hpp" +#include "interpreter2_register_types.hpp" +#endif + +#include +#ifdef NOT_YET +#include +#endif + +namespace xo { +#ifdef NOT_YET + using xo::scm::interpreter2_register_facets; + using xo::scm::interpreter2_register_types; + using xo::mm::CollectorTypeRegistry; +#endif + + void + InitSubsys::init() + { +#ifdef NOT_YET + interpreter2_register_facets(); + + CollectorTypeRegistry::instance().register_types(&interpreter2_register_types); +#endif + } + + InitEvidence + InitSubsys::require() + { + InitEvidence retval; + + /* direct subsystem deps for xo-interpreter2/ */ + retval ^= InitSubsys::require(); + + /* xo-interpreter2/'s own initialization code */ + retval ^= Subsystem::provide("interpreter2", &init); + + return retval; + } +} /*namespace xo*/ + +/* end init_interpreter2.cpp */ diff --git a/utest/CMakeLists.txt b/utest/CMakeLists.txt new file mode 100644 index 00000000..e45cffaa --- /dev/null +++ b/utest/CMakeLists.txt @@ -0,0 +1,11 @@ +# build unittest xo-interpreter2/utest + +set(UTEST_EXE utest.interpreter2) +set(UTEST_SRCS + interpreter2_utest_main.cpp + VirtualSchematikaMachine.test.cpp +) + +xo_add_utest_executable(${UTEST_EXE} ${UTEST_SRCS}) +xo_self_dependency(${UTEST_EXE} xo_interpreter2) +xo_external_target_dependency(${UTEST_EXE} Catch2 Catch2::Catch2) diff --git a/utest/VirtualSchematikaMachine.test.cpp b/utest/VirtualSchematikaMachine.test.cpp new file mode 100644 index 00000000..29301b1f --- /dev/null +++ b/utest/VirtualSchematikaMachine.test.cpp @@ -0,0 +1,63 @@ +/** @file VirtualSchematikaMachine.test.cpp + * + * @author Roland Conybeare, Jan 2026 + **/ + +#include + +#ifdef NOT_YET +#include +#include +#include +#include +#include +#endif +#include +#ifdef NOT_YET +#include +#endif + +#include + +namespace xo { +#ifdef NOT_YET + using xo::scm::SchematikaParser; + using xo::scm::ASyntaxStateMachine; + using xo::scm::syntaxstatetype; +// using xo::scm::DDefineSsm; + using xo::scm::DExpectExprSsm; +// using xo::scm::defexprstatetype; + //using xo::scm::ParserResult; + //using xo::scm::parser_result_type; + using xo::scm::Token; + using xo::scm::DString; + using xo::mm::ArenaConfig; + using xo::mm::AAllocator; + using xo::mm::DArena; + using xo::facet::with_facet; +#endif + + static InitEvidence s_init = (InitSubsys::require()); + + namespace ut { + TEST_CASE("VirtualSchematikaMachine-ctor", "[interpreter2][VSM]") + { +#ifdef NOT_YET + ArenaConfig config; + config.name_ = "test-arena"; + config.size_ = 16 * 1024; + + DArena expr_arena = DArena::map(config); + obj expr_alloc = with_facet::mkobj(&expr_arena); + + SchematikaParser parser(config, 4096, expr_alloc, false /*debug_flag*/); + + REQUIRE(parser.debug_flag() == false); + REQUIRE(parser.is_at_toplevel() == true); +#endif + } + + } /*namespace ut*/ +} /*namespace xo*/ + +/* end SchematikaParser.test.cpp */ diff --git a/utest/interpreter2_utest_main.cpp b/utest/interpreter2_utest_main.cpp new file mode 100644 index 00000000..addc079a --- /dev/null +++ b/utest/interpreter2_utest_main.cpp @@ -0,0 +1,27 @@ +/** @file interpreter2_utest_main.cpp + * + * @author Roland Conybeare, Jan 2026 + **/ + +#include + +#define CATCH_CONFIG_RUNNER +#include "catch2/catch.hpp" + +int +main(int argc, char* argv[]) +{ + using xo::Subsystem; + + // initialize subsystems + Subsystem::initialize_all(); + + // Run Catch2's test session + int result = Catch::Session().run(argc, argv); + + // cleanup here, if any + + return result; +} + +/* end interpreter2_utest_main.cpp */