-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathopcode.h
More file actions
97 lines (91 loc) · 1.76 KB
/
opcode.h
File metadata and controls
97 lines (91 loc) · 1.76 KB
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
89
90
91
92
93
94
95
96
97
#ifndef cb_opcode_h
#define cb_opcode_h
#include "compiler.h"
#define CB_OPCODE_LIST(X) \
X(OP_HALT) \
X(OP_LOAD_CONST) \
X(OP_CONST_STRING) \
X(OP_CONST_TRUE) \
X(OP_CONST_FALSE) \
X(OP_CONST_NULL) \
X(OP_ADD) \
X(OP_SUB) \
X(OP_MUL) \
X(OP_DIV) \
X(OP_MOD) \
X(OP_EXP) \
X(OP_JUMP) \
X(OP_JUMP_IF_TRUE) \
X(OP_JUMP_IF_FALSE) \
X(OP_CALL) \
X(OP_RETURN) \
X(OP_POP) \
X(OP_LOAD_LOCAL) \
X(OP_STORE_LOCAL) \
X(OP_LOAD_GLOBAL) \
X(OP_DECLARE_GLOBAL) \
X(OP_STORE_GLOBAL) \
X(OP_BIND_LOCAL) \
X(OP_BIND_UPVALUE) \
X(OP_LOAD_UPVALUE) \
X(OP_STORE_UPVALUE) \
X(OP_LOAD_FROM_MODULE) \
X(OP_NEW_ARRAY_WITH_VALUES) \
X(OP_ARRAY_GET) \
X(OP_ARRAY_SET) \
X(OP_EQUAL) \
X(OP_NOT_EQUAL) \
X(OP_LESS_THAN) \
X(OP_LESS_THAN_EQUAL) \
X(OP_GREATER_THAN) \
X(OP_GREATER_THAN_EQUAL) \
X(OP_BITWISE_AND) \
X(OP_BITWISE_OR) \
X(OP_BITWISE_XOR) \
X(OP_BITWISE_NOT) \
X(OP_NOT) \
X(OP_NEG) \
X(OP_DUP) \
X(OP_DUP_2) \
X(OP_ALLOCATE_LOCALS) \
X(OP_NEW_STRUCT) \
X(OP_LOAD_STRUCT) \
X(OP_STORE_STRUCT) \
X(OP_ADD_STRUCT_FIELD) \
X(OP_ROT_2) \
X(OP_ROT_3) \
X(OP_ROT_4) \
X(OP_IMPORT_MODULE) \
X(OP_APPLY_DEFAULT_ARG) \
X(OP_THROW) \
X(OP_PUSH_TRY) \
X(OP_POP_TRY) \
X(OP_CATCH) \
X(OP_INC) \
X(OP_DEC) \
X(OP_LOAD_THIS) \
X(OP_SET_METHOD) \
X(OP_LOAD_METHOD) \
X(OP_CALL_METHOD) \
X(OP_MAX)
enum cb_opcode {
#define COMMA(V) V,
CB_OPCODE_LIST(COMMA)
#undef COMMA
};
union cb_op_encoding {
size_t as_size_t;
struct __attribute__((packed)) {
enum cb_opcode op : 8;
size_t arg : 56;
} unary;
struct __attribute__((packed)) {
enum cb_opcode op : 8;
size_t arg1 : 28;
size_t arg2 : 28;
} binary;
};
const char *cb_opcode_name(enum cb_opcode);
int cb_opcode_stack_effect(const cb_instruction);
enum cb_opcode cb_opcode_assert(size_t);
#endif