xo-interpreter2 stack: define-expr's work at top-level

This commit is contained in:
Roland Conybeare 2026-02-17 14:42:17 -05:00
commit 6f3833d6fb
56 changed files with 1550 additions and 65 deletions

View file

@ -25,18 +25,55 @@ namespace xo {
**/
class DGlobalEnv {
public:
using ACollector = xo::mm::ACollector;
using AAllocator = xo::mm::AAllocator;
using AGCObject = xo::mm::AGCObject;
using MemorySizeVisitor = xo::mm::MemorySizeVisitor;
using ppindentinfo = xo::print::ppindentinfo;
using size_type = std::uint32_t;
public:
DGlobalEnv() = default;
/** @defgroup scm-globalenv-ctors constructors **/
///@{
/** visit env-owned memory pools; call visitor(info) for each **/
void visit_pools(const MemorySizeVisitor & visitor) const;
DGlobalEnv(DGlobalSymtab * symtab, DArray * values);
protected: // temporary, to appease compiler
static DGlobalEnv * _make(obj<AAllocator> mm,
DGlobalSymtab * symtab);
// absurd O(n) implementation for now
// replace with gc-aware hashtable, when available.
///@}
/** @defgroup scm-globalenv-methods methods **/
///@{
/** symbol-table size. Is the number of distinct global symbols **/
size_type size() const noexcept { return symtab_->size(); }
/** lookup current value associated with binding @p ix **/
obj<AGCObject> lookup_value(Binding ix) const noexcept;
/** assign value associated with binding @p to @p x.
* If need to expand size of this env, use memory from @p mm
**/
void assign_value(obj<AAllocator> mm, Binding ix, obj<AGCObject> x);
///@}
/** @defgroup scm-globalenv-gcobject-facet **/
///@{
std::size_t shallow_size() const noexcept;
DGlobalEnv * shallow_copy(obj<AAllocator> mm) const noexcept;
std::size_t forward_children(obj<ACollector> gc) noexcept;
///@}
/** @defgroup scm-globalenv-printable-facet **/
///@{
bool pretty(const ppindentinfo & ppii) const;
///@}
private:
/** symbol table assigns a unique index for each symbol **/
DGlobalSymtab * symtab_;

View file

@ -37,7 +37,7 @@ namespace xo {
DArray * args);
///@}
/** @defgroup scm-local-env-methods methods **/
/** @defgroup scm-localenv-methods methods **/
///@{
DLocalEnv * parent() const noexcept { return parent_; }

View file

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

View file

@ -0,0 +1,12 @@
/** @file GlobalEnv.hpp
*
* @author Roland Conybeare, Feb 2026
**/
#pragma once
#include "DGlobalEnv.hpp"
#include "env/IGCObject_DGlobalEnv.hpp"
#include "env/IPrintable_DGlobalEnv.hpp"
/* end GlobalEnv.hpp */

View file

@ -191,6 +191,11 @@ namespace xo {
/** call primitive @ref fn_ with arguments @ref args_ **/
void _do_call_primitive_op();
/** perform assignment after evaluating
* the rhs of a define-expr
**/
void _do_def_cont_op();
/** restore registers from stack frame
* (specifically: local_env_, stack_, cont_)
* after invoking a schematika closure
@ -225,13 +230,13 @@ namespace xo {
#ifdef NOT_YET
/** allocator (likely DArena) for globals.
* For example DArenaHashMap in global symtab,
* For example DArenaHashMap in global symta.
**/
obj<AAllocator> aux_mm_;
#endif
/** allocator (likely DX1Collector or similar) for
* expressions and values
* expressions and values. Schemaatika reader will use this also
**/
abox<AAllocator> mm_;
@ -267,19 +272,17 @@ namespace xo {
/** expression register **/
obj<AExpression> expr_;
/** environment pointer. Maintains bindings
* for global variables.
**/
DGlobalEnv * global_env_ = nullptr;
/** environment pointer. Provides bindings
* for surrounding lexical scope at this point
* in execution
**/
DLocalEnv * local_env_ = nullptr;
protected: // temporarily, to appease compiler
/** environment pointer. Maintains bindings
* for global variables.
**/
DGlobalEnv * global_env_ = nullptr;
private:
/** evaluated function to call **/
obj<AGCObject> fn_;
/** evaluated argument list **/

View file

@ -0,0 +1,12 @@
/** @file VsmDefContFrame.hpp
*
* @author Roland Conybeare, Feb 2026
**/
#pragma once
#include "DVsmDefContFrame.hpp"
#include "define/IGCObject_DVsmDefContFrame.hpp"
#include "define/IPrintable_DVsmDefContFrame.hpp"
/* end VsmDefContFrame.hpp */

View file

@ -9,15 +9,25 @@
namespace xo {
namespace scm {
/**
* Thin instruction wrapper for VSM (virtual schematika machine) instructions.
* For exeuction see VirtualSchematikaMachine.cpp
**/
class VsmInstr {
public:
explicit VsmInstr(vsm_opcode oc) : opcode_{oc} {}
// instructions
static VsmInstr c_sentinel;
static VsmInstr c_halt;
static VsmInstr c_eval;
/** proceed to assignment after evaluating rhs
* of define-expression
**/
static VsmInstr c_def_cont;
static VsmInstr c_apply;
static VsmInstr c_evalargs;
/** restore VSM state for continuation of an apply expression **/

View file

@ -14,6 +14,8 @@ namespace xo {
* exeucted by VirtualSchematikaMachine
**/
enum class vsm_opcode {
/** Flags bad state (defect in VSM itself) **/
sentinel,
/** Immediately halt virtual schematika machine. **/
halt,
/** Evaluate expression in expr register **/
@ -28,6 +30,11 @@ namespace xo {
**/
evalargs,
/** continuation to complete execution of define-expression,
* after evaluting rhs expression
**/
def_cont,
/** continuation to restore vsm registers (local_env, stack, cont)
* after invoking a closure
**/
@ -58,4 +65,3 @@ namespace xo {
} /*namespace xo*/
/* end VsmOpcode.hpp */

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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