![]() |
Phasor 2.2.0
Stack VM based Programming Language
|
Virtual Machine. More...
#include <VM.hpp>
Public Types | |
| enum | Register { r0 , r1 , r2 , r3 , r4 , r5 , r6 , r7 , r8 , r9 , r10 , r11 , r12 , r13 , r14 , r15 , r16 , r17 , r18 , r19 , r20 , r21 , r22 , r23 , r24 , r25 } |
| Enum for lower 26 registers. More... | |
| using | NativeFunction = std::function<Value(const std::vector<Value> &args, VM *vm)> |
| Native function signature. | |
| using | ImportHandler = std::function<void(const std::filesystem::path &path)> |
Public Member Functions | |
| void | run (const Bytecode &bytecode) |
| Run the virtual machine. | |
| void | registerNativeFunction (const std::string &name, NativeFunction fn) |
| Register a native function. | |
| void | setImportHandler (ImportHandler handler) |
| void | freeVariable (const size_t index) |
| Free a variable in the VM. | |
| size_t | addVariable (const Value &value) |
| Add a variable to the VM. | |
| void | setVariable (const size_t index, const Value &value) |
| Set a variable in the VM. | |
| Value | getVariable (const size_t index) |
| Get a variable from the VM. | |
| size_t | getVariableCount () |
| Get the number of variables in the VM. | |
| void | setRegister (uint8_t index, const Value &value) |
| Set a register value. | |
| void | freeRegister (uint8_t index) |
| Free a register (reset to null). | |
| Value | getRegister (uint8_t index) |
| Get a register value. | |
| size_t | getRegisterCount () |
| Get the total number of registers. | |
| 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. | |
| void | push (const Value &value) |
| Push a value onto the stack. | |
| Value | pop () |
| Pop a value from the stack. | |
| Value | peek () |
| Peek at the top value on the stack. | |
| 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. | |
| void | log (const Value &msg) |
| Use the VM's logging via print opcode. | |
| void | logerr (const Value &msg) |
Private Attributes | |
| ImportHandler | importHandler |
| Import handler for loading modules. | |
| std::array< Value, 256 > | registers |
| Virtual registers for register-based operations (v2.0). | |
| std::vector< Value > | stack |
| Stack for function calls. | |
| std::vector< int > | callStack |
| Call stack for function calls. | |
| std::vector< Value > | variables |
| Variable storage indexed by variable index. | |
| const Bytecode * | bytecode |
| Bytecode to execute. | |
| size_t | pc = 0 |
| Program counter. | |
| std::map< std::string, NativeFunction > | nativeFunctions |
| Native function registry. | |
| using Phasor::VM::ImportHandler = std::function<void(const std::filesystem::path &path)> |
| using Phasor::VM::NativeFunction = std::function<Value(const std::vector<Value> &args, VM *vm)> |
| enum Phasor::VM::Register |
| size_t Phasor::VM::addVariable | ( | const Value & | value | ) |
| void Phasor::VM::freeRegister | ( | uint8_t | index | ) |
| void Phasor::VM::freeVariable | ( | const size_t | index | ) |
| std::string Phasor::VM::getInformation | ( | ) |
| Value Phasor::VM::getRegister | ( | uint8_t | index | ) |
| size_t Phasor::VM::getRegisterCount | ( | ) |
| Value Phasor::VM::getVariable | ( | const size_t | index | ) |
| size_t Phasor::VM::getVariableCount | ( | ) |
| void Phasor::VM::log | ( | const Value & | msg | ) |
| void Phasor::VM::logerr | ( | const Value & | msg | ) |
| Value Phasor::VM::peek | ( | ) |
| Value Phasor::VM::pop | ( | ) |
| void Phasor::VM::push | ( | const Value & | value | ) |
| void Phasor::VM::registerNativeFunction | ( | const std::string & | name, |
| NativeFunction | fn ) |
| void Phasor::VM::reset | ( | const bool & | resetStack = true, |
| const bool & | resetFunctions = true, | ||
| const bool & | resetVariables = true ) |
| void Phasor::VM::run | ( | const Bytecode & | bytecode | ) |
| void Phasor::VM::setImportHandler | ( | ImportHandler | handler | ) |
| void Phasor::VM::setRegister | ( | uint8_t | index, |
| const Value & | value ) |
| void Phasor::VM::setVariable | ( | const size_t | index, |
| const Value & | value ) |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |