xo-interpreter2: apply sequence now working in interpreter
This commit is contained in:
parent
5292518eaf
commit
a63e4b1dae
7 changed files with 201 additions and 33 deletions
|
|
@ -29,6 +29,8 @@ namespace xo {
|
|||
obj<AProcedure> fn() const noexcept { return fn_; }
|
||||
DArray * args() const noexcept { return args_; }
|
||||
|
||||
void assign_fn(obj<AProcedure> x) { this->fn_ = x; }
|
||||
|
||||
std::size_t shallow_size() const noexcept;
|
||||
DVsmApplyFrame * shallow_copy(obj<AAllocator> mm) const noexcept;
|
||||
std::size_t forward_children(obj<ACollector> gc) noexcept;
|
||||
|
|
|
|||
|
|
@ -5,16 +5,18 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "DVsmApplyFrame.hpp"
|
||||
#include "VsmApplyFrame.hpp"
|
||||
#include <xo/expression2/DApplyExpr.hpp>
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
|
||||
/** frame for executing an apply expression **/
|
||||
class DVsmEvalArgsFrame : public VsmFrame {
|
||||
class DVsmEvalArgsFrame {
|
||||
public:
|
||||
using ACollector = xo::mm::ACollector;
|
||||
using AAllocator = xo::mm::AAllocator;
|
||||
using AGCObject = xo::mm::AGCObject;
|
||||
using ppindentinfo = xo::print::ppindentinfo;
|
||||
|
||||
public:
|
||||
|
|
@ -24,12 +26,21 @@ namespace xo {
|
|||
* old_cont = [xfer to called function]
|
||||
*
|
||||
**/
|
||||
DVsmEvalArgsFrame(obj<AGCObject> old_parent,
|
||||
VsmInstr old_cont);
|
||||
DVsmEvalArgsFrame(DVsmApplyFrame * parent,
|
||||
VsmInstr cont,
|
||||
const DApplyExpr * apply_expr);
|
||||
|
||||
static DVsmEvalArgsFrame * make(obj<AAllocator> mm,
|
||||
obj<AGCObject> apply_frame,
|
||||
VsmInstr old_cont);
|
||||
DVsmApplyFrame * apply_frame,
|
||||
VsmInstr old_cont,
|
||||
const DApplyExpr * apply_expr);
|
||||
|
||||
DVsmApplyFrame * parent() const noexcept { return parent_; }
|
||||
VsmInstr cont() const noexcept { return cont_; }
|
||||
const DApplyExpr * apply_expr() const noexcept { return apply_expr_; }
|
||||
int32_t i_arg() const noexcept { return i_arg_; }
|
||||
|
||||
int32_t increment_arg() { return ++i_arg_; }
|
||||
|
||||
std::size_t shallow_size() const noexcept;
|
||||
DVsmEvalArgsFrame * shallow_copy(obj<AAllocator> mm) const noexcept;
|
||||
|
|
@ -38,6 +49,14 @@ namespace xo {
|
|||
bool pretty(const ppindentinfo & ppii) const;
|
||||
|
||||
protected:
|
||||
/** parent stack frame **/
|
||||
DVsmApplyFrame * parent_ = nullptr;
|
||||
/** continuation after eval args completed (always VsmInstr::c_apply) **/
|
||||
VsmInstr cont_;
|
||||
|
||||
/** expression being evaluated **/
|
||||
const DApplyExpr * apply_expr_ = nullptr;
|
||||
|
||||
/** next argument to be evaluated. -1 means function head **/
|
||||
int32_t i_arg_ = -1;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -147,7 +147,14 @@ namespace xo {
|
|||
/** apply a function to evaluated arguments **/
|
||||
void _do_apply_op();
|
||||
|
||||
/** evaluate arguments on behalf of a function call **/
|
||||
/** evaluate arguments on behalf of a function call
|
||||
* Require:
|
||||
* - expression value in @ref value_
|
||||
* - stack:
|
||||
* [0] VsmEvalArgsFrame
|
||||
* [1] VsmApplyFrame
|
||||
* ...
|
||||
**/
|
||||
void _do_evalargs_op();
|
||||
|
||||
private:
|
||||
|
|
@ -159,6 +166,8 @@ namespace xo {
|
|||
* Other registers are not preserved
|
||||
* pc_
|
||||
* expr_
|
||||
* fn_
|
||||
* args_
|
||||
* value_
|
||||
*/
|
||||
|
||||
|
|
@ -170,6 +179,11 @@ namespace xo {
|
|||
**/
|
||||
box<AAllocator> mm_;
|
||||
|
||||
/** runtime context for this vsm.
|
||||
* For example, provides allocator to primitives
|
||||
**/
|
||||
box<ARuntimeContext> rcx_;
|
||||
|
||||
// consider separate allocator (which _may_ turn out to be the same)
|
||||
// for VM stack. Only works for code that doesn't rely on fancy
|
||||
// lexical scoping
|
||||
|
|
@ -186,6 +200,11 @@ namespace xo {
|
|||
/** expression register **/
|
||||
obj<AExpression> expr_;
|
||||
|
||||
/** function to call **/
|
||||
obj<AProcedure> fn_;
|
||||
/** evaluated argument list **/
|
||||
DArray * args_;
|
||||
|
||||
/** result register **/
|
||||
VsmResult value_;
|
||||
|
||||
|
|
|
|||
|
|
@ -20,9 +20,7 @@ namespace xo {
|
|||
VsmInstr cont) : parent_{parent}, cont_{cont} {}
|
||||
|
||||
//obj<AGCObject> parent() const noexcept { return parent_; }
|
||||
VsmFrame * parent() const noexcept {
|
||||
return reinterpret_cast<VsmFrame *>(parent_.data());
|
||||
}
|
||||
obj<AGCObject> parent() const noexcept { return parent_; }
|
||||
VsmInstr cont() const noexcept { return cont_; }
|
||||
|
||||
protected:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue