29 using ImportHandler = std::function<void(
const std::filesystem::path &path)>;
101 Value operation(
const OpCode &op,
const int &operand1 = 0,
const int &operand2 = 0,
const int &operand3 = 0,
102 const int &operand4 = 0,
const int &operand5 = 0);
114 void reset(
const bool &resetStack =
true,
const bool &resetFunctions =
true,
const bool &resetVariables =
true);
ImportHandler importHandler
Import handler for loading modules.
std::vector< Value > variables
Variable storage indexed by variable index.
std::function< Value(const std::vector< Value > &args, VM *vm)> NativeFunction
Native function signature.
Value pop()
Pop a value from the stack.
std::function< void(const std::filesystem::path &path)> ImportHandler
void logerr(const Value &msg)
std::vector< Value > stack
Stack for function calls.
std::array< Value, 256 > registers
Virtual registers for register-based operations (v2.0).
std::vector< int > callStack
Call stack for function calls.
std::map< std::string, NativeFunction > nativeFunctions
Native function registry.
void registerNativeFunction(const std::string &name, NativeFunction fn)
Register a native function.
Value getRegister(uint8_t index)
Get a register value.
size_t getVariableCount()
Get the number of variables in the VM.
void log(const Value &msg)
Use the VM's logging via print opcode.
size_t addVariable(const Value &value)
Add a variable to the VM.
void freeVariable(const size_t index)
Free a variable in the VM.
size_t pc
Program counter.
void setVariable(const size_t index, const Value &value)
Set a variable in the VM.
void push(const Value &value)
Push a value onto the stack.
void setRegister(uint8_t index, const Value &value)
Set a register value.
void setImportHandler(ImportHandler handler)
void freeRegister(uint8_t index)
Free a register (reset to null).
void run(const Bytecode &bytecode)
Run the virtual machine.
const Bytecode * bytecode
Bytecode to execute.
Value getVariable(const size_t index)
Get a variable from the VM.
Value operation(const OpCode &op, const int &operand1=0, const int &operand2=0, const int &operand3=0, const int &operand4=0, const int &operand5=0)
Execute a single operation.
Register
Enum for lower 26 registers.
Value peek()
Peek at the top value on the stack.
size_t getRegisterCount()
Get the total number of registers.
void reset(const bool &resetStack=true, const bool &resetFunctions=true, const bool &resetVariables=true)
Reset the virtual machine.
std::string getInformation()
Get VM information for debugging.
A value in the Phasor VM.
The Phasor Programming Language and Runtime.
Complete bytecode structure.