Phasor 3.1.1
Stack VM based Programming Language
Loading...
Searching...
No Matches
Register.cpp
Go to the documentation of this file.
1#ifndef CMAKE
2#include "VM.hpp"
3#endif
4
5namespace Phasor
6{
7
8void VM::setRegister(const uint8_t index, const Value &value)
9{
10#ifdef TRACING
11 log(std::format("VM::{}(r{}, {:T})\n", __func__, index, value));
12 flush();
13#endif
14 registers[index] = value;
15}
16
17void VM::freeRegister(const uint8_t index)
18{
19#ifdef TRACING
20 log(std::format("VM::{}(r{})\n", __func__, index));
21 flush();
22#endif
23 registers[index] = Value();
24}
25
26Value VM::getRegister(const uint8_t index)
27{
28#ifdef TRACING
29 log(std::format("VM::{}(r{}) -> {:T}\n", __func__, index, registers[index]));
30 flush();
31#endif
32 return registers[index];
33}
34
36{
37#ifdef TRACING
38 log(std::format("VM::{}() -> {}\n", __func__, registers.size()));
39 flush();
40#endif
41 return registers.size();
42}
43
44} // namespace Phasor
Value getRegister(uint8_t index)
Get a register value.
Definition Register.cpp:26
void log(const Value &msg)
Log a Value to stdout.
Definition Utility.cpp:176
std::array< Value, MAX_REGISTERS > registers
Virtual registers for register-based operations (v2.0).
Definition VM.hpp:261
void flush()
Flush stdout.
Definition Utility.cpp:188
void setRegister(uint8_t index, const Value &value)
Set a register value.
Definition Register.cpp:8
void freeRegister(uint8_t index)
Free a register (reset to null).
Definition Register.cpp:17
size_t getRegisterCount()
Get the total number of registers.
Definition Register.cpp:35
A value in the Phasor VM.
Definition Value.hpp:67
The Phasor Programming Language and Runtime.
Definition AST.hpp:11