xo-interpreter2 stack: handle SequenceExpr + gc for frames

This commit is contained in:
Roland Conybeare 2026-02-13 15:16:05 -05:00
commit caed95c54d
22 changed files with 559 additions and 36 deletions

View file

@ -5,7 +5,9 @@
#pragma once
#include "VsmFrame.hpp"
#include "VsmInstr.hpp"
#include <xo/procedure2/Procedure.hpp>
#include <xo/object2/DArray.hpp>
namespace xo {
namespace scm {

View file

@ -28,12 +28,12 @@ namespace xo {
**/
DVsmEvalArgsFrame(DVsmApplyFrame * parent,
VsmInstr cont,
const DApplyExpr * apply_expr);
DApplyExpr * apply_expr);
static DVsmEvalArgsFrame * make(obj<AAllocator> 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;

View file

@ -0,0 +1,89 @@
/** @file DVsmSeqContFrame.hpp
*
* @author Roland Conybeare, Feb 2026
**/
#pragma once
#include "VsmInstr.hpp"
#include <xo/expression2/SequenceExpr.hpp>
#include <xo/gc/GCObject.hpp>
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<AGCObject> parent,
VsmInstr cont,
DSequenceExpr * seq_expr,
uint32_t i_seq);
/** create instance using memory from allocator @p mm **/
static DVsmSeqContFrame * make(obj<AAllocator> mm,
obj<AGCObject> parent,
VsmInstr cont,
DSequenceExpr * seq_expr,
uint32_t i_seq);
///@}
/** @defgroup scm-vsmevalsequenceframe-access-methods access methods **/
///@{
obj<AGCObject> 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<AAllocator> mm) const noexcept;
std::size_t forward_children(obj<ACollector> 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<AGCObject> 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 */

View file

@ -187,6 +187,8 @@ namespace xo {
**/
void _do_applycoda_op();
/** loop continuation after evaluating element of a SequenceExpr **/
void _do_seq_cont_op();
private:
/*

View file

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

View file

@ -33,6 +33,9 @@ namespace xo {
**/
applycoda,
/** Loop over elements of a SequenceExpr **/
seq_cont,
/** sentinel, counts number of opcodes **/
N,
};

View file

@ -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 */

View file

@ -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 <xo/gc/GCObject.hpp>
#include <xo/alloc2/Allocator.hpp>
#include "DVsmSeqContFrame.hpp"
namespace xo { namespace scm { class IGCObject_DVsmSeqContFrame; } }
namespace xo {
namespace facet {
template <>
struct FacetImplementation<xo::mm::AGCObject,
xo::scm::DVsmSeqContFrame>
{
using ImplType = xo::mm::IGCObject_Xfer
<xo::scm::DVsmSeqContFrame,
xo::scm::IGCObject_DVsmSeqContFrame>;
};
}
}
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<AAllocator> mm) noexcept;
// non-const methods
/** during GC: forward immdiate children **/
static size_type forward_children(DVsmSeqContFrame & self, obj<ACollector> gc) noexcept;
///@}
};
} /*namespace scm*/
} /*namespace xo*/
/* end */

View file

@ -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 <xo/printable2/Printable.hpp>
#include <xo/printable2/detail/IPrintable_Xfer.hpp>
#include "DVsmSeqContFrame.hpp"
namespace xo { namespace scm { class IPrintable_DVsmSeqContFrame; } }
namespace xo {
namespace facet {
template <>
struct FacetImplementation<xo::print::APrintable,
xo::scm::DVsmSeqContFrame>
{
using ImplType = xo::print::IPrintable_Xfer
<xo::scm::DVsmSeqContFrame,
xo::scm::IPrintable_DVsmSeqContFrame>;
};
}
}
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 */