xo-interpreter2 stack: define-expr's work at top-level
This commit is contained in:
parent
735acc966b
commit
5e9b13c516
35 changed files with 1247 additions and 38 deletions
|
|
@ -25,6 +25,26 @@ add_subdirectory(utest)
|
|||
|
||||
# ----------------------------------------------------------------
|
||||
|
||||
# note: manual target; generated code committed to git
|
||||
xo_add_genfacetimpl(
|
||||
TARGET xo-interpreter2-facetimpl-gcobject-vsmdefcontframe
|
||||
FACET_PKG xo_gc
|
||||
FACET GCObject
|
||||
REPR VsmDefContFrame
|
||||
INPUT idl/IGCObject_DVsmDefContFrame.json5
|
||||
)
|
||||
|
||||
# note: manual target; generated code committed to git
|
||||
xo_add_genfacetimpl(
|
||||
TARGET xo-interpreter2-facetimpl-printable-vsmdefcontframe
|
||||
FACET_PKG xo_printable2
|
||||
FACET Printable
|
||||
REPR VsmDefContFrame
|
||||
INPUT idl/IPrintable_DVsmDefContFrame.json5
|
||||
)
|
||||
|
||||
# ----------------------------------------------------------------
|
||||
|
||||
# note: manual target; generated code committed to git
|
||||
xo_add_genfacetimpl(
|
||||
TARGET xo-interpreter2-facetimpl-gcobject-vsmapplyframe
|
||||
|
|
@ -155,6 +175,26 @@ xo_add_genfacetimpl(
|
|||
|
||||
# ----------------------------------------------------------------
|
||||
|
||||
# note: manual target; generated code committed to git
|
||||
xo_add_genfacetimpl(
|
||||
TARGET xo-interpreter2-facetimpl-gcobject-globalenv
|
||||
FACET_PKG xo_gc
|
||||
FACET GCObject
|
||||
REPR GlobalEnv
|
||||
INPUT idl/IGCObject_DGlobalEnv.json5
|
||||
)
|
||||
|
||||
# note: manual target; generated code committed to git
|
||||
xo_add_genfacetimpl(
|
||||
TARGET xo-interpreter2-facetimpl-printable-globalenv
|
||||
FACET_PKG xo_printable2
|
||||
FACET Printable
|
||||
REPR GlobalEnv
|
||||
INPUT idl/IPrintable_DGlobalEnv.json5
|
||||
)
|
||||
|
||||
# ----------------------------------------------------------------
|
||||
|
||||
# note: manual target; generated code committed to git
|
||||
xo_add_genfacetimpl(
|
||||
TARGET xo-interpreter2-facetimpl-gcobject-localenv
|
||||
|
|
|
|||
18
idl/IGCObject_DGlobalEnv.json5
Normal file
18
idl/IGCObject_DGlobalEnv.json5
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
mode: "implementation",
|
||||
output_cpp_dir: "src/interpreter2",
|
||||
output_hpp_dir: "include/xo/interpreter2",
|
||||
output_impl_subdir: "env",
|
||||
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 GlobalEnv",
|
||||
using_doxygen: true,
|
||||
repr: "DGlobalEnv",
|
||||
doc: [ "implement AGCObject for DGlobalEnv" ],
|
||||
}
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
mode: "implementation",
|
||||
output_cpp_dir: "src/interpreter2",
|
||||
output_hpp_dir: "include/xo/interpreter2",
|
||||
output_impl_subdir: "detail",
|
||||
output_impl_subdir: "env",
|
||||
includes: [
|
||||
"<xo/gc/GCObject.hpp>",
|
||||
"<xo/alloc2/Allocator.hpp>"
|
||||
|
|
|
|||
18
idl/IGCObject_DVsmDefContFrame.json5
Normal file
18
idl/IGCObject_DVsmDefContFrame.json5
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
mode: "implementation",
|
||||
output_cpp_dir: "src/interpreter2",
|
||||
output_hpp_dir: "include/xo/interpreter2",
|
||||
output_impl_subdir: "define",
|
||||
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 DVsmDefContFrame",
|
||||
using_doxygen: true,
|
||||
repr: "DVsmDefContFrame",
|
||||
doc: [ "implement AGCObject for DVsmDefContFrame" ],
|
||||
}
|
||||
16
idl/IPrintable_DGlobalEnv.json5
Normal file
16
idl/IPrintable_DGlobalEnv.json5
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
mode: "implementation",
|
||||
output_cpp_dir: "src/interpreter2",
|
||||
output_hpp_dir: "include/xo/interpreter2",
|
||||
output_impl_subdir: "env",
|
||||
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 DGlobalEnv",
|
||||
using_doxygen: true,
|
||||
repr: "DGlobalEnv",
|
||||
doc: [ "implement APrintable for DGlobalEnv" ],
|
||||
}
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
mode: "implementation",
|
||||
output_cpp_dir: "src/interpreter2",
|
||||
output_hpp_dir: "include/xo/interpreter2",
|
||||
output_impl_subdir: "detail",
|
||||
output_impl_subdir: "env",
|
||||
includes: [ "<xo/printable2/Printable.hpp>",
|
||||
"<xo/printable2/detail/IPrintable_Xfer.hpp>" ],
|
||||
local_types: [ ],
|
||||
|
|
|
|||
16
idl/IPrintable_DVsmDefContFrame.json5
Normal file
16
idl/IPrintable_DVsmDefContFrame.json5
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
mode: "implementation",
|
||||
output_cpp_dir: "src/interpreter2",
|
||||
output_hpp_dir: "include/xo/interpreter2",
|
||||
output_impl_subdir: "define",
|
||||
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 DVsmDefContFrame",
|
||||
using_doxygen: true,
|
||||
repr: "DVsmDefContFrame",
|
||||
doc: [ "implement APrintable for DVsmDefContFrame" ],
|
||||
}
|
||||
|
|
@ -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_;
|
||||
|
|
|
|||
|
|
@ -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_; }
|
||||
|
|
|
|||
82
include/xo/interpreter2/DVsmDefContFrame.hpp
Normal file
82
include/xo/interpreter2/DVsmDefContFrame.hpp
Normal 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 */
|
||||
12
include/xo/interpreter2/GlobalEnv.hpp
Normal file
12
include/xo/interpreter2/GlobalEnv.hpp
Normal 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 */
|
||||
|
|
@ -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 **/
|
||||
|
|
|
|||
12
include/xo/interpreter2/VsmDefContFrame.hpp
Normal file
12
include/xo/interpreter2/VsmDefContFrame.hpp
Normal 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 */
|
||||
|
|
@ -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 **/
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
@ -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 */
|
||||
67
include/xo/interpreter2/env/IGCObject_DGlobalEnv.hpp
vendored
Normal file
67
include/xo/interpreter2/env/IGCObject_DGlobalEnv.hpp
vendored
Normal 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 */
|
||||
67
include/xo/interpreter2/env/IGCObject_DLocalEnv.hpp
vendored
Normal file
67
include/xo/interpreter2/env/IGCObject_DLocalEnv.hpp
vendored
Normal 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 */
|
||||
62
include/xo/interpreter2/env/IPrintable_DGlobalEnv.hpp
vendored
Normal file
62
include/xo/interpreter2/env/IPrintable_DGlobalEnv.hpp
vendored
Normal 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 */
|
||||
62
include/xo/interpreter2/env/IPrintable_DLocalEnv.hpp
vendored
Normal file
62
include/xo/interpreter2/env/IPrintable_DLocalEnv.hpp
vendored
Normal 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 */
|
||||
|
|
@ -8,6 +8,10 @@ set(SELF_SRCS
|
|||
|
||||
VirtualSchematikaMachine.cpp
|
||||
|
||||
DVsmDefContFrame.cpp
|
||||
IGCObject_DVsmDefContFrame.cpp
|
||||
IPrintable_DVsmDefContFrame.cpp
|
||||
|
||||
DVsmEvalArgsFrame.cpp
|
||||
IGCObject_DVsmEvalArgsFrame.cpp
|
||||
IPrintable_DVsmEvalArgsFrame.cpp
|
||||
|
|
@ -32,9 +36,13 @@ set(SELF_SRCS
|
|||
IGCObject_DClosure.cpp
|
||||
IPrintable_DClosure.cpp
|
||||
|
||||
DGlobalEnv.cpp
|
||||
IGCObject_DGlobalEnv.cpp
|
||||
IPrintable_DGlobalEnv.cpp
|
||||
|
||||
DLocalEnv.cpp
|
||||
IGCObject_DLocalEnv.cpp
|
||||
IPrintable_DLocalEnv.cpp
|
||||
DLocalEnv.cpp
|
||||
|
||||
DVsmRcx.cpp
|
||||
IRuntimeContext_DVsmRcx.cpp
|
||||
|
|
|
|||
128
src/interpreter2/DGlobalEnv.cpp
Normal file
128
src/interpreter2/DGlobalEnv.cpp
Normal file
|
|
@ -0,0 +1,128 @@
|
|||
/** @file DGlobalEnv.cpp
|
||||
*
|
||||
* @author Roland Conybeare, Feb 2026
|
||||
**/
|
||||
|
||||
#include "GlobalEnv.hpp"
|
||||
#include <xo/expression2/GlobalSymtab.hpp>
|
||||
#include <xo/object2/Array.hpp>
|
||||
|
||||
namespace xo {
|
||||
using xo::mm::AAllocator;
|
||||
using xo::mm::AGCObject;
|
||||
|
||||
namespace scm {
|
||||
|
||||
DGlobalEnv::DGlobalEnv(DGlobalSymtab * symtab, DArray * values)
|
||||
: symtab_{symtab}, values_{values}
|
||||
{}
|
||||
|
||||
DGlobalEnv *
|
||||
DGlobalEnv::_make(obj<AAllocator> mm,
|
||||
DGlobalSymtab * symtab)
|
||||
{
|
||||
DArray * values = DArray::empty(mm, symtab->capacity());
|
||||
|
||||
void * mem = mm.alloc_for<DGlobalSymtab>();
|
||||
|
||||
return new (mem) DGlobalEnv(symtab, values);
|
||||
}
|
||||
|
||||
obj<AGCObject>
|
||||
DGlobalEnv::lookup_value(Binding ix) const noexcept
|
||||
{
|
||||
if (!ix.is_global()) {
|
||||
assert(false);
|
||||
return obj<AGCObject>();
|
||||
}
|
||||
|
||||
if (ix.j_slot() >= static_cast<int32_t>(values_->size())) {
|
||||
assert(false);
|
||||
return obj<AGCObject>();
|
||||
}
|
||||
|
||||
return (*values_)[ix.j_slot()];
|
||||
}
|
||||
|
||||
void
|
||||
DGlobalEnv::assign_value(obj<AAllocator> mm, Binding ix, obj<AGCObject> x)
|
||||
{
|
||||
scope log(XO_DEBUG(true),
|
||||
xtag("ix.j_slot", ix.j_slot()),
|
||||
xtag("values.cap", values_->capacity()));
|
||||
|
||||
assert(ix.is_global());
|
||||
|
||||
if (ix.j_slot() >= static_cast<int32_t>(values_->size())) {
|
||||
// Control will come here in interpreter as new definitions are introduced.
|
||||
// After seeing
|
||||
// def foo = 1.2345;
|
||||
// introducing new symbol foo:
|
||||
// GlobalSymtab extends to include foo without this GlobalEnv
|
||||
// knowing about it.
|
||||
|
||||
if (ix.j_slot() + 1 > static_cast<int32_t>(values_->capacity())) {
|
||||
// realloc global array for more size
|
||||
|
||||
size_t cap_2x = 2 * values_->capacity();
|
||||
|
||||
while (cap_2x < static_cast<size_t>(ix.j_slot() + 1))
|
||||
cap_2x = 2 * cap_2x;
|
||||
|
||||
DArray * values_2x = DArray::copy(mm, values_, cap_2x);
|
||||
assert(values_2x);
|
||||
|
||||
if (values_2x) {
|
||||
log && log("STUB: need write barrier for GC (also in GlobalSymtab!)");
|
||||
this->values_ = values_2x;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/** expand size sot that j_slot is valid **/
|
||||
values_->resize(ix.j_slot() + 1);
|
||||
}
|
||||
|
||||
log && log("STUB: need write barrier for GC here");
|
||||
(*values_)[ix.j_slot()] = x;
|
||||
}
|
||||
|
||||
// ----- AGCObject facet -----
|
||||
|
||||
std::size_t
|
||||
DGlobalEnv::shallow_size() const noexcept
|
||||
{
|
||||
return sizeof(*this);
|
||||
}
|
||||
|
||||
DGlobalEnv *
|
||||
DGlobalEnv::shallow_copy(obj<AAllocator> mm) const noexcept
|
||||
{
|
||||
return mm.std_copy_for<DGlobalEnv>(this);
|
||||
}
|
||||
|
||||
std::size_t
|
||||
DGlobalEnv::forward_children(obj<ACollector> gc) noexcept
|
||||
{
|
||||
gc.forward_inplace(&symtab_);
|
||||
gc.forward_inplace(&values_);
|
||||
|
||||
return this->shallow_size();
|
||||
}
|
||||
|
||||
// ----- APrintable facet -----
|
||||
|
||||
bool
|
||||
DGlobalEnv::pretty(const ppindentinfo & ppii) const
|
||||
{
|
||||
return ppii.pps()->pretty_struct
|
||||
(ppii,
|
||||
"DGlobalEnv",
|
||||
refrtag("size", symtab_->size()));
|
||||
}
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end DGlobalEnv.cpp */
|
||||
|
|
@ -6,6 +6,7 @@
|
|||
#include "LocalEnv.hpp"
|
||||
#include <xo/object2/Array.hpp>
|
||||
#include <xo/reflectutil/typeseq.hpp>
|
||||
#include <xo/indentlog/scope.hpp>
|
||||
|
||||
namespace xo {
|
||||
using xo::mm::AGCObject;
|
||||
|
|
@ -64,6 +65,8 @@ namespace xo {
|
|||
void
|
||||
DLocalEnv::assign_value(Binding ix, obj<AGCObject> x)
|
||||
{
|
||||
scope log(XO_DEBUG(true));
|
||||
|
||||
assert(!ix.is_global());
|
||||
|
||||
const DLocalEnv * env = this;
|
||||
|
|
@ -76,6 +79,7 @@ namespace xo {
|
|||
auto j = ix.j_slot();
|
||||
|
||||
if (j < static_cast<decltype(j)>(env->size())) {
|
||||
log && log("STUB: need write barrier for GC here");
|
||||
(*(env->args_))[j] = x;
|
||||
} else {
|
||||
assert(false);
|
||||
|
|
|
|||
68
src/interpreter2/DVsmDefContFrame.cpp
Normal file
68
src/interpreter2/DVsmDefContFrame.cpp
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
/** @file DVsmDefContFrame.cpp
|
||||
*
|
||||
* @author Roland Conybeare, Feb 2026
|
||||
**/
|
||||
|
||||
#include "DVsmDefContFrame.hpp"
|
||||
#include <xo/expression2/DefineExpr.hpp>
|
||||
#include <xo/gc/Collector.hpp>
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
|
||||
DVsmDefContFrame::DVsmDefContFrame(obj<AGCObject> parent,
|
||||
VsmInstr cont,
|
||||
DDefineExpr * def_expr)
|
||||
: parent_{parent},
|
||||
cont_{cont},
|
||||
def_expr_{def_expr}
|
||||
{}
|
||||
|
||||
DVsmDefContFrame *
|
||||
DVsmDefContFrame::make(obj<AAllocator> mm,
|
||||
obj<AGCObject> parent,
|
||||
VsmInstr cont,
|
||||
DDefineExpr * def_expr)
|
||||
{
|
||||
void * mem = mm.alloc_for<DVsmDefContFrame>();
|
||||
|
||||
return new (mem) DVsmDefContFrame(parent, cont, def_expr);
|
||||
}
|
||||
|
||||
// gcobject facet
|
||||
|
||||
std::size_t
|
||||
DVsmDefContFrame::shallow_size() const noexcept
|
||||
{
|
||||
return sizeof(*this);
|
||||
}
|
||||
|
||||
DVsmDefContFrame *
|
||||
DVsmDefContFrame::shallow_copy(obj<AAllocator> mm) const noexcept
|
||||
{
|
||||
return mm.std_copy_for<DVsmDefContFrame>(this);
|
||||
}
|
||||
|
||||
std::size_t
|
||||
DVsmDefContFrame::forward_children(obj<ACollector> gc) noexcept
|
||||
{
|
||||
gc.forward_inplace(&parent_);
|
||||
gc.forward_inplace(&def_expr_);
|
||||
|
||||
return this->shallow_size();
|
||||
}
|
||||
|
||||
// printable facet
|
||||
|
||||
bool
|
||||
DVsmDefContFrame::pretty(const ppindentinfo & ppii) const noexcept
|
||||
{
|
||||
return ppii.pps()->pretty_struct(ppii,
|
||||
"DVsmDefContFrame",
|
||||
refrtag("cont", cont_));
|
||||
}
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end DVsmDefContFrame.cpp */
|
||||
39
src/interpreter2/IGCObject_DGlobalEnv.cpp
Normal file
39
src/interpreter2/IGCObject_DGlobalEnv.cpp
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
/** @file IGCObject_DGlobalEnv.cpp
|
||||
*
|
||||
* 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_any.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/IGCObject_DGlobalEnv.json5]
|
||||
**/
|
||||
|
||||
#include "env/IGCObject_DGlobalEnv.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
auto
|
||||
IGCObject_DGlobalEnv::shallow_size(const DGlobalEnv & self) noexcept -> size_type
|
||||
{
|
||||
return self.shallow_size();
|
||||
}
|
||||
|
||||
auto
|
||||
IGCObject_DGlobalEnv::shallow_copy(const DGlobalEnv & self, obj<AAllocator> mm) noexcept -> Opaque
|
||||
{
|
||||
return self.shallow_copy(mm);
|
||||
}
|
||||
|
||||
auto
|
||||
IGCObject_DGlobalEnv::forward_children(DGlobalEnv & self, obj<ACollector> gc) noexcept -> size_type
|
||||
{
|
||||
return self.forward_children(gc);
|
||||
}
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end IGCObject_DGlobalEnv.cpp */
|
||||
|
|
@ -11,7 +11,7 @@
|
|||
* [idl/IGCObject_DLocalEnv.json5]
|
||||
**/
|
||||
|
||||
#include "detail/IGCObject_DLocalEnv.hpp"
|
||||
#include "env/IGCObject_DLocalEnv.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
|
|
|
|||
39
src/interpreter2/IGCObject_DVsmDefContFrame.cpp
Normal file
39
src/interpreter2/IGCObject_DVsmDefContFrame.cpp
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
/** @file IGCObject_DVsmDefContFrame.cpp
|
||||
*
|
||||
* 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_any.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/IGCObject_DVsmDefContFrame.json5]
|
||||
**/
|
||||
|
||||
#include "define/IGCObject_DVsmDefContFrame.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
auto
|
||||
IGCObject_DVsmDefContFrame::shallow_size(const DVsmDefContFrame & self) noexcept -> size_type
|
||||
{
|
||||
return self.shallow_size();
|
||||
}
|
||||
|
||||
auto
|
||||
IGCObject_DVsmDefContFrame::shallow_copy(const DVsmDefContFrame & self, obj<AAllocator> mm) noexcept -> Opaque
|
||||
{
|
||||
return self.shallow_copy(mm);
|
||||
}
|
||||
|
||||
auto
|
||||
IGCObject_DVsmDefContFrame::forward_children(DVsmDefContFrame & self, obj<ACollector> gc) noexcept -> size_type
|
||||
{
|
||||
return self.forward_children(gc);
|
||||
}
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end IGCObject_DVsmDefContFrame.cpp */
|
||||
28
src/interpreter2/IPrintable_DGlobalEnv.cpp
Normal file
28
src/interpreter2/IPrintable_DGlobalEnv.cpp
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
/** @file IPrintable_DGlobalEnv.cpp
|
||||
*
|
||||
* 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_any.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/IPrintable_DGlobalEnv.json5]
|
||||
**/
|
||||
|
||||
#include "env/IPrintable_DGlobalEnv.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
auto
|
||||
IPrintable_DGlobalEnv::pretty(const DGlobalEnv & self, const ppindentinfo & ppii) -> bool
|
||||
{
|
||||
return self.pretty(ppii);
|
||||
}
|
||||
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end IPrintable_DGlobalEnv.cpp */
|
||||
|
|
@ -11,7 +11,7 @@
|
|||
* [idl/IPrintable_DLocalEnv.json5]
|
||||
**/
|
||||
|
||||
#include "detail/IPrintable_DLocalEnv.hpp"
|
||||
#include "env/IPrintable_DLocalEnv.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
|
|
|
|||
28
src/interpreter2/IPrintable_DVsmDefContFrame.cpp
Normal file
28
src/interpreter2/IPrintable_DVsmDefContFrame.cpp
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
/** @file IPrintable_DVsmDefContFrame.cpp
|
||||
*
|
||||
* 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_any.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/IPrintable_DVsmDefContFrame.json5]
|
||||
**/
|
||||
|
||||
#include "define/IPrintable_DVsmDefContFrame.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
auto
|
||||
IPrintable_DVsmDefContFrame::pretty(const DVsmDefContFrame & self, const ppindentinfo & ppii) -> bool
|
||||
{
|
||||
return self.pretty(ppii);
|
||||
}
|
||||
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end IPrintable_DVsmDefContFrame.cpp */
|
||||
|
|
@ -4,6 +4,7 @@
|
|||
**/
|
||||
|
||||
#include "VirtualSchematikaMachine.hpp"
|
||||
#include "VsmDefContFrame.hpp"
|
||||
#include "VsmApplyFrame.hpp"
|
||||
#include "VsmEvalArgsFrame.hpp"
|
||||
#include "VsmApplyClosureFrame.hpp"
|
||||
|
|
@ -11,10 +12,12 @@
|
|||
#include "VsmSeqContFrame.hpp"
|
||||
#include "VsmRcx.hpp"
|
||||
#include "Closure.hpp"
|
||||
#include <xo/expression2/DefineExpr.hpp>
|
||||
#include <xo/expression2/ApplyExpr.hpp>
|
||||
#include <xo/expression2/LambdaExpr.hpp>
|
||||
#include <xo/expression2/Constant.hpp>
|
||||
#include <xo/expression2/SequenceExpr.hpp>
|
||||
#include <xo/expression2/UniqueString.hpp>
|
||||
#include <xo/object2/Boolean.hpp>
|
||||
#include <xo/procedure2/RuntimeContext.hpp>
|
||||
//#include <xo/procedure2/SimpleRcx.hpp>
|
||||
|
|
@ -65,10 +68,10 @@ namespace xo {
|
|||
DArena * arena = new DArena(config_.error_config_);
|
||||
assert(arena);
|
||||
|
||||
error_mm_.adopt(obj<AAllocator,DArena>(arena));
|
||||
this->error_mm_.adopt(obj<AAllocator,DArena>(arena));
|
||||
}
|
||||
|
||||
// TODO: allocate global_env
|
||||
this->global_env_ = DGlobalEnv::_make(mm_.to_op(), reader_.global_symtab());
|
||||
}
|
||||
|
||||
obj<AAllocator>
|
||||
|
|
@ -166,17 +169,20 @@ namespace xo {
|
|||
VirtualSchematikaMachine::execute_one()
|
||||
{
|
||||
scope log(XO_DEBUG(config_.debug_flag_));
|
||||
|
||||
log && log(xtag("pc", pc_),
|
||||
xtag("cont", cont_));
|
||||
|
||||
obj<APrintable> stack_pr = stack_.to_facet<APrintable>();
|
||||
// = (FacetRegistry::instance()
|
||||
// .try_variant<APrintable,AGCObject>(stack_));
|
||||
auto expr_pr = expr_.to_facet<APrintable>();
|
||||
if (expr_pr)
|
||||
log && log(xtag("expr", expr_pr));
|
||||
|
||||
auto stack_pr = stack_.to_facet<APrintable>();
|
||||
if (stack_pr)
|
||||
log && log(xtag("stack", stack_pr));
|
||||
|
||||
switch (pc_.opcode()) {
|
||||
case vsm_opcode::sentinel:
|
||||
case vsm_opcode::halt:
|
||||
case vsm_opcode::N:
|
||||
return false;
|
||||
|
|
@ -189,6 +195,9 @@ namespace xo {
|
|||
case vsm_opcode::evalargs:
|
||||
_do_evalargs_op();
|
||||
break;
|
||||
case vsm_opcode::def_cont:
|
||||
_do_def_cont_op();
|
||||
break;
|
||||
case vsm_opcode::apply_cont:
|
||||
_do_apply_cont_op();
|
||||
break;
|
||||
|
|
@ -244,14 +253,84 @@ namespace xo {
|
|||
= obj<AExpression,DConstant>::from(expr_);
|
||||
|
||||
this->value_ = VsmResult(expr.data()->value());
|
||||
|
||||
this->pc_ = this->cont_;
|
||||
this->cont_ = VsmInstr::c_sentinel;
|
||||
}
|
||||
|
||||
void
|
||||
VirtualSchematikaMachine::_do_eval_define_op()
|
||||
{
|
||||
// not implemented
|
||||
assert(false);
|
||||
scope log(XO_DEBUG(true));
|
||||
|
||||
auto def_expr
|
||||
= obj<AExpression,DDefineExpr>::from(expr_);
|
||||
|
||||
if (local_env_ == nullptr) {
|
||||
// top-level define
|
||||
|
||||
// .stack_ --+
|
||||
// |
|
||||
// v
|
||||
// +------DVsmDefContFrame------+
|
||||
// | .parent x | .cont | .def x |
|
||||
// +---------|-+-------+------|-+
|
||||
// | |
|
||||
// ParserStack* <-----/ |
|
||||
// |
|
||||
// v
|
||||
// DDefineExpr
|
||||
|
||||
/* stack frame for nested continuation
|
||||
* (to perform assignment)
|
||||
*/
|
||||
auto defcont_frame
|
||||
= obj<AGCObject,DVsmDefContFrame>
|
||||
(DVsmDefContFrame::make(mm_.to_op(),
|
||||
this->stack_ /*saved stack*/,
|
||||
this->cont_ /*saved cont*/,
|
||||
def_expr.data() /*saved expr*/));
|
||||
|
||||
this->stack_ = defcont_frame;
|
||||
|
||||
// setup evaluation of rhs
|
||||
|
||||
this->expr_ = def_expr->rhs();
|
||||
this->pc_ = VsmInstr::c_eval;
|
||||
this->cont_ = VsmInstr::c_def_cont;
|
||||
} else {
|
||||
// nested defines implemented by rewriting,
|
||||
// so this branch should be unreachable
|
||||
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
VirtualSchematikaMachine::_do_def_cont_op()
|
||||
{
|
||||
// see DVsmDefContFrame
|
||||
|
||||
auto frame = obj<AGCObject,DVsmDefContFrame>::from(stack_);
|
||||
|
||||
assert(frame);
|
||||
assert(value_.is_value());
|
||||
|
||||
// TODO: verify that value satisfies expected type ?
|
||||
|
||||
DVariable * lhs = frame->def_expr()->lhs();
|
||||
obj<AGCObject> rhs = *value_.value();
|
||||
|
||||
assert(lhs->path().is_global());
|
||||
|
||||
global_env_->assign_value(mm_.to_op(), lhs->path(), rhs);
|
||||
|
||||
// TODO: unfortunate const_cast here, because obj<> doesn't support const DRepr yet
|
||||
this->value_ = VsmResult(obj<AGCObject,DUniqueString>(const_cast<DUniqueString*>(lhs->name())));
|
||||
|
||||
this->stack_ = frame->parent();
|
||||
this->pc_ = frame->cont();
|
||||
this->cont_ = VsmInstr::c_sentinel;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -294,7 +373,9 @@ namespace xo {
|
|||
|
||||
this->value_
|
||||
= VsmResult(obj<AGCObject>(obj<AGCObject,DClosure>(closure)));
|
||||
|
||||
this->pc_ = this->cont_;
|
||||
this->cont_ = VsmInstr::c_sentinel;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -320,7 +401,9 @@ namespace xo {
|
|||
|
||||
if (value) {
|
||||
this->value_ = VsmResult(value);
|
||||
|
||||
this->pc_ = this->cont_;
|
||||
this->cont_ = VsmInstr::c_sentinel;
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -338,6 +421,7 @@ namespace xo {
|
|||
// 3. have every vsm instruction check inputs for errors
|
||||
|
||||
this->pc_ = VsmInstr::c_halt;
|
||||
this->cont_ = VsmInstr::c_sentinel;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -385,9 +469,9 @@ namespace xo {
|
|||
|
||||
// Setup evaluation of first argument. No new stack for this.
|
||||
|
||||
this->cont_ = VsmInstr::c_evalargs;
|
||||
this->expr_ = apply->fn();
|
||||
this->pc_ = VsmInstr::c_eval;
|
||||
this->cont_ = VsmInstr::c_evalargs;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -404,9 +488,9 @@ namespace xo {
|
|||
stack_, cont_, ifelse_expr.data()));
|
||||
|
||||
this->stack_ = ifelse_frame;
|
||||
this->cont_ = VsmInstr::c_ifelse_cont;
|
||||
this->expr_ = ifelse_expr->test();
|
||||
this->pc_ = VsmInstr::c_eval;
|
||||
this->cont_ = VsmInstr::c_ifelse_cont;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -445,9 +529,9 @@ namespace xo {
|
|||
|
||||
// Setup evaluation of first sequence element
|
||||
|
||||
this->cont_ = VsmInstr::c_seq_cont;
|
||||
this->expr_ = (*seq_expr.data())[0];
|
||||
this->pc_ = VsmInstr::c_eval;
|
||||
this->cont_ = VsmInstr::c_seq_cont;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -514,6 +598,7 @@ namespace xo {
|
|||
this->local_env_ = local_env;
|
||||
this->expr_ = lambda->body_expr();
|
||||
this->pc_ = VsmInstr::c_eval;
|
||||
// cont_ already established
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -523,6 +608,7 @@ namespace xo {
|
|||
|
||||
this->value_ = VsmResult(fn.apply_nocheck(rcx_.to_op(), args_));
|
||||
this->pc_ = cont_;
|
||||
this->cont_ = VsmInstr::c_sentinel;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -537,6 +623,7 @@ namespace xo {
|
|||
log && log("error in apply -> terminating app");
|
||||
|
||||
this->pc_ = VsmInstr::c_halt;
|
||||
this->cont_ = VsmInstr::c_sentinel;
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -595,7 +682,7 @@ namespace xo {
|
|||
|
||||
this->expr_ = apply_expr->arg(i_arg);
|
||||
this->pc_ = VsmInstr::c_eval;
|
||||
//this->cont_ = VsmInstra::c_evalargs; // redundant, since preserved
|
||||
this->cont_ = VsmInstr::c_evalargs;
|
||||
|
||||
return;
|
||||
} else {
|
||||
|
|
@ -633,7 +720,7 @@ namespace xo {
|
|||
} else {
|
||||
this->expr_ = apply_expr->arg(i_arg);
|
||||
this->pc_ = VsmInstr::c_eval;
|
||||
//this->cont_ = VsmInstra::c_evalargs; // redundant, since preserved
|
||||
this->cont_ = VsmInstr::c_evalargs;
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
@ -655,6 +742,7 @@ namespace xo {
|
|||
this->stack_ = frame->parent();
|
||||
this->local_env_ = frame->local_env();
|
||||
this->pc_ = frame->cont();
|
||||
this->cont_ = VsmInstr::c_sentinel;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -682,9 +770,9 @@ namespace xo {
|
|||
}
|
||||
|
||||
this->stack_ = frame->parent();
|
||||
this->cont_ = frame->cont();
|
||||
this->expr_ = next_expr;
|
||||
this->pc_ = VsmInstr::c_eval;
|
||||
this->cont_ = frame->cont();
|
||||
} else {
|
||||
auto error = DRuntimeError::make(mm_.to_op(),
|
||||
"_do_ifelse_cont_op",
|
||||
|
|
@ -698,6 +786,7 @@ namespace xo {
|
|||
// 3. have every vsm instruction check inputs for errors
|
||||
|
||||
this->pc_ = VsmInstr::c_halt;
|
||||
this->cont_ = VsmInstr::c_sentinel;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -722,13 +811,16 @@ namespace xo {
|
|||
|
||||
this->stack_ = frame->parent();
|
||||
this->pc_ = frame->cont();
|
||||
this->cont_ = VsmInstr::c_sentinel;
|
||||
|
||||
return;
|
||||
} else {
|
||||
frame->incr_i_seq();
|
||||
|
||||
this->cont_ = VsmInstr::c_seq_cont;
|
||||
this->expr_ = (*seq_expr)[i_seq];
|
||||
this->pc_ = VsmInstr::c_eval;
|
||||
this->cont_ = VsmInstr::c_seq_cont;
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,10 +11,12 @@ namespace xo {
|
|||
vsm_opcode_descr(vsm_opcode x)
|
||||
{
|
||||
switch (x) {
|
||||
case vsm_opcode::sentinel: return "sentinel";
|
||||
case vsm_opcode::halt: return "halt";
|
||||
case vsm_opcode::eval: return "eval";
|
||||
case vsm_opcode::apply: return "apply";
|
||||
case vsm_opcode::evalargs: return "evalargs";
|
||||
case vsm_opcode::def_cont: return "def_cont";
|
||||
case vsm_opcode::apply_cont: return "apply_cont";
|
||||
case vsm_opcode::ifelse_cont: return "ifelse_cont";
|
||||
case vsm_opcode::seq_cont: return "seq_cont";
|
||||
|
|
@ -25,6 +27,9 @@ namespace xo {
|
|||
return "opcode?";
|
||||
}
|
||||
|
||||
VsmInstr
|
||||
VsmInstr::c_sentinel = VsmInstr(vsm_opcode::sentinel);
|
||||
|
||||
VsmInstr
|
||||
VsmInstr::c_halt = VsmInstr(vsm_opcode::halt);
|
||||
|
||||
|
|
@ -37,12 +42,15 @@ namespace xo {
|
|||
VsmInstr
|
||||
VsmInstr::c_evalargs = VsmInstr(vsm_opcode::evalargs);
|
||||
|
||||
VsmInstr
|
||||
VsmInstr::c_def_cont = VsmInstr(vsm_opcode::def_cont);
|
||||
|
||||
VsmInstr
|
||||
VsmInstr::c_apply_cont = VsmInstr(vsm_opcode::apply_cont);
|
||||
|
||||
VsmInstr
|
||||
VsmInstr::c_ifelse_cont = VsmInstr(vsm_opcode::ifelse_cont);
|
||||
|
||||
|
||||
VsmInstr
|
||||
VsmInstr::c_seq_cont = VsmInstr(vsm_opcode::seq_cont);
|
||||
} /*namespace scm*/
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
#include "interpreter2_register_facets.hpp"
|
||||
|
||||
#include "DPrimitive_gco_2_gco_gco.hpp"
|
||||
#include "VsmDefContFrame.hpp"
|
||||
#include "VsmApplyFrame.hpp"
|
||||
#include "VsmEvalArgsFrame.hpp"
|
||||
#include "VsmApplyClosureFrame.hpp"
|
||||
|
|
@ -13,6 +14,7 @@
|
|||
#include "VsmSeqContFrame.hpp"
|
||||
#include "Primitive_gco_2_gco_gco.hpp"
|
||||
#include "Closure.hpp"
|
||||
#include "GlobalEnv.hpp"
|
||||
#include "LocalEnv.hpp"
|
||||
#include "VsmRcx.hpp"
|
||||
|
||||
|
|
@ -39,6 +41,7 @@ namespace xo {
|
|||
// +- VsmApplyFrame
|
||||
// +- VsmEvalArgsFrame
|
||||
// +- VsmApplyClosureFrame
|
||||
// +- VsmDefContFrame
|
||||
// +- VsmIfElseContFrame
|
||||
// \- VsmSeqContFrame
|
||||
|
||||
|
|
@ -51,12 +54,20 @@ namespace xo {
|
|||
FacetRegistry::register_impl<AGCObject, DVsmApplyClosureFrame>();
|
||||
FacetRegistry::register_impl<APrintable, DVsmApplyClosureFrame>();
|
||||
|
||||
FacetRegistry::register_impl<AGCObject, DVsmDefContFrame>();
|
||||
FacetRegistry::register_impl<APrintable, DVsmDefContFrame>();
|
||||
|
||||
FacetRegistry::register_impl<AGCObject, DVsmIfElseContFrame>();
|
||||
FacetRegistry::register_impl<APrintable, DVsmIfElseContFrame>();
|
||||
|
||||
FacetRegistry::register_impl<AGCObject, DVsmSeqContFrame>();
|
||||
FacetRegistry::register_impl<APrintable, DVsmSeqContFrame>();
|
||||
|
||||
// GlobalEnv
|
||||
|
||||
FacetRegistry::register_impl<AGCObject, DGlobalEnv>();
|
||||
FacetRegistry::register_impl<APrintable, DGlobalEnv>();
|
||||
|
||||
// LocalEnv
|
||||
|
||||
FacetRegistry::register_impl<AGCObject, DLocalEnv>();
|
||||
|
|
@ -84,8 +95,12 @@ namespace xo {
|
|||
log && log(xtag("DVsmApplyFrame.tseq", typeseq::id<DVsmApplyFrame>()));
|
||||
log && log(xtag("DVsmEvalArgsFrame.tseq", typeseq::id<DVsmEvalArgsFrame>()));
|
||||
log && log(xtag("DVsmApplyClosureFrame.tseq", typeseq::id<DVsmApplyClosureFrame>()));
|
||||
log && log(xtag("DVsmDefContFrame.tseq", typeseq::id<DVsmDefContFrame>()));
|
||||
log && log(xtag("DVsmDefContFrame.tseq", typeseq::id<DVsmDefContFrame>()));
|
||||
log && log(xtag("DVsmIfElseContFrame.tseq", typeseq::id<DVsmIfElseContFrame>()));
|
||||
log && log(xtag("DVsmSeqContFrame.tseq", typeseq::id<DVsmSeqContFrame>()));
|
||||
log && log(xtag("DClosure.tseq", typeseq::id<DClosure>()));
|
||||
log && log(xtag("DGlobalEnv.tseq", typeseq::id<DGlobalEnv>()));
|
||||
log && log(xtag("DLocalEnv.tseq", typeseq::id<DLocalEnv>()));
|
||||
log && log(xtag("DVsmRcx.tseq", typeseq::id<DVsmRcx>()));
|
||||
|
||||
|
|
|
|||
|
|
@ -5,11 +5,13 @@
|
|||
|
||||
#include <xo/interpreter2/VirtualSchematikaMachine.hpp>
|
||||
#include <xo/interpreter2/Closure.hpp>
|
||||
#include <xo/expression2/UniqueString.hpp>
|
||||
#include <xo/object2/Float.hpp>
|
||||
#include <xo/object2/Integer.hpp>
|
||||
#include <xo/object2/Boolean.hpp>
|
||||
#include <xo/object2/RuntimeError.hpp>
|
||||
#include <xo/alloc2/Arena.hpp>
|
||||
#include <xo/facet/TypeRegistry.hpp>
|
||||
|
||||
#ifdef NOT_YET
|
||||
#include <xo/reader2/SchematikaParser.hpp>
|
||||
|
|
@ -32,6 +34,7 @@ namespace xo {
|
|||
using xo::scm::VsmResultExt;
|
||||
using xo::scm::DClosure;
|
||||
using xo::scm::DString;
|
||||
using xo::scm::DUniqueString; // aks Symbol in lisp
|
||||
using xo::scm::DFloat;
|
||||
using xo::scm::DBoolean;
|
||||
using xo::scm::DInteger;
|
||||
|
|
@ -42,6 +45,7 @@ namespace xo {
|
|||
using xo::mm::DArena;
|
||||
using xo::mm::ArenaConfig;
|
||||
using xo::facet::FacetRegistry;
|
||||
using xo::facet::TypeRegistry;
|
||||
using span_type = xo::scm::VirtualSchematikaMachine::span_type;
|
||||
using Catch::Matchers::WithinAbs;
|
||||
|
||||
|
|
@ -81,6 +85,7 @@ namespace xo {
|
|||
|
||||
aux_mm_.arena_.visit_pools(visitor);
|
||||
FacetRegistry::instance().visit_pools(visitor);
|
||||
TypeRegistry::instance().visit_pools(visitor);
|
||||
vsm_.visit_pools(visitor);
|
||||
|
||||
return true;
|
||||
|
|
@ -298,7 +303,7 @@ namespace xo {
|
|||
{
|
||||
const auto & testname = Catch::getResultCapture().getCurrentTestName();
|
||||
|
||||
bool c_debug_flag = true;
|
||||
bool c_debug_flag = false;
|
||||
scope log(XO_DEBUG(c_debug_flag), xtag("test", testname));
|
||||
|
||||
VsmFixture vsm_fixture(testname, c_debug_flag);
|
||||
|
|
@ -333,6 +338,96 @@ namespace xo {
|
|||
log && vsm_fixture.log_memory_layout(&log);
|
||||
}
|
||||
|
||||
TEST_CASE("VirtualSchematikaMachine-def1", "[interpreter2][VSM]")
|
||||
{
|
||||
const auto & testname = Catch::getResultCapture().getCurrentTestName();
|
||||
|
||||
bool c_debug_flag = false;
|
||||
scope log(XO_DEBUG(c_debug_flag), xtag("test", testname));
|
||||
|
||||
VsmFixture vsm_fixture(testname, c_debug_flag);
|
||||
auto & vsm = vsm_fixture.vsm_;
|
||||
|
||||
bool eof_flag = false;
|
||||
|
||||
vsm.begin_interactive_session();
|
||||
VsmResultExt res
|
||||
= vsm.read_eval_print(span_type::from_cstr("def foo = 3.14159;"),
|
||||
eof_flag);
|
||||
|
||||
REQUIRE(res.is_value());
|
||||
REQUIRE(res.value());
|
||||
|
||||
log && log(xtag("res.tseq", res.value()->_typeseq()),
|
||||
xtag("res.type", TypeRegistry::id2name(res.value()->_typeseq())));
|
||||
|
||||
// currently get not-implemented error
|
||||
auto x = obj<AGCObject,DUniqueString>::from(*res.value());
|
||||
|
||||
REQUIRE(x);
|
||||
REQUIRE(strcmp(x->chars(), "foo") == 0);
|
||||
|
||||
//log && log("runtime-error", xtag("ex.src", x->src_function()), xtag("ex.descr", x->error_descr()));
|
||||
|
||||
//REQUIRE(x.data()->value() == 1.570796325);
|
||||
|
||||
REQUIRE(res.remaining_.size() == 1);
|
||||
REQUIRE(*res.remaining_.lo() == '\n');
|
||||
|
||||
log && vsm_fixture.log_memory_layout(&log);
|
||||
}
|
||||
|
||||
TEST_CASE("VirtualSchematikaMachine-def2", "[interpreter2][VSM]")
|
||||
{
|
||||
const auto & testname = Catch::getResultCapture().getCurrentTestName();
|
||||
|
||||
bool c_debug_flag = true;
|
||||
scope log(XO_DEBUG(c_debug_flag), xtag("test", testname));
|
||||
|
||||
VsmFixture vsm_fixture(testname, c_debug_flag);
|
||||
auto & vsm = vsm_fixture.vsm_;
|
||||
|
||||
bool eof_flag = false;
|
||||
|
||||
vsm.begin_interactive_session();
|
||||
|
||||
span_type input = span_type::from_cstr("def foo = 3.14159; foo");
|
||||
|
||||
for (int i_expr = 0; i_expr < 2; ++i_expr) {
|
||||
VsmResultExt res
|
||||
= vsm.read_eval_print(input, eof_flag);
|
||||
|
||||
REQUIRE(res.is_value());
|
||||
REQUIRE(res.value());
|
||||
|
||||
log && log(xtag("res.tseq", res.value()->_typeseq()),
|
||||
xtag("res.type", TypeRegistry::id2name(res.value()->_typeseq())));
|
||||
|
||||
if (i_expr == 0) {
|
||||
auto x = obj<AGCObject,DUniqueString>::from(*res.value());
|
||||
REQUIRE(x);
|
||||
REQUIRE(strcmp(x->chars(), "foo") == 0);
|
||||
|
||||
REQUIRE(res.remaining_.size() > 1);
|
||||
|
||||
input = res.remaining_;
|
||||
} else if (i_expr == 1) {
|
||||
auto x = obj<AGCObject,DFloat>::from(*res.value());
|
||||
REQUIRE(x);
|
||||
REQUIRE(x->value() == 3.14159);
|
||||
|
||||
REQUIRE(res.remaining_.size() == 1);
|
||||
REQUIRE(*res.remaining_.lo() == '\n');
|
||||
input = res.remaining_;
|
||||
}
|
||||
|
||||
++i_expr;
|
||||
}
|
||||
|
||||
log && vsm_fixture.log_memory_layout(&log);
|
||||
|
||||
}
|
||||
|
||||
} /*namespace ut*/
|
||||
} /*namespace xo*/
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue