diff --git a/xo-expression2/CMakeLists.txt b/xo-expression2/CMakeLists.txt index a9060ce1..d826a155 100644 --- a/xo-expression2/CMakeLists.txt +++ b/xo-expression2/CMakeLists.txt @@ -317,7 +317,7 @@ xo_add_genfacetimpl( TARGET xo-expression2-facetimpl-printable-uniquestring FACET_PKG xo_printable2 FACET Printable - REPR DUniqueString + REPR UniqueString INPUT idl/IPrintable_DUniqueString.json5 OUTPUT_HPP_DIR include/xo/expression2 OUTPUT_IMPL_SUBDIR detail diff --git a/xo-interpreter/src/interpreter/VirtualSchematikaMachine.cpp b/xo-interpreter/src/interpreter/VirtualSchematikaMachine.cpp index 9a9c7ddf..25f620b0 100644 --- a/xo-interpreter/src/interpreter/VirtualSchematikaMachine.cpp +++ b/xo-interpreter/src/interpreter/VirtualSchematikaMachine.cpp @@ -189,7 +189,8 @@ namespace xo { VirtualSchematikaMachine::execute_one() { scope log(XO_DEBUG(true)); - log && log("stack", stack_); + log && log(xtag("pc", pc_), xtag("cont", cont_)); + log && log(xtag("stack", stack_)); using Opcode = VsmInstr::Opcode; diff --git a/xo-interpreter2/CMakeLists.txt b/xo-interpreter2/CMakeLists.txt index 466e1a1c..259c3f03 100644 --- a/xo-interpreter2/CMakeLists.txt +++ b/xo-interpreter2/CMakeLists.txt @@ -23,6 +23,65 @@ add_definitions(${PROJECT_CXX_FLAGS}) add_subdirectory(src/interpreter2) add_subdirectory(utest) +# ---------------------------------------------------------------- + +# note: manual target; generated code committed to git +xo_add_genfacetimpl( + TARGET xo-interpreter2-facetimpl-gcobject-vsmapplyframe + FACET_PKG xo_gc + FACET GCObject + REPR VsmApplyFrame + INPUT idl/IGCObject_DVsmApplyFrame.json5 + OUTPUT_HPP_DIR include/xo/interpreter2 + OUTPUT_IMPL_SUBDIR detail + OUTPUT_CPP_DIR src/interpreter2 +) + +# note: manual target; generated code committed to git +xo_add_genfacetimpl( + TARGET xo-interpreter2-facetimpl-printable-vsmapplyframe + FACET_PKG xo_printable2 + FACET Printable + REPR VsmApplyFrame + INPUT idl/IPrintable_DVsmApplyFrame.json5 + OUTPUT_HPP_DIR include/xo/interpreter2 + OUTPUT_IMPL_SUBDIR detail + OUTPUT_CPP_DIR src/interpreter2 +) + +# ---------------------------------------------------------------- + +# note: manual target; generated code committed to git +xo_add_genfacetimpl( + TARGET xo-interpreter2-facetimpl-gcobject-vsmevalargsframe + FACET_PKG xo_gc + FACET GCObject + REPR VsmEvalArgsFrame + INPUT idl/IGCObject_DVsmEvalArgsFrame.json5 + OUTPUT_HPP_DIR include/xo/interpreter2 + OUTPUT_IMPL_SUBDIR detail + OUTPUT_CPP_DIR src/interpreter2 +) + +# note: manual target; generated code committed to git +xo_add_genfacetimpl( + TARGET xo-interpreter2-facetimpl-printable-vsmevalargsframe + FACET_PKG xo_printable2 + FACET Printable + REPR DVsmEvalArgsFrame + INPUT idl/IPrintable_DVsmEvalArgsFrame.json5 + OUTPUT_HPP_DIR include/xo/interpreter2 + OUTPUT_IMPL_SUBDIR detail + OUTPUT_CPP_DIR src/interpreter2 +) + +# ---------------------------------------------------------------- + +xo_add_genfacet_all(xo-interpreter2-genfacet-all) + +# ---------------------------------------------------------------- +# cmake helper (for external xo-interpreter2 users) + xo_export_cmake_config(${PROJECT_NAME} ${PROJECT_VERSION} ${PROJECT_NAME}Targets) # ---------------------------------------------------------------- diff --git a/xo-interpreter2/idl/IGCObject_DVsmApplyFrame.json5 b/xo-interpreter2/idl/IGCObject_DVsmApplyFrame.json5 new file mode 100644 index 00000000..979c14bf --- /dev/null +++ b/xo-interpreter2/idl/IGCObject_DVsmApplyFrame.json5 @@ -0,0 +1,15 @@ +{ + mode: "implementation", + includes: [ + "", + "" + ], + local_types: [ ], + namespace1: "xo", + namespace2: "scm", + facet_idl: "idl/GCObject.json5", + brief: "provide AGCObject interface for DVsmApplyFrame", + using_doxygen: true, + repr: "DVsmApplyFrame", + doc: [ "implement AGCObject for DVsmApplyFrame" ], +} diff --git a/xo-interpreter2/idl/IGCObject_DVsmEvalArgsFrame.json5 b/xo-interpreter2/idl/IGCObject_DVsmEvalArgsFrame.json5 new file mode 100644 index 00000000..8bebc6ec --- /dev/null +++ b/xo-interpreter2/idl/IGCObject_DVsmEvalArgsFrame.json5 @@ -0,0 +1,15 @@ +{ + mode: "implementation", + includes: [ + "", + "" + ], + local_types: [ ], + namespace1: "xo", + namespace2: "scm", + facet_idl: "idl/GCObject.json5", + brief: "provide AGCObject interface for DVsmEvalArgsFrame", + using_doxygen: true, + repr: "DVsmEvalArgsFrame", + doc: [ "implement AGCObject for DVsmEvalArgsFrame" ], +} diff --git a/xo-interpreter2/idl/IPrintable_DVsmApplyFrame.json5 b/xo-interpreter2/idl/IPrintable_DVsmApplyFrame.json5 new file mode 100644 index 00000000..f5957d7e --- /dev/null +++ b/xo-interpreter2/idl/IPrintable_DVsmApplyFrame.json5 @@ -0,0 +1,13 @@ +{ + mode: "implementation", + includes: [ "", + "" ], + local_types: [ ], + namespace1: "xo", + namespace2: "scm", + facet_idl: "idl/Printable.json5", + brief: "provide APrintable interface for DVsmApplyFrame", + using_doxygen: true, + repr: "DVsmApplyFrame", + doc: [ "implement APrintable for DVsmApplyFrame" ], +} diff --git a/xo-interpreter2/idl/IPrintable_DVsmEvalArgsFrame.json5 b/xo-interpreter2/idl/IPrintable_DVsmEvalArgsFrame.json5 new file mode 100644 index 00000000..24df6cbd --- /dev/null +++ b/xo-interpreter2/idl/IPrintable_DVsmEvalArgsFrame.json5 @@ -0,0 +1,13 @@ +{ + mode: "implementation", + includes: [ "", + "" ], + local_types: [ ], + namespace1: "xo", + namespace2: "scm", + facet_idl: "idl/Printable.json5", + brief: "provide APrintable interface for DVsmEvalArgsFrame", + using_doxygen: true, + repr: "DVsmEvalArgsFrame", + doc: [ "implement APrintable for DVsmEvalArgsFrame" ], +} diff --git a/xo-interpreter2/include/xo/interpreter2/DVsmApplyFrame.hpp b/xo-interpreter2/include/xo/interpreter2/DVsmApplyFrame.hpp new file mode 100644 index 00000000..d947a8bc --- /dev/null +++ b/xo-interpreter2/include/xo/interpreter2/DVsmApplyFrame.hpp @@ -0,0 +1,53 @@ +/** @file DVsmApplyFrame.hpp + * + * @author Roland Conybeare, Feb 2026 + **/ + +#pragma once + +#include "VsmFrame.hpp" + +namespace xo { + namespace scm { + class DVsmApplyFrame : public VsmFrame { + public: + using AProcedure = xo::scm::AProcedure; + using ACollector = xo::mm::ACollector; + using AAllocator = xo::mm::AAllocator; + using ppindentinfo = xo::print::ppindentinfo; + + public: + DVsmApplyFrame(obj old_parent, + VsmInstr old_cont, + DArray * args); + + static DVsmApplyFrame * make(obj mm, + obj old_parent, + VsmInstr old_cont, + DArray * args); + + obj fn() const noexcept { return fn_; } + DArray * args() const noexcept { return args_; } + + std::size_t shallow_size() const noexcept; + DVsmApplyFrame * shallow_copy(obj mm) const noexcept; + std::size_t forward_children(obj gc) noexcept; + + /** pretty-printing support **/ + bool pretty(const ppindentinfo & ppii) const; + + private: + /** evaluated target procedure. + * + * note: when initially created, this will be unpopulated; + * don't know correct value until we evaluate + * expression in head position + **/ + obj fn_; + /** evaluated arguments (to target procedure) **/ + DArray * args_; + }; + } /*namespace scm*/ +} /*namespace xo*/ + +/* end DVsmApplyFrame.hpp */ diff --git a/xo-interpreter2/include/xo/interpreter2/DVsmEvalArgsFrame.hpp b/xo-interpreter2/include/xo/interpreter2/DVsmEvalArgsFrame.hpp new file mode 100644 index 00000000..a8ef0226 --- /dev/null +++ b/xo-interpreter2/include/xo/interpreter2/DVsmEvalArgsFrame.hpp @@ -0,0 +1,48 @@ +/** @file DVsmEvalArgsFrame.hpp + * + * @author Roland Conybeare, Feb 2026 + **/ + +#pragma once + +#include "DVsmApplyFrame.hpp" + +namespace xo { + namespace scm { + + /** frame for executing an apply expression **/ + class DVsmEvalArgsFrame : public VsmFrame { + public: + using ACollector = xo::mm::ACollector; + using AAllocator = xo::mm::AAllocator; + using ppindentinfo = xo::print::ppindentinfo; + + public: + /** see picture in VirtualSchematikaMachine._do_eval_apply_op() + * + * old_parent = [apply frame] + * old_cont = [xfer to called function] + * + **/ + DVsmEvalArgsFrame(obj old_parent, + VsmInstr old_cont); + + static DVsmEvalArgsFrame * make(obj mm, + obj apply_frame, + VsmInstr old_cont); + + std::size_t shallow_size() const noexcept; + DVsmEvalArgsFrame * shallow_copy(obj mm) const noexcept; + std::size_t forward_children(obj gc) noexcept; + + bool pretty(const ppindentinfo & ppii) const; + + protected: + /** next argument to be evaluated. -1 means function head **/ + int32_t i_arg_ = -1; + }; + + } /*namespace scm*/ +} /*namespace xo*/ + +/* end DVsmEvalArgsFrame.hpp */ diff --git a/xo-interpreter2/include/xo/interpreter2/VirtualSchematikaMachine.hpp b/xo-interpreter2/include/xo/interpreter2/VirtualSchematikaMachine.hpp index 26366d50..78c2f3f7 100644 --- a/xo-interpreter2/include/xo/interpreter2/VirtualSchematikaMachine.hpp +++ b/xo-interpreter2/include/xo/interpreter2/VirtualSchematikaMachine.hpp @@ -181,7 +181,7 @@ namespace xo { VsmInstr pc_ = VsmInstr::c_halt; /** stack pointer **/ - VsmFrame * stack_ = nullptr; + obj stack_; /** expression register **/ obj expr_; diff --git a/xo-interpreter2/include/xo/interpreter2/VsmApplyFrame.hpp b/xo-interpreter2/include/xo/interpreter2/VsmApplyFrame.hpp new file mode 100644 index 00000000..5ed121ba --- /dev/null +++ b/xo-interpreter2/include/xo/interpreter2/VsmApplyFrame.hpp @@ -0,0 +1,12 @@ +/** @file VsmApplyFrame.hpp + * + * @author Roland Conybeare, Feb 2026 + **/ + +#pragma once + +#include "DVsmApplyFrame.hpp" +#include "detail/IGCObject_DVsmApplyFrame.hpp" +#include "detail/IPrintable_DVsmApplyFrame.hpp" + +/* end VsmApplyFrame.hpp */ diff --git a/xo-interpreter2/include/xo/interpreter2/VsmEvalArgsFrame.hpp b/xo-interpreter2/include/xo/interpreter2/VsmEvalArgsFrame.hpp new file mode 100644 index 00000000..8c45b25e --- /dev/null +++ b/xo-interpreter2/include/xo/interpreter2/VsmEvalArgsFrame.hpp @@ -0,0 +1,12 @@ +/** @file VsmEvalArgsFrame.hpp +* +* @author Roland Conybeare, Feb 2026 +**/ + +#pragma once + +#include "DVsmEvalArgsFrame.hpp" +#include "detail/IGCObject_DVsmEvalArgsFrame.hpp" +#include "detail/IPrintable_DVsmEvalArgsFrame.hpp" + +/* end VsmEvalArgsFrame.hpp */ diff --git a/xo-interpreter2/include/xo/interpreter2/VsmFrame.hpp b/xo-interpreter2/include/xo/interpreter2/VsmFrame.hpp index 09b542a8..f4cf5f1e 100644 --- a/xo-interpreter2/include/xo/interpreter2/VsmFrame.hpp +++ b/xo-interpreter2/include/xo/interpreter2/VsmFrame.hpp @@ -13,74 +13,26 @@ namespace xo { namespace scm { class VsmFrame { public: - VsmFrame(VsmFrame * parent, VsmInstr cont) : parent_{parent}, cont_{cont} {} + using AGCObject = xo::mm::AGCObject; - VsmFrame * parent() const noexcept { return parent_; } + public: + VsmFrame(obj parent, + VsmInstr cont) : parent_{parent}, cont_{cont} {} + + //obj parent() const noexcept { return parent_; } + VsmFrame * parent() const noexcept { + return reinterpret_cast(parent_.data()); + } VsmInstr cont() const noexcept { return cont_; } protected: /** saved VSM stack; restore when this frame consumed **/ - VsmFrame * parent_ = nullptr; + obj parent_; /** saved continuation; restore when this frame consumed **/ VsmInstr cont_; }; - class VsmApplyFrame : public VsmFrame { - public: - using AProcedure = xo::scm::AProcedure; - using AAllocator = xo::mm::AAllocator; - - public: - VsmApplyFrame(VsmFrame * old_parent, - VsmInstr old_cont, - DArray * args); - - static VsmApplyFrame * make(obj mm, - VsmFrame * old_parent, - VsmInstr old_cont, - DArray * args); - - obj fn() const noexcept { return fn_; } - DArray * args() const noexcept { return args_; } - - private: - /** evaluated target procedure. - * - * note: when initially created, this will be unpopulated; - * don't know correct value until we evaluate - * expression in head position - **/ - obj fn_; - /** evaluated arguments (to target procedure) **/ - DArray * args_; - }; - - /** frame for executing an apply expression **/ - class VsmEvalArgsFrame : public VsmFrame { - public: - using AAllocator = xo::mm::AAllocator; - - public: - /** see picture in VirtualSchematikaMachine._do_eval_apply_op() - * - * old_parent = [apply frame] - * old_cont = [xfer to called function] - * - **/ - VsmEvalArgsFrame(VsmApplyFrame * old_parent, - VsmInstr old_cont); - - static VsmEvalArgsFrame * make(obj mm, - VsmApplyFrame * apply_frame, - VsmInstr old_cont); - - private: - /** next argument to be evaluated. -1 means function head **/ - int32_t i_arg_ = -1; - }; - } /*namespace scm*/ } /*namespace xo*/ /* end VsmFrame.hpp */ - diff --git a/xo-interpreter2/include/xo/interpreter2/VsmInstr.hpp b/xo-interpreter2/include/xo/interpreter2/VsmInstr.hpp index a94ee625..ec836c4d 100644 --- a/xo-interpreter2/include/xo/interpreter2/VsmInstr.hpp +++ b/xo-interpreter2/include/xo/interpreter2/VsmInstr.hpp @@ -24,6 +24,12 @@ namespace xo { private: vsm_opcode opcode_; }; + + inline std::ostream & + operator<<(std::ostream & os, VsmInstr x) { + os << x.opcode(); + return os; + } } /*namespace scm*/ } /*namespace xo*/ diff --git a/xo-interpreter2/include/xo/interpreter2/VsmOpcode.hpp b/xo-interpreter2/include/xo/interpreter2/VsmOpcode.hpp index 6e41c5c1..2c58c04f 100644 --- a/xo-interpreter2/include/xo/interpreter2/VsmOpcode.hpp +++ b/xo-interpreter2/include/xo/interpreter2/VsmOpcode.hpp @@ -5,6 +5,7 @@ #pragma once +#include #include namespace xo { @@ -32,6 +33,16 @@ namespace xo { }; static constexpr uint32_t n_opcode = static_cast(vsm_opcode::N); + + /** stringified enum value **/ + const char * + vsm_opcode_descr(vsm_opcode x); + + inline std::ostream & + operator<<(std::ostream & os, vsm_opcode x) { + os << vsm_opcode_descr(x); + return os; + } } /*namespace scm*/ } /*namespace xo*/ diff --git a/xo-interpreter2/include/xo/interpreter2/detail/IGCObject_DVsmApplyFrame.hpp b/xo-interpreter2/include/xo/interpreter2/detail/IGCObject_DVsmApplyFrame.hpp new file mode 100644 index 00000000..ca6d3b10 --- /dev/null +++ b/xo-interpreter2/include/xo/interpreter2/detail/IGCObject_DVsmApplyFrame.hpp @@ -0,0 +1,67 @@ +/** @file IGCObject_DVsmApplyFrame.hpp + * + * Generated automagically from ingredients: + * 1. code generator: + * [xo-facet/codegen/genfacet] + * arguments: + * --input [idl/IGCObject_DVsmApplyFrame.json5] + * 2. jinja2 template for abstract facet .hpp file: + * [iface_facet_repr.hpp.j2] + * 3. idl for facet methods + * [idl/IGCObject_DVsmApplyFrame.json5] + **/ + +#pragma once + +#include "GCObject.hpp" +#include +#include +#include "DVsmApplyFrame.hpp" + +namespace xo { namespace scm { class IGCObject_DVsmApplyFrame; } } + +namespace xo { + namespace facet { + template <> + struct FacetImplementation + { + using ImplType = xo::mm::IGCObject_Xfer + ; + }; + } +} + +namespace xo { + namespace scm { + /** @class IGCObject_DVsmApplyFrame + **/ + class IGCObject_DVsmApplyFrame { + public: + /** @defgroup scm-gcobject-dvsmapplyframe-type-traits **/ + ///@{ + using size_type = xo::mm::AGCObject::size_type; + using AAllocator = xo::mm::AGCObject::AAllocator; + using ACollector = xo::mm::AGCObject::ACollector; + using Copaque = xo::mm::AGCObject::Copaque; + using Opaque = xo::mm::AGCObject::Opaque; + ///@} + /** @defgroup scm-gcobject-dvsmapplyframe-methods **/ + ///@{ + // const methods + /** memory consumption for this instance **/ + static size_type shallow_size(const DVsmApplyFrame & self) noexcept; + /** copy instance using allocator **/ + static Opaque shallow_copy(const DVsmApplyFrame & self, obj mm) noexcept; + + // non-const methods + /** during GC: forward immdiate children **/ + static size_type forward_children(DVsmApplyFrame & self, obj gc) noexcept; + ///@} + }; + + } /*namespace scm*/ +} /*namespace xo*/ + +/* end */ \ No newline at end of file diff --git a/xo-interpreter2/include/xo/interpreter2/detail/IGCObject_DVsmEvalArgsFrame.hpp b/xo-interpreter2/include/xo/interpreter2/detail/IGCObject_DVsmEvalArgsFrame.hpp new file mode 100644 index 00000000..4a8ad18a --- /dev/null +++ b/xo-interpreter2/include/xo/interpreter2/detail/IGCObject_DVsmEvalArgsFrame.hpp @@ -0,0 +1,67 @@ +/** @file IGCObject_DVsmEvalArgsFrame.hpp + * + * Generated automagically from ingredients: + * 1. code generator: + * [xo-facet/codegen/genfacet] + * arguments: + * --input [idl/IGCObject_DVsmEvalArgsFrame.json5] + * 2. jinja2 template for abstract facet .hpp file: + * [iface_facet_repr.hpp.j2] + * 3. idl for facet methods + * [idl/IGCObject_DVsmEvalArgsFrame.json5] + **/ + +#pragma once + +#include "GCObject.hpp" +#include +#include +#include "DVsmEvalArgsFrame.hpp" + +namespace xo { namespace scm { class IGCObject_DVsmEvalArgsFrame; } } + +namespace xo { + namespace facet { + template <> + struct FacetImplementation + { + using ImplType = xo::mm::IGCObject_Xfer + ; + }; + } +} + +namespace xo { + namespace scm { + /** @class IGCObject_DVsmEvalArgsFrame + **/ + class IGCObject_DVsmEvalArgsFrame { + public: + /** @defgroup scm-gcobject-dvsmevalargsframe-type-traits **/ + ///@{ + using size_type = xo::mm::AGCObject::size_type; + using AAllocator = xo::mm::AGCObject::AAllocator; + using ACollector = xo::mm::AGCObject::ACollector; + using Copaque = xo::mm::AGCObject::Copaque; + using Opaque = xo::mm::AGCObject::Opaque; + ///@} + /** @defgroup scm-gcobject-dvsmevalargsframe-methods **/ + ///@{ + // const methods + /** memory consumption for this instance **/ + static size_type shallow_size(const DVsmEvalArgsFrame & self) noexcept; + /** copy instance using allocator **/ + static Opaque shallow_copy(const DVsmEvalArgsFrame & self, obj mm) noexcept; + + // non-const methods + /** during GC: forward immdiate children **/ + static size_type forward_children(DVsmEvalArgsFrame & self, obj gc) noexcept; + ///@} + }; + + } /*namespace scm*/ +} /*namespace xo*/ + +/* end */ \ No newline at end of file diff --git a/xo-interpreter2/include/xo/interpreter2/detail/IPrintable_DVsmApplyFrame.hpp b/xo-interpreter2/include/xo/interpreter2/detail/IPrintable_DVsmApplyFrame.hpp new file mode 100644 index 00000000..af1a4e02 --- /dev/null +++ b/xo-interpreter2/include/xo/interpreter2/detail/IPrintable_DVsmApplyFrame.hpp @@ -0,0 +1,62 @@ +/** @file IPrintable_DVsmApplyFrame.hpp + * + * Generated automagically from ingredients: + * 1. code generator: + * [xo-facet/codegen/genfacet] + * arguments: + * --input [idl/IPrintable_DVsmApplyFrame.json5] + * 2. jinja2 template for abstract facet .hpp file: + * [iface_facet_repr.hpp.j2] + * 3. idl for facet methods + * [idl/IPrintable_DVsmApplyFrame.json5] + **/ + +#pragma once + +#include "Printable.hpp" +#include +#include +#include "DVsmApplyFrame.hpp" + +namespace xo { namespace scm { class IPrintable_DVsmApplyFrame; } } + +namespace xo { + namespace facet { + template <> + struct FacetImplementation + { + using ImplType = xo::print::IPrintable_Xfer + ; + }; + } +} + +namespace xo { + namespace scm { + /** @class IPrintable_DVsmApplyFrame + **/ + class IPrintable_DVsmApplyFrame { + public: + /** @defgroup scm-printable-dvsmapplyframe-type-traits **/ + ///@{ + using ppindentinfo = xo::print::APrintable::ppindentinfo; + using Copaque = xo::print::APrintable::Copaque; + using Opaque = xo::print::APrintable::Opaque; + ///@} + /** @defgroup scm-printable-dvsmapplyframe-methods **/ + ///@{ + // const methods + /** Pretty-printing support for this object. +See [xo-indentlog/xo/indentlog/pretty.hpp] **/ + static bool pretty(const DVsmApplyFrame & self, const ppindentinfo & ppii); + + // non-const methods + ///@} + }; + + } /*namespace scm*/ +} /*namespace xo*/ + +/* end */ \ No newline at end of file diff --git a/xo-interpreter2/include/xo/interpreter2/detail/IPrintable_DVsmEvalArgsFrame.hpp b/xo-interpreter2/include/xo/interpreter2/detail/IPrintable_DVsmEvalArgsFrame.hpp new file mode 100644 index 00000000..1c06f71e --- /dev/null +++ b/xo-interpreter2/include/xo/interpreter2/detail/IPrintable_DVsmEvalArgsFrame.hpp @@ -0,0 +1,62 @@ +/** @file IPrintable_DVsmEvalArgsFrame.hpp + * + * Generated automagically from ingredients: + * 1. code generator: + * [xo-facet/codegen/genfacet] + * arguments: + * --input [idl/IPrintable_DVsmEvalArgsFrame.json5] + * 2. jinja2 template for abstract facet .hpp file: + * [iface_facet_repr.hpp.j2] + * 3. idl for facet methods + * [idl/IPrintable_DVsmEvalArgsFrame.json5] + **/ + +#pragma once + +#include "Printable.hpp" +#include +#include +#include "DVsmEvalArgsFrame.hpp" + +namespace xo { namespace scm { class IPrintable_DVsmEvalArgsFrame; } } + +namespace xo { + namespace facet { + template <> + struct FacetImplementation + { + using ImplType = xo::print::IPrintable_Xfer + ; + }; + } +} + +namespace xo { + namespace scm { + /** @class IPrintable_DVsmEvalArgsFrame + **/ + class IPrintable_DVsmEvalArgsFrame { + public: + /** @defgroup scm-printable-dvsmevalargsframe-type-traits **/ + ///@{ + using ppindentinfo = xo::print::APrintable::ppindentinfo; + using Copaque = xo::print::APrintable::Copaque; + using Opaque = xo::print::APrintable::Opaque; + ///@} + /** @defgroup scm-printable-dvsmevalargsframe-methods **/ + ///@{ + // const methods + /** Pretty-printing support for this object. +See [xo-indentlog/xo/indentlog/pretty.hpp] **/ + static bool pretty(const DVsmEvalArgsFrame & self, const ppindentinfo & ppii); + + // non-const methods + ///@} + }; + + } /*namespace scm*/ +} /*namespace xo*/ + +/* end */ \ No newline at end of file diff --git a/xo-interpreter2/include/xo/interpreter2/interpreter2_register_facets.hpp b/xo-interpreter2/include/xo/interpreter2/interpreter2_register_facets.hpp new file mode 100644 index 00000000..587f882b --- /dev/null +++ b/xo-interpreter2/include/xo/interpreter2/interpreter2_register_facets.hpp @@ -0,0 +1,15 @@ +/** @file interpreter2_register_facets.hpp + * + * @author Roland Conybeare, Feb 2026 + **/ + +#pragma once + +namespace xo { + namespace scm { + /** Register interpreter2 (facet,impl) combinations with FacetRegistry **/ + bool interpreter2_register_facets(); + } +} + +/* end interpreter2_register_facets.hpp */ diff --git a/xo-interpreter2/include/xo/interpreter2/interpreter2_register_types.hpp b/xo-interpreter2/include/xo/interpreter2/interpreter2_register_types.hpp new file mode 100644 index 00000000..1409d13a --- /dev/null +++ b/xo-interpreter2/include/xo/interpreter2/interpreter2_register_types.hpp @@ -0,0 +1,17 @@ +/** @file interpreter2_register_types.hpp + * + * @author Roland Conybeare, Dec 2025 + **/ + +#pragma once + +#include + +namespace xo { + namespace scm { + /** Register interpreter2 (facet,impl) combinations with FacetRegistry **/ + bool interpreter2_register_types(obj gc); + } +} + +/* end interpreter2_register_types.hpp */ diff --git a/xo-interpreter2/src/interpreter2/CMakeLists.txt b/xo-interpreter2/src/interpreter2/CMakeLists.txt index 8ce214ba..635ecff3 100644 --- a/xo-interpreter2/src/interpreter2/CMakeLists.txt +++ b/xo-interpreter2/src/interpreter2/CMakeLists.txt @@ -3,11 +3,21 @@ set(SELF_LIB xo_interpreter2) set(SELF_SRCS init_interpreter2.cpp + interpreter2_register_facets.cpp + interpreter2_register_types.cpp + VirtualSchematikaMachine.cpp - VsmFrame.cpp + + DVsmEvalArgsFrame.cpp + IGCObject_DVsmEvalArgsFrame.cpp + IPrintable_DVsmEvalArgsFrame.cpp + + DVsmApplyFrame.cpp + IGCObject_DVsmApplyFrame.cpp + IPrintable_DVsmApplyFrame.cpp + VsmInstr.cpp #IExpression_Any.cpp - #interpreter2_register_facets.cpp ) xo_add_shared_library4(${SELF_LIB} ${PROJECT_NAME}Targets ${PROJECT_VERSION} 1 ${SELF_SRCS}) diff --git a/xo-interpreter2/src/interpreter2/DVsmApplyFrame.cpp b/xo-interpreter2/src/interpreter2/DVsmApplyFrame.cpp new file mode 100644 index 00000000..75da5877 --- /dev/null +++ b/xo-interpreter2/src/interpreter2/DVsmApplyFrame.cpp @@ -0,0 +1,82 @@ +/** @file DVsmApplyFrame.cpp + * + * @author Roland Conybeare, Feb 2026 + **/ + +#include "DVsmApplyFrame.hpp" +#include + +namespace xo { + using xo::facet::typeseq; + + namespace scm { + + DVsmApplyFrame::DVsmApplyFrame(obj old_parent, + VsmInstr old_cont, + DArray * args) + : VsmFrame(old_parent, old_cont), + args_{args} + {} + + DVsmApplyFrame * + DVsmApplyFrame::make(obj mm, + obj old_parent, + VsmInstr old_cont, + DArray * args) + { + DVsmApplyFrame * result = nullptr; + + void * mem = mm.alloc(typeseq::id(), + sizeof(DVsmApplyFrame)); + + result = new (mem) DVsmApplyFrame(old_parent, + old_cont, + args); + + assert(result); + + return result; + } + + std::size_t + DVsmApplyFrame::shallow_size() const noexcept + { + return sizeof(DVsmApplyFrame); + } + + DVsmApplyFrame * + DVsmApplyFrame::shallow_copy(obj mm) const noexcept + { + DVsmApplyFrame * copy = (DVsmApplyFrame *)mm.alloc_copy((std::byte *)this); + + if (copy) + *copy = *this; + + return copy; + } + + std::size_t + DVsmApplyFrame::forward_children(obj gc) noexcept + { + // GC needs to locate AGCObject iface for each member + + (void)gc; + + return this->shallow_size(); + } + + bool + DVsmApplyFrame::pretty(const ppindentinfo & ppii) const + { + return ppii.pps()->pretty_struct + (ppii, + "DVsmApplyFrame", + refrtag("cont", cont_), + refrtag("n_args", args_->size()) + ); + } + + } /*namespace scm*/ +} /*namespace xo*/ + +/* end DVsmApplyFrame.cpp */ diff --git a/xo-interpreter2/src/interpreter2/DVsmEvalArgsFrame.cpp b/xo-interpreter2/src/interpreter2/DVsmEvalArgsFrame.cpp new file mode 100644 index 00000000..cb2b328e --- /dev/null +++ b/xo-interpreter2/src/interpreter2/DVsmEvalArgsFrame.cpp @@ -0,0 +1,77 @@ +/** @file DVsmEvalArgsFrame.cpp + * + * @author Roland Conybeare, Feb 2026 + **/ + +#include "DVsmEvalArgsFrame.hpp" +#include + +namespace xo { + using xo::facet::typeseq; + using xo::print::ppindentinfo; + + namespace scm { + + // ----- VsmEvalArgsFrame ----- + + DVsmEvalArgsFrame::DVsmEvalArgsFrame(obj old_parent, + VsmInstr old_cont) + : VsmFrame(old_parent, old_cont) + {} + + DVsmEvalArgsFrame * + DVsmEvalArgsFrame::make(obj mm, + obj apply_frame, + VsmInstr cont) + { + DVsmEvalArgsFrame * result = nullptr; + + void * mem = mm.alloc(typeseq::id(), + sizeof(DVsmEvalArgsFrame)); + + result = new (mem) DVsmEvalArgsFrame(apply_frame, cont); + + assert(result); + + return result; + } + + std::size_t + DVsmEvalArgsFrame::shallow_size() const noexcept + { + return sizeof(DVsmEvalArgsFrame); + } + + DVsmEvalArgsFrame * + DVsmEvalArgsFrame::shallow_copy(obj mm) const noexcept + { + DVsmEvalArgsFrame * copy = (DVsmEvalArgsFrame *)mm.alloc_copy((std::byte *)this); + + if (copy) + *copy = *this; + + return copy; + } + + std::size_t + DVsmEvalArgsFrame::forward_children(obj gc) noexcept + { + (void)gc; + + return this->shallow_size(); + } + + bool + DVsmEvalArgsFrame::pretty(const ppindentinfo & ppii) const + { + return ppii.pps()->pretty_struct + (ppii, + "DVsmEvalArgsFrame", + refrtag("cont", cont_), + refrtag("i_arg", i_arg_) + ); + } + } /*namespace scm*/ +} /*namespace xo*/ + +/* end VsmEvalArgsFrame.cpp */ diff --git a/xo-interpreter2/src/interpreter2/IGCObject_DVsmApplyFrame.cpp b/xo-interpreter2/src/interpreter2/IGCObject_DVsmApplyFrame.cpp new file mode 100644 index 00000000..1e794477 --- /dev/null +++ b/xo-interpreter2/src/interpreter2/IGCObject_DVsmApplyFrame.cpp @@ -0,0 +1,39 @@ +/** @file IGCObject_DVsmApplyFrame.cpp + * + * Generated automagically from ingredients: + * 1. code generator: + * [xo-facet/codegen/genfacet] + * arguments: + * --input [idl/IGCObject_DVsmApplyFrame.json5] + * 2. jinja2 template for abstract facet .hpp file: + * [iface_facet_any.hpp.j2] + * 3. idl for facet methods + * [idl/IGCObject_DVsmApplyFrame.json5] +**/ + +#include "detail/IGCObject_DVsmApplyFrame.hpp" + +namespace xo { + namespace scm { + auto + IGCObject_DVsmApplyFrame::shallow_size(const DVsmApplyFrame & self) noexcept -> size_type + { + return self.shallow_size(); + } + + auto + IGCObject_DVsmApplyFrame::shallow_copy(const DVsmApplyFrame & self, obj mm) noexcept -> Opaque + { + return self.shallow_copy(mm); + } + + auto + IGCObject_DVsmApplyFrame::forward_children(DVsmApplyFrame & self, obj gc) noexcept -> size_type + { + return self.forward_children(gc); + } + + } /*namespace scm*/ +} /*namespace xo*/ + +/* end IGCObject_DVsmApplyFrame.cpp */ diff --git a/xo-interpreter2/src/interpreter2/IGCObject_DVsmEvalArgsFrame.cpp b/xo-interpreter2/src/interpreter2/IGCObject_DVsmEvalArgsFrame.cpp new file mode 100644 index 00000000..d64b47bd --- /dev/null +++ b/xo-interpreter2/src/interpreter2/IGCObject_DVsmEvalArgsFrame.cpp @@ -0,0 +1,39 @@ +/** @file IGCObject_DVsmEvalArgsFrame.cpp + * + * Generated automagically from ingredients: + * 1. code generator: + * [xo-facet/codegen/genfacet] + * arguments: + * --input [idl/IGCObject_DVsmEvalArgsFrame.json5] + * 2. jinja2 template for abstract facet .hpp file: + * [iface_facet_any.hpp.j2] + * 3. idl for facet methods + * [idl/IGCObject_DVsmEvalArgsFrame.json5] +**/ + +#include "detail/IGCObject_DVsmEvalArgsFrame.hpp" + +namespace xo { + namespace scm { + auto + IGCObject_DVsmEvalArgsFrame::shallow_size(const DVsmEvalArgsFrame & self) noexcept -> size_type + { + return self.shallow_size(); + } + + auto + IGCObject_DVsmEvalArgsFrame::shallow_copy(const DVsmEvalArgsFrame & self, obj mm) noexcept -> Opaque + { + return self.shallow_copy(mm); + } + + auto + IGCObject_DVsmEvalArgsFrame::forward_children(DVsmEvalArgsFrame & self, obj gc) noexcept -> size_type + { + return self.forward_children(gc); + } + + } /*namespace scm*/ +} /*namespace xo*/ + +/* end IGCObject_DVsmEvalArgsFrame.cpp */ diff --git a/xo-interpreter2/src/interpreter2/IPrintable_DVsmApplyFrame.cpp b/xo-interpreter2/src/interpreter2/IPrintable_DVsmApplyFrame.cpp new file mode 100644 index 00000000..5faa360f --- /dev/null +++ b/xo-interpreter2/src/interpreter2/IPrintable_DVsmApplyFrame.cpp @@ -0,0 +1,28 @@ +/** @file IPrintable_DVsmApplyFrame.cpp + * + * Generated automagically from ingredients: + * 1. code generator: + * [xo-facet/codegen/genfacet] + * arguments: + * --input [idl/IPrintable_DVsmApplyFrame.json5] + * 2. jinja2 template for abstract facet .hpp file: + * [iface_facet_any.hpp.j2] + * 3. idl for facet methods + * [idl/IPrintable_DVsmApplyFrame.json5] +**/ + +#include "detail/IPrintable_DVsmApplyFrame.hpp" + +namespace xo { + namespace scm { + auto + IPrintable_DVsmApplyFrame::pretty(const DVsmApplyFrame & self, const ppindentinfo & ppii) -> bool + { + return self.pretty(ppii); + } + + + } /*namespace scm*/ +} /*namespace xo*/ + +/* end IPrintable_DVsmApplyFrame.cpp */ diff --git a/xo-interpreter2/src/interpreter2/IPrintable_DVsmEvalArgsFrame.cpp b/xo-interpreter2/src/interpreter2/IPrintable_DVsmEvalArgsFrame.cpp new file mode 100644 index 00000000..25d81800 --- /dev/null +++ b/xo-interpreter2/src/interpreter2/IPrintable_DVsmEvalArgsFrame.cpp @@ -0,0 +1,28 @@ +/** @file IPrintable_DVsmEvalArgsFrame.cpp + * + * Generated automagically from ingredients: + * 1. code generator: + * [xo-facet/codegen/genfacet] + * arguments: + * --input [idl/IPrintable_DVsmEvalArgsFrame.json5] + * 2. jinja2 template for abstract facet .hpp file: + * [iface_facet_any.hpp.j2] + * 3. idl for facet methods + * [idl/IPrintable_DVsmEvalArgsFrame.json5] +**/ + +#include "detail/IPrintable_DVsmEvalArgsFrame.hpp" + +namespace xo { + namespace scm { + auto + IPrintable_DVsmEvalArgsFrame::pretty(const DVsmEvalArgsFrame & self, const ppindentinfo & ppii) -> bool + { + return self.pretty(ppii); + } + + + } /*namespace scm*/ +} /*namespace xo*/ + +/* end IPrintable_DVsmEvalArgsFrame.cpp */ diff --git a/xo-interpreter2/src/interpreter2/VirtualSchematikaMachine.cpp b/xo-interpreter2/src/interpreter2/VirtualSchematikaMachine.cpp index dc876b44..22f9ed12 100644 --- a/xo-interpreter2/src/interpreter2/VirtualSchematikaMachine.cpp +++ b/xo-interpreter2/src/interpreter2/VirtualSchematikaMachine.cpp @@ -4,6 +4,8 @@ **/ #include "VirtualSchematikaMachine.hpp" +#include "VsmApplyFrame.hpp" +#include "VsmEvalArgsFrame.hpp" #include #include #include @@ -111,6 +113,17 @@ namespace xo { bool VirtualSchematikaMachine::execute_one() { + scope log(XO_DEBUG(true)); + log && log(xtag("pc", pc_), + xtag("cont", cont_)); + + obj stack_pr + = (FacetRegistry::instance() + .try_variant(stack_)); + + if (stack_pr) + log && log(xtag("stack", stack_pr)); + switch (pc_.opcode()) { case vsm_opcode::halt: case vsm_opcode::N: @@ -222,11 +235,13 @@ namespace xo { // TODO: check function signature - VsmApplyFrame * apply_frame - = VsmApplyFrame::make(mm_.to_op(), stack_, cont_, args); + auto apply_frame + = obj + (DVsmApplyFrame::make(mm_.to_op(), stack_, cont_, args)); - VsmEvalArgsFrame * evalargs_frame - = VsmEvalArgsFrame::make(mm_.to_op(), apply_frame, VsmInstr::c_apply); + auto evalargs_frame + = obj + (DVsmEvalArgsFrame::make(mm_.to_op(), apply_frame, VsmInstr::c_apply)); this->stack_ = evalargs_frame; diff --git a/xo-interpreter2/src/interpreter2/VsmApplyFrame.cpp b/xo-interpreter2/src/interpreter2/VsmApplyFrame.cpp new file mode 100644 index 00000000..e69de29b diff --git a/xo-interpreter2/src/interpreter2/VsmFrame.cpp b/xo-interpreter2/src/interpreter2/VsmFrame.cpp deleted file mode 100644 index 2f262431..00000000 --- a/xo-interpreter2/src/interpreter2/VsmFrame.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/** @file VsmFrame.cpp - * - * @author Roland Conybeare, Feb 2026 - **/ - -#include "VsmFrame.hpp" - -namespace xo { - using xo::facet::typeseq; - - namespace scm { - - VsmApplyFrame::VsmApplyFrame(VsmFrame * old_parent, - VsmInstr old_cont, - DArray * args) - : VsmFrame(old_parent, old_cont), - args_{args} - {} - - VsmApplyFrame * - VsmApplyFrame::make(obj mm, - VsmFrame * old_parent, - VsmInstr old_cont, - DArray * args) - { - VsmApplyFrame * result = nullptr; - - void * mem = mm.alloc(typeseq::id(), - sizeof(VsmApplyFrame)); - - result = new (mem) VsmApplyFrame(old_parent, - old_cont, - args); - - assert(result); - - return result; - } - - // ----- VsmEvalArgsFrame ----- - - VsmEvalArgsFrame::VsmEvalArgsFrame(VsmApplyFrame * old_parent, - VsmInstr old_cont) - : VsmFrame(old_parent, old_cont) - {} - - VsmEvalArgsFrame * - VsmEvalArgsFrame::make(obj mm, - VsmApplyFrame * apply_frame, - VsmInstr cont) - { - VsmEvalArgsFrame * result = nullptr; - - void * mem = mm.alloc(typeseq::id(), - sizeof(VsmEvalArgsFrame)); - - result = new (mem) VsmEvalArgsFrame(apply_frame, cont); - - assert(result); - - return result; - } - - } /*namespace scm*/ -} /*namespace xo*/ - -/* end VsmFrame.cpp */ - diff --git a/xo-interpreter2/src/interpreter2/VsmInstr.cpp b/xo-interpreter2/src/interpreter2/VsmInstr.cpp index 8d0907fc..ddcc8c20 100644 --- a/xo-interpreter2/src/interpreter2/VsmInstr.cpp +++ b/xo-interpreter2/src/interpreter2/VsmInstr.cpp @@ -7,6 +7,21 @@ namespace xo { namespace scm { + const char * + vsm_opcode_descr(vsm_opcode x) + { + switch (x) { + case vsm_opcode::halt: return "halt"; + case vsm_opcode::eval: return "eval"; + case vsm_opcode::apply: return "apply"; + case vsm_opcode::evalargs: return "evalargs"; + case vsm_opcode::N: + break; + } + + return "opcode?"; + } + VsmInstr VsmInstr::c_halt = VsmInstr(vsm_opcode::halt); diff --git a/xo-interpreter2/src/interpreter2/init_interpreter2.cpp b/xo-interpreter2/src/interpreter2/init_interpreter2.cpp index b0e8a71c..07308863 100644 --- a/xo-interpreter2/src/interpreter2/init_interpreter2.cpp +++ b/xo-interpreter2/src/interpreter2/init_interpreter2.cpp @@ -5,31 +5,23 @@ #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 diff --git a/xo-interpreter2/src/interpreter2/interpreter2_register_facets.cpp b/xo-interpreter2/src/interpreter2/interpreter2_register_facets.cpp new file mode 100644 index 00000000..b16d33ef --- /dev/null +++ b/xo-interpreter2/src/interpreter2/interpreter2_register_facets.cpp @@ -0,0 +1,47 @@ +/** @file interpreter2_register_facets.cpp + * + * @author Roland Conybeare, Feb 2026 + **/ + +#include "interpreter2_register_facets.hpp" + +#include "VsmApplyFrame.hpp" +#include "VsmEvalArgsFrame.hpp" + +#include +#include +#include +#include + +namespace xo { + using xo::mm::AGCObject; + using xo::print::APrintable; + using xo::facet::FacetRegistry; + using xo::reflect::typeseq; + using xo::xtag; + + namespace scm { + bool + interpreter2_register_facets() + { + scope log(XO_DEBUG(true)); + + // VsmStackFrame + // +- VsmApplyFrame + // \- VsmEvalArgsFrame + + FacetRegistry::register_impl(); + FacetRegistry::register_impl(); + + FacetRegistry::register_impl(); + FacetRegistry::register_impl(); + + log && log(xtag("DVsmApplyFrame.tseq", typeseq::id())); + log && log(xtag("DVsmEvalArgsFrame.tseq", typeseq::id())); + + return true; + } + } /*namespace scm*/ +} /*namespace xo*/ + +/* end interpreter2_register_facets.cpp */ diff --git a/xo-interpreter2/src/interpreter2/interpreter2_register_types.cpp b/xo-interpreter2/src/interpreter2/interpreter2_register_types.cpp new file mode 100644 index 00000000..54351beb --- /dev/null +++ b/xo-interpreter2/src/interpreter2/interpreter2_register_types.cpp @@ -0,0 +1,36 @@ +/** @file interpreter2_register_types.cpp + * + * @author Roland Conybeare, Jan 2026 + **/ + +#include "interpreter2_register_types.hpp" + +#include "VsmApplyFrame.hpp" +#include "VsmEvalArgsFrame.hpp" + +#include + +namespace xo { + using xo::mm::ACollector; + using xo::mm::AGCObject; + using xo::facet::impl_for; + //using xo::facet::typeseq; + using xo::scope; + + namespace scm { + bool + interpreter2_register_types(obj gc) + { + scope log(XO_DEBUG(true)); + + bool ok = true; + + ok &= gc.install_type(impl_for()); + ok &= gc.install_type(impl_for()); + + return ok; + } + } +} /*namespace xo*/ + +/* end interpreter2_register_types.cpp */