Debian Codegraph @

src/h/bytecodes.h

raw symbols SCIP
1 /* -*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*- */
2 /* vim: set filetype=c tabstop=8 shiftwidth=4 expandtab: */
3
4 /* -----------------------------------------------------------------------------
5 *** IMPORTANT: ANY CHANGE IN THIS FILE MUST BE MATCHED BY APPROPRIATE CHANGES
6 *** IN THE INTERPRETER AND COMPILER IN PARTICULAR, IT MAY HURT THE THREADED
7 *** INTERPRETER CODE.
8 ----------------------------------------------------------------------------- */
9 #ifndef ECL_BYTECODES_H
10 #define ECL_BYTECODES_H
11
12 /* See ecl/src/c/interpreter.d for a detailed explanation of all opcodes. */
13 enum {
14 OP_NOP,
15 OP_QUOTE,
16 OP_ENDP,
17 OP_CONS,
18 OP_CAR,
19 OP_CDR,
20 OP_LIST,
21 OP_LISTA,
22 OP_CONS_CAR,
23 OP_CONS_CDR,
24 OP_INT,
25 OP_PINT,
26 OP_VAR,
27 OP_VARC,
28 OP_VARS,
29 OP_PUSH,
30 OP_PUSHV,
31 OP_PUSHVC,
32 OP_PUSHVS,
33 OP_PUSHQ,
34 OP_CALLG1,
35 OP_CALLG2,
36 OP_CALL,
37 OP_CALLG,
38 OP_FCALL,
39 OP_MCALL,
40 OP_POP,
41 OP_POP1,
42 OP_POPREQ,
43 OP_POPOPT,
44 OP_NOMORE,
45 OP_POPREST,
46 OP_PUSHKEYS,
47 OP_EXIT,
48 OP_FLET,
49 OP_LABELS,
50 OP_LFUNCTION,
51 OP_CFUNCTION,
52 OP_FUNCTION,
53 OP_CLOSE,
54 OP_GO,
55 OP_GO_CFB,
56 OP_RETURN,
57 OP_RETURN_CFB,
58 OP_THROW,
59 OP_JMP,
60 OP_JNIL,
61 OP_JT,
62 OP_JEQL,
63 OP_JNEQL,
64 OP_UNBIND,
65 OP_UNBINDS,
66 OP_BIND,
67 OP_PBIND,
68 OP_VBIND,
69 OP_BINDS,
70 OP_PBINDS,
71 OP_VBINDS,
72 OP_SETQ,
73 OP_SETQC,
74 OP_SETQS,
75 OP_PSETQ,
76 OP_PSETQC,
77 OP_PSETQS,
78 OP_VSETQ,
79 OP_VSETQC,
80 OP_VSETQS,
81 OP_BLOCK,
82 OP_DO,
83 OP_CATCH,
84 OP_FRAME,
85 OP_TAGBODY,
86 OP_EXIT_TAGBODY,
87 OP_EXIT_FRAME,
88 OP_PROTECT,
89 OP_PROTECT_NORMAL,
90 OP_PROTECT_EXIT,
91 OP_PROGV,
92 OP_EXIT_PROGV,
93 OP_PUSHVALUES,
94 OP_POPVALUES,
95 OP_PUSHMOREVALUES,
96 OP_VALUES,
97 OP_VALUEREG0,
98 OP_NTHVAL,
99 OP_NIL,
100 OP_NOT,
101 OP_PUSHNIL,
102 OP_CSET,
103 OP_STEPIN,
104 OP_STEPCALL,
105 OP_STEPOUT,
106 OP_MAXOPCODES = 128,
107 OP_OPCODE_SHIFT = 7
108 };
109
110 #define MAX_OPARG 0x7FFF
111 typedef int16_t cl_oparg;
112
113 typedef int16_t cl_opcode;
114 # define OPCODE_SIZE 1
115 # define OPARG_SIZE 1
116 # define READ_OPCODE(v) v[0]
117 # define READ_OPARG(v) v[0]
118 # define GET_OPARG(r,v) { r = *(v++); }
119
120 #define GET_OPCODE(v) *((v)++)
121 #define GET_DATA(r,v,data) { \
122 cl_oparg ndx; \
123 GET_OPARG(ndx, v); \
124 r = data[ndx]; \
125 }
126 #define GET_DATA_PTR(r,v,data) { \
127 cl_oparg ndx; \
128 GET_OPARG(ndx, v); \
129 r = data+ndx; \
130 }
131 #define GET_LABEL(pc,v) { \
132 pc = (v) + READ_OPARG(v); \
133 v += OPARG_SIZE; \
134 }
135
136 /**********************************************************************
137 * THREADED INTERPRETER CODE
138 *
139 * By using labels as values, we can build a variant of the
140 * interpreter code that leads to better performance because (i) it
141 * saves a range check on the opcode size and (ii) each opcode has a
142 * dispatch instruction at the end, so that the processor may better
143 * predict jumps.
144 *
145 * NOTE: We cannot use this in Solaris because GCC erroneously produces
146 * relocation tables.
147 */
148 #if (defined(__GNUC__) && !defined(__STRICT_ANSI__) && !defined(__clang__) && !defined(__llvm__))
149 #define ECL_THREADED_INTERPRETER
150 # if defined(__sun__) && (ECL_FIXNUM_BITS > 32)
151 # undef ECL_THREADED_INTERPRETER
152 # endif
153 #endif
154
155 #ifdef ECL_THREADED_INTERPRETER
156 #define BEGIN_SWITCH \
157 THREAD_NEXT;
158 #define CASE(name) \
159 LBL_##name:
160 #define THREAD_NEXT \
161 goto *(&&LBL_OP_NOP + offsets[GET_OPCODE(vector)])
162 #else
163 #define BEGIN_SWITCH \
164 BEGIN: \
165 switch (GET_OPCODE(vector))
166 #define THREAD_NEXT \
167 goto BEGIN
168 #define CASE(name) \
169 case name:
170 #endif
171
172 #if !defined(ECL_THREADED_INTERPRETER)
173 #define ECL_OFFSET_TABLE
174 #else
175 #define ECL_OFFSET_TABLE \
176 static const int offsets[] = {\
177 &&LBL_OP_NOP - &&LBL_OP_NOP,\
178 &&LBL_OP_QUOTE - &&LBL_OP_NOP,\
179 &&LBL_OP_ENDP - &&LBL_OP_NOP,\
180 &&LBL_OP_CONS - &&LBL_OP_NOP,\
181 &&LBL_OP_CAR - &&LBL_OP_NOP,\
182 &&LBL_OP_CDR - &&LBL_OP_NOP,\
183 &&LBL_OP_LIST - &&LBL_OP_NOP,\
184 &&LBL_OP_LISTA - &&LBL_OP_NOP,\
185 &&LBL_OP_CONS_CAR - &&LBL_OP_NOP,\
186 &&LBL_OP_CONS_CDR - &&LBL_OP_NOP,\
187 &&LBL_OP_INT - &&LBL_OP_NOP,\
188 &&LBL_OP_PINT - &&LBL_OP_NOP,\
189 &&LBL_OP_VAR - &&LBL_OP_NOP,\
190 &&LBL_OP_VARC - &&LBL_OP_NOP,\
191 &&LBL_OP_VARS - &&LBL_OP_NOP,\
192 &&LBL_OP_PUSH - &&LBL_OP_NOP,\
193 &&LBL_OP_PUSHV - &&LBL_OP_NOP,\
194 &&LBL_OP_PUSHVC - &&LBL_OP_NOP,\
195 &&LBL_OP_PUSHVS - &&LBL_OP_NOP,\
196 &&LBL_OP_PUSHQ - &&LBL_OP_NOP,\
197 &&LBL_OP_CALLG1 - &&LBL_OP_NOP,\
198 &&LBL_OP_CALLG2 - &&LBL_OP_NOP,\
199 &&LBL_OP_CALL - &&LBL_OP_NOP,\
200 &&LBL_OP_CALLG - &&LBL_OP_NOP,\
201 &&LBL_OP_FCALL - &&LBL_OP_NOP,\
202 &&LBL_OP_MCALL - &&LBL_OP_NOP,\
203 &&LBL_OP_POP - &&LBL_OP_NOP,\
204 &&LBL_OP_POP1 - &&LBL_OP_NOP,\
205 &&LBL_OP_POPREQ - &&LBL_OP_NOP,\
206 &&LBL_OP_POPOPT - &&LBL_OP_NOP,\
207 &&LBL_OP_NOMORE - &&LBL_OP_NOP,\
208 &&LBL_OP_POPREST - &&LBL_OP_NOP,\
209 &&LBL_OP_PUSHKEYS - &&LBL_OP_NOP,\
210 &&LBL_OP_EXIT - &&LBL_OP_NOP,\
211 &&LBL_OP_FLET - &&LBL_OP_NOP,\
212 &&LBL_OP_LABELS - &&LBL_OP_NOP,\
213 &&LBL_OP_LFUNCTION - &&LBL_OP_NOP,\
214 &&LBL_OP_CFUNCTION - &&LBL_OP_NOP,\
215 &&LBL_OP_FUNCTION - &&LBL_OP_NOP,\
216 &&LBL_OP_CLOSE - &&LBL_OP_NOP,\
217 &&LBL_OP_GO - &&LBL_OP_NOP,\
218 &&LBL_OP_GO_CFB - &&LBL_OP_NOP,\
219 &&LBL_OP_RETURN - &&LBL_OP_NOP,\
220 &&LBL_OP_RETURN_CFB - &&LBL_OP_NOP,\
221 &&LBL_OP_THROW - &&LBL_OP_NOP,\
222 &&LBL_OP_JMP - &&LBL_OP_NOP,\
223 &&LBL_OP_JNIL - &&LBL_OP_NOP,\
224 &&LBL_OP_JT - &&LBL_OP_NOP,\
225 &&LBL_OP_JEQL - &&LBL_OP_NOP,\
226 &&LBL_OP_JNEQL - &&LBL_OP_NOP,\
227 &&LBL_OP_UNBIND - &&LBL_OP_NOP,\
228 &&LBL_OP_UNBINDS - &&LBL_OP_NOP,\
229 &&LBL_OP_BIND - &&LBL_OP_NOP,\
230 &&LBL_OP_PBIND - &&LBL_OP_NOP,\
231 &&LBL_OP_VBIND - &&LBL_OP_NOP,\
232 &&LBL_OP_BINDS - &&LBL_OP_NOP,\
233 &&LBL_OP_PBINDS - &&LBL_OP_NOP,\
234 &&LBL_OP_VBINDS - &&LBL_OP_NOP,\
235 &&LBL_OP_SETQ - &&LBL_OP_NOP,\
236 &&LBL_OP_SETQC - &&LBL_OP_NOP,\
237 &&LBL_OP_SETQS - &&LBL_OP_NOP,\
238 &&LBL_OP_PSETQ - &&LBL_OP_NOP,\
239 &&LBL_OP_PSETQC - &&LBL_OP_NOP,\
240 &&LBL_OP_PSETQS - &&LBL_OP_NOP,\
241 &&LBL_OP_VSETQ - &&LBL_OP_NOP,\
242 &&LBL_OP_VSETQC - &&LBL_OP_NOP,\
243 &&LBL_OP_VSETQS - &&LBL_OP_NOP,\
244 &&LBL_OP_BLOCK - &&LBL_OP_NOP,\
245 &&LBL_OP_DO - &&LBL_OP_NOP,\
246 &&LBL_OP_CATCH - &&LBL_OP_NOP,\
247 &&LBL_OP_FRAME - &&LBL_OP_NOP,\
248 &&LBL_OP_TAGBODY - &&LBL_OP_NOP,\
249 &&LBL_OP_EXIT_TAGBODY - &&LBL_OP_NOP,\
250 &&LBL_OP_EXIT_FRAME - &&LBL_OP_NOP,\
251 &&LBL_OP_PROTECT - &&LBL_OP_NOP,\
252 &&LBL_OP_PROTECT_NORMAL - &&LBL_OP_NOP,\
253 &&LBL_OP_PROTECT_EXIT - &&LBL_OP_NOP,\
254 &&LBL_OP_PROGV - &&LBL_OP_NOP,\
255 &&LBL_OP_EXIT_PROGV - &&LBL_OP_NOP,\
256 &&LBL_OP_PUSHVALUES - &&LBL_OP_NOP,\
257 &&LBL_OP_POPVALUES - &&LBL_OP_NOP,\
258 &&LBL_OP_PUSHMOREVALUES - &&LBL_OP_NOP,\
259 &&LBL_OP_VALUES - &&LBL_OP_NOP,\
260 &&LBL_OP_VALUEREG0 - &&LBL_OP_NOP,\
261 &&LBL_OP_NTHVAL - &&LBL_OP_NOP,\
262 &&LBL_OP_NIL - &&LBL_OP_NOP,\
263 &&LBL_OP_NOT - &&LBL_OP_NOP,\
264 &&LBL_OP_PUSHNIL - &&LBL_OP_NOP,\
265 &&LBL_OP_CSET - &&LBL_OP_NOP,\
266 &&LBL_OP_STEPIN - &&LBL_OP_NOP,\
267 &&LBL_OP_STEPCALL - &&LBL_OP_NOP,\
268 &&LBL_OP_STEPOUT - &&LBL_OP_NOP };
269 #endif
270
271 #endif /* ECL_BYTECODES_H */