Phasor 3.3.0
Stack VM based Programming Language
Loading...
Searching...
No Matches
VM.cpp
Go to the documentation of this file.
1#ifndef CMAKE_PCH
2#include "VM.hpp"
3#endif
4
5namespace Phasor
6{
7
9{
10#ifdef TRACING
11 log(std::format("Phasor::VM::{}(): v{}:\nnormal instance created {:#x}\n", __func__, getVersion(),
12 (uintptr_t)this));
13 log(std::format("Value size: {}, VM Size: {}\n", sizeof(Phasor::Value), sizeof(Phasor::VM)));
14 flush();
15#endif
16}
17
18VM::VM(const Bytecode &bytecode) : stack_pool(), stack(&stack_pool)
19{
20#ifdef TRACING
21 log(std::format("Phasor::VM::{}(): v{}:\nfast instance created {:#x}\n", __func__, getVersion(), (uintptr_t)this));
22 flush();
23#endif
24 run(bytecode);
25}
26
27VM::VM(const OpCode &op, const int &operand1, const int &operand2, const int &operand3) : stack_pool(), stack(&stack_pool)
28{
29#ifdef TRACING
30 log(std::format("Phasor::VM::{}(): v{}:\noperation instance created {:#x}\n", __func__, getVersion(),
31 (uintptr_t)this));
32 flush();
33#endif
34 operation(op, operand1, operand2, operand3);
35}
36
38{
39 cleanup();
40#ifdef TRACING
41 log(std::format("Phasor::VM::{}(): deconstructed {:#x}\n", __func__, (uintptr_t)this));
42 flush();
43#endif
44}
45} // namespace Phasor
Virtual Machine.
Definition VM.hpp:33
Value operation(const OpCode &op, const int &operand1=0, const int &operand2=0, const int &operand3=0)
Execute a single operation.
Definition Operations.cpp:8
VM()
Definition VM.cpp:8
std::string getVersion()
Get Phasor VM version.
Definition Utility.cpp:34
void log(const Value &msg)
Log a Value to stdout.
Definition Utility.cpp:269
~VM()
Definition VM.cpp:37
void flush()
Flush stdout.
Definition Utility.cpp:281
std::pmr::vector< Value > stack
Definition VM.hpp:253
void cleanup()
Clean up the virtual machine.
Definition Utility.cpp:162
int run(const Bytecode &bytecode, const size_t startPC=0)
Run the virtual machine Exits -1 on uncaught exception.
Definition Utility.cpp:88
std::pmr::monotonic_buffer_resource stack_pool
Stack.
Definition VM.hpp:252
A value in the Phasor VM.
Definition Value.hpp:58
The Phasor Programming Language and Runtime.
Definition AST.hpp:12
OpCode
Definition ISA.hpp:12
Complete bytecode structure.
Definition CodeGen.hpp:50