From 1a17da2ff9dce06a0405f549522a4e08026c3124 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 2 Feb 1999 15:57:49 -0200 Subject: [PATCH] opcodes with builtin parameters are too complicated for very little extra performance. --- lopcodes.h | 84 ++----------------- lparser.c | 86 +++++++++----------- lvm.c | 235 ++++++++++++----------------------------------------- 3 files changed, 96 insertions(+), 309 deletions(-) diff --git a/lopcodes.h b/lopcodes.h index f4a8a9cc..810d1ebe 100644 --- a/lopcodes.h +++ b/lopcodes.h @@ -1,5 +1,5 @@ /* -** $Id: lopcodes.h,v 1.17 1998/03/25 18:52:29 roberto Exp roberto $ +** $Id: lopcodes.h,v 1.18 1998/06/25 14:37:00 roberto Exp roberto $ ** Opcodes for Lua virtual machine ** See Copyright Notice in lua.h */ @@ -8,10 +8,11 @@ #define lopcodes_h +#define NUMOFFSET 100 + /* ** NOTICE: variants of the same opcode must be consecutive: First, those -** with byte parameter, then with built-in parameters, and last with -** word parameter. +** with byte parameter, then with word parameter. */ @@ -21,98 +22,34 @@ typedef enum { ENDCODE,/* - - - */ PUSHNIL,/* b - nil_0...nil_b */ -PUSHNIL0,/* - - nil */ -PUSHNUMBER,/* b - (float)b */ -PUSHNUMBER0,/* - - 0.0 */ -PUSHNUMBER1,/* - - 1.0 */ -PUSHNUMBER2,/* - - 2.0 */ -PUSHNUMBERW,/* w - (float)w */ +PUSHNUMBER,/* b - (float)(b-NUMOFFSET) */ +PUSHNUMBERW,/* w - (float)(w-NUMOFFSET) */ PUSHCONSTANT,/* b - CNST[b] */ -PUSHCONSTANT0,/*- - CNST[0] */ -PUSHCONSTANT1,/*- - CNST[1] */ -PUSHCONSTANT2,/*- - CNST[2] */ -PUSHCONSTANT3,/*- - CNST[3] */ -PUSHCONSTANT4,/*- - CNST[4] */ -PUSHCONSTANT5,/*- - CNST[5] */ -PUSHCONSTANT6,/*- - CNST[6] */ -PUSHCONSTANT7,/*- - CNST[7] */ PUSHCONSTANTW,/*w - CNST[w] */ PUSHUPVALUE,/* b - Closure[b] */ -PUSHUPVALUE0,/* - - Closure[0] */ -PUSHUPVALUE1,/* - - Closure[1] */ PUSHLOCAL,/* b - LOC[b] */ -PUSHLOCAL0,/* - - LOC[0] */ -PUSHLOCAL1,/* - - LOC[1] */ -PUSHLOCAL2,/* - - LOC[2] */ -PUSHLOCAL3,/* - - LOC[3] */ -PUSHLOCAL4,/* - - LOC[4] */ -PUSHLOCAL5,/* - - LOC[5] */ -PUSHLOCAL6,/* - - LOC[6] */ -PUSHLOCAL7,/* - - LOC[7] */ GETGLOBAL,/* b - VAR[CNST[b]] */ -GETGLOBAL0,/* - - VAR[CNST[0]] */ -GETGLOBAL1,/* - - VAR[CNST[1]] */ -GETGLOBAL2,/* - - VAR[CNST[2]] */ -GETGLOBAL3,/* - - VAR[CNST[3]] */ -GETGLOBAL4,/* - - VAR[CNST[4]] */ -GETGLOBAL5,/* - - VAR[CNST[5]] */ -GETGLOBAL6,/* - - VAR[CNST[6]] */ -GETGLOBAL7,/* - - VAR[CNST[7]] */ GETGLOBALW,/* w - VAR[CNST[w]] */ GETTABLE,/* - i t t[i] */ GETDOTTED,/* b t t[CNST[b]] */ -GETDOTTED0,/* - t t[CNST[0]] */ -GETDOTTED1,/* - t t[CNST[1]] */ -GETDOTTED2,/* - t t[CNST[2]] */ -GETDOTTED3,/* - t t[CNST[3]] */ -GETDOTTED4,/* - t t[CNST[4]] */ -GETDOTTED5,/* - t t[CNST[5]] */ -GETDOTTED6,/* - t t[CNST[6]] */ -GETDOTTED7,/* - t t[CNST[7]] */ GETDOTTEDW,/* w t t[CNST[w]] */ PUSHSELF,/* b t t t[CNST[b]] */ -PUSHSELF0,/* - t t t[CNST[0]] */ -PUSHSELF1,/* - t t t[CNST[1]] */ -PUSHSELF2,/* - t t t[CNST[2]] */ -PUSHSELF3,/* - t t t[CNST[3]] */ -PUSHSELF4,/* - t t t[CNST[4]] */ -PUSHSELF5,/* - t t t[CNST[5]] */ -PUSHSELF6,/* - t t t[CNST[6]] */ -PUSHSELF7,/* - t t t[CNST[7]] */ PUSHSELFW,/* w t t t[CNST[w]] */ CREATEARRAY,/* b - newarray(size = b) */ -CREATEARRAY0,/* - - newarray(size = 0) */ -CREATEARRAY1,/* - - newarray(size = 1) */ CREATEARRAYW,/* w - newarray(size = w) */ SETLOCAL,/* b x - LOC[b]=x */ -SETLOCAL0,/* - x - LOC[0]=x */ -SETLOCAL1,/* - x - LOC[1]=x */ -SETLOCAL2,/* - x - LOC[2]=x */ -SETLOCAL3,/* - x - LOC[3]=x */ -SETLOCAL4,/* - x - LOC[4]=x */ -SETLOCAL5,/* - x - LOC[5]=x */ -SETLOCAL6,/* - x - LOC[6]=x */ -SETLOCAL7,/* - x - LOC[7]=x */ SETGLOBAL,/* b x - VAR[CNST[b]]=x */ -SETGLOBAL0,/* - x - VAR[CNST[0]]=x */ -SETGLOBAL1,/* - x - VAR[CNST[1]]=x */ -SETGLOBAL2,/* - x - VAR[CNST[2]]=x */ -SETGLOBAL3,/* - x - VAR[CNST[3]]=x */ -SETGLOBAL4,/* - x - VAR[CNST[4]]=x */ -SETGLOBAL5,/* - x - VAR[CNST[5]]=x */ -SETGLOBAL6,/* - x - VAR[CNST[6]]=x */ -SETGLOBAL7,/* - x - VAR[CNST[7]]=x */ SETGLOBALW,/* w x - VAR[CNST[w]]=x */ SETTABLE0,/* - v i t - t[i]=v */ @@ -120,11 +57,9 @@ SETTABLE0,/* - v i t - t[i]=v */ SETTABLE,/* b v a_b...a_1 i t a_b...a_1 i t t[i]=v */ SETLIST,/* b c v_c...v_1 t - t[i+b*FPF]=v_i */ -SETLIST0,/* b v_b...v_1 t - t[i]=v_i */ SETLISTW,/* w c v_c...v_1 t - t[i+w*FPF]=v_i */ SETMAP,/* b v_b k_b ...v_0 k_0 t t t[k_i]=v_i */ -SETMAP0,/* - v_0 k_0 t t t[k_0]=v_0 */ EQOP,/* - y x (x==y)? 1 : nil */ NEQOP,/* - y x (x~=y)? 1 : nil */ @@ -155,20 +90,15 @@ IFFUPJMP,/* b x - (x==nil)? PC-=b */ IFFUPJMPW,/* w x - (x==nil)? PC-=w */ CLOSURE,/* b c v_c...v_1 closure(CNST[b], v_c...v_1) */ -CLOSUREW,/* w c v_b...v_1 closure(CNST[w], v_c...v_1) */ CALLFUNC,/* b c v_c...v_1 f r_b...r_1 f(v1,...,v_c) */ -CALLFUNC0,/* b v_b...v_1 f - f(v1,...,v_b) */ -CALLFUNC1,/* b v_b...v_1 f r_1 f(v1,...,v_b) */ RETCODE,/* b - - */ SETLINE,/* b - - LINE=b */ SETLINEW,/* w - - LINE=w */ -POP,/* b - - TOP-=(b+1) */ -POP0,/* - - - TOP-=1 */ -POP1/* - - - TOP-=2 */ +POP /* b - - TOP-=(b+1) */ } OpCode; diff --git a/lparser.c b/lparser.c index 263277f4..8d632038 100644 --- a/lparser.c +++ b/lparser.c @@ -1,5 +1,5 @@ /* -** $Id: lparser.c,v 1.11 1999/02/01 18:52:05 roberto Exp roberto $ +** $Id: lparser.c,v 1.12 1999/02/02 13:47:31 roberto Exp roberto $ ** LL(1) Parser and code generator for Lua ** See Copyright Notice in lua.h */ @@ -153,24 +153,19 @@ static void deltastack (LexState *ls, int delta) { } -static int code_oparg_at (LexState *ls, int pc, OpCode op, int builtin, - int arg, int delta) { +static int code_oparg_at (LexState *ls, int pc, OpCode op, int arg, int delta) { Byte *code = ls->fs->f->code; deltastack(ls, delta); - if (arg < builtin) { - code[pc] = (Byte)(op+1+arg); - return 1; - } - else if (arg <= 255) { + if (arg <= 255) { code[pc] = (Byte)op; code[pc+1] = (Byte)arg; - return 2; + return 2; /* code size (opcode + 1 byte) */ } else if (arg <= MAX_WORD) { - code[pc] = (Byte)(op+1+builtin); + code[pc] = (Byte)(op+1); code[pc+1] = (Byte)(arg>>8); code[pc+2] = (Byte)(arg&0xFF); - return 3; + return 3; /* code size (opcode + 1 word) */ } else luaX_error(ls, "code too long " MES_LIM("64K") " (try turning off debug mode)"); @@ -178,25 +173,21 @@ static int code_oparg_at (LexState *ls, int pc, OpCode op, int builtin, } -static int fix_opcode (LexState *ls, int pc, OpCode op, int builtin, int arg) { +static int fix_opcode (LexState *ls, int pc, OpCode op, int arg) { FuncState *fs = ls->fs; TProtoFunc *f = fs->f; - if (arg < builtin) { /* close space */ - luaO_memdown(f->code+pc+1, f->code+pc+2, fs->pc-(pc+2)); - fs->pc--; - } - else if (arg > 255) { /* open space */ + if (arg > 255) { /* open space */ check_pc(fs, 1); luaO_memup(f->code+pc+1, f->code+pc, fs->pc-pc); fs->pc++; } - return code_oparg_at(ls, pc, op, builtin, arg, 0) - 2; + return code_oparg_at(ls, pc, op, arg, 0) - 2; } -static void code_oparg (LexState *ls, OpCode op, int builtin, int arg, - int delta) { + +static void code_oparg (LexState *ls, OpCode op, int arg, int delta) { check_pc(ls->fs, 3); /* maximum code size */ - ls->fs->pc += code_oparg_at(ls, ls->fs->pc, op, builtin, arg, delta); + ls->fs->pc += code_oparg_at(ls, ls->fs->pc, op, arg, delta); } @@ -207,7 +198,7 @@ static void code_opcode (LexState *ls, OpCode op, int delta) { static void code_constant (LexState *ls, int c) { - code_oparg(ls, PUSHCONSTANT, 8, c, 1); + code_oparg(ls, PUSHCONSTANT, c, 1); } @@ -261,8 +252,9 @@ static int real_constant (FuncState *fs, real r) { static void code_number (LexState *ls, real f) { int i; - if (0 <= f && f <= (real)MAX_WORD && (real)(i=(int)f) == f) - code_oparg(ls, PUSHNUMBER, 3, i, 1); /* f has a short integer value */ + if (0 <= f+NUMOFFSET && f+NUMOFFSET <= (real)MAX_WORD && + (real)(i=(int)f) == f) /* f+NUMOFFSET has a short integer value? */ + code_oparg(ls, PUSHNUMBER, i+NUMOFFSET, 1); else code_constant(ls, real_constant(ls->fs, f)); } @@ -270,13 +262,13 @@ static void code_number (LexState *ls, real f) { static void flush_record (LexState *ls, int n) { if (n > 0) - code_oparg(ls, SETMAP, 1, n-1, -2*n); + code_oparg(ls, SETMAP, n-1, -2*n); } static void flush_list (LexState *ls, int m, int n) { if (n == 0) return; - code_oparg(ls, SETLIST, 1, m, -n); + code_oparg(ls, SETLIST, m, -n); code_byte(ls->fs, (Byte)n); } @@ -285,14 +277,12 @@ static void luaI_registerlocalvar (FuncState *fs, TaggedString *varname, int line) { if (fs->maxvars != -1) { /* debug information? */ TProtoFunc *f = fs->f; - if (fs->nvars+2 > fs->maxvars) - fs->maxvars = luaM_growvector(&f->locvars, fs->maxvars+2, + if (fs->nvars+1 > fs->maxvars) + fs->maxvars = luaM_growvector(&f->locvars, fs->maxvars+1, LocVar, "", MAX_WORD); f->locvars[fs->nvars].varname = varname; f->locvars[fs->nvars].line = line; fs->nvars++; - f->locvars[fs->nvars].line = -1; /* flag end of vector */ - } } @@ -369,14 +359,14 @@ static void pushupvalue (LexState *ls, TaggedString *n) { if (aux_localname(ls->fs, n) >= 0) luaX_syntaxerror(ls, "cannot access an upvalue in current scope", n->str); i = indexupvalue(ls, n); - code_oparg(ls, PUSHUPVALUE, 2, i, 1); + code_oparg(ls, PUSHUPVALUE, i, 1); } static void check_debugline (LexState *ls) { if (lua_debug && ls->linenumber != ls->fs->lastsetline) { - code_oparg(ls, SETLINE, 0, ls->linenumber, 0); + code_oparg(ls, SETLINE, ls->linenumber, 0); ls->fs->lastsetline = ls->linenumber; } } @@ -384,9 +374,9 @@ static void check_debugline (LexState *ls) { static void adjuststack (LexState *ls, int n) { if (n > 0) - code_oparg(ls, POP, 2, n-1, -n); + code_oparg(ls, POP, n-1, -n); else if (n < 0) - code_oparg(ls, PUSHNIL, 1, (-n)-1, -n); + code_oparg(ls, PUSHNIL, (-n)-1, -n); } @@ -394,7 +384,7 @@ static void close_exp (LexState *ls, int pc, int nresults) { if (pc > 0) { /* expression is an open function call */ Byte *code = ls->fs->f->code; Byte nparams = code[pc]; /* save nparams */ - pc += fix_opcode(ls, pc-2, CALLFUNC, 2, nresults); + pc += fix_opcode(ls, pc-2, CALLFUNC, nresults); code[pc] = nparams; /* restore nparams */ if (nresults != MULT_RET) deltastack(ls, nresults); /* "push" results */ @@ -442,13 +432,13 @@ static void code_args (LexState *ls, int nparams, int dots) { static void lua_pushvar (LexState *ls, vardesc *var) { switch (var->k) { case VLOCAL: - code_oparg(ls, PUSHLOCAL, 8, var->info, 1); + code_oparg(ls, PUSHLOCAL, var->info, 1); break; case VGLOBAL: - code_oparg(ls, GETGLOBAL, 8, var->info, 1); + code_oparg(ls, GETGLOBAL, var->info, 1); break; case VDOT: - code_oparg(ls, GETDOTTED, 8, var->info, 0); + code_oparg(ls, GETDOTTED, var->info, 0); break; case VINDEXED: code_opcode(ls, GETTABLE, -1); @@ -465,10 +455,10 @@ static void lua_pushvar (LexState *ls, vardesc *var) { static void storevar (LexState *ls, vardesc *var) { switch (var->k) { case VLOCAL: - code_oparg(ls, SETLOCAL, 8, var->info, -1); + code_oparg(ls, SETLOCAL, var->info, -1); break; case VGLOBAL: - code_oparg(ls, SETGLOBAL, 8, var->info, -1); + code_oparg(ls, SETGLOBAL, var->info, -1); break; case VINDEXED: code_opcode(ls, SETTABLE0, -3); @@ -481,14 +471,14 @@ static void storevar (LexState *ls, vardesc *var) { static int fix_jump (LexState *ls, int pc, OpCode op, int n) { /* jump is relative to position following jump instruction */ - return fix_opcode(ls, pc, op, 0, n-(pc+JMPSIZE)); + return fix_opcode(ls, pc, op, n-(pc+JMPSIZE)); } static void fix_upjmp (LexState *ls, OpCode op, int pos) { int delta = ls->fs->pc+JMPSIZE - pos; /* jump is relative */ if (delta > 255) delta++; - code_oparg(ls, op, 0, delta, 0); + code_oparg(ls, op, delta, 0); } @@ -516,7 +506,7 @@ static void func_onstack (LexState *ls, FuncState *func) { else { for (i=0; inupvalues; i++) lua_pushvar(ls, &func->upvalues[i]); - code_oparg(ls, CLOSURE, 0, c, -func->nupvalues+1); + code_oparg(ls, CLOSURE, c, -func->nupvalues+1); code_byte(fs, (Byte)func->nupvalues); } } @@ -862,7 +852,7 @@ static void ifpart (LexState *ls, int isexp, int line) { } else { /* is exp */ if (elsepart) exp1(ls); - else code_oparg(ls, PUSHNIL, 1, 0, 1); /* empty else exp */ + else adjuststack(ls, -1); /* empty else exp -> push nil */ } check_match(ls, END, IF, line); } @@ -878,7 +868,7 @@ static void ret (LexState *ls) { next(ls); explist(ls, &e); close_exp(ls, e.pc, MULT_RET); - code_oparg(ls, RETCODE, 0, ls->fs->nlocalvar, 0); + code_oparg(ls, RETCODE, ls->fs->nlocalvar, 0); ls->fs->stacksize = ls->fs->nlocalvar; /* removes all temp values */ optional(ls, ';'); } @@ -1078,7 +1068,7 @@ static void var_or_func_tail (LexState *ls, vardesc *v) { case ':': /* var_or_func_tail -> ':' NAME funcparams */ next(ls); lua_pushvar(ls, v); /* 'v' must be on stack */ - code_oparg(ls, PUSHSELF, 8, checkname(ls), 1); + code_oparg(ls, PUSHSELF, checkname(ls), 1); v->k = VEXP; v->info = funcparams(ls, 1); break; @@ -1242,7 +1232,7 @@ static int assignment (LexState *ls, vardesc *v, int nvars) { storevar(ls, v); } else { /* indexed var with values in between*/ - code_oparg(ls, SETTABLE, 0, left+(nvars-1), -1); + code_oparg(ls, SETTABLE, left+(nvars-1), -1); left += 2; /* table/index are not popped, because they aren't on top */ } return left; @@ -1267,7 +1257,7 @@ static void constructor (LexState *ls) { nelems += other_cd.n; } check_match(ls, '}', '{', line); - fix_opcode(ls, pc, CREATEARRAY, 2, nelems); + fix_opcode(ls, pc, CREATEARRAY, nelems); } static void part (LexState *ls, constdesc *cd) { diff --git a/lvm.c b/lvm.c index 55481f4e..082c7e8f 100644 --- a/lvm.c +++ b/lvm.c @@ -1,5 +1,5 @@ /* -** $Id: lvm.c,v 1.40 1999/01/20 20:22:06 roberto Exp roberto $ +** $Id: lvm.c,v 1.41 1999/01/25 17:39:28 roberto Exp roberto $ ** Lua virtual machine ** See Copyright Notice in lua.h */ @@ -31,9 +31,7 @@ #endif -#define skip_word(pc) (pc+=2) -#define get_word(pc) ((*(pc)<<8)+(*((pc)+1))) -#define next_word(pc) (pc+=2, get_word(pc-2)) +#define highbyte(x) ((x)<<8) /* Extra stack size to run a function: LUA_T_LINE(1), TM calls(2), ... */ @@ -315,10 +313,9 @@ static void adjust_varargs (StkId first_extra_arg) ** [stack+base,top). Returns n such that the the results are between ** [stack+n,top). */ -StkId luaV_execute (Closure *cl, TProtoFunc *tf, StkId base) -{ +StkId luaV_execute (Closure *cl, TProtoFunc *tf, StkId base) { struct Stack *S = &L->stack; /* to optimize */ - Byte *pc = tf->code; + register Byte *pc = tf->code; TObject *consts = tf->consts; if (lua_callhook) luaD_callHook(base, tf, 0); @@ -330,54 +327,28 @@ StkId luaV_execute (Closure *cl, TProtoFunc *tf, StkId base) adjust_varargs(base+(*pc++)-ZEROVARARG); } for (;;) { - int aux; - switch ((OpCode)(aux = *pc++)) { + register int aux = 0; + switch ((OpCode)*pc++) { - case PUSHNIL0: - ttype(S->top++) = LUA_T_NIL; - break; - - case PUSHNIL: - aux = *pc++; + case PUSHNIL: aux = *pc++; do { ttype(S->top++) = LUA_T_NIL; } while (aux--); break; - case PUSHNUMBER: - aux = *pc++; goto pushnumber; - - case PUSHNUMBERW: - aux = next_word(pc); goto pushnumber; - - case PUSHNUMBER0: case PUSHNUMBER1: case PUSHNUMBER2: - aux -= PUSHNUMBER0; - pushnumber: + case PUSHNUMBERW: aux = highbyte(*pc++); + case PUSHNUMBER: aux += *pc++; ttype(S->top) = LUA_T_NUMBER; - nvalue(S->top) = aux; + nvalue(S->top) = aux-NUMOFFSET; S->top++; break; - case PUSHLOCAL: - aux = *pc++; goto pushlocal; - - case PUSHLOCAL0: case PUSHLOCAL1: case PUSHLOCAL2: case PUSHLOCAL3: - case PUSHLOCAL4: case PUSHLOCAL5: case PUSHLOCAL6: case PUSHLOCAL7: - aux -= PUSHLOCAL0; - pushlocal: + case PUSHLOCAL: aux = *pc++; *S->top++ = *((S->stack+base) + aux); break; - case GETGLOBALW: - aux = next_word(pc); goto getglobal; - - case GETGLOBAL: - aux = *pc++; goto getglobal; - - case GETGLOBAL0: case GETGLOBAL1: case GETGLOBAL2: case GETGLOBAL3: - case GETGLOBAL4: case GETGLOBAL5: case GETGLOBAL6: case GETGLOBAL7: - aux -= GETGLOBAL0; - getglobal: + case GETGLOBALW: aux = highbyte(*pc++); + case GETGLOBAL: aux += *pc++; luaV_getglobal(tsvalue(&consts[aux])); break; @@ -385,30 +356,14 @@ StkId luaV_execute (Closure *cl, TProtoFunc *tf, StkId base) luaV_gettable(); break; - case GETDOTTEDW: - aux = next_word(pc); goto getdotted; - - case GETDOTTED: - aux = *pc++; goto getdotted; - - case GETDOTTED0: case GETDOTTED1: case GETDOTTED2: case GETDOTTED3: - case GETDOTTED4: case GETDOTTED5: case GETDOTTED6: case GETDOTTED7: - aux -= GETDOTTED0; - getdotted: + case GETDOTTEDW: aux = highbyte(*pc++); + case GETDOTTED: aux += *pc++; *S->top++ = consts[aux]; luaV_gettable(); break; - case PUSHSELFW: - aux = next_word(pc); goto pushself; - - case PUSHSELF: - aux = *pc++; goto pushself; - - case PUSHSELF0: case PUSHSELF1: case PUSHSELF2: case PUSHSELF3: - case PUSHSELF4: case PUSHSELF5: case PUSHSELF6: case PUSHSELF7: - aux -= PUSHSELF0; - pushself: { + case PUSHSELFW: aux = highbyte(*pc++); + case PUSHSELF: aux += *pc++; { TObject receiver = *(S->top-1); *S->top++ = consts[aux]; luaV_gettable(); @@ -416,49 +371,21 @@ StkId luaV_execute (Closure *cl, TProtoFunc *tf, StkId base) break; } - case PUSHCONSTANTW: - aux = next_word(pc); goto pushconstant; - - case PUSHCONSTANT: - aux = *pc++; goto pushconstant; - - case PUSHCONSTANT0: case PUSHCONSTANT1: case PUSHCONSTANT2: - case PUSHCONSTANT3: case PUSHCONSTANT4: case PUSHCONSTANT5: - case PUSHCONSTANT6: case PUSHCONSTANT7: - aux -= PUSHCONSTANT0; - pushconstant: + case PUSHCONSTANTW: aux = highbyte(*pc++); + case PUSHCONSTANT: aux += *pc++; *S->top++ = consts[aux]; break; - case PUSHUPVALUE: - aux = *pc++; goto pushupvalue; - - case PUSHUPVALUE0: case PUSHUPVALUE1: - aux -= PUSHUPVALUE0; - pushupvalue: + case PUSHUPVALUE: aux = *pc++; *S->top++ = cl->consts[aux+1]; break; - case SETLOCAL: - aux = *pc++; goto setlocal; - - case SETLOCAL0: case SETLOCAL1: case SETLOCAL2: case SETLOCAL3: - case SETLOCAL4: case SETLOCAL5: case SETLOCAL6: case SETLOCAL7: - aux -= SETLOCAL0; - setlocal: + case SETLOCAL: aux = *pc++; *((S->stack+base) + aux) = *(--S->top); break; - case SETGLOBALW: - aux = next_word(pc); goto setglobal; - - case SETGLOBAL: - aux = *pc++; goto setglobal; - - case SETGLOBAL0: case SETGLOBAL1: case SETGLOBAL2: case SETGLOBAL3: - case SETGLOBAL4: case SETGLOBAL5: case SETGLOBAL6: case SETGLOBAL7: - aux -= SETGLOBAL0; - setglobal: + case SETGLOBALW: aux = highbyte(*pc++); + case SETGLOBAL: aux += *pc++; luaV_setglobal(tsvalue(&consts[aux])); break; @@ -470,28 +397,17 @@ StkId luaV_execute (Closure *cl, TProtoFunc *tf, StkId base) luaV_settable(S->top-3-(*pc++), 1); break; - case SETLISTW: - aux = next_word(pc); aux *= LFIELDS_PER_FLUSH; goto setlist; - - case SETLIST: - aux = *(pc++) * LFIELDS_PER_FLUSH; goto setlist; - - case SETLIST0: - aux = 0; - setlist: { + case SETLISTW: aux = highbyte(*pc++); + case SETLIST: aux += *pc++; { int n = *(pc++); TObject *arr = S->top-n-1; + aux *= LFIELDS_PER_FLUSH; for (; n; n--) luaH_setint(avalue(arr), n+aux, --S->top); break; } - case SETMAP0: - aux = 0; goto setmap; - - case SETMAP: - aux = *pc++; - setmap: { + case SETMAP: aux = *pc++; { TObject *arr = S->top-(2*aux)-3; do { luaH_set(avalue(arr), S->top-2, S->top-1); @@ -500,34 +416,23 @@ StkId luaV_execute (Closure *cl, TProtoFunc *tf, StkId base) break; } - case POP: - aux = *pc++; goto pop; - - case POP0: case POP1: - aux -= POP0; - pop: + case POP: aux = *pc++; S->top -= (aux+1); break; - case CREATEARRAYW: - aux = next_word(pc); goto createarray; - - case CREATEARRAY0: case CREATEARRAY1: - aux -= CREATEARRAY0; goto createarray; - - case CREATEARRAY: - aux = *pc++; - createarray: + case CREATEARRAYW: aux = highbyte(*pc++); + case CREATEARRAY: aux += *pc++; luaC_checkGC(); avalue(S->top) = luaH_new(aux); ttype(S->top) = LUA_T_ARRAY; S->top++; break; - case EQOP: case NEQOP: { + case NEQOP: aux = 1; + case EQOP: { int res = luaO_equalObj(S->top-2, S->top-1); + if (aux) res = !res; S->top--; - if (aux == NEQOP) res = !res; ttype(S->top-1) = res ? LUA_T_NUMBER : LUA_T_NIL; nvalue(S->top-1) = 1; break; @@ -630,98 +535,60 @@ StkId luaV_execute (Closure *cl, TProtoFunc *tf, StkId base) nvalue(S->top-1) = 1; break; - case ONTJMPW: - aux = next_word(pc); goto ontjmp; - - case ONTJMP: - aux = *pc++; - ontjmp: + case ONTJMPW: aux = highbyte(*pc++); + case ONTJMP: aux += *pc++; if (ttype(S->top-1) != LUA_T_NIL) pc += aux; else S->top--; break; - case ONFJMPW: - aux = next_word(pc); goto onfjmp; - - case ONFJMP: - aux = *pc++; - onfjmp: + case ONFJMPW: aux = highbyte(*pc++); + case ONFJMP: aux += *pc++; if (ttype(S->top-1) == LUA_T_NIL) pc += aux; else S->top--; break; - case JMPW: - aux = next_word(pc); goto jmp; - - case JMP: - aux = *pc++; - jmp: + case JMPW: aux = highbyte(*pc++); + case JMP: aux += *pc++; pc += aux; break; - case IFFJMPW: - aux = next_word(pc); goto iffjmp; - - case IFFJMP: - aux = *pc++; - iffjmp: + case IFFJMPW: aux = highbyte(*pc++); + case IFFJMP: aux += *pc++; if (ttype(--S->top) == LUA_T_NIL) pc += aux; break; - case IFTUPJMPW: - aux = next_word(pc); goto iftupjmp; - - case IFTUPJMP: - aux = *pc++; - iftupjmp: + case IFTUPJMPW: aux = highbyte(*pc++); + case IFTUPJMP: aux += *pc++; if (ttype(--S->top) != LUA_T_NIL) pc -= aux; break; - case IFFUPJMPW: - aux = next_word(pc); goto iffupjmp; - - case IFFUPJMP: - aux = *pc++; - iffupjmp: + case IFFUPJMPW: aux = highbyte(*pc++); + case IFFUPJMP: aux += *pc++; if (ttype(--S->top) == LUA_T_NIL) pc -= aux; break; - case CLOSUREW: - aux = next_word(pc); goto closure; - - case CLOSURE: - aux = *pc++; - closure: + case CLOSURE: aux = *pc++; *S->top++ = consts[aux]; luaV_closure(*pc++); luaC_checkGC(); break; - case CALLFUNC: - aux = *pc++; goto callfunc; - - case CALLFUNC0: case CALLFUNC1: - aux -= CALLFUNC0; - callfunc: { + case CALLFUNC: aux = *pc++; { StkId newBase = (S->top-S->stack)-(*pc++); luaD_call(newBase, aux); break; } - case ENDCODE: + case ENDCODE: aux = 1; S->top = S->stack + base; /* goes through */ case RETCODE: if (lua_callhook) luaD_callHook(base, NULL, 1); - return (base + ((aux==RETCODE) ? *pc : 0)); + return base + (aux ? 0 : *pc); - case SETLINEW: - aux = next_word(pc); goto setline; - - case SETLINE: - aux = *pc++; - setline: + case SETLINEW: aux = highbyte(*pc++); + case SETLINE: aux += *pc++; if ((S->stack+base-1)->ttype != LUA_T_LINE) { /* open space for LINE value */ luaD_openstack((S->top-S->stack)-base);