xo-interpreter2: ifelse expressions working + utest

This commit is contained in:
Roland Conybeare 2026-02-14 11:15:38 -05:00
commit 8ff02d52c1
18 changed files with 508 additions and 7 deletions

View file

@ -0,0 +1,82 @@
/** @file DVsmIfElseContFrame.hpp
*
* @author Roland Conybeare, Feb 2026
**/
#pragma once
#include "VsmInstr.hpp"
#include <xo/expression2/IfElseExpr.hpp>
#include <xo/gc/GCObject.hpp>
namespace xo {
namespace scm {
/** @brief saved VSM state during evaluation of a SequenceExpr
**/
class DVsmIfElseContFrame {
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 **/
///@{
DVsmIfElseContFrame(obj<AGCObject> parent,
VsmInstr cont,
DIfElseExpr * ifelse_expr);
/** create instance using memory from allocator @p mm **/
static DVsmIfElseContFrame * make(obj<AAllocator> mm,
obj<AGCObject> parent,
VsmInstr cont,
DIfElseExpr * ifelse_expr);
///@}
/** @defgroup scm-vsmevalsequenceframe-access-methods access methods **/
///@{
obj<AGCObject> parent() const noexcept { return parent_; }
VsmInstr cont() const noexcept { return cont_; }
DIfElseExpr * ifelse_expr() const noexcept { return ifelse_expr_; }
///@}
/** @defgroup scm-vsmevalsequenceframe-general-methods general methods **/
///@{
///@}
/** @defgroup scm-vsmevalsequenceframe-gcobject-facet gcobject facet **/
///@{
std::size_t shallow_size() const noexcept;
DVsmIfElseContFrame * 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 **/
DIfElseExpr * ifelse_expr_ = nullptr;
///@}
};
} /*namespace scm*/
} /*namespace xo*/
/* end DVsmIfElseContFrame.hpp */

View file

