+ xo-interpreter2 scaffold for constant expression [WIP]
This commit is contained in:
parent
5be6650bd1
commit
2521751f0a
7 changed files with 217 additions and 7 deletions
78
include/xo/interpreter2/VirtualSchematikaMachine.hpp
Normal file
78
include/xo/interpreter2/VirtualSchematikaMachine.hpp
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
/** @file VirtualSchematikaMachine.hpp
|
||||
*
|
||||
* @author Roland Conybare, Jan 2026
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "VsmInstr.hpp"
|
||||
#include <xo/expression2/Expression.hpp>
|
||||
#include <xo/gc/GCObject.hpp>
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
/** @class VirtualSchematikaMachine
|
||||
* @brief virtual machine for schematika
|
||||
**/
|
||||
class VirtualSchematikaMachine {
|
||||
public:
|
||||
// will be DArenaVector<obj<StackFrame>> probably
|
||||
using Stack = void *;
|
||||
using AGCObject = xo::mm::AGCObject;
|
||||
|
||||
public:
|
||||
VirtualSchematikaMachine();
|
||||
|
||||
/** borrow calling thread to run indefinitely,
|
||||
* until halt instruction
|
||||
**/
|
||||
void run();
|
||||
|
||||
/** execute vsm instruction in @ref pc_.
|
||||
* @retval instruction count. 1 unless pc_ is halt.
|
||||
**/
|
||||
bool execute_one();
|
||||
|
||||
private:
|
||||
/** Require:
|
||||
* - expression in @ref expr_
|
||||
**/
|
||||
void _do_eval_op();
|
||||
|
||||
/** evaluate a constant expression
|
||||
* Require:
|
||||
* - expression in @ref expr_
|
||||
**/
|
||||
void _do_eval_constant_op();
|
||||
|
||||
private:
|
||||
/*
|
||||
* Some registers are preserved by evaluation:
|
||||
* stack_
|
||||
* cont_
|
||||
*
|
||||
* Other registers are not preserved
|
||||
* pc_
|
||||
* expr_
|
||||
* value_
|
||||
*/
|
||||
|
||||
/** program counter **/
|
||||
VsmInstr pc_ = VsmInstr::halt();
|
||||
|
||||
/** stack pointer **/
|
||||
Stack stack_;
|
||||
|
||||
/** expression register **/
|
||||
obj<AExpression> expr_;
|
||||
|
||||
/** result register **/
|
||||
obj<AGCObject> value_;
|
||||
|
||||
/** continuation register **/
|
||||
VsmInstr cont_ = VsmInstr::halt();
|
||||
};
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end VirtualSchematikaMachine.hpp */
|
||||
27
include/xo/interpreter2/VsmInstr.hpp
Normal file
27
include/xo/interpreter2/VsmInstr.hpp
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/** @file VsmInstr.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Jan 2026
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "VsmOpcode.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
class VsmInstr {
|
||||
public:
|
||||
explicit VsmInstr(vsm_opcode oc) : opcode_{oc} {}
|
||||
|
||||
static VsmInstr halt() { return VsmInstr{vsm_opcode::halt}; }
|
||||
static VsmInstr eval() { return VsmInstr{vsm_opcode::eval}; }
|
||||
|
||||
vsm_opcode opcode() const noexcept { return opcode_; }
|
||||
|
||||
private:
|
||||
vsm_opcode opcode_;
|
||||
};
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end VsmInstr.hpp */
|
||||
29
include/xo/interpreter2/VsmOpcode.hpp
Normal file
29
include/xo/interpreter2/VsmOpcode.hpp
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
/** @file VsmOpcode.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Jan 2026
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
/** Opcode for a virtual schematika expression;
|
||||
* exeucted by VirtualSchematikaMachine
|
||||
**/
|
||||
enum class vsm_opcode {
|
||||
/** Immediately halt virtual schematika machine. **/
|
||||
halt,
|
||||
/** Evaluate expression in expr register **/
|
||||
eval,
|
||||
|
||||
/** sentinel, counts number of opcodes **/
|
||||
N,
|
||||
};
|
||||
|
||||
static constexpr uint32_t n_opcode = static_cast<uint32_t>(vsm_opcode::N);
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end VsmOpcode.hpp */
|
||||
Loading…
Add table
Add a link
Reference in a new issue