From f0dffaa209d80b9852e873830243245c1facdd05 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 12 Jan 1998 11:35:37 -0200 Subject: new way to hanlde arg information --- lopcodes.h | 13 ++++--------- lua.stx | 15 ++++++++++----- lvm.c | 22 +++++++--------------- 3 files changed, 21 insertions(+), 29 deletions(-) diff --git a/lopcodes.h b/lopcodes.h index 3f25e828..ee0f9354 100644 --- a/lopcodes.h +++ b/lopcodes.h @@ -1,5 +1,5 @@ /* -** $Id: lopcodes.h,v 1.13 1997/12/29 17:35:46 roberto Exp roberto $ +** $Id: lopcodes.h,v 1.14 1997/12/30 19:08:23 roberto Exp roberto $ ** Opcodes for Lua virtual machine ** See Copyright Notice in lua.h */ @@ -169,19 +169,14 @@ SETLINEW,/* w - - LINE=w */ POP,/* b - - TOP-=(b+1) */ POP0,/* - - - TOP-=1 */ -POP1,/* - - - TOP-=2 */ - -ARGS,/* b - - TOP=BASE+b */ -ARGS0,/* - - - TOP=BASE+0 */ -ARGS1,/* - - - TOP=BASE+1 */ -ARGS2,/* - - - TOP=BASE+2 */ -ARGS3,/* - - - TOP=BASE+3 */ -VARARGS/* b v_x...v_1 {v_1...v_x;n=x} TOP=BASE+b+1 */ +POP1/* - - - TOP-=2 */ + } OpCode; #define RFIELDS_PER_FLUSH 32 /* records (SETMAP) */ #define LFIELDS_PER_FLUSH 64 /* lists (SETLIST) */ +#define ZEROVARARG 64 #endif diff --git a/lua.stx b/lua.stx index b10ea3bb..0208a638 100644 --- a/lua.stx +++ b/lua.stx @@ -1,6 +1,6 @@ %{ /* -** $Id: lua.stx,v 1.31 1997/12/30 19:08:23 roberto Exp roberto $ +** $Id: lua.stx,v 1.32 1998/01/12 13:00:51 roberto Exp roberto $ ** Syntax analizer and code generator ** See Copyright Notice in lua.h */ @@ -448,11 +448,15 @@ static void adjust_mult_assign (int vars, long exps) static void code_args (int nparams, int dots) { - L->currState->nlocalvar += nparams; - if (!dots) - code_oparg(ARGS, 4, L->currState->nlocalvar, L->currState->nlocalvar); + L->currState->nlocalvar += nparams; /* "self" may already be there */ + nparams = L->currState->nlocalvar; + if (!dots) { + L->currState->f->code[1] = nparams; /* fill-in arg information */ + deltastack(nparams); + } else { - code_oparg(VARARGS, 0, L->currState->nlocalvar, L->currState->nlocalvar+1); + L->currState->f->code[1] = nparams+ZEROVARARG; + deltastack(nparams+1); add_localvar(luaS_new("arg")); } } @@ -577,6 +581,7 @@ static void init_state (TaggedString *filename) else fs->maxvars = -1; /* flag no debug information */ code_byte(0); /* to be filled with stacksize */ + code_byte(0); /* to be filled with arg information */ L->lexstate->lastline = 0; /* invalidate it */ } diff --git a/lvm.c b/lvm.c index 0fcaff2c..3140b4e4 100644 --- a/lvm.c +++ b/lvm.c @@ -1,5 +1,5 @@ /* -** $Id: lvm.c,v 1.20 1997/12/29 17:35:46 roberto Exp roberto $ +** $Id: lvm.c,v 1.21 1997/12/30 19:08:23 roberto Exp roberto $ ** Lua virtual machine ** See Copyright Notice in lua.h */ @@ -289,6 +289,12 @@ StkId luaV_execute (Closure *cl, TProtoFunc *tf, StkId base) if (lua_callhook) luaD_callHook(base, tf, 0); luaD_checkstack((*pc++)+EXTRA_STACK); + if (*pc < ZEROVARARG) + luaD_adjusttop(base+*(pc++)); + else { /* varargs */ + luaC_checkGC(); + adjust_varargs(base+(*pc++)-ZEROVARARG); + } while (1) { int aux; switch ((OpCode)(aux = *pc++)) { @@ -473,20 +479,6 @@ StkId luaV_execute (Closure *cl, TProtoFunc *tf, StkId base) S->top -= (aux+1); break; - case ARGS: - aux = *pc++; goto args; - - case ARGS0: case ARGS1: case ARGS2: case ARGS3: - aux -= ARGS0; - args: - luaD_adjusttop(base+aux); - break; - - case VARARGS: - luaC_checkGC(); - adjust_varargs(base+(*pc++)); - break; - case CREATEARRAYW: aux = next_word(pc); goto createarray; -- cgit v1.2.3-55-g6feb