xo-interpreter2: + VsmApplyClosureFrame [WIP, not used]

This commit is contained in:
Roland Conybeare 2026-02-13 00:09:43 -05:00
commit 0ab3b63a38
17 changed files with 410 additions and 12 deletions

View file

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

View file

@ -0,0 +1,15 @@
{
mode: "implementation",
includes: [
"<xo/gc/GCObject.hpp>",
"<xo/alloc2/Allocator.hpp>"
],
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" ],
}

View file

@ -0,0 +1,13 @@
{
mode: "implementation",
includes: [ "<xo/printable2/Printable.hpp>",
"<xo/printable2/detail/IPrintable_Xfer.hpp>" ],
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" ],
}

View file

@ -0,0 +1,52 @@
/** @file DVsmApplyClosureFrame.hpp
*
* @author Roland Conybeare, Feb 2026
**/
#pragma once
#include "VsmInstr.hpp"
#include "DLocalEnv.hpp"
#include <xo/expression2/DApplyExpr.hpp>
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<AGCObject> stack,
VsmInstr cont,
DLocalEnv * env);
/** gcobject facet **/
std::size_t shallow_size() const noexcept;
DVsmApplyClosureFrame * 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;
protected:
/** saved VSM stack_ register **/
obj<AGCObject> stack_;
/** saved VSM cont_ register **/
VsmInstr cont_;
/** saved VSM local_env_ register **/
DLocalEnv * local_env_ = nullptr;
};
} /*namespace scm*/
} /*namespace xo*/
/* end DVsmApplyClosureFrame.hpp */

View file

@ -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<AGCObject> parent() const noexcept { return parent_; }
VsmInstr cont() const noexcept { return cont_; }
obj<AProcedure> 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<AGCObject> parent_;
/** saved continuation; restore when this frame consumed **/
VsmInstr cont_;
/** evaluated target procedure.
*
* note: when initially created, this will be unpopulated;

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -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<AGCObject> 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<AAllocator> 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<ACollector> 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 */

View file

@ -14,8 +14,9 @@ namespace xo {
DVsmApplyFrame::DVsmApplyFrame(obj<AGCObject> old_parent,
VsmInstr old_cont,
DArray * args)
: VsmFrame(old_parent, old_cont),
args_{args}
: parent_{old_parent},
cont_{old_cont},
args_{args}
{}
DVsmApplyFrame *

View file

@ -49,7 +49,8 @@ namespace xo {
DVsmEvalArgsFrame *
DVsmEvalArgsFrame::shallow_copy(obj<AAllocator> 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;

View file

@ -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<AAllocator> mm) noexcept -> Opaque
{
return self.shallow_copy(mm);
}
auto
IGCObject_DVsmApplyClosureFrame::forward_children(DVsmApplyClosureFrame & self, obj<ACollector> gc) noexcept -> size_type
{
return self.forward_children(gc);
}
} /*namespace scm*/
} /*namespace xo*/
/* end IGCObject_DVsmApplyClosureFrame.cpp */

View file

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

View file

@ -62,7 +62,7 @@ namespace xo {
error_mm_.adopt(obj<AAllocator,DArena>(arena));
}
// TODO: allocate global_env
}

View file

@ -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<AGCObject, DVsmApplyFrame>();
FacetRegistry::register_impl<APrintable, DVsmApplyFrame>();
@ -39,9 +43,10 @@ namespace xo {
FacetRegistry::register_impl<AGCObject, DVsmEvalArgsFrame>();
FacetRegistry::register_impl<APrintable, DVsmEvalArgsFrame>();
FacetRegistry::register_impl<AProcedure, DClosure>();
FacetRegistry::register_impl<AGCObject, DClosure>();
FacetRegistry::register_impl<APrintable, DClosure>();
FacetRegistry::register_impl<AGCObject, DVsmApplyClosureFrame>();
FacetRegistry::register_impl<APrintable, DVsmApplyClosureFrame>();
// LocalEnv
FacetRegistry::register_impl<AGCObject, DLocalEnv>();
FacetRegistry::register_impl<APrintable, DLocalEnv>();
@ -50,7 +55,13 @@ namespace xo {
// +- Primitive_gco_2_gco_gco
// \- Closure
FacetRegistry::register_impl<AProcedure, DPrimitive_gco_2_gco_gco>();
FacetRegistry::register_impl<AGCObject, DPrimitive_gco_2_gco_gco>();
FacetRegistry::register_impl<APrintable, DPrimitive_gco_2_gco_gco>();
FacetRegistry::register_impl<AProcedure, DClosure>();
FacetRegistry::register_impl<AGCObject, DClosure>();
FacetRegistry::register_impl<APrintable, DClosure>();
// RuntimeContext
// \- VsmRcx