This repository has been archived on 2023-09-09. You can view files and clone it, but cannot push or open issues/pull-requests.
skemla/lib/Program.hpp

43 lines
822 B
C++
Raw Normal View History

2023-09-08 11:13:47 +00:00
#ifndef sk_PROGRAM_HPP
#define sk_PROGRAM_HPP
#include "commons.hpp"
#include "opcodes.hpp"
namespace sk
{
struct Instr {
OpcodeType opcode;
std::optional<param_t> param;
};
class Value;
class Program
{
public:
explicit Program();
virtual ~Program();
std::string string() const;
size_t size() const { return m_instrs.size(); }
size_t value_size() const { return m_values.size(); }
void push_instr(OpcodeType opcode,
std::optional<param_t> param = std::nullopt);
Instr const& instr(size_t index) const;
Instr& instr(size_t index);
size_t push_value(std::shared_ptr<Value> value);
std::shared_ptr<Value> value(size_t index);
private:
std::vector<Instr> m_instrs;
std::vector<std::shared_ptr<Value>> m_values;
};
}
#endif