![]() |
Phasor 3.3.0
Stack VM based Programming Language
|
Virtual Machine. More...
#include <VM.hpp>
Classes | |
| class | Halt |
| Throws when the HALT opcode is reached. More... | |
Public Types | |
| enum | Register : uint8_t { 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 , r26 , r27 , r28 , r29 , r30 , r31 , 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 , r26 , r27 , r28 , r29 , r30 , r31 } |
| Enum for registers. More... | |
| enum | Register : uint8_t { 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 , r26 , r27 , r28 , r29 , r30 , r31 , 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 , r26 , r27 , r28 , r29 , r30 , r31 } |
| Enum for 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)> |
| 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 | |
| VM () | |
| VM (const Bytecode &bytecode) | |
| VM (const OpCode &op, const int &operand1=0, const int &operand2=0, const int &operand3=0) | |
| ~VM () | |
| void | initFFI (const std::filesystem::path &path) |
| Initialize the FFI plugins. | |
| std::string | getVersion () |
| Get Phasor VM version. | |
| int | run (const Bytecode &bytecode, const size_t startPC=0) |
| Run the virtual machine Exits -1 on uncaught exception. | |
| Value | runFunction (const std::string &name, const Bytecode &bytecode) |
| Run a function from bytecode on the virtual machine. | |
| void | registerNativeFunction (const std::string &name, NativeFunction fn) |
| Register a native function. | |
| void | setImportHandler (const ImportHandler &handler) |
| Set the import handler for importing modules. | |
| void | freeVariable (size_t index) |
| Free a variable in the VM. | |
| void | freeVariableByName (const std::string &name) |
| Free a variable by name in the VM. | |
| size_t | addVariable (const Value &value) |
| Add a variable to the VM. | |
| void | setVariable (size_t index, const Value &value) |
| Set a variable in the VM. | |
| Value | getVariable (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) |
| 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 | cleanup () |
| Clean up the virtual machine. | |
| 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. | |
| std::string | getBytecodeInformation () |
| Get bytecode information for debugging. | |
| void | log (const Value &msg) |
| Log a Value to stdout. | |
| void | logerr (const Value &msg) |
| Log a Value to stderr. | |
| void | flush () |
| Flush stdout. | |
| void | flusherr () |
| Flush stderr. | |
| void | setStatus (int newStatus) |
| Set VM exit code. | |
| void | resetStatus () |
| int | getStatus () |
| template<typename... Args> | |
| Value | regRun (OpCode opcode, Args &&...args) |
| Run an opcode with arguments pre-loaded into registers. | |
| template<typename... Args> | |
| Value | stackRun (OpCode opcode, Args &&...args) |
| Run an opcode with values pushed to the stack. | |
| VM () | |
| VM (const Bytecode &bytecode) | |
| VM (const OpCode &op, const int &operand1=0, const int &operand2=0, const int &operand3=0) | |
| ~VM () | |
| void | initFFI (const std::filesystem::path &path) |
| Initialize the FFI plugins. | |
| std::string | getVersion () |
| Get Phasor VM version. | |
| int | run (const Bytecode &bytecode, const size_t startPC=0) |
| Run the virtual machine Exits -1 on uncaught exception. | |
| Value | runFunction (const std::string &name, const Bytecode &bytecode) |
| Run a function from bytecode on the virtual machine. | |
| void | registerNativeFunction (const std::string &name, NativeFunction fn) |
| Register a native function. | |
| void | setImportHandler (const ImportHandler &handler) |
| Set the import handler for importing modules. | |
| void | freeVariable (size_t index) |
| Free a variable in the VM. | |
| void | freeVariableByName (const std::string &name) |
| Free a variable by name in the VM. | |
| size_t | addVariable (const Value &value) |
| Add a variable to the VM. | |
| void | setVariable (size_t index, const Value &value) |
| Set a variable in the VM. | |
| Value | getVariable (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) |
| 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 | cleanup () |
| Clean up the virtual machine. | |
| 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. | |
| std::string | getBytecodeInformation () |
| Get bytecode information for debugging. | |
| void | log (const Value &msg) |
| Log a Value to stdout. | |
| void | logerr (const Value &msg) |
| Log a Value to stderr. | |
| void | flush () |
| Flush stdout. | |
| void | flusherr () |
| Flush stderr. | |
| void | setStatus (int newStatus) |
| Set VM exit code. | |
| void | resetStatus () |
| int | getStatus () |
| template<typename... Args> | |
| Value | regRun (OpCode opcode, Args &&...args) |
| Run an opcode with arguments pre-loaded into registers. | |
| template<typename... Args> | |
| Value | stackRun (OpCode opcode, Args &&...args) |
| Run an opcode with values pushed to the stack. | |
Private Member Functions | |
| void | setup (const Bytecode &bc, const size_t initialPC) |
| void | evalLoop () |
| void | setup (const Bytecode &bc, const size_t initialPC) |
| void | evalLoop () |
Private Attributes | |
| bool | isDirectCall = false |
| is a direct call to a function | |
| std::unique_ptr< FFI > | ffi |
| FFI. | |
| int | status = 0 |
| Exit code. | |
| ImportHandler | importHandler |
| Import handler for loading modules. | |
| std::array< Value, MAX_REGISTERS > | registers |
| Virtual registers for register-based operations (v2.0). | |
| std::pmr::monotonic_buffer_resource | stack_pool |
| Stack. | |
| std::pmr::vector< Value > | stack |
| std::vector< int > | callStack |
| Call stack for function calls. | |
| std::vector< Value > | variables |
| Variable storage indexed by variable index, or simply: the managed heap. | |
| const Bytecode * | m_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)> |
Definition at line 90 of file PhasorVM.hpp.
| 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)> |
Native function signature.
Definition at line 85 of file PhasorVM.hpp.
| using Phasor::VM::NativeFunction = std::function<Value(const std::vector<Value> &args, VM *vm)> |
| enum Phasor::VM::Register : uint8_t |
Enum for registers.
Definition at line 135 of file PhasorVM.hpp.
| enum Phasor::VM::Register : uint8_t |
| Phasor::VM::VM | ( | const Bytecode & | bytecode | ) |
| Phasor::VM::VM | ( | const OpCode & | op, |
| const int & | operand1 = 0, | ||
| const int & | operand2 = 0, | ||
| const int & | operand3 = 0 ) |
| Phasor::VM::VM | ( | ) |
| Phasor::VM::VM | ( | const Bytecode & | bytecode | ) |
| Phasor::VM::VM | ( | const OpCode & | op, |
| const int & | operand1 = 0, | ||
| const int & | operand2 = 0, | ||
| const int & | operand3 = 0 ) |
| Phasor::VM::~VM | ( | ) |
| size_t Phasor::VM::addVariable | ( | const Value & | value | ) |
| size_t Phasor::VM::addVariable | ( | const Value & | value | ) |
Add a variable to the VM.
| value | The value to add |
Definition at line 8 of file Variables.cpp.
| void Phasor::VM::cleanup | ( | ) |
Clean up the virtual machine.
| void Phasor::VM::cleanup | ( | ) |
Clean up the virtual machine.
Definition at line 162 of file Utility.cpp.
|
private |
|
private |
Definition at line 73 of file Utility.cpp.
| void Phasor::VM::flush | ( | ) |
Flush stdout.
| void Phasor::VM::flush | ( | ) |
Flush stdout.
Definition at line 281 of file Utility.cpp.
| void Phasor::VM::flusherr | ( | ) |
Flush stderr.
| void Phasor::VM::flusherr | ( | ) |
Flush stderr.
Definition at line 286 of file Utility.cpp.
| void Phasor::VM::freeRegister | ( | uint8_t | index | ) |
Free a register (reset to null).
| index | Register index to free |
| void Phasor::VM::freeRegister | ( | uint8_t | index | ) |
Free a register (reset to null).
| index | Register index to free |
Definition at line 17 of file Register.cpp.
| void Phasor::VM::freeVariable | ( | size_t | index | ) |
Free a variable in the VM.
| void Phasor::VM::freeVariable | ( | size_t | index | ) |
Free a variable in the VM.
Definition at line 18 of file Variables.cpp.
| void Phasor::VM::freeVariableByName | ( | const std::string & | name | ) |
Free a variable by name in the VM.
| void Phasor::VM::freeVariableByName | ( | const std::string & | name | ) |
Free a variable by name in the VM.
Definition at line 30 of file Variables.cpp.
| std::string Phasor::VM::getBytecodeInformation | ( | ) |
Get bytecode information for debugging.
| std::string Phasor::VM::getBytecodeInformation | ( | ) |
Get bytecode information for debugging.
Definition at line 234 of file Utility.cpp.
| std::string Phasor::VM::getInformation | ( | ) |
Get VM information for debugging.
| std::string Phasor::VM::getInformation | ( | ) |
Get VM information for debugging.
Definition at line 207 of file Utility.cpp.
| Value Phasor::VM::getRegister | ( | uint8_t | index | ) |
| Value Phasor::VM::getRegister | ( | uint8_t | index | ) |
Get a register value.
| index | Register index |
Definition at line 26 of file Register.cpp.
| size_t Phasor::VM::getRegisterCount | ( | ) |
Get the total number of registers.
| size_t Phasor::VM::getRegisterCount | ( | ) |
Get the total number of registers.
Definition at line 35 of file Register.cpp.
| int Phasor::VM::getStatus | ( | ) |
| int Phasor::VM::getStatus | ( | ) |
Definition at line 46 of file Utility.cpp.
| Value Phasor::VM::getVariable | ( | size_t | index | ) |
Get a variable from the VM.
Definition at line 58 of file Variables.cpp.
| size_t Phasor::VM::getVariableCount | ( | ) |
Get the number of variables in the VM.
| size_t Phasor::VM::getVariableCount | ( | ) |
Get the number of variables in the VM.
Definition at line 75 of file Variables.cpp.
| std::string Phasor::VM::getVersion | ( | ) |
| void Phasor::VM::initFFI | ( | const std::filesystem::path & | path | ) |
Initialize the FFI plugins.
| void Phasor::VM::initFFI | ( | const std::filesystem::path & | path | ) |
Initialize the FFI plugins.
Definition at line 51 of file Utility.cpp.
| void Phasor::VM::log | ( | const Value & | msg | ) |
Log a Value to stdout.
Definition at line 269 of file Utility.cpp.
| void Phasor::VM::logerr | ( | const Value & | msg | ) |
Log a Value to stderr.
Definition at line 275 of file Utility.cpp.
| Value Phasor::VM::operation | ( | const OpCode & | op, |
| const int & | operand1 = 0, | ||
| const int & | operand2 = 0, | ||
| const int & | operand3 = 0 ) |
Execute a single operation.
| Value Phasor::VM::operation | ( | const OpCode & | op, |
| const int & | operand1 = 0, | ||
| const int & | operand2 = 0, | ||
| const int & | operand3 = 0 ) |
Execute a single operation.
Definition at line 8 of file Operations.cpp.
| Value Phasor::VM::peek | ( | ) |
Peek at the top value on the stack.
| Value Phasor::VM::peek | ( | ) |
| Value Phasor::VM::pop | ( | ) |
Pop a value from the stack.
| Value Phasor::VM::pop | ( | ) |
| void Phasor::VM::push | ( | const Value & | value | ) |
Push a value onto the stack.
| void Phasor::VM::push | ( | const Value & | value | ) |
| void Phasor::VM::registerNativeFunction | ( | const std::string & | name, |
| NativeFunction | fn ) |
Register a native function.
| void Phasor::VM::registerNativeFunction | ( | const std::string & | name, |
| NativeFunction | fn ) |
Register a native function.
Definition at line 5 of file Native.cpp.
Run an opcode with arguments pre-loaded into registers.
| Args | Argument types |
| opcode | Opcode to run |
| args | Arguments to load into registers |
Definition at line 228 of file PhasorVM.hpp.
Run an opcode with arguments pre-loaded into registers.
| Args | Argument types |
| opcode | Opcode to run |
| args | Arguments to load into registers |
Definition at line 208 of file VM.hpp.
| void Phasor::VM::reset | ( | const bool & | resetStack = true, |
| const bool & | resetFunctions = true, | ||
| const bool & | resetVariables = true ) |
Reset the virtual machine.
| void Phasor::VM::reset | ( | const bool & | resetStack = true, |
| const bool & | resetFunctions = true, | ||
| const bool & | resetVariables = true ) |
Reset the virtual machine.
Definition at line 181 of file Utility.cpp.
| void Phasor::VM::resetStatus | ( | ) |
| void Phasor::VM::resetStatus | ( | ) |
| int Phasor::VM::run | ( | const Bytecode & | bytecode, |
| const size_t | startPC = 0 ) |
Run the virtual machine Exits -1 on uncaught exception.
| int Phasor::VM::run | ( | const Bytecode & | bytecode, |
| const size_t | startPC = 0 ) |
Run the virtual machine Exits -1 on uncaught exception.
Definition at line 88 of file Utility.cpp.
Run a function from bytecode on the virtual machine.
Run a function from bytecode on the virtual machine.
Definition at line 144 of file Utility.cpp.
| void Phasor::VM::setImportHandler | ( | const ImportHandler & | handler | ) |
Set the import handler for importing modules.
| void Phasor::VM::setImportHandler | ( | const ImportHandler & | handler | ) |
Set the import handler for importing modules.
Definition at line 153 of file Utility.cpp.
| void Phasor::VM::setRegister | ( | uint8_t | index, |
| const Value & | value ) |
| void Phasor::VM::setRegister | ( | uint8_t | index, |
| const Value & | value ) |
Set a register value.
Definition at line 8 of file Register.cpp.
| void Phasor::VM::setStatus | ( | int | newStatus | ) |
Set VM exit code.
| void Phasor::VM::setStatus | ( | int | newStatus | ) |
Set VM exit code.
Definition at line 38 of file Utility.cpp.
|
private |
|
private |
Definition at line 58 of file Utility.cpp.
| void Phasor::VM::setVariable | ( | size_t | index, |
| const Value & | value ) |
Set a variable in the VM.
| index | The index of the variable |
| value | The value to set |
| void Phasor::VM::setVariable | ( | size_t | index, |
| const Value & | value ) |
Set a variable in the VM.
| index | The index of the variable |
| value | The value to set |
Definition at line 45 of file Variables.cpp.
Run an opcode with values pushed to the stack.
| Args | Argument types |
| opcode | Opcode to run |
| args | Arguments to push to the stack |
Definition at line 243 of file PhasorVM.hpp.
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |