#include "Program.hpp" #include "Value.hpp" namespace sk { /*explicit*/ Program::Program() { } /*virtual*/ Program::~Program() { } std::string Program::string() const { std::stringstream ss; size_t i = 0; for (auto const& instr: m_instrs) { ss << i << "\t"; ss << std::string(OpcodeTypeStr[instr.opcode]) .substr(std::string("OPCODE_").size()); if (instr.param) { ss << "\t" << *instr.param; } ss << "\n"; i++; } return ss.str(); } void Program::push_instr(OpcodeType opcode, std::optional param) { m_instrs.push_back({opcode, param}); } Instr const& Program::instr(size_t index) const { assert(index < size()); return m_instrs[index]; } Instr& Program::instr(size_t index) { assert(index < size()); return m_instrs[index]; } size_t Program::push_value(std::shared_ptr value) { for (size_t i=0; iequals(*m_values[i])) { return i; } } m_values.push_back(value); return m_values.size() - 1; } std::shared_ptr Program::value(size_t index) { assert(index < m_values.size()); return m_values[index]; } }