[e90b2f]: src / h / bytecodes.h Maximize Restore History

Download this file

bytecodes.h    265 lines (259 with data), 6.7 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
 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
/* -*- mode: c; c-basic-offset: 8 -*- */
/**********************************************************************
***
*** IMPORTANT: ANY CHANGE IN THIS FILE MUST BE MATCHED BY
*** APPROPRIATE CHANGES IN THE INTERPRETER AND COMPILER
*** IN PARTICULAR, IT MAY HURT THE THREADED INTERPRETER
*** CODE.
**********************************************************************/
/*
* See ecl/src/c/interpreter.d for a detailed explanation of all opcodes
*/
enum {
OP_NOP,
OP_QUOTE,
OP_ENDP,
OP_CONS,
OP_CAR,
OP_CDR,
OP_LIST,
OP_LISTA,
OP_INT,
OP_PINT,
OP_VAR,
OP_VARS,
OP_PUSH,
OP_PUSHV,
OP_PUSHVS,
OP_PUSHQ,
OP_CALLG1,
OP_CALLG2,
OP_CALL,
OP_CALLG,
OP_FCALL,
OP_MCALL,
OP_POP,
OP_POP1,
OP_POPREQ,
OP_POPOPT,
OP_NOMORE,
OP_POPREST,
OP_PUSHKEYS,
OP_EXIT,
OP_FLET,
OP_LABELS,
OP_LFUNCTION,
OP_FUNCTION,
OP_CLOSE,
OP_GO,
OP_RETURN,
OP_THROW,
OP_JMP,
OP_JNIL,
OP_JT,
OP_JEQL,
OP_JNEQL,
OP_UNBIND,
OP_UNBINDS,
OP_BIND,
OP_PBIND,
OP_VBIND,
OP_BINDS,
OP_PBINDS,
OP_VBINDS,
OP_SETQ,
OP_SETQS,
OP_PSETQ,
OP_PSETQS,
OP_VSETQ,
OP_VSETQS,
OP_BLOCK,
OP_DO,
OP_CATCH,
OP_FRAME,
OP_TAGBODY,
OP_EXIT_TAGBODY,
OP_EXIT_FRAME,
OP_PROTECT,
OP_PROTECT_NORMAL,
OP_PROTECT_EXIT,
OP_PROGV,
OP_EXIT_PROGV,
OP_PUSHVALUES,
OP_POPVALUES,
OP_PUSHMOREVALUES,
OP_VALUES,
OP_VALUEREG0,
OP_NTHVAL,
OP_NIL,
OP_NOT,
OP_PUSHNIL,
OP_CSET,
OP_STEPIN,
OP_STEPCALL,
OP_STEPOUT,
OP_MAXOPCODES = 128,
OP_OPCODE_SHIFT = 7
};
#define MAX_OPARG 0x7FFF
typedef int16_t cl_oparg;
/*
* Note that in the small bytecodes case, we have to recompose a signed
* small integer out of its pieces. We have to be careful because the
* least significant byte has to be interpreted as unsigned, while the
* most significant byte carries a sign.
*/
#ifdef ECL_SMALL_BYTECODES
typedef signed char cl_opcode;
# define OPCODE_SIZE 1
# define OPARG_SIZE 2
# ifdef WORDS_BIGENDIAN
# define READ_OPARG(v) ((cl_fixnum)v[0] << 8) + (unsigned char)v[1]
# else
# define READ_OPARG(v) ((cl_fixnum)v[1] << 8) + (unsigned char)v[0]
# endif
# define GET_OPARG(r,v) { r = READ_OPARG(v); v += 2; }
#else
typedef int16_t cl_opcode;
# define OPCODE_SIZE 1
# define OPARG_SIZE 1
# define READ_OPCODE(v) v[0]
# define READ_OPARG(v) v[0]
# define GET_OPARG(r,v) { r = *(v++); }
#endif
#define GET_OPCODE(v) *((v)++)
#define GET_DATA(r,v,data) { \
cl_oparg ndx; \
GET_OPARG(ndx, v); \
r = data[ndx]; \
}
#define GET_DATA_PTR(r,v,data) { \
cl_oparg ndx; \
GET_OPARG(ndx, v); \
r = data+ndx; \
}
#define GET_LABEL(pc,v) { \
pc = (v) + READ_OPARG(v); \
v += OPARG_SIZE; \
}
/**********************************************************************
* THREADED INTERPRETER CODE
*
* By using labels as values, we can build a variant of the
* interpreter code that leads to better performance because (i) it
* saves a range check on the opcode size and (ii) each opcode has a
* dispatch instruction at the end, so that the processor may better
* predict jumps.
*
* NOTE: We cannot use this in Solaris because GCC erroneously produces
* relocation tables.
*/
#if (defined(__GNUC__) && !defined(__STRICT_ANSI__) && !defined(__clang__) && !defined(__llvm__))
#define ECL_THREADED_INTERPRETER
# if defined(__sun__) && (FIXNUM_BITS > 32)
# undef ECL_THREADED_INTERPRETER
# endif
#endif
#ifdef ECL_THREADED_INTERPRETER
#define BEGIN_SWITCH \
THREAD_NEXT;
#define CASE(name) \
LBL_##name:
#define THREAD_NEXT \
goto *(&&LBL_OP_NOP + offsets[GET_OPCODE(vector)])
#else
#define BEGIN_SWITCH \
switch (GET_OPCODE(vector))
#define THREAD_NEXT \
goto BEGIN
#define CASE(name) \
case name:
#endif
#if !defined(ECL_THREADED_INTERPRETER)
#define ECL_OFFSET_TABLE
#else
#define ECL_OFFSET_TABLE \
static const int offsets[] = {\
&&LBL_OP_NOP - &&LBL_OP_NOP,\
&&LBL_OP_QUOTE - &&LBL_OP_NOP,\
&&LBL_OP_ENDP - &&LBL_OP_NOP,\
&&LBL_OP_CONS - &&LBL_OP_NOP,\
&&LBL_OP_CAR - &&LBL_OP_NOP,\
&&LBL_OP_CDR - &&LBL_OP_NOP,\
&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AL - &&LBL_OP_NOP,\
&&LBL_OP_NIL - &&LBL_OP_NOP,\
&&LBL_OP_NOT - &&LBL_OP_NOP,\
&&LBL_OP_PUSHNIL - &&LBL_OP_NOP,\
&&LBL_OP_CSET - &&LBL_OP_NOP,\
&&LBL_OP_STEPIN - &&LBL_OP_NOP,\
&&LBL_OP_STEPCALL - &&LBL_OP_NOP,\
&&LBL_OP_STEPOUT - &&LBL_OP_NOP };
#endif