xo-interpreter: + VSM work in progress

This commit is contained in:
Roland Conybeare 2026-02-03 21:44:40 -05:00
commit dc88663271
10 changed files with 307 additions and 7 deletions

View file

@ -4,6 +4,7 @@ set(SELF_LIB xo_interpreter2)
set(SELF_SRCS
init_interpreter2.cpp
VirtualSchematikaMachine.cpp
VsmFrame.cpp
VsmInstr.cpp
#IExpression_Any.cpp
#interpreter2_register_facets.cpp

View file

@ -4,8 +4,8 @@
**/
#include "VirtualSchematikaMachine.hpp"
#include <xo/expression2/detail/IExpression_DConstant.hpp>
#include <xo/expression2/DConstant.hpp>
#include <xo/expression2/ApplyExpr.hpp>
#include <xo/expression2/Constant.hpp>
#include <xo/gc/DX1Collector.hpp>
#include <xo/gc/detail/IAllocator_DX1Collector.hpp>
#include <xo/printable2/Printable.hpp>
@ -117,6 +117,13 @@ namespace xo {
return false;
case vsm_opcode::eval:
_do_eval_op();
break;
case vsm_opcode::apply:
_do_apply_op();
break;
case vsm_opcode::evalargs:
_do_evalargs_op();
break;
}
return true;
@ -187,8 +194,47 @@ namespace xo {
void
VirtualSchematikaMachine::_do_eval_apply_op()
{
// not implemented
assert(false);
// ApplyExpr in expr_ register
// assuming bump allocator:
//
// DArray VsmApplyFrame VsmEvalArgsFrame
// v v v
// +----------------------+-------+------+----+--------+-------+------+-------+
// | argument expressions | par x | cont | fn | args x | par x | cont | i_arg |
// +----------------------+-----|-+------+----+------|-+-----|-+------+-------+
// ^ ^ | | |
// | \----------------------------------/
// \ | /
// \-----------------------------------------------/
// /
// <---------------------------/
//
// - VsmEvalArgsFrame: owned by VSM, state for evalargs loop
// - VsmApplyFrame: owned by VSM, state for transferring control to called function
// - DArray: contains evaluated args; owned by called primitive
auto apply = obj<AExpression,DApplyExpr>::from(expr_);
// evaluated arguments
DArray * args = DArray::empty(mm_.to_op(),
apply->n_args());
// TODO: check function signature
VsmApplyFrame * apply_frame
= VsmApplyFrame::make(mm_.to_op(), stack_, cont_, args);
VsmEvalArgsFrame * evalargs_frame
= VsmEvalArgsFrame::make(mm_.to_op(), apply_frame, VsmInstr::c_apply);
this->stack_ = evalargs_frame;
// Setup evaluation of first argument. No new stack for this.
this->cont_ = VsmInstr::c_evalargs;
this->expr_ = apply->fn();
this->pc_ = VsmInstr::c_eval;
}
void
@ -204,6 +250,21 @@ namespace xo {
// not implemented
assert(false);
}
void
VirtualSchematikaMachine::_do_apply_op()
{
// not implemented
assert(false);
}
void
VirtualSchematikaMachine::_do_evalargs_op()
{
// not implemented
assert(false);
}
} /*namespace scm*/
} /*namespace xo*/

View file

@ -0,0 +1,68 @@
/** @file VsmFrame.cpp
*
* @author Roland Conybeare, Feb 2026
**/
#include "VsmFrame.hpp"
namespace xo {
using xo::facet::typeseq;
namespace scm {
VsmApplyFrame::VsmApplyFrame(VsmFrame * old_parent,
VsmInstr old_cont,
DArray * args)
: VsmFrame(old_parent, old_cont),
args_{args}
{}
VsmApplyFrame *
VsmApplyFrame::make(obj<AAllocator> mm,
VsmFrame * old_parent,
VsmInstr old_cont,
DArray * args)
{
VsmApplyFrame * result = nullptr;
void * mem = mm.alloc(typeseq::id<VsmApplyFrame>(),
sizeof(VsmApplyFrame));
result = new (mem) VsmApplyFrame(old_parent,
old_cont,
args);
assert(result);
return result;
}
// ----- VsmEvalArgsFrame -----
VsmEvalArgsFrame::VsmEvalArgsFrame(VsmApplyFrame * old_parent,
VsmInstr old_cont)
: VsmFrame(old_parent, old_cont)
{}
VsmEvalArgsFrame *
VsmEvalArgsFrame::make(obj<AAllocator> mm,
VsmApplyFrame * apply_frame,
VsmInstr cont)
{
VsmEvalArgsFrame * result = nullptr;
void * mem = mm.alloc(typeseq::id<VsmEvalArgsFrame>(),
sizeof(VsmEvalArgsFrame));
result = new (mem) VsmEvalArgsFrame(apply_frame, cont);
assert(result);
return result;
}
} /*namespace scm*/
} /*namespace xo*/
/* end VsmFrame.cpp */

View file

@ -12,6 +12,12 @@ namespace xo {
VsmInstr
VsmInstr::c_eval = VsmInstr(vsm_opcode::eval);
VsmInstr
VsmInstr::c_apply = VsmInstr(vsm_opcode::apply);
VsmInstr
VsmInstr::c_evalargs = VsmInstr(vsm_opcode::evalargs);
} /*namespace scm*/
} /*namespace xo*/