xo-interpreter2: work towards utest w/ vsm+reader [WIP]

This commit is contained in:
Roland Conybeare 2026-02-01 22:12:28 -05:00
commit a10c7dcab2
10 changed files with 224 additions and 4 deletions

View file

@ -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)

View file

@ -5,9 +5,12 @@
#pragma once
#include "VsmConfig.hpp"
#include "VsmInstr.hpp"
#include <xo/reader2/SchematikaReader.hpp>
#include <xo/expression2/Expression.hpp>
#include <xo/gc/GCObject.hpp>
#include <xo/facet/box.hpp>
namespace xo {
namespace scm {
@ -18,10 +21,11 @@ namespace xo {
public:
// will be DArenaVector<obj<StackFrame>> 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<AAllocator> mm_;
/** reader: text -> expression **/
SchematikaReader reader_;
/** program counter **/
VsmInstr pc_ = VsmInstr::halt();

View file

@ -0,0 +1,28 @@
/** @file VsmConfig.hpp
*
* @author Roland Conybeare, Jan 2026
**/
#pragma once
#include <xo/reader2/ReaderConfig.hpp>
#include <xo/gc/X1CollectorConfig.hpp>
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 */

View file

@ -0,0 +1,21 @@
/** @file init_interpreter2.hpp
*
* @author Roland Conybeare, Jan 2026
**/
#pragma once
#include <xo/subsys/Subsystem.hpp>
namespace xo {
/* tag to represent the xo-interpreter2/ subsystem within ordered initialization */
enum S_interpreter2_tag {};
template <>
struct InitSubsys<S_interpreter2_tag> {
static void init();
static InitEvidence require();
};
} /*namespace xo*/
/* end init_interpreter2.hpp */

View file

@ -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)

View file

@ -6,12 +6,19 @@
#include "VirtualSchematikaMachine.hpp"
#include <xo/expression2/detail/IExpression_DConstant.hpp>
#include <xo/expression2/DConstant.hpp>
#include <xo/gc/DX1Collector.hpp>
#include <xo/gc/detail/IAllocator_DX1Collector.hpp>
#include <cassert>
namespace xo {
using xo::mm::DX1Collector;
namespace scm {
VirtualSchematikaMachine::VirtualSchematikaMachine()
VirtualSchematikaMachine::VirtualSchematikaMachine(const VsmConfig & config)
: config_{config},
mm_(box<AAllocator,DX1Collector>(new DX1Collector(config.x1_config_))),
reader_{config.rdr_config_, mm_.to_op()}
{}
void

View file

@ -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 <xo/reader2/init_reader2.hpp>
#ifdef NOT_YET
#include <xo/gc/CollectorTypeRegistry.hpp>
#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<S_interpreter2_tag>::init()
{
#ifdef NOT_YET
interpreter2_register_facets();
CollectorTypeRegistry::instance().register_types(&interpreter2_register_types);
#endif
}
InitEvidence
InitSubsys<S_interpreter2_tag>::require()
{
InitEvidence retval;
/* direct subsystem deps for xo-interpreter2/ */
retval ^= InitSubsys<S_reader2_tag>::require();
/* xo-interpreter2/'s own initialization code */
retval ^= Subsystem::provide<S_interpreter2_tag>("interpreter2", &init);
return retval;
}
} /*namespace xo*/
/* end init_interpreter2.cpp */

11
utest/CMakeLists.txt Normal file
View file

@ -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)

View file

@ -0,0 +1,63 @@
/** @file VirtualSchematikaMachine.test.cpp
*
* @author Roland Conybeare, Jan 2026
**/
#include <xo/interpreter2/VirtualSchematikaMachine.hpp>
#ifdef NOT_YET
#include <xo/reader2/SchematikaParser.hpp>
#include <xo/reader2/DDefineSsm.hpp>
#include <xo/reader2/DExpectExprSsm.hpp>
#include <xo/reader2/ssm/ISyntaxStateMachine_DExpectExprSsm.hpp>
#include <xo/reader2/ssm/ISyntaxStateMachine_DDefineSsm.hpp>
#endif
#include <xo/interpreter2/init_interpreter2.hpp>
#ifdef NOT_YET
#include <xo/alloc2/arena/IAllocator_DArena.hpp>
#endif
#include <catch2/catch.hpp>
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<S_interpreter2_tag>::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<AAllocator> expr_alloc = with_facet<AAllocator>::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 */

View file

@ -0,0 +1,27 @@
/** @file interpreter2_utest_main.cpp
*
* @author Roland Conybeare, Jan 2026
**/
#include <xo/subsys/Subsystem.hpp>
#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 */