xo-interpreter: vsm work on environments [WIP]
This commit is contained in:
parent
d869e87516
commit
6f87a2324a
5 changed files with 72 additions and 2 deletions
29
xo-interpreter2/include/xo/interpreter2/DGlobalEnv.hpp
Normal file
29
xo-interpreter2/include/xo/interpreter2/DGlobalEnv.hpp
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
/** @file DGlobalEnv.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Feb 2026
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <xo/expression2/DGlobalSymtab.hpp>
|
||||
#include <xo/object2/DList.hpp>
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
|
||||
|
||||
/** @brief runtime bindings for global variabels
|
||||
**/
|
||||
class DGlobalEnv {
|
||||
public:
|
||||
DGLobalEnv() = default;
|
||||
|
||||
private:
|
||||
// absurd O(n) implementation for now
|
||||
// replace with gc-aware hashtable, when available.
|
||||
|
||||
/** globals. Slots in @ref global_v_ are numbered in DLocalSymtab **/
|
||||
DArray * global_v_ = nullptr;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -11,7 +11,7 @@
|
|||
namespace xo {
|
||||
namespace scm {
|
||||
|
||||
/** @brief bindings for arguments to a lambda
|
||||
/** @brief runtime bindings for arguments to a lambda
|
||||
**/
|
||||
class DLocalEnv {
|
||||
public:
|
||||
|
|
|
|||
2
xo-interpreter2/include/xo/interpreter2/DVsmRcx.hpp
Normal file
2
xo-interpreter2/include/xo/interpreter2/DVsmRcx.hpp
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
/** @file DVsmRcx.hpp
|
||||
n*
|
||||
|
|
@ -194,6 +194,9 @@ namespace xo {
|
|||
// for VM stack. Only works for code that doesn't rely on fancy
|
||||
// lexical scoping
|
||||
|
||||
// consider separate allocator for reader (i.e. program code)
|
||||
// and data (program execution)
|
||||
|
||||
/** reader: text -> expression **/
|
||||
SchematikaReader reader_;
|
||||
|
||||
|
|
@ -206,6 +209,16 @@ namespace xo {
|
|||
/** expression register **/
|
||||
obj<AExpression> expr_;
|
||||
|
||||
/** environment pointer. Provides bindings
|
||||
* for surrounding lexical scope at this point
|
||||
* in execution
|
||||
**/
|
||||
DLocalEnv * local_env_ = nullptr;
|
||||
/** environment pointer. Maintains bindings
|
||||
* for global variables.
|
||||
**/
|
||||
DGlobalEnv * global_env_ = nullptr;
|
||||
|
||||
/** function to call **/
|
||||
obj<AProcedure> fn_;
|
||||
/** evaluated argument list **/
|
||||
|
|
|
|||
|
|
@ -36,7 +36,9 @@ namespace xo {
|
|||
mm_(box<AAllocator,DX1Collector>(new DX1Collector(config.x1_config_))),
|
||||
rcx_(box<ARuntimeContext,DSimpleRcx>(new DSimpleRcx(mm_.to_op()))),
|
||||
reader_{config.rdr_config_, mm_.to_op()}
|
||||
{}
|
||||
{
|
||||
// TODO: allocate global_env
|
||||
}
|
||||
|
||||
void
|
||||
VirtualSchematikaMachine::visit_pools(const MemorySizeVisitor & visitor) const
|
||||
|
|
@ -202,6 +204,30 @@ namespace xo {
|
|||
void
|
||||
VirtualSchematikaMachine::_do_eval_lambda_op()
|
||||
{
|
||||
// assuming bump allocator
|
||||
//
|
||||
// +----------- DArray---------+ +-------------DLocalEnv-----------+ +-----DClosure-------+
|
||||
// | .cap |.size | .elts_[]... |h| .parent x | .symtab x | .args x |h| .lambda x | .env x |
|
||||
// +------+------+-------------+ +---------|-+---------|-+-------|-+ +---------|-+------|-+
|
||||
// ^ ^ | | | | |
|
||||
// \-----------------------------|---------|-----------|---------/ | |
|
||||
// | | | | |
|
||||
// \---------|-----------|-----------------------|--------/
|
||||
// | | |
|
||||
// <--------------------------------------/ | |
|
||||
// | |
|
||||
// v v
|
||||
// DLocalSymtab DLambdaExpr
|
||||
//
|
||||
// DClosure runtime procedure (created below)
|
||||
// DArray bound non-local variables (established by VSM)
|
||||
// DLocalEnv local environment (copy ref from VSM state)
|
||||
// h alloc header
|
||||
// DLocalSymtab local symbol table (created by parser)
|
||||
// DLambdaExpr lambda expression (created by parser)
|
||||
|
||||
DArray * args =
|
||||
|
||||
// not implemented
|
||||
assert(false);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue