42 lines
812 B
C++
42 lines
812 B
C++
|
#ifndef jk_VM_HPP
|
||
|
#define jk_VM_HPP
|
||
|
|
||
|
#include "commons.hpp"
|
||
|
#include "Program.hpp"
|
||
|
|
||
|
namespace jk
|
||
|
{
|
||
|
struct Frame {
|
||
|
std::shared_ptr<Program> program;
|
||
|
std::unordered_map<int, std::shared_ptr<Value>> locals;
|
||
|
};
|
||
|
|
||
|
class VM
|
||
|
{
|
||
|
public:
|
||
|
explicit VM();
|
||
|
virtual ~VM();
|
||
|
|
||
|
void execute(std::shared_ptr<Program> program);
|
||
|
|
||
|
std::string string() const;
|
||
|
|
||
|
size_t push_heap(std::shared_ptr<Value> value);
|
||
|
std::shared_ptr<Value> heap(size_t addr);
|
||
|
|
||
|
void set_global(size_t addr, std::shared_ptr<Value> value);
|
||
|
|
||
|
private:
|
||
|
size_t m_pc = 0;
|
||
|
std::vector<Frame> m_frames;
|
||
|
std::vector<param_t> m_stack;
|
||
|
std::vector<std::shared_ptr<Value>> m_heap;
|
||
|
std::unordered_map<size_t, std::shared_ptr<Value>> m_globals;
|
||
|
|
||
|
void push(param_t param);
|
||
|
param_t pop();
|
||
|
};
|
||
|
}
|
||
|
|
||
|
#endif
|