4 /* limit for table tag-method chains (to avoid loops) */
8 +#define COMPUTED_GOTO 1
12 * If 'obj' is a string, it is tried to be interpreted as a number.
18 +#define OPCODE_TARGET(op) DO_OP_##op:
19 +#define CALL_OPCODE(op) goto *opcodes[op];
20 +#define OPCODE_PTR(op) [OP_##op] = &&DO_OP_##op
22 +#define OPCODE_TARGET(op) case OP_##op:
23 +#define CALL_OPCODE(op) switch (op)
27 void luaV_execute (lua_State *L, int nexeccalls) {
31 const Instruction *pc;
33 + static const void *opcodes[] = {
36 + OPCODE_PTR(LOADBOOL),
37 + OPCODE_PTR(LOADNIL),
38 + OPCODE_PTR(GETUPVAL),
39 + OPCODE_PTR(GETGLOBAL),
40 + OPCODE_PTR(GETTABLE),
41 + OPCODE_PTR(SETGLOBAL),
42 + OPCODE_PTR(SETUPVAL),
43 + OPCODE_PTR(SETTABLE),
44 + OPCODE_PTR(NEWTABLE),
61 + OPCODE_PTR(TESTSET),
63 + OPCODE_PTR(TAILCALL),
65 + OPCODE_PTR(FORLOOP),
66 + OPCODE_PTR(FORPREP),
67 + OPCODE_PTR(TFORLOOP),
68 + OPCODE_PTR(SETLIST),
70 + OPCODE_PTR(CLOSURE),
74 reentry: /* entry point */
75 lua_assert(isLua(L->ci));
78 lua_assert(base == L->base && L->base == L->ci->base);
79 lua_assert(base <= L->top && L->top <= L->stack + L->stacksize);
80 lua_assert(L->top == L->ci->top || luaG_checkopenop(i));
81 - switch (GET_OPCODE(i)) {
83 + CALL_OPCODE(GET_OPCODE(i)) {
84 + OPCODE_TARGET(MOVE) {
85 setobjs2s(L, ra, RB(i));
89 + OPCODE_TARGET(LOADK) {
90 setobj2s(L, ra, KBx(i));
94 + OPCODE_TARGET(LOADBOOL) {
95 setbvalue(ra, GETARG_B(i));
96 if (GETARG_C(i)) pc++; /* skip next instruction (if C) */
100 + OPCODE_TARGET(LOADNIL) {
107 - case OP_GETUPVAL: {
108 + OPCODE_TARGET(GETUPVAL) {
110 setobj2s(L, ra, cl->upvals[b]->v);
113 - case OP_GETGLOBAL: {
114 + OPCODE_TARGET(GETGLOBAL) {
117 sethvalue(L, &g, cl->env);
118 @@ -628,88 +682,88 @@
119 Protect(luaV_gettable(L, &g, rb, ra));
122 - case OP_GETTABLE: {
123 + OPCODE_TARGET(GETTABLE) {
124 Protect(luaV_gettable(L, RB(i), RKC(i), ra));
127 - case OP_SETGLOBAL: {
128 + OPCODE_TARGET(SETGLOBAL) {
130 sethvalue(L, &g, cl->env);
131 lua_assert(ttisstring(KBx(i)));
132 Protect(luaV_settable(L, &g, KBx(i), ra));
135 - case OP_SETUPVAL: {
136 + OPCODE_TARGET(SETUPVAL) {
137 UpVal *uv = cl->upvals[GETARG_B(i)];
138 setobj(L, uv->v, ra);
139 luaC_barrier(L, uv, ra);
142 - case OP_SETTABLE: {
143 + OPCODE_TARGET(SETTABLE) {
144 Protect(luaV_settable(L, ra, RKB(i), RKC(i)));
147 - case OP_NEWTABLE: {
148 + OPCODE_TARGET(NEWTABLE) {
151 sethvalue(L, ra, luaH_new(L, luaO_fb2int(b), luaO_fb2int(c)));
152 Protect(luaC_checkGC(L));
156 + OPCODE_TARGET(SELF) {
158 setobjs2s(L, ra+1, rb);
159 Protect(luaV_gettable(L, rb, RKC(i), ra));
163 + OPCODE_TARGET(ADD) {
164 TValue *rb = RKB(i), *rc= RKC(i);
165 arith_op_continue( luai_numadd, try_addint, luai_vectadd );
166 Protect(Arith(L, ra, rb, rc, TM_ADD)); \
170 + OPCODE_TARGET(SUB) {
171 TValue *rb = RKB(i), *rc= RKC(i);
172 arith_op_continue( luai_numsub, try_subint, luai_vectsub );
173 Protect(Arith(L, ra, rb, rc, TM_SUB));
177 + OPCODE_TARGET(MUL) {
178 TValue *rb = RKB(i), *rc= RKC(i);
179 arith_op_continue(luai_nummul, try_mulint, luai_vectmul);
180 Protect(Arith(L, ra, rb, rc, TM_MUL));
184 + OPCODE_TARGET(DIV) {
185 TValue *rb = RKB(i), *rc= RKC(i);
186 arith_op_continue(luai_numdiv, try_divint, luai_vectdiv);
187 Protect(Arith(L, ra, rb, rc, TM_DIV));
191 + OPCODE_TARGET(MOD) {
192 TValue *rb = RKB(i), *rc= RKC(i);
193 arith_op_continue_scalar(luai_nummod, try_modint); /* scalars only */
194 Protect(Arith(L, ra, rb, rc, TM_MOD));
198 + OPCODE_TARGET(POW) {
199 TValue *rb = RKB(i), *rc= RKC(i);
200 arith_op_continue(luai_numpow, try_powint, luai_vectpow);
201 Protect(Arith(L, ra, rb, rc, TM_POW));
205 + OPCODE_TARGET(UNM) {
207 arith_op1_continue(luai_numunm, try_unmint, luai_vectunm);
208 Protect(Arith(L, ra, rb, rb, TM_UNM));
212 + OPCODE_TARGET(NOT) {
213 int res = l_isfalse(RB(i)); /* next assignment may change this value */
218 + OPCODE_TARGET(LEN) {
219 const TValue *rb = RB(i);
222 @@ -729,18 +783,18 @@
227 + OPCODE_TARGET(CONCAT) {
230 Protect(luaV_concat(L, c-b+1, c); luaC_checkGC(L));
231 setobjs2s(L, RA(i), base+b);
235 + OPCODE_TARGET(JMP) {
236 dojump(L, pc, GETARG_sBx(i));
240 + OPCODE_TARGET(EQ) {
249 + OPCODE_TARGET(LT) {
251 if (luaV_lessthan(L, RKB(i), RKC(i)) == GETARG_A(i))
252 dojump(L, pc, GETARG_sBx(*pc));
258 + OPCODE_TARGET(LE) {
260 if (lessequal(L, RKB(i), RKC(i)) == GETARG_A(i))
261 dojump(L, pc, GETARG_sBx(*pc));
262 @@ -766,13 +820,13 @@
267 + OPCODE_TARGET(TEST) {
268 if (l_isfalse(ra) != GETARG_C(i))
269 dojump(L, pc, GETARG_sBx(*pc));
274 + OPCODE_TARGET(TESTSET) {
276 if (l_isfalse(rb) != GETARG_C(i)) {
277 setobjs2s(L, ra, rb);
283 + OPCODE_TARGET(CALL) {
285 int nresults = GETARG_C(i) - 1;
286 if (b != 0) L->top = ra+b; /* else previous instruction set top */
291 - case OP_TAILCALL: {
292 + OPCODE_TARGET(TAILCALL) {
294 if (b != 0) L->top = ra+b; /* else previous instruction set top */
301 + OPCODE_TARGET(RETURN) {
303 if (b != 0) L->top = ra+b-1;
304 if (L->openupval) luaF_close(L, base);
310 + OPCODE_TARGET(FORLOOP) {
311 /* If start,step and limit are all integers, we don't need to check
312 * against overflow in the looping.
319 + OPCODE_TARGET(FORPREP) {
320 const TValue *init = ra;
321 const TValue *plimit = ra+1;
322 const TValue *pstep = ra+2;
324 dojump(L, pc, GETARG_sBx(i));
327 - case OP_TFORLOOP: {
328 + OPCODE_TARGET(TFORLOOP) {
329 StkId cb = ra + 3; /* call base */
330 setobjs2s(L, cb+2, ra+2);
331 setobjs2s(L, cb+1, ra+1);
337 + OPCODE_TARGET(SETLIST) {
341 @@ -938,11 +992,11 @@
346 + OPCODE_TARGET(CLOSE) {
351 + OPCODE_TARGET(CLOSURE) {
356 Protect(luaC_checkGC(L));
360 + OPCODE_TARGET(VARARG) {
361 int b = GETARG_B(i) - 1;
363 CallInfo *ci = L->ci;