roza/lib/Program.hpp

44 lines
883 B
C++
Raw Permalink Normal View History

2023-08-30 18:06:26 +00:00
#ifndef roza_PROGRAM_HPP
#define roza_PROGRAM_HPP
#include "commons.hpp"
#include "opcodes.hpp"
#include "Value.hpp"
namespace roza
{
using param_t = int;
struct Instr {
Opcode opcode;
std::optional<param_t> param;
};
class Program
{
public:
explicit Program();
virtual ~Program();
size_t size() const { return m_instrs.size(); }
void push_instr(Opcode opcode, std::optional<param_t> param = std::nullopt);
size_t push_value(std::shared_ptr<Value> value);
Opcode opcode(size_t index) const;
std::optional<param_t> param(size_t index) const;
2023-08-30 22:31:19 +00:00
std::shared_ptr<Value> value(size_t index) const;
bool has_value(size_t index) const;
2023-08-30 18:06:26 +00:00
2023-08-31 23:22:51 +00:00
void set_param(size_t index, param_t param);
2023-08-30 18:06:26 +00:00
std::string string() const;
private:
std::vector<Instr> m_instrs;
std::vector<std::shared_ptr<Value>> m_values;
};
}
#endif