From ad6c7b0dd4b31965ccf6f1c02448f4c306cc316b Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 9 Feb 1999 13:59:10 -0200 Subject: small corrections in opcodes. --- lopcodes.h | 18 ++++++++++-------- lparser.c | 13 ++++++++----- lvm.c | 16 ++++++++++++---- 3 files changed, 30 insertions(+), 17 deletions(-) diff --git a/lopcodes.h b/lopcodes.h index 9a2ef6a5..faae8597 100644 --- a/lopcodes.h +++ b/lopcodes.h @@ -1,5 +1,5 @@ /* -** $Id: lopcodes.h,v 1.22 1999/02/08 17:07:59 roberto Exp roberto $ +** $Id: lopcodes.h,v 1.23 1999/02/08 18:54:19 roberto Exp roberto $ ** Opcodes for Lua virtual machine ** See Copyright Notice in lua.h */ @@ -21,11 +21,14 @@ ENDCODE,/* - - - */ RETCODE,/* b - - */ PUSHNIL,/* b - nil_0...nil_b */ -POP,/* b - - TOP-=(b+1) */ -POPDUP,/* b v v TOP-=(b+1) */ +POP,/* b - - TOP-=b */ +POPDUP,/* b v v TOP-=b */ -PUSHNUMBERW,/* w - (float)(w-NUMOFFSET) */ -PUSHNUMBER,/* b - (float)(b-NUMOFFSET) */ +PUSHNUMBERW,/* w - (float)w */ +PUSHNUMBER,/* b - (float)b */ + +PUSHNEGW,/* w - (float)-w */ +PUSHNEG,/* b - (float)-b */ PUSHCONSTANTW,/*w - CNST[w] */ PUSHCONSTANT,/* b - CNST[b] */ @@ -57,7 +60,7 @@ SETGLOBALDUPW,/*w x x VAR[CNST[w]]=x */ SETGLOBALDUP,/* b x x VAR[CNST[b]]=x */ SETTABLEPOP,/* - v i t - t[i]=v */ -SETTABPPDUP,/* - v i t v t[i]=v */ +SETTABLEPOPDUP,/* - v i t v t[i]=v */ SETTABLE,/* b v a_b...a_1 i t a_b...a_1 i t t[i]=v */ SETTABLEDUP,/* b v a_b...a_1 i t v a_b...a_1 i t t[i]=v */ @@ -95,6 +98,7 @@ IFTUPJMP,/* b x - (x!=nil)? PC-=b */ IFFUPJMPW,/* w x - (x==nil)? PC-=w */ IFFUPJMP,/* b x - (x==nil)? PC-=b */ +CLOSUREW,/* w c v_c...v_1 closure(CNST[w], v_c...v_1) */ CLOSURE,/* b c v_c...v_1 closure(CNST[b], v_c...v_1) */ CALLFUNC,/* b c v_c...v_1 f r_b...r_1 f(v1,...,v_c) */ @@ -107,8 +111,6 @@ LONGARG /* b (add b*(1<<16) to arg of next instruction) */ } OpCode; -#define NUMOFFSET 100 /* offset for immediate numbers */ - #define RFIELDS_PER_FLUSH 32 /* records (SETMAP) */ #define LFIELDS_PER_FLUSH 64 /* FPF - lists (SETLIST) */ diff --git a/lparser.c b/lparser.c index be44c693..c41f8b49 100644 --- a/lparser.c +++ b/lparser.c @@ -1,5 +1,5 @@ /* -** $Id: lparser.c,v 1.17 1999/02/08 17:07:59 roberto Exp roberto $ +** $Id: lparser.c,v 1.18 1999/02/08 18:54:19 roberto Exp roberto $ ** LL(1) Parser and code generator for Lua ** See Copyright Notice in lua.h */ @@ -267,9 +267,11 @@ static int real_constant (FuncState *fs, real r) { static void code_number (LexState *ls, real f) { - if (-NUMOFFSET <= f && f <= (real)(MAX_WORD-NUMOFFSET) && - (int)f == f) /* f+NUMOFFSET has a short integer value? */ - code_oparg(ls, PUSHNUMBER, (int)f+NUMOFFSET, 1); + real af = (f<0) ? -f : f; + if (0 <= af && af <= (real)MAX_WORD && (int)af == af) { + /* abs(f) has a short integer value */ + code_oparg(ls, (f<0) ? PUSHNEG : PUSHNUMBER, (int)af, 1); + } else code_constant(ls, real_constant(ls->fs, f)); } @@ -474,7 +476,7 @@ static void lua_pushvar (LexState *ls, vardesc *var) { /* to be used by "storevar" and assignment */ static OpCode set_pop[] = {SETLOCAL, SETGLOBAL, SETTABLEPOP, SETTABLE}; -static OpCode set_dup[] = {SETLOCALDUP, SETGLOBALDUP, SETTABPPDUP, +static OpCode set_dup[] = {SETLOCALDUP, SETGLOBALDUP, SETTABLEPOPDUP, SETTABLEDUP}; @@ -563,6 +565,7 @@ static void init_state (LexState *ls, FuncState *fs, TaggedString *filename) { incr_top; } + static void close_func (LexState *ls) { FuncState *fs = ls->fs; TProtoFunc *f = fs->f; diff --git a/lvm.c b/lvm.c index f321cb83..1cc025df 100644 --- a/lvm.c +++ b/lvm.c @@ -1,5 +1,5 @@ /* -** $Id: lvm.c,v 1.46 1999/02/08 17:07:59 roberto Exp roberto $ +** $Id: lvm.c,v 1.47 1999/02/08 18:54:19 roberto Exp roberto $ ** Lua virtual machine ** See Copyright Notice in lua.h */ @@ -355,7 +355,14 @@ StkId luaV_execute (Closure *cl, TProtoFunc *tf, StkId base) { case PUSHNUMBERW: aux += highbyte(*pc++); case PUSHNUMBER: aux += *pc++; ttype(S->top) = LUA_T_NUMBER; - nvalue(S->top) = aux-NUMOFFSET; + nvalue(S->top) = aux; + S->top++; + break; + + case PUSHNEGW: aux += highbyte(*pc++); + case PUSHNEG: aux += *pc++; + ttype(S->top) = LUA_T_NUMBER; + nvalue(S->top) = -aux; S->top++; break; @@ -429,7 +436,7 @@ StkId luaV_execute (Closure *cl, TProtoFunc *tf, StkId base) { S->top -= 2; /* pop table and index */ break; - case SETTABPPDUP: { + case SETTABLEPOPDUP: { TObject temp = *(S->top-1); luaV_settable(S->top-3); S->top--; /* pop index (temp goes into "table" position) */ @@ -605,7 +612,8 @@ StkId luaV_execute (Closure *cl, TProtoFunc *tf, StkId base) { if (ttype(--S->top) == LUA_T_NIL) pc -= aux; break; - case CLOSURE: aux = *pc++; + case CLOSUREW: aux += highbyte(*pc++); + case CLOSURE: aux += *pc++; *S->top++ = consts[aux]; luaV_closure(*pc++); luaC_checkGC(); -- cgit v1.2.3-55-g6feb