|
@ -1,6 +1,6 @@ |
|
|
%{ |
|
|
%{ |
|
|
/* |
|
|
/* |
|
|
** $Id: lua.stx,v 1.9 1997/10/13 22:12:04 roberto Exp roberto $ |
|
|
** $Id: lua.stx,v 1.10 1997/10/15 20:16:00 roberto Exp roberto $ |
|
|
** Syntax analizer and code generator |
|
|
** Syntax analizer and code generator |
|
|
** See Copyright Notice in lua.h |
|
|
** See Copyright Notice in lua.h |
|
|
*/ |
|
|
*/ |
|
@ -57,6 +57,7 @@ typedef struct State { |
|
|
int stacksize; /* number of values on activation register */ |
|
|
int stacksize; /* number of values on activation register */ |
|
|
int maxstacksize; /* maximum number of values on activation register */ |
|
|
int maxstacksize; /* maximum number of values on activation register */ |
|
|
int nlocalvar; /* number of active local variables */ |
|
|
int nlocalvar; /* number of active local variables */ |
|
|
|
|
|
int nupvalues; /* number of upvalues */ |
|
|
int nvars; /* number of entries in f->locvars */ |
|
|
int nvars; /* number of entries in f->locvars */ |
|
|
int maxcode; /* size of f->code */ |
|
|
int maxcode; /* size of f->code */ |
|
|
int maxvars; /* size of f->locvars (-1 if no debug information) */ |
|
|
int maxvars; /* size of f->locvars (-1 if no debug information) */ |
|
@ -347,14 +348,14 @@ static int indexupvalue (TaggedString *n) |
|
|
{ |
|
|
{ |
|
|
vardesc v = singlevar(n, currState-1); |
|
|
vardesc v = singlevar(n, currState-1); |
|
|
int i; |
|
|
int i; |
|
|
for (i=0; i<currState->f->nupvalues; i++) { |
|
|
for (i=0; i<currState->nupvalues; i++) { |
|
|
if (currState->upvalues[i] == v) |
|
|
if (currState->upvalues[i] == v) |
|
|
return i; |
|
|
return i; |
|
|
} |
|
|
} |
|
|
/* new one */ |
|
|
/* new one */ |
|
|
if (++currState->f->nupvalues > MAXUPVALUES) |
|
|
if (++currState->nupvalues > MAXUPVALUES) |
|
|
luaY_error("too many upvalues in a single function"); |
|
|
luaY_error("too many upvalues in a single function"); |
|
|
currState->upvalues[i] = v; /* i = currState->f->nupvalues - 1 */ |
|
|
currState->upvalues[i] = v; /* i = currState->nupvalues - 1 */ |
|
|
return i; |
|
|
return i; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -515,13 +516,14 @@ static void codereturn (void) |
|
|
static void func_onstack (TProtoFunc *f) |
|
|
static void func_onstack (TProtoFunc *f) |
|
|
{ |
|
|
{ |
|
|
int i; |
|
|
int i; |
|
|
int nupvalues = (currState+1)->f->nupvalues; |
|
|
int nupvalues = (currState+1)->nupvalues; |
|
|
int c = next_constant(currState); |
|
|
int c = next_constant(currState); |
|
|
ttype(&currState->f->consts[c]) = LUA_T_PROTO; |
|
|
ttype(&currState->f->consts[c]) = LUA_T_PROTO; |
|
|
currState->f->consts[c].value.tf = (currState+1)->f; |
|
|
currState->f->consts[c].value.tf = (currState+1)->f; |
|
|
|
|
|
code_constant(c); |
|
|
for (i=0; i<nupvalues; i++) |
|
|
for (i=0; i<nupvalues; i++) |
|
|
lua_pushvar((currState+1)->upvalues[i]); |
|
|
lua_pushvar((currState+1)->upvalues[i]); |
|
|
code_oparg(CLOSURE, 0, c, 1-nupvalues); |
|
|
code_oparg(CLOSURE, 2, nupvalues, -nupvalues); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -531,6 +533,7 @@ static void init_state (TaggedString *filename) |
|
|
currState->stacksize = 0; |
|
|
currState->stacksize = 0; |
|
|
currState->maxstacksize = 0; |
|
|
currState->maxstacksize = 0; |
|
|
currState->nlocalvar = 0; |
|
|
currState->nlocalvar = 0; |
|
|
|
|
|
currState->nupvalues = 0; |
|
|
currState->f = f; |
|
|
currState->f = f; |
|
|
f->fileName = filename; |
|
|
f->fileName = filename; |
|
|
currState->pc = 0; |
|
|
currState->pc = 0; |
|
|