diff --git a/CMakeLists.txt b/CMakeLists.txt index 6f3b14bc..ae8893a6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -77,6 +77,32 @@ xo_add_genfacetimpl( # ---------------------------------------------------------------- +# note: manual target; generated code committed to git +xo_add_genfacetimpl( + TARGET xo-interpreter2-facetimpl-gcobject-vsmapplyclosureframe + FACET_PKG xo_gc + FACET GCObject + REPR VsmApplyClosureFrame + INPUT idl/IGCObject_DVsmApplyClosureFrame.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-vsmapplyclosureframe + FACET_PKG xo_printable2 + FACET Printable + REPR DVsmApplyClosureFrame + INPUT idl/IPrintable_DVsmApplyClosureFrame.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-procedure-closure diff --git a/idl/IGCObject_DVsmApplyClosureFrame.json5 b/idl/IGCObject_DVsmApplyClosureFrame.json5 new file mode 100644 index 00000000..398d53e9 --- /dev/null +++ b/idl/IGCObject_DVsmApplyClosureFrame.json5 @@ -0,0 +1,15 @@ +{ + mode: "implementation", + includes: [ + "", + "" + ], + local_types: [ ], + namespace1: "xo", + namespace2: "scm", + facet_idl: "idl/GCObject.json5", + brief: "provide AGCObject interface for DVsmApplyClosureFrame", + using_doxygen: true, + repr: "DVsmApplyClosureFrame", + doc: [ "implement AGCObject for DVsmApplyClosureFrame" ], +} diff --git a/idl/IPrintable_DVsmApplyClosureFrame.json5 b/idl/IPrintable_DVsmApplyClosureFrame.json5 new file mode 100644 index 00000000..717aa85f --- /dev/null +++ b/idl/IPrintable_DVsmApplyClosureFrame.json5 @@ -0,0 +1,13 @@ +{ + mode: "implementation", + includes: [ "", + "" ], + local_types: [ ], + namespace1: "xo", + namespace2: "scm", + facet_idl: "idl/Printable.json5", + brief: "provide APrintable interface for DVsmApplyClosureFrame", + using_doxygen: true, + repr: "DVsmApplyClosureFrame", + doc: [ "implement APrintable for DVsmApplyClosureFrame" ], +} diff --git a/include/xo/interpreter2/DVsmApplyClosureFrame.hpp b/include/xo/interpreter2/DVsmApplyClosureFrame.hpp new file mode 100644 index 00000000..185b818f --- /dev/null +++ b/include/xo/interpreter2/DVsmApplyClosureFrame.hpp @@ -0,0 +1,52 @@ +/** @file DVsmApplyClosureFrame.hpp + * + * @author Roland Conybeare, Feb 2026 + **/ + +#pragma once + +#include "VsmInstr.hpp" +#include "DLocalEnv.hpp" +#include + +namespace xo { + namespace scm { + + /** Frame to preserve VSM registers: + * (stack_, parent_, cont_) + * while applying a closure. + **/ + class DVsmApplyClosureFrame { + public: + using ACollector = xo::mm::ACollector; + using AAllocator = xo::mm::AAllocator; + using AGCObject = xo::mm::AGCObject; + using ppindentinfo = xo::print::ppindentinfo; + + public: + DVsmApplyClosureFrame(obj stack, + VsmInstr cont, + DLocalEnv * env); + + /** gcobject facet **/ + std::size_t shallow_size() const noexcept; + DVsmApplyClosureFrame * shallow_copy(obj mm) const noexcept; + std::size_t forward_children(obj gc) noexcept; + + /** pretty-printing support **/ + bool pretty(const ppindentinfo & ppii) const; + + protected: + /** saved VSM stack_ register **/ + obj stack_; + /** saved VSM cont_ register **/ + VsmInstr cont_; + /** saved VSM local_env_ register **/ + DLocalEnv * local_env_ = nullptr; + }; + + + } /*namespace scm*/ +} /*namespace xo*/ + +/* end DVsmApplyClosureFrame.hpp */ diff --git a/include/xo/interpreter2/DVsmApplyFrame.hpp b/include/xo/interpreter2/DVsmApplyFrame.hpp index 72900eb2..b4b46de2 100644 --- a/include/xo/interpreter2/DVsmApplyFrame.hpp +++ b/include/xo/interpreter2/DVsmApplyFrame.hpp @@ -9,11 +9,12 @@ namespace xo { namespace scm { - class DVsmApplyFrame : public VsmFrame { + class DVsmApplyFrame { public: using AProcedure = xo::scm::AProcedure; using ACollector = xo::mm::ACollector; using AAllocator = xo::mm::AAllocator; + using AGCObject = xo::mm::AGCObject; using ppindentinfo = xo::print::ppindentinfo; public: @@ -27,6 +28,8 @@ namespace xo { VsmInstr old_cont, DArray * args); + obj parent() const noexcept { return parent_; } + VsmInstr cont() const noexcept { return cont_; } obj fn() const noexcept { return fn_; } DArray * args() const noexcept { return args_; } @@ -40,6 +43,10 @@ namespace xo { bool pretty(const ppindentinfo & ppii) const; private: + /** saved VSM stack; restore when this frame consumed **/ + obj parent_; + /** saved continuation; restore when this frame consumed **/ + VsmInstr cont_; /** evaluated target procedure. * * note: when initially created, this will be unpopulated; diff --git a/include/xo/interpreter2/VirtualSchematikaMachine.hpp b/include/xo/interpreter2/VirtualSchematikaMachine.hpp index 39421981..67307700 100644 --- a/include/xo/interpreter2/VirtualSchematikaMachine.hpp +++ b/include/xo/interpreter2/VirtualSchematikaMachine.hpp @@ -21,7 +21,7 @@ namespace xo { #ifdef OBSOLETE // see DVsmError // TODO: move error to collected space? // or special arena? - // + // struct EvaluationError { /** source location (in vsm implementation) at which error identified **/ std::string_view src_function_; @@ -182,9 +182,10 @@ namespace xo { * stack_ * cont_ * - * Other registers are not preserved + * Other registers not preserved * pc_ * expr_ + * local_env_ * fn_ * args_ * value_ @@ -200,7 +201,7 @@ namespace xo { /** Sidecar allocator for error reporting. * Separate to mitigate interference with @ref mm_ - * (separate memory so we can for example report + * (separate memory so we can for example report * an out-of-memory error). * Likely DArena or similar **/ diff --git a/include/xo/interpreter2/VsmApplyClosureFrame.hpp b/include/xo/interpreter2/VsmApplyClosureFrame.hpp new file mode 100644 index 00000000..09b68d09 --- /dev/null +++ b/include/xo/interpreter2/VsmApplyClosureFrame.hpp @@ -0,0 +1,12 @@ +/** @file VsmApplyClosureFrame.hpp + * + * @author Roland Conybeare, Feb 2026 + **/ + +#pragma once + +#include "DVsmApplyClosureFrame.hpp" +#include "detail/IGCObject_DVsmApplyClosureFrame.hpp" +#include "detail/IPrintable_DVsmApplyClosureFrame.hpp" + +/* end VsmApplyClosureFrame.hpp */ diff --git a/include/xo/interpreter2/detail/IGCObject_DVsmApplyClosureFrame.hpp b/include/xo/interpreter2/detail/IGCObject_DVsmApplyClosureFrame.hpp new file mode 100644 index 00000000..2baacd05 --- /dev/null +++ b/include/xo/interpreter2/detail/IGCObject_DVsmApplyClosureFrame.hpp @@ -0,0 +1,67 @@ +/** @file IGCObject_DVsmApplyClosureFrame.hpp + * + * Generated automagically from ingredients: + * 1. code generator: + * [xo-facet/codegen/genfacet] + * arguments: + * --input [idl/IGCObject_DVsmApplyClosureFrame.json5] + * 2. jinja2 template for abstract facet .hpp file: + * [iface_facet_repr.hpp.j2] + * 3. idl for facet methods + * [idl/IGCObject_DVsmApplyClosureFrame.json5] + **/ + +#pragma once + +#include "GCObject.hpp" +#include +#include +#include "DVsmApplyClosureFrame.hpp" + +namespace xo { namespace scm { class IGCObject_DVsmApplyClosureFrame; } } + +namespace xo { + namespace facet { + template <> + struct FacetImplementation + { + using ImplType = xo::mm::IGCObject_Xfer + ; + }; + } +} + +namespace xo { + namespace scm { + /** @class IGCObject_DVsmApplyClosureFrame + **/ + class IGCObject_DVsmApplyClosureFrame { + public: + /** @defgroup scm-gcobject-dvsmapplyclosureframe-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-dvsmapplyclosureframe-methods **/ + ///@{ + // const methods + /** memory consumption for this instance **/ + static size_type shallow_size(const DVsmApplyClosureFrame & self) noexcept; + /** copy instance using allocator **/ + static Opaque shallow_copy(const DVsmApplyClosureFrame & self, obj mm) noexcept; + + // non-const methods + /** during GC: forward immdiate children **/ + static size_type forward_children(DVsmApplyClosureFrame & self, obj gc) noexcept; + ///@} + }; + + } /*namespace scm*/ +} /*namespace xo*/ + +/* end */ \ No newline at end of file diff --git a/include/xo/interpreter2/detail/IPrintable_DVsmApplyClosureFrame.hpp b/include/xo/interpreter2/detail/IPrintable_DVsmApplyClosureFrame.hpp new file mode 100644 index 00000000..f2e5a072 --- /dev/null +++ b/include/xo/interpreter2/detail/IPrintable_DVsmApplyClosureFrame.hpp @@ -0,0 +1,62 @@ +/** @file IPrintable_DVsmApplyClosureFrame.hpp + * + * Generated automagically from ingredients: + * 1. code generator: + * [xo-facet/codegen/genfacet] + * arguments: + * --input [idl/IPrintable_DVsmApplyClosureFrame.json5] + * 2. jinja2 template for abstract facet .hpp file: + * [iface_facet_repr.hpp.j2] + * 3. idl for facet methods + * [idl/IPrintable_DVsmApplyClosureFrame.json5] + **/ + +#pragma once + +#include "Printable.hpp" +#include +#include +#include "DVsmApplyClosureFrame.hpp" + +namespace xo { namespace scm { class IPrintable_DVsmApplyClosureFrame; } } + +namespace xo { + namespace facet { + template <> + struct FacetImplementation + { + using ImplType = xo::print::IPrintable_Xfer + ; + }; + } +} + +namespace xo { + namespace scm { + /** @class IPrintable_DVsmApplyClosureFrame + **/ + class IPrintable_DVsmApplyClosureFrame { + public: + /** @defgroup scm-printable-dvsmapplyclosureframe-type-traits **/ + ///@{ + using ppindentinfo = xo::print::APrintable::ppindentinfo; + using Copaque = xo::print::APrintable::Copaque; + using Opaque = xo::print::APrintable::Opaque; + ///@} + /** @defgroup scm-printable-dvsmapplyclosureframe-methods **/ + ///@{ + // const methods + /** Pretty-printing support for this object. +See [xo-indentlog/xo/indentlog/pretty.hpp] **/ + static bool pretty(const DVsmApplyClosureFrame & self, const ppindentinfo & ppii); + + // non-const methods + ///@} + }; + + } /*namespace scm*/ +} /*namespace xo*/ + +/* end */ \ No newline at end of file diff --git a/src/interpreter2/CMakeLists.txt b/src/interpreter2/CMakeLists.txt index f6fbd10b..4a477874 100644 --- a/src/interpreter2/CMakeLists.txt +++ b/src/interpreter2/CMakeLists.txt @@ -16,6 +16,10 @@ set(SELF_SRCS IGCObject_DVsmApplyFrame.cpp IPrintable_DVsmApplyFrame.cpp + DVsmApplyClosureFrame.cpp + IGCObject_DVsmApplyClosureFrame.cpp + IPrintable_DVsmApplyClosureFrame.cpp + DClosure.cpp IProcedure_DClosure.cpp IGCObject_DClosure.cpp diff --git a/src/interpreter2/DVsmApplyClosureFrame.cpp b/src/interpreter2/DVsmApplyClosureFrame.cpp new file mode 100644 index 00000000..b7962ebd --- /dev/null +++ b/src/interpreter2/DVsmApplyClosureFrame.cpp @@ -0,0 +1,59 @@ +/** @file DVsmApplyClosureFrame.cpp + * + * @author Roland Conybeare, Feb 2026 + **/ + +#include "DVsmApplyClosureFrame.hpp" + +namespace xo { + using xo::mm::AGCObject; + + namespace scm { + + DVsmApplyClosureFrame::DVsmApplyClosureFrame(obj stack, + VsmInstr cont, + DLocalEnv * local_env) + : stack_{stack}, + cont_{cont}, + local_env_{local_env} + {} + + std::size_t + DVsmApplyClosureFrame::shallow_size() const noexcept + { + return sizeof(DVsmApplyClosureFrame); + } + + DVsmApplyClosureFrame * + DVsmApplyClosureFrame::shallow_copy(obj mm) const noexcept + { + DVsmApplyClosureFrame * copy + = (DVsmApplyClosureFrame *)mm.alloc_copy((std::byte *)this); + + if (copy) + *copy = *this; + + return copy; + } + + std::size_t + DVsmApplyClosureFrame::forward_children(obj gc) noexcept + { + (void)gc; + + return this->shallow_size(); + } + + bool + DVsmApplyClosureFrame::pretty(const ppindentinfo & ppii) const + { + return ppii.pps()->pretty_struct + (ppii, + "DVsmApplyClosureFrame", + refrtag("cont", cont_), + refrtag("env", local_env_)); + } + } /*namespace scm*/ +} /*namespace xo*/ + +/* end DVsmApplyClosureFrame.cpp */ diff --git a/src/interpreter2/DVsmApplyFrame.cpp b/src/interpreter2/DVsmApplyFrame.cpp index 75da5877..55d59b37 100644 --- a/src/interpreter2/DVsmApplyFrame.cpp +++ b/src/interpreter2/DVsmApplyFrame.cpp @@ -14,8 +14,9 @@ namespace xo { DVsmApplyFrame::DVsmApplyFrame(obj old_parent, VsmInstr old_cont, DArray * args) - : VsmFrame(old_parent, old_cont), - args_{args} + : parent_{old_parent}, + cont_{old_cont}, + args_{args} {} DVsmApplyFrame * diff --git a/src/interpreter2/DVsmEvalArgsFrame.cpp b/src/interpreter2/DVsmEvalArgsFrame.cpp index 01391cf2..1ca470e9 100644 --- a/src/interpreter2/DVsmEvalArgsFrame.cpp +++ b/src/interpreter2/DVsmEvalArgsFrame.cpp @@ -49,7 +49,8 @@ namespace xo { DVsmEvalArgsFrame * DVsmEvalArgsFrame::shallow_copy(obj mm) const noexcept { - DVsmEvalArgsFrame * copy = (DVsmEvalArgsFrame *)mm.alloc_copy((std::byte *)this); + DVsmEvalArgsFrame * copy + = (DVsmEvalArgsFrame *)mm.alloc_copy((std::byte *)this); if (copy) *copy = *this; diff --git a/src/interpreter2/IGCObject_DVsmApplyClosureFrame.cpp b/src/interpreter2/IGCObject_DVsmApplyClosureFrame.cpp new file mode 100644 index 00000000..7a05d47e --- /dev/null +++ b/src/interpreter2/IGCObject_DVsmApplyClosureFrame.cpp @@ -0,0 +1,39 @@ +/** @file IGCObject_DVsmApplyClosureFrame.cpp + * + * Generated automagically from ingredients: + * 1. code generator: + * [xo-facet/codegen/genfacet] + * arguments: + * --input [idl/IGCObject_DVsmApplyClosureFrame.json5] + * 2. jinja2 template for abstract facet .hpp file: + * [iface_facet_any.hpp.j2] + * 3. idl for facet methods + * [idl/IGCObject_DVsmApplyClosureFrame.json5] +**/ + +#include "detail/IGCObject_DVsmApplyClosureFrame.hpp" + +namespace xo { + namespace scm { + auto + IGCObject_DVsmApplyClosureFrame::shallow_size(const DVsmApplyClosureFrame & self) noexcept -> size_type + { + return self.shallow_size(); + } + + auto + IGCObject_DVsmApplyClosureFrame::shallow_copy(const DVsmApplyClosureFrame & self, obj mm) noexcept -> Opaque + { + return self.shallow_copy(mm); + } + + auto + IGCObject_DVsmApplyClosureFrame::forward_children(DVsmApplyClosureFrame & self, obj gc) noexcept -> size_type + { + return self.forward_children(gc); + } + + } /*namespace scm*/ +} /*namespace xo*/ + +/* end IGCObject_DVsmApplyClosureFrame.cpp */ diff --git a/src/interpreter2/IPrintable_DVsmApplyClosureFrame.cpp b/src/interpreter2/IPrintable_DVsmApplyClosureFrame.cpp new file mode 100644 index 00000000..36b89a10 --- /dev/null +++ b/src/interpreter2/IPrintable_DVsmApplyClosureFrame.cpp @@ -0,0 +1,28 @@ +/** @file IPrintable_DVsmApplyClosureFrame.cpp + * + * Generated automagically from ingredients: + * 1. code generator: + * [xo-facet/codegen/genfacet] + * arguments: + * --input [idl/IPrintable_DVsmApplyClosureFrame.json5] + * 2. jinja2 template for abstract facet .hpp file: + * [iface_facet_any.hpp.j2] + * 3. idl for facet methods + * [idl/IPrintable_DVsmApplyClosureFrame.json5] +**/ + +#include "detail/IPrintable_DVsmApplyClosureFrame.hpp" + +namespace xo { + namespace scm { + auto + IPrintable_DVsmApplyClosureFrame::pretty(const DVsmApplyClosureFrame & self, const ppindentinfo & ppii) -> bool + { + return self.pretty(ppii); + } + + + } /*namespace scm*/ +} /*namespace xo*/ + +/* end IPrintable_DVsmApplyClosureFrame.cpp */ diff --git a/src/interpreter2/VirtualSchematikaMachine.cpp b/src/interpreter2/VirtualSchematikaMachine.cpp index 641723f9..1242375a 100644 --- a/src/interpreter2/VirtualSchematikaMachine.cpp +++ b/src/interpreter2/VirtualSchematikaMachine.cpp @@ -62,7 +62,7 @@ namespace xo { error_mm_.adopt(obj(arena)); } - + // TODO: allocate global_env } diff --git a/src/interpreter2/interpreter2_register_facets.cpp b/src/interpreter2/interpreter2_register_facets.cpp index 5d1467e5..f945956e 100644 --- a/src/interpreter2/interpreter2_register_facets.cpp +++ b/src/interpreter2/interpreter2_register_facets.cpp @@ -5,8 +5,11 @@ #include "interpreter2_register_facets.hpp" +#include "DPrimitive_gco_2_gco_gco.hpp" #include "VsmApplyFrame.hpp" #include "VsmEvalArgsFrame.hpp" +#include "VsmApplyClosureFrame.hpp" +#include "Primitive_gco_2_gco_gco.hpp" #include "Closure.hpp" #include "LocalEnv.hpp" #include "VsmRcx.hpp" @@ -31,7 +34,8 @@ namespace xo { // VsmStackFrame // +- VsmApplyFrame - // \- VsmEvalArgsFrame + // +- VsmEvalArgsFrame + // \- VsmApplyClosureFrame FacetRegistry::register_impl(); FacetRegistry::register_impl(); @@ -39,9 +43,10 @@ namespace xo { FacetRegistry::register_impl(); FacetRegistry::register_impl(); - FacetRegistry::register_impl(); - FacetRegistry::register_impl(); - FacetRegistry::register_impl(); + FacetRegistry::register_impl(); + FacetRegistry::register_impl(); + + // LocalEnv FacetRegistry::register_impl(); FacetRegistry::register_impl(); @@ -50,7 +55,13 @@ namespace xo { // +- Primitive_gco_2_gco_gco // \- Closure + FacetRegistry::register_impl(); + FacetRegistry::register_impl(); + FacetRegistry::register_impl(); + FacetRegistry::register_impl(); + FacetRegistry::register_impl(); + FacetRegistry::register_impl(); // RuntimeContext // \- VsmRcx