@ -187,6 +187,11 @@ namespace xo {
**/
void _do_apply_cont_op();
/** proceed with if- or else- branch of an if-else expression
* after evaluating test condition
**/
void _do_ifelse_cont_op();
/** loop continuation after evaluating element of a SequenceExpr **/
void _do_seq_cont_op();

View file

@ -0,0 +1,12 @@
/** @file VsmIfElseContFrame.hpp
*
* @author Roland Conybeare, Feb 2026
**/
#pragma once
#include "DVsmIfElseContFrame.hpp"
#include "ifelse/IGCObject_DVsmIfElseContFrame.hpp"
#include "ifelse/IPrintable_DVsmIfElseContFrame.hpp"
/* end VsmIfElseContFrame.hpp */

View file

@ -13,14 +13,21 @@ namespace xo {
public:
explicit VsmInstr(vsm_opcode oc) : opcode_{oc} {}
// instructions
static VsmInstr c_halt;
static VsmInstr c_eval;
static VsmInstr c_apply;
static VsmInstr c_evalargs;
/** proceed to continuation after an ApplyExpr **/
/** restore VSM state for continuation of an apply expression **/
static VsmInstr c_apply_cont;
/** proceed to branch of if-else expression after evaluating
* test condition
**/
static VsmInstr c_ifelse_cont;
/** loop to evaluate members of a SequenceExpr **/
static VsmInstr c_seq_cont;

View file

@ -28,11 +28,14 @@ namespace xo {
**/
evalargs,
/** Coda to restore vsm registers (local_env, stack, cont)
/** continuation to restore vsm registers (local_env, stack, cont)
* after invoking a closure
**/
apply_cont,
/** continuation to act on a branch **/
ifelse_cont,
/** Loop over elements of a SequenceExpr **/
seq_cont,
@ -55,3 +58,4 @@ namespace xo {
} /*namespace xo*/
/* end VsmOpcode.hpp */

View file

@ -0,0 +1,67 @@
/** @file IGCObject_DVsmIfElseContFrame.hpp
*
* Generated automagically from ingredients:
* 1. code generator:
* [xo-facet/codegen/genfacet]
* arguments:
* --input [idl/IGCObject_DVsmIfElseContFrame.json5]
* 2. jinja2 template for abstract facet .hpp file:
* [iface_facet_repr.hpp.j2]
* 3. idl for facet methods
* [idl/IGCObject_DVsmIfElseContFrame.json5]
**/
#pragma once
#include "GCObject.hpp"
#include <xo/gc/GCObject.hpp>
#include <xo/alloc2/Allocator.hpp>
#include "DVsmIfElseContFrame.hpp"
namespace xo { namespace scm { class IGCObject_DVsmIfElseContFrame; } }
namespace xo {
namespace facet {
template <>
struct FacetImplementation<xo::mm::AGCObject,
xo::scm::DVsmIfElseContFrame>
{
using ImplType = xo::mm::IGCObject_Xfer
<xo::scm::DVsmIfElseContFrame,
xo::scm::IGCObject_DVsmIfElseContFrame>;
};
}
}
namespace xo {
namespace scm {
/** @class IGCObject_DVsmIfElseContFrame
**/
class IGCObject_DVsmIfElseContFrame {
public:
/** @defgroup scm-gcobject-dvsmifelsecontframe-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-dvsmifelsecontframe-methods **/
///@{
// const methods
/** memory consumption for this instance **/
static size_type shallow_size(const DVsmIfElseContFrame & self) noexcept;
/** copy instance using allocator **/
static Opaque shallow_copy(const DVsmIfElseContFrame & self, obj<AAllocator> mm) noexcept;
// non-const methods
/** during GC: forward immdiate children **/
static size_type forward_children(DVsmIfElseContFrame & self, obj<ACollector> gc) noexcept;
///@}
};
} /*namespace scm*/
} /*namespace xo*/
/* end */

View file

@ -0,0 +1,62 @@
/** @file IPrintable_DVsmIfElseContFrame.hpp
*
* Generated automagically from ingredients:
* 1. code generator:
* [xo-facet/codegen/genfacet]
* arguments:
* --input [idl/IPrintable_DVsmIfElseContFrame.json5]
* 2. jinja2 template for abstract facet .hpp file:
* [iface_facet_repr.hpp.j2]
* 3. idl for facet methods
* [idl/IPrintable_DVsmIfElseContFrame.json5]
**/
#pragma once
#include "Printable.hpp"
#include <xo/printable2/Printable.hpp>
#include <xo/printable2/detail/IPrintable_Xfer.hpp>
#include "DVsmIfElseContFrame.hpp"
namespace xo { namespace scm { class IPrintable_DVsmIfElseContFrame; } }
namespace xo {
namespace facet {
template <>
struct FacetImplementation<xo::print::APrintable,
xo::scm::DVsmIfElseContFrame>
{
using ImplType = xo::print::IPrintable_Xfer
<xo::scm::DVsmIfElseContFrame,
xo::scm::IPrintable_DVsmIfElseContFrame>;
};
}
}
namespace xo {
namespace scm {
/** @class IPrintable_DVsmIfElseContFrame
**/
class IPrintable_DVsmIfElseContFrame {
public:
/** @defgroup scm-printable-dvsmifelsecontframe-type-traits **/
///@{
using ppindentinfo = xo::print::APrintable::ppindentinfo;
using Copaque = xo::print::APrintable::Copaque;
using Opaque = xo::print::APrintable::Opaque;
///@}
/** @defgroup scm-printable-dvsmifelsecontframe-methods **/
///@{
// const methods
/** Pretty-printing support for this object.
See [xo-indentlog/xo/indentlog/pretty.hpp] **/
static bool pretty(const DVsmIfElseContFrame & self, const ppindentinfo & ppii);
// non-const methods
///@}
};
} /*namespace scm*/
} /*namespace xo*/
/* end */