-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChunk.h
88 lines (83 loc) · 1.95 KB
/
Chunk.h
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#pragma once
#include <vector>
#include "Value.h"
#include "Token.h"
namespace lwscript
{
enum OpCode : uint8_t
{
OP_CONSTANT,
OP_NULL,
OP_ADD,
OP_SUB,
OP_MUL,
OP_DIV,
OP_MOD,
OP_EQUAL,
OP_GREATER,
OP_LESS,
OP_NOT,
OP_MINUS,
OP_BIT_AND,
OP_BIT_OR,
OP_BIT_XOR,
OP_BIT_NOT,
OP_BIT_LEFT_SHIFT,
OP_BIT_RIGHT_SHIFT,
OP_RETURN,
OP_FACTORIAL,
OP_ARRAY,
OP_DICT,
OP_GET_INDEX,
OP_SET_INDEX,
OP_JUMP_IF_FALSE,
OP_JUMP,
OP_LOOP,
OP_POP,
OP_SET_GLOBAL,
OP_GET_GLOBAL,
OP_SET_LOCAL,
OP_GET_LOCAL,
OP_GET_UPVALUE,
OP_SET_UPVALUE,
OP_CLOSE_UPVALUE,
OP_REF_GLOBAL,
OP_REF_LOCAL,
OP_REF_INDEX_GLOBAL,
OP_REF_INDEX_LOCAL,
OP_REF_UPVALUE,
OP_REF_INDEX_UPVALUE,
OP_CALL,
OP_CLASS,
OP_STRUCT,
OP_SET_PROPERTY,
OP_GET_PROPERTY,
OP_GET_BASE,
OP_CLOSURE,
OP_APPREGATE_RESOLVE,
OP_APPREGATE_RESOLVE_VAR_ARG,
OP_MODULE,
OP_RESET,
};
using OpCodes = std::vector<uint8_t>;
class LWSCRIPT_API Chunk
{
public:
Chunk() = default;
Chunk(const OpCodes &opcodes, const std::vector<Value> &constants);
~Chunk() = default;
#ifndef NDEBUG
STD_STRING ToString() const;
#endif
std::vector<uint8_t> Serialize() const;
void Deserialize(const std::vector<uint8_t> &data);
OpCodes opCodes;
std::vector<Value> constants;
std::vector<const Token *> opCodeRelatedTokens;
private:
STD_STRING OpCodeToString(const OpCodes &opcodes) const;
uint32_t GetBiggestTokenLength() const;
};
bool operator==(const Chunk &left, const Chunk &right);
bool operator!=(const Chunk &left, const Chunk &right);
}