xo-interpreter2: vsm stack: facet + gcobject + printable + init

This commit is contained in:
Roland Conybeare 2026-02-04 01:44:28 -05:00
commit 5292518eaf
33 changed files with 980 additions and 141 deletions

View file

@ -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<AGCObject> old_parent,
VsmInstr old_cont,
DArray * args);
static DVsmApplyFrame * make(obj<AAllocator> mm,
obj<AGCObject> old_parent,
VsmInstr old_cont,
DArray * args);
obj<AProcedure> fn() const noexcept { return fn_; }
DArray * args() const noexcept { return args_; }
std::size_t shallow_size() const noexcept;
DVsmApplyFrame * shallow_copy(obj<AAllocator> mm) const noexcept;
std::size_t forward_children(obj<ACollector> 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<AProcedure> fn_;
/** evaluated arguments (to target procedure) **/
DArray * args_;
};
} /*namespace scm*/
} /*namespace xo*/
/* end DVsmApplyFrame.hpp */

View file

@ -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<AGCObject> old_parent,
VsmInstr old_cont);
static DVsmEvalArgsFrame * make(obj<AAllocator> mm,
obj<AGCObject> apply_frame,
VsmInstr old_cont);
std::size_t shallow_size() const noexcept;
DVsmEvalArgsFrame * shallow_copy(obj<AAllocator> mm) const noexcept;
std::size_t forward_children(obj<ACollector> 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 */

View file

@ -181,7 +181,7 @@ namespace xo {
VsmInstr pc_ = VsmInstr::c_halt;
/** stack pointer **/
VsmFrame * stack_ = nullptr;
obj<AGCObject> stack_;
/** expression register **/
obj<AExpression> expr_;

View file

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

View file

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

View file

@ -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<AGCObject> parent,
VsmInstr cont) : parent_{parent}, cont_{cont} {}
//obj<AGCObject> parent() const noexcept { return parent_; }
VsmFrame * parent() const noexcept {
return reinterpret_cast<VsmFrame *>(parent_.data());
}
VsmInstr cont() const noexcept { return cont_; }
protected:
/** saved VSM stack; restore when this frame consumed **/
VsmFrame * parent_ = nullptr;
obj<AGCObject> 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<AAllocator> mm,
VsmFrame * old_parent,
VsmInstr old_cont,
DArray * args);
obj<AProcedure> 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<AProcedure> 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<AAllocator> 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 */

View file

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

View file

@ -5,6 +5,7 @@
#pragma once
#include <ostream>
#include <cstdint>
namespace xo {
@ -32,6 +33,16 @@ namespace xo {
};
static constexpr uint32_t n_opcode = static_cast<uint32_t>(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*/

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -0,0 +1,17 @@
/** @file interpreter2_register_types.hpp
*
* @author Roland Conybeare, Dec 2025
**/
#pragma once
#include <xo/gc/Collector.hpp>
namespace xo {
namespace scm {
/** Register interpreter2 (facet,impl) combinations with FacetRegistry **/
bool interpreter2_register_types(obj<xo::mm::ACollector> gc);
}
}
/* end interpreter2_register_types.hpp */