-
Notifications
You must be signed in to change notification settings - Fork 3
/
BytecodeInterpreter.hpp
43 lines (34 loc) · 1.56 KB
/
BytecodeInterpreter.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#pragma once
#include "Instruction.hpp"
#include <cstdint>
#include <vector>
#include <optional>
namespace bytecodeinterpreter {
using namespace std;
struct InterpreterRegisters {
vector<int16_t> stack;
vector<Instruction*> returnAddressStack;
Instruction *currentInstruction;
size_t baseIndex;
};
typedef void (*InstructionFunction)(InterpreterRegisters& registers);
void ExitInstruction(InterpreterRegisters& registers);
void AddIntInstruction(InterpreterRegisters& registers);
void PushIntInstruction(InterpreterRegisters& registers);
void PopIntInstruction(InterpreterRegisters& registers);
void PrintIntInstruction(InterpreterRegisters& registers);
void CompareIntLessThanInstruction(InterpreterRegisters& registers);
void LoadIntInstruction(InterpreterRegisters& registers);
void StoreIntInstruction(InterpreterRegisters& registers);
void JumpByIfZeroInstruction(InterpreterRegisters& registers);
void JumpByInstruction(InterpreterRegisters& registers);
void LoadIntBasepointerRelativeInstruction(InterpreterRegisters& registers);
void StoreIntBasepointerRelativeInstruction(InterpreterRegisters& registers);
void CallInstruction(InterpreterRegisters& registers);
void ReturnInstruction(InterpreterRegisters& registers);
extern InstructionFunction gInstructionFunctions[NUM_INSTRUCTIONS];
class BytecodeInterpreter {
public:
static void Run(Instruction* code, vector<int16_t> arguments, int16_t* result = nullptr);
};
} /* namespace bytecodeinterpreter */