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