-
Notifications
You must be signed in to change notification settings - Fork 3
/
command.h
130 lines (102 loc) · 2.4 KB
/
command.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#ifndef __TAB_COMMAND_H
#define __TAB_COMMAND_H
namespace tab {
namespace obj {
struct Object;
} // namespace obj
struct Command {
enum cmd_t {
VAL,
VAW,
VAR,
EXP,
MUL_I,
MUL_R,
DIV_I,
DIV_R,
MOD,
ADD_I,
ADD_R,
SUB_I,
SUB_R,
NOT,
AND,
OR,
XOR,
I2R_1,
I2R_2,
U2R_1,
U2R_2,
EQ,
LT,
NEG,
ROT,
ARR,
MAP,
FUN,
FUN0,
SEQ,
TUP,
GEN,
GEN_TRY,
REC,
LAMD
};
cmd_t cmd;
Atom arg;
struct Closure {
std::vector<Command> code;
void swap(Closure& c) {
code.swap(c.code);
}
};
std::vector< Closure > closure;
Type type;
obj::Object* object;
void* function;
Command(cmd_t c = VAL) : cmd(c), object(nullptr), function(nullptr) {}
template <typename T>
Command(cmd_t c, const T& t) : cmd(c), arg(t), object(nullptr), function(nullptr) {}
static std::string print(cmd_t c) {
switch (c) {
case VAL: return "VAL";
case VAW: return "VAW";
case VAR: return "VAR";
case EXP: return "EXP";
case MUL_I: return "MUL_I";
case MUL_R: return "MUL_R";
case DIV_I: return "DIV_I";
case DIV_R: return "DIV_R";
case MOD: return "MOD";
case ADD_I: return "ADD_I";
case ADD_R: return "ADD_R";
case SUB_I: return "SUB_I";
case SUB_R: return "SUB_R";
case NOT: return "NOT";
case AND: return "AND";
case OR: return "OR";
case XOR: return "XOR";
case I2R_1: return "I2R_1";
case I2R_2: return "I2R_2";
case U2R_1: return "U2R_1";
case U2R_2: return "U2R_2";
case EQ: return "EQ";
case LT: return "LT";
case NEG: return "NEG";
case ROT: return "ROT";
case ARR: return "ARR";
case MAP: return "MAP";
case FUN: return "FUN";
case FUN0: return "FUN0";
case SEQ: return "SEQ";
case TUP: return "TUP";
case GEN: return "GEN";
case GEN_TRY: return "GEN_TRY";
case REC: return "REC";
case LAMD: return "LAMD";
}
return ":~(";
}
};
} // namespace tab
#endif