-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBytecodeMethodBlock.hpp
51 lines (38 loc) · 1.46 KB
/
BytecodeMethodBlock.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
44
45
46
47
48
49
50
51
#ifndef BYTECODE_METHOD_BLOCK_HPP
#define BYTECODE_METHOD_BLOCK_HPP
#include <memory>
#include <string>
#include <variant>
#include <vector>
#include "BytecodeInstruction.hpp"
#include "serialize.hpp"
class BytecodeMethodBlock {
std::vector<std::unique_ptr<BytecodeInstruction>> instructions;
std::string name;
public:
bool operator==(const std::string &rhsName) { return name == rhsName; };
BytecodeMethodBlock(const std::string &name_) : name(name_){};
[[nodiscard]] const std::string &getName() const { return name; }
void print(std::ostream &os) const;
void addBytecodeInstruction(BytecodeInstruction *instr);
BytecodeMethodBlock &push(const std::variant<std::string, int> &operand);
BytecodeMethodBlock &store(const std::string &result);
BytecodeMethodBlock &add();
BytecodeMethodBlock &subtract();
BytecodeMethodBlock &multiply();
BytecodeMethodBlock ÷();
BytecodeMethodBlock &less_than();
BytecodeMethodBlock &greater_than();
BytecodeMethodBlock &equal_to();
BytecodeMethodBlock &l_and();
BytecodeMethodBlock &l_or();
BytecodeMethodBlock &l_not();
BytecodeMethodBlock &ret();
BytecodeMethodBlock &write();
BytecodeMethodBlock &call(const std::string &method);
BytecodeMethodBlock &jump(const std::string &location);
BytecodeMethodBlock &cjump(const std::string &location);
BytecodeMethodBlock &stop();
void serialize(Serializer &serializer) const;
};
#endif