42 lines
770 B
C++
42 lines
770 B
C++
|
#ifndef jk_PROGRAM_HPP
|
||
|
#define jk_PROGRAM_HPP
|
||
|
|
||
|
#include "commons.hpp"
|
||
|
#include "Opcodes.hpp"
|
||
|
#include "Value.hpp"
|
||
|
|
||
|
namespace jk
|
||
|
{
|
||
|
using param_t = size_t;
|
||
|
|
||
|
struct Instr {
|
||
|
OpcodeType opcode;
|
||
|
std::optional<param_t> param;
|
||
|
};
|
||
|
|
||
|
class Program
|
||
|
{
|
||
|
public:
|
||
|
explicit Program();
|
||
|
virtual ~Program();
|
||
|
|
||
|
size_t size() const { return m_instrs.size(); }
|
||
|
|
||
|
Instr get(size_t index) const;
|
||
|
|
||
|
void push_instr(OpcodeType opcode,
|
||
|
std::optional<param_t> param = std::nullopt);
|
||
|
|
||
|
size_t push_constant(std::shared_ptr<Value> value);
|
||
|
std::shared_ptr<Value> constant(size_t index) const;
|
||
|
|
||
|
std::string string() const;
|
||
|
|
||
|
private:
|
||
|
std::vector<Instr> m_instrs;
|
||
|
std::vector<std::shared_ptr<Value>> m_constants;
|
||
|
};
|
||
|
}
|
||
|
|
||
|
#endif
|