diff --git a/xo-expression2/include/xo/expression2/SequenceExpr.hpp b/xo-expression2/include/xo/expression2/SequenceExpr.hpp new file mode 100644 index 00000000..0cfe188c --- /dev/null +++ b/xo-expression2/include/xo/expression2/SequenceExpr.hpp @@ -0,0 +1,14 @@ +/** @file SequenceExpr.hpp + * + * @author Roland Conybeare, Feb 2026 + **/ + +#pragma once + +#include "DSequenceExpr.hpp" +#include "detail/IExpression_DSequenceExpr.hpp" +#include "detail/IGCObject_DSequenceExpr.hpp" +#include "detail/IPrintable_DSequenceExpr.hpp" + +/* end SequenceExpr.hpp */ + diff --git a/xo-expression2/src/expression2/DSequenceExpr.cpp b/xo-expression2/src/expression2/DSequenceExpr.cpp index a9783802..22b097fb 100644 --- a/xo-expression2/src/expression2/DSequenceExpr.cpp +++ b/xo-expression2/src/expression2/DSequenceExpr.cpp @@ -135,7 +135,7 @@ namespace xo { gc.forward_inplace(&iface, (void**)&expr_v_); - return shallow_size(); + return this->shallow_size(); } } /*namespace scm*/ diff --git a/xo-interpreter2/CMakeLists.txt b/xo-interpreter2/CMakeLists.txt index 8a1b1b3c..26124a21 100644 --- a/xo-interpreter2/CMakeLists.txt +++ b/xo-interpreter2/CMakeLists.txt @@ -103,6 +103,32 @@ xo_add_genfacetimpl( # ---------------------------------------------------------------- +# note: manual target; generated code committed to git +xo_add_genfacetimpl( + TARGET xo-interpreter2-facetimpl-gcobject-vsmseqcontframe + FACET_PKG xo_gc + FACET GCObject + REPR VsmSeqContFrame + INPUT idl/IGCObject_DVsmSeqContFrame.json5 + OUTPUT_HPP_DIR include/xo/interpreter2 + OUTPUT_IMPL_SUBDIR sequence + OUTPUT_CPP_DIR src/interpreter2 +) + +# note: manual target; generated code committed to git +xo_add_genfacetimpl( + TARGET xo-interpreter2-facetimpl-printable-vsmseqcontframe + FACET_PKG xo_printable2 + FACET Printable + REPR DVsmSeqContFrame + INPUT idl/IPrintable_DVsmSeqContFrame.json5 + OUTPUT_HPP_DIR include/xo/interpreter2 + OUTPUT_IMPL_SUBDIR sequence + OUTPUT_CPP_DIR src/interpreter2 +) + +# ---------------------------------------------------------------- + # note: manual target; generated code committed to git # #xo_add_genfacetimpl( diff --git a/xo-interpreter2/idl/IGCObject_DVsmSeqContFrame.json5 b/xo-interpreter2/idl/IGCObject_DVsmSeqContFrame.json5 new file mode 100644 index 00000000..cf7196c6 --- /dev/null +++ b/xo-interpreter2/idl/IGCObject_DVsmSeqContFrame.json5 @@ -0,0 +1,15 @@ +{ + mode: "implementation", + includes: [ + "", + "" + ], + local_types: [ ], + namespace1: "xo", + namespace2: "scm", + facet_idl: "idl/GCObject.json5", + brief: "provide AGCObject interface for DVsmSeqContFrame", + using_doxygen: true, + repr: "DVsmSeqContFrame", + doc: [ "implement AGCObject for DVsmSeqContFrame" ], +} diff --git a/xo-interpreter2/idl/IPrintable_DVsmSeqContFrame.json5 b/xo-interpreter2/idl/IPrintable_DVsmSeqContFrame.json5 new file mode 100644 index 00000000..e9ec796e --- /dev/null +++ b/xo-interpreter2/idl/IPrintable_DVsmSeqContFrame.json5 @@ -0,0 +1,13 @@ +{ + mode: "implementation", + includes: [ "", + "" ], + local_types: [ ], + namespace1: "xo", + namespace2: "scm", + facet_idl: "idl/Printable.json5", + brief: "provide APrintable interface for DVsmSeqContFrame", + using_doxygen: true, + repr: "DVsmSeqContFrame", + doc: [ "implement APrintable for DVsmSeqContFrame" ], +} diff --git a/xo-interpreter2/include/xo/interpreter2/DVsmApplyFrame.hpp b/xo-interpreter2/include/xo/interpreter2/DVsmApplyFrame.hpp index a5df3504..47735afe 100644 --- a/xo-interpreter2/include/xo/interpreter2/DVsmApplyFrame.hpp +++ b/xo-interpreter2/include/xo/interpreter2/DVsmApplyFrame.hpp @@ -5,7 +5,9 @@ #pragma once -#include "VsmFrame.hpp" +#include "VsmInstr.hpp" +#include +#include namespace xo { namespace scm { diff --git a/xo-interpreter2/include/xo/interpreter2/DVsmEvalArgsFrame.hpp b/xo-interpreter2/include/xo/interpreter2/DVsmEvalArgsFrame.hpp index 7131a001..e3b8b2b5 100644 --- a/xo-interpreter2/include/xo/interpreter2/DVsmEvalArgsFrame.hpp +++ b/xo-interpreter2/include/xo/interpreter2/DVsmEvalArgsFrame.hpp @@ -28,12 +28,12 @@ namespace xo { **/ DVsmEvalArgsFrame(DVsmApplyFrame * parent, VsmInstr cont, - const DApplyExpr * apply_expr); + DApplyExpr * apply_expr); static DVsmEvalArgsFrame * make(obj mm, DVsmApplyFrame * apply_frame, VsmInstr old_cont, - const DApplyExpr * apply_expr); + DApplyExpr * apply_expr); DVsmApplyFrame * parent() const noexcept { return parent_; } VsmInstr cont() const noexcept { return cont_; } @@ -55,7 +55,7 @@ namespace xo { VsmInstr cont_; /** expression being evaluated **/ - const DApplyExpr * apply_expr_ = nullptr; + DApplyExpr * apply_expr_ = nullptr; /** next argument to be evaluated. -1 means function head **/ int32_t i_arg_ = -1; diff --git a/xo-interpreter2/include/xo/interpreter2/DVsmSeqContFrame.hpp b/xo-interpreter2/include/xo/interpreter2/DVsmSeqContFrame.hpp new file mode 100644 index 00000000..cb63f0d4 --- /dev/null +++ b/xo-interpreter2/include/xo/interpreter2/DVsmSeqContFrame.hpp @@ -0,0 +1,89 @@ +/** @file DVsmSeqContFrame.hpp + * + * @author Roland Conybeare, Feb 2026 + **/ + +#pragma once + +#include "VsmInstr.hpp" +#include +#include + +namespace xo { + namespace scm { + /** @brief saved VSM state during evaluation of a SequenceExpr + **/ + class DVsmSeqContFrame { + public: + using ACollector = xo::mm::ACollector; + using AAllocator = xo::mm::AAllocator; + using AGCObject = xo::mm::AGCObject; + using ppindentinfo = xo::print::ppindentinfo; + + public: + /** @defgroup scm-vsmevalsequenceframe-ctors constructors **/ + ///@{ + + DVsmSeqContFrame(obj parent, + VsmInstr cont, + DSequenceExpr * seq_expr, + uint32_t i_seq); + + /** create instance using memory from allocator @p mm **/ + static DVsmSeqContFrame * make(obj mm, + obj parent, + VsmInstr cont, + DSequenceExpr * seq_expr, + uint32_t i_seq); + + ///@} + /** @defgroup scm-vsmevalsequenceframe-access-methods access methods **/ + ///@{ + + obj parent() const noexcept { return parent_; } + VsmInstr cont() const noexcept { return cont_; } + DSequenceExpr * seq_expr() const noexcept { return seq_expr_; } + uint32_t i_seq() const noexcept { return i_seq_; } + + ///@} + /** @defgroup scm-vsmevalsequenceframe-general-methods general methods **/ + ///@{ + + uint32_t incr_i_seq() noexcept { return ++(this->i_seq_); } + + ///@} + /** @defgroup scm-vsmevalsequenceframe-gcobject-facet gcobject facet **/ + ///@{ + + std::size_t shallow_size() const noexcept; + DVsmSeqContFrame * shallow_copy(obj mm) const noexcept; + std::size_t forward_children(obj gc) noexcept; + + ///@} + /** @defgrouop scm-vsmseqcontframe-printable-facet printable facet **/ + ///@{ + + bool pretty(const ppindentinfo & ppii) const noexcept; + + ///@} + + private: + /** @defgroup scm-vsmevalsequenceframe-members member variables **/ + ///@{ + + /** saved VSM stack; restore when this frame consumed **/ + obj parent_; + /** saved continuation; restore when this frame consumed **/ + VsmInstr cont_; + /** saved expr. evaluate elements of this sequence in order **/ + DSequenceExpr * seq_expr_ = nullptr; + /** current sequence element being evaluated **/ + uint32_t i_seq_ = 0; + + ///@} + }; + + } /*namespace scm*/ +} /*namespace xo*/ + +/* end DVsmSeqContFrame.hpp */ diff --git a/xo-interpreter2/include/xo/interpreter2/VirtualSchematikaMachine.hpp b/xo-interpreter2/include/xo/interpreter2/VirtualSchematikaMachine.hpp index 569d9d48..d7e1ec77 100644 --- a/xo-interpreter2/include/xo/interpreter2/VirtualSchematikaMachine.hpp +++ b/xo-interpreter2/include/xo/interpreter2/VirtualSchematikaMachine.hpp @@ -187,6 +187,8 @@ namespace xo { **/ void _do_applycoda_op(); + /** loop continuation after evaluating element of a SequenceExpr **/ + void _do_seq_cont_op(); private: /* diff --git a/xo-interpreter2/include/xo/interpreter2/VsmInstr.hpp b/xo-interpreter2/include/xo/interpreter2/VsmInstr.hpp index bdde3ab7..4b51361d 100644 --- a/xo-interpreter2/include/xo/interpreter2/VsmInstr.hpp +++ b/xo-interpreter2/include/xo/interpreter2/VsmInstr.hpp @@ -18,10 +18,12 @@ namespace xo { static VsmInstr c_apply; static VsmInstr c_evalargs; - /** restore registers after calling a schematika closure **/ static VsmInstr c_applycoda; + /** loop to evaluate members of a SequenceExpr **/ + static VsmInstr c_seq_cont; + vsm_opcode opcode() const noexcept { return opcode_; } private: diff --git a/xo-interpreter2/include/xo/interpreter2/VsmOpcode.hpp b/xo-interpreter2/include/xo/interpreter2/VsmOpcode.hpp index ec21b988..06b3d08b 100644 --- a/xo-interpreter2/include/xo/interpreter2/VsmOpcode.hpp +++ b/xo-interpreter2/include/xo/interpreter2/VsmOpcode.hpp @@ -33,6 +33,9 @@ namespace xo { **/ applycoda, + /** Loop over elements of a SequenceExpr **/ + seq_cont, + /** sentinel, counts number of opcodes **/ N, }; diff --git a/xo-interpreter2/include/xo/interpreter2/VsmSeqContFrame.hpp b/xo-interpreter2/include/xo/interpreter2/VsmSeqContFrame.hpp new file mode 100644 index 00000000..96e8d053 --- /dev/null +++ b/xo-interpreter2/include/xo/interpreter2/VsmSeqContFrame.hpp @@ -0,0 +1,12 @@ +/** @file VsmSeqContFrame.hpp + * + * @author Roland Conybeare, Feb 2026 + **/ + +#pragma once + +#include "DVsmSeqContFrame.hpp" +#include "sequence/IGCObject_DVsmSeqContFrame.hpp" +#include "sequence/IPrintable_DVsmSeqContFrame.hpp" + +/* end VsmSeqContFrame.hpp */ diff --git a/xo-interpreter2/include/xo/interpreter2/sequence/IGCObject_DVsmSeqContFrame.hpp b/xo-interpreter2/include/xo/interpreter2/sequence/IGCObject_DVsmSeqContFrame.hpp new file mode 100644 index 00000000..1bdbe2ab --- /dev/null +++ b/xo-interpreter2/include/xo/interpreter2/sequence/IGCObject_DVsmSeqContFrame.hpp @@ -0,0 +1,67 @@ +/** @file IGCObject_DVsmSeqContFrame.hpp + * + * Generated automagically from ingredients: + * 1. code generator: + * [xo-facet/codegen/genfacet] + * arguments: + * --input [idl/IGCObject_DVsmSeqContFrame.json5] + * 2. jinja2 template for abstract facet .hpp file: + * [iface_facet_repr.hpp.j2] + * 3. idl for facet methods + * [idl/IGCObject_DVsmSeqContFrame.json5] + **/ + +#pragma once + +#include "GCObject.hpp" +#include +#include +#include "DVsmSeqContFrame.hpp" + +namespace xo { namespace scm { class IGCObject_DVsmSeqContFrame; } } + +namespace xo { + namespace facet { + template <> + struct FacetImplementation + { + using ImplType = xo::mm::IGCObject_Xfer + ; + }; + } +} + +namespace xo { + namespace scm { + /** @class IGCObject_DVsmSeqContFrame + **/ + class IGCObject_DVsmSeqContFrame { + public: + /** @defgroup scm-gcobject-dvsmseqcontframe-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-dvsmseqcontframe-methods **/ + ///@{ + // const methods + /** memory consumption for this instance **/ + static size_type shallow_size(const DVsmSeqContFrame & self) noexcept; + /** copy instance using allocator **/ + static Opaque shallow_copy(const DVsmSeqContFrame & self, obj mm) noexcept; + + // non-const methods + /** during GC: forward immdiate children **/ + static size_type forward_children(DVsmSeqContFrame & self, obj gc) noexcept; + ///@} + }; + + } /*namespace scm*/ +} /*namespace xo*/ + +/* end */ \ No newline at end of file diff --git a/xo-interpreter2/include/xo/interpreter2/sequence/IPrintable_DVsmSeqContFrame.hpp b/xo-interpreter2/include/xo/interpreter2/sequence/IPrintable_DVsmSeqContFrame.hpp new file mode 100644 index 00000000..0fb46c45 --- /dev/null +++ b/xo-interpreter2/include/xo/interpreter2/sequence/IPrintable_DVsmSeqContFrame.hpp @@ -0,0 +1,62 @@ +/** @file IPrintable_DVsmSeqContFrame.hpp + * + * Generated automagically from ingredients: + * 1. code generator: + * [xo-facet/codegen/genfacet] + * arguments: + * --input [idl/IPrintable_DVsmSeqContFrame.json5] + * 2. jinja2 template for abstract facet .hpp file: + * [iface_facet_repr.hpp.j2] + * 3. idl for facet methods + * [idl/IPrintable_DVsmSeqContFrame.json5] + **/ + +#pragma once + +#include "Printable.hpp" +#include +#include +#include "DVsmSeqContFrame.hpp" + +namespace xo { namespace scm { class IPrintable_DVsmSeqContFrame; } } + +namespace xo { + namespace facet { + template <> + struct FacetImplementation + { + using ImplType = xo::print::IPrintable_Xfer + ; + }; + } +} + +namespace xo { + namespace scm { + /** @class IPrintable_DVsmSeqContFrame + **/ + class IPrintable_DVsmSeqContFrame { + public: + /** @defgroup scm-printable-dvsmseqcontframe-type-traits **/ + ///@{ + using ppindentinfo = xo::print::APrintable::ppindentinfo; + using Copaque = xo::print::APrintable::Copaque; + using Opaque = xo::print::APrintable::Opaque; + ///@} + /** @defgroup scm-printable-dvsmseqcontframe-methods **/ + ///@{ + // const methods + /** Pretty-printing support for this object. +See [xo-indentlog/xo/indentlog/pretty.hpp] **/ + static bool pretty(const DVsmSeqContFrame & self, const ppindentinfo & ppii); + + // non-const methods + ///@} + }; + + } /*namespace scm*/ +} /*namespace xo*/ + +/* end */ \ No newline at end of file diff --git a/xo-interpreter2/src/interpreter2/CMakeLists.txt b/xo-interpreter2/src/interpreter2/CMakeLists.txt index 1ddb3207..64e7dfe8 100644 --- a/xo-interpreter2/src/interpreter2/CMakeLists.txt +++ b/xo-interpreter2/src/interpreter2/CMakeLists.txt @@ -20,6 +20,10 @@ set(SELF_SRCS IGCObject_DVsmApplyClosureFrame.cpp IPrintable_DVsmApplyClosureFrame.cpp + DVsmSeqContFrame.cpp + IGCObject_DVsmSeqContFrame.cpp + IPrintable_DVsmSeqContFrame.cpp + DClosure.cpp IGCObject_DClosure.cpp IPrintable_DClosure.cpp diff --git a/xo-interpreter2/src/interpreter2/DVsmApplyClosureFrame.cpp b/xo-interpreter2/src/interpreter2/DVsmApplyClosureFrame.cpp index 6a86ce27..26a215a4 100644 --- a/xo-interpreter2/src/interpreter2/DVsmApplyClosureFrame.cpp +++ b/xo-interpreter2/src/interpreter2/DVsmApplyClosureFrame.cpp @@ -4,6 +4,7 @@ **/ #include "DVsmApplyClosureFrame.hpp" +#include "LocalEnv.hpp" namespace xo { using xo::mm::AGCObject; @@ -52,7 +53,8 @@ namespace xo { std::size_t DVsmApplyClosureFrame::forward_children(obj gc) noexcept { - (void)gc; + gc.forward_inplace(&stack_); + gc.forward_inplace(&local_env_); return this->shallow_size(); } diff --git a/xo-interpreter2/src/interpreter2/DVsmApplyFrame.cpp b/xo-interpreter2/src/interpreter2/DVsmApplyFrame.cpp index 55d59b37..72b81405 100644 --- a/xo-interpreter2/src/interpreter2/DVsmApplyFrame.cpp +++ b/xo-interpreter2/src/interpreter2/DVsmApplyFrame.cpp @@ -4,6 +4,7 @@ **/ #include "DVsmApplyFrame.hpp" +#include #include namespace xo { @@ -59,9 +60,9 @@ namespace xo { std::size_t DVsmApplyFrame::forward_children(obj gc) noexcept { - // GC needs to locate AGCObject iface for each member - - (void)gc; + gc.forward_inplace(&parent_); + gc.forward_inplace(&fn_); + gc.forward_inplace(&args_); return this->shallow_size(); } @@ -69,12 +70,10 @@ namespace xo { bool DVsmApplyFrame::pretty(const ppindentinfo & ppii) const { - return ppii.pps()->pretty_struct - (ppii, - "DVsmApplyFrame", - refrtag("cont", cont_), - refrtag("n_args", args_->size()) - ); + return ppii.pps()->pretty_struct(ppii, + "DVsmApplyFrame", + refrtag("cont", cont_), + refrtag("n_args", args_->size())); } } /*namespace scm*/ diff --git a/xo-interpreter2/src/interpreter2/DVsmEvalArgsFrame.cpp b/xo-interpreter2/src/interpreter2/DVsmEvalArgsFrame.cpp index 1ca470e9..09439f2e 100644 --- a/xo-interpreter2/src/interpreter2/DVsmEvalArgsFrame.cpp +++ b/xo-interpreter2/src/interpreter2/DVsmEvalArgsFrame.cpp @@ -4,6 +4,7 @@ **/ #include "DVsmEvalArgsFrame.hpp" +#include #include namespace xo { @@ -16,7 +17,7 @@ namespace xo { DVsmEvalArgsFrame::DVsmEvalArgsFrame(DVsmApplyFrame * parent, VsmInstr cont, - const DApplyExpr * apply_expr) + DApplyExpr * apply_expr) : parent_{parent}, cont_{cont}, apply_expr_{apply_expr} @@ -26,7 +27,7 @@ namespace xo { DVsmEvalArgsFrame::make(obj mm, DVsmApplyFrame * apply_frame, VsmInstr cont, - const DApplyExpr * apply_expr) + DApplyExpr * apply_expr) { DVsmEvalArgsFrame * result = nullptr; @@ -61,7 +62,8 @@ namespace xo { std::size_t DVsmEvalArgsFrame::forward_children(obj gc) noexcept { - (void)gc; + gc.forward_inplace(&parent_); + gc.forward_inplace(&apply_expr_); return this->shallow_size(); } @@ -69,12 +71,10 @@ namespace xo { bool DVsmEvalArgsFrame::pretty(const ppindentinfo & ppii) const { - return ppii.pps()->pretty_struct - (ppii, - "DVsmEvalArgsFrame", - refrtag("cont", cont_), - refrtag("i_arg", i_arg_) - ); + return ppii.pps()->pretty_struct(ppii, + "DVsmEvalArgsFrame", + refrtag("cont", cont_), + refrtag("i_arg", i_arg_)); } } /*namespace scm*/ } /*namespace xo*/ diff --git a/xo-interpreter2/src/interpreter2/DVsmSeqContFrame.cpp b/xo-interpreter2/src/interpreter2/DVsmSeqContFrame.cpp new file mode 100644 index 00000000..80c1665f --- /dev/null +++ b/xo-interpreter2/src/interpreter2/DVsmSeqContFrame.cpp @@ -0,0 +1,70 @@ +/** @file DVsmSeqContFrame.cpp + * + * @author Roland Conybeare, Feb 2026 + **/ + +#include "DVsmSeqContFrame.hpp" + +namespace xo { + namespace scm { + + DVsmSeqContFrame::DVsmSeqContFrame(obj parent, + VsmInstr cont, + DSequenceExpr * seq_expr, + uint32_t i_seq) + : parent_{parent}, + cont_{cont}, + seq_expr_{seq_expr}, + i_seq_{i_seq} + {} + + DVsmSeqContFrame * + DVsmSeqContFrame::make(obj mm, + obj parent, + VsmInstr cont, + DSequenceExpr * seq_expr, + uint32_t i_seq) + { + void * mem = mm.alloc_for(); + + return new (mem) DVsmSeqContFrame(parent, cont, seq_expr, i_seq); + } + + // gcobject facet + + std::size_t + DVsmSeqContFrame::shallow_size() const noexcept + { + return sizeof(*this); + } + + DVsmSeqContFrame * + DVsmSeqContFrame::shallow_copy(obj mm) const noexcept + { + return mm.std_copy_for(this); + } + + std::size_t + DVsmSeqContFrame::forward_children(obj gc) noexcept + { + gc.forward_inplace(&parent_); + gc.forward_inplace(&seq_expr_); + + return this->shallow_size(); + } + + // printable facet + + bool + DVsmSeqContFrame::pretty(const ppindentinfo & ppii) const noexcept + { + return ppii.pps()->pretty_struct(ppii, + "DVsmSeqContFrame", + refrtag("cont", cont_), + refrtag("i_seq", i_seq_)); + } + + } /*namespace scm*/ +} /*namespace xo*/ + +/* end DVsmSeqContFrame.cpp */ diff --git a/xo-interpreter2/src/interpreter2/IGCObject_DVsmSeqContFrame.cpp b/xo-interpreter2/src/interpreter2/IGCObject_DVsmSeqContFrame.cpp new file mode 100644 index 00000000..eecdf291 --- /dev/null +++ b/xo-interpreter2/src/interpreter2/IGCObject_DVsmSeqContFrame.cpp @@ -0,0 +1,39 @@ +/** @file IGCObject_DVsmSeqContFrame.cpp + * + * Generated automagically from ingredients: + * 1. code generator: + * [xo-facet/codegen/genfacet] + * arguments: + * --input [idl/IGCObject_DVsmSeqContFrame.json5] + * 2. jinja2 template for abstract facet .hpp file: + * [iface_facet_any.hpp.j2] + * 3. idl for facet methods + * [idl/IGCObject_DVsmSeqContFrame.json5] +**/ + +#include "sequence/IGCObject_DVsmSeqContFrame.hpp" + +namespace xo { + namespace scm { + auto + IGCObject_DVsmSeqContFrame::shallow_size(const DVsmSeqContFrame & self) noexcept -> size_type + { + return self.shallow_size(); + } + + auto + IGCObject_DVsmSeqContFrame::shallow_copy(const DVsmSeqContFrame & self, obj mm) noexcept -> Opaque + { + return self.shallow_copy(mm); + } + + auto + IGCObject_DVsmSeqContFrame::forward_children(DVsmSeqContFrame & self, obj gc) noexcept -> size_type + { + return self.forward_children(gc); + } + + } /*namespace scm*/ +} /*namespace xo*/ + +/* end IGCObject_DVsmSeqContFrame.cpp */ diff --git a/xo-interpreter2/src/interpreter2/IPrintable_DVsmSeqContFrame.cpp b/xo-interpreter2/src/interpreter2/IPrintable_DVsmSeqContFrame.cpp new file mode 100644 index 00000000..74801873 --- /dev/null +++ b/xo-interpreter2/src/interpreter2/IPrintable_DVsmSeqContFrame.cpp @@ -0,0 +1,28 @@ +/** @file IPrintable_DVsmSeqContFrame.cpp + * + * Generated automagically from ingredients: + * 1. code generator: + * [xo-facet/codegen/genfacet] + * arguments: + * --input [idl/IPrintable_DVsmSeqContFrame.json5] + * 2. jinja2 template for abstract facet .hpp file: + * [iface_facet_any.hpp.j2] + * 3. idl for facet methods + * [idl/IPrintable_DVsmSeqContFrame.json5] +**/ + +#include "sequence/IPrintable_DVsmSeqContFrame.hpp" + +namespace xo { + namespace scm { + auto + IPrintable_DVsmSeqContFrame::pretty(const DVsmSeqContFrame & self, const ppindentinfo & ppii) -> bool + { + return self.pretty(ppii); + } + + + } /*namespace scm*/ +} /*namespace xo*/ + +/* end IPrintable_DVsmSeqContFrame.cpp */ diff --git a/xo-interpreter2/src/interpreter2/VirtualSchematikaMachine.cpp b/xo-interpreter2/src/interpreter2/VirtualSchematikaMachine.cpp index 8ff78ae0..9408c966 100644 --- a/xo-interpreter2/src/interpreter2/VirtualSchematikaMachine.cpp +++ b/xo-interpreter2/src/interpreter2/VirtualSchematikaMachine.cpp @@ -7,11 +7,13 @@ #include "VsmApplyFrame.hpp" #include "VsmEvalArgsFrame.hpp" #include "VsmApplyClosureFrame.hpp" +#include "VsmSeqContFrame.hpp" #include "VsmRcx.hpp" #include "Closure.hpp" #include #include #include +#include #include //#include #include @@ -188,6 +190,9 @@ namespace xo { case vsm_opcode::applycoda: _do_applycoda_op(); break; + case vsm_opcode::seq_cont: + _do_seq_cont_op(); + break; } return true; @@ -328,7 +333,7 @@ namespace xo { auto apply = obj::from(expr_); - // evaluated arguments + // accumulate evaluated arguments here DArray * args = DArray::empty(mm_.to_op(), apply->n_args()); @@ -361,8 +366,42 @@ namespace xo { void VirtualSchematikaMachine::_do_eval_sequence_op() { - // not implemented - assert(false); + // assuming bump allocator: + // + // VsmEvalSequence + // v + // +-------+------+-------+-------+ + // | par x | cont | seq | i_elt | + // +-----|-+------+-------+-------+ + // | + // <-----/ + // + + auto seq_expr = obj::from(expr_); + + if (seq_expr->size() == 0) { + /* empty sequence expression does not produce a value */ + + this->value_ = VsmResult(obj()); + this->pc_ = this->cont_; + return; + } + + auto seqexpr_frame + = obj + (DVsmSeqContFrame::make(mm_.to_op(), + this->stack_ /*saved stack*/, + this->cont_ /*saved cont*/, + seq_expr.data() /*saved expr*/, + 0 /*index of seq element*/)); + + this->stack_ = seqexpr_frame; + + // Setup evaluation of first sequence element + + this->cont_ = VsmInstr::c_seq_cont; + this->expr_ = (*seq_expr.data())[0]; + this->pc_ = VsmInstr::c_eval; } void @@ -380,7 +419,7 @@ namespace xo { _do_call_closure_op(); return; } else { - _do_call_closure_op(); + _do_call_primitive_op(); return; } } @@ -393,6 +432,8 @@ namespace xo { auto closure = obj::from(fn_); + assert(closure); + // TODO: for tail recursion: // check whether stack_ already refers to a // DVsmApplyClosureFrame instance, in which case @@ -496,8 +537,8 @@ namespace xo { = evalargs_frame->apply_expr(); if (i_arg == -1) { - bool is_native_fn = value.to_facet(); bool is_closure = obj::from(value); + bool is_native_fn = value.try_to_facet(); if (is_native_fn || is_closure) { apply_frame->assign_fn(value); @@ -572,6 +613,39 @@ namespace xo { // not implemented assert(false); } + + void + VirtualSchematikaMachine::_do_seq_cont_op() + { + auto frame = obj::from(stack_); + + assert(frame); + + uint32_t i_seq = 1 + frame->i_seq(); + + auto seq_expr = frame->seq_expr(); + + assert(seq_expr); + + if (i_seq == seq_expr->size()) { + /* done with sequence + * value of sequence-expr is the value of the last expression in that sequence, + * which is already in the value_ register + */ + + this->stack_ = frame->parent(); + this->pc_ = frame->cont(); + return; + } else { + frame->incr_i_seq(); + + this->cont_ = VsmInstr::c_seq_cont; + this->expr_ = (*seq_expr)[i_seq]; + this->pc_ = VsmInstr::c_eval; + return; + } + } + } /*namespace scm*/ } /*namespace xo*/ diff --git a/xo-interpreter2/src/interpreter2/VsmInstr.cpp b/xo-interpreter2/src/interpreter2/VsmInstr.cpp index 02ac8325..640ac9fe 100644 --- a/xo-interpreter2/src/interpreter2/VsmInstr.cpp +++ b/xo-interpreter2/src/interpreter2/VsmInstr.cpp @@ -16,6 +16,7 @@ namespace xo { case vsm_opcode::apply: return "apply"; case vsm_opcode::evalargs: return "evalargs"; case vsm_opcode::applycoda: return "applycoda"; + case vsm_opcode::seq_cont: return "seq_cont"; case vsm_opcode::N: break; } @@ -37,6 +38,9 @@ namespace xo { VsmInstr VsmInstr::c_applycoda = VsmInstr(vsm_opcode::applycoda); + + VsmInstr + VsmInstr::c_seq_cont = VsmInstr(vsm_opcode::seq_cont); } /*namespace scm*/ } /*namespace xo*/ diff --git a/xo-interpreter2/src/interpreter2/interpreter2_register_facets.cpp b/xo-interpreter2/src/interpreter2/interpreter2_register_facets.cpp index 1548aeaf..588419a2 100644 --- a/xo-interpreter2/src/interpreter2/interpreter2_register_facets.cpp +++ b/xo-interpreter2/src/interpreter2/interpreter2_register_facets.cpp @@ -9,6 +9,7 @@ #include "VsmApplyFrame.hpp" #include "VsmEvalArgsFrame.hpp" #include "VsmApplyClosureFrame.hpp" +#include "VsmSeqContFrame.hpp" #include "Primitive_gco_2_gco_gco.hpp" #include "Closure.hpp" #include "LocalEnv.hpp" @@ -32,10 +33,12 @@ namespace xo { { scope log(XO_DEBUG(true)); - // VsmStackFrame + + // VsmStqackFrame // +- VsmApplyFrame // +- VsmEvalArgsFrame - // \- VsmApplyClosureFrame + // +- VsmApplyClosureFrame + // \- VsmSeqContFrame FacetRegistry::register_impl(); FacetRegistry::register_impl(); @@ -46,22 +49,27 @@ namespace xo { FacetRegistry::register_impl(); FacetRegistry::register_impl(); + FacetRegistry::register_impl(); + FacetRegistry::register_impl(); + // LocalEnv FacetRegistry::register_impl(); FacetRegistry::register_impl(); // Procedure - // +- Primitive_gco_2_gco_gco - // \- Closure + // \- Primitive_gco_2_gco_gco FacetRegistry::register_impl(); FacetRegistry::register_impl(); FacetRegistry::register_impl(); -// FacetRegistry::register_impl(); -// FacetRegistry::register_impl(); -// FacetRegistry::register_impl(); + // Closure + +// FacetRegistry::register_impl(); // if/when provided + FacetRegistry::register_impl(); + FacetRegistry::register_impl(); + // RuntimeContext // \- VsmRcx @@ -70,6 +78,8 @@ namespace xo { log && log(xtag("DVsmApplyFrame.tseq", typeseq::id())); log && log(xtag("DVsmEvalArgsFrame.tseq", typeseq::id())); + log && log(xtag("DVsmApplyClosureFrame.tseq", typeseq::id())); + log && log(xtag("DVsmSeqContFrame.tseq", typeseq::id())); log && log(xtag("DClosure.tseq", typeseq::id())); log && log(xtag("DLocalEnv.tseq", typeseq::id())); log && log(xtag("DVsmRcx.tseq", typeseq::id()));