more changes to reduce stack usage by the parser

This commit is contained in:
Roberto Ierusalimschy 2003-07-09 17:11:30 -03:00
parent 00180bb133
commit 265530478b
2 changed files with 11 additions and 9 deletions

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lparser.c,v 1.211 2003/05/14 21:02:39 roberto Exp roberto $ ** $Id: lparser.c,v 1.212 2003/07/09 15:36:38 roberto Exp roberto $
** Lua Parser ** Lua Parser
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -139,7 +139,7 @@ static int luaI_registerlocalvar (LexState *ls, TString *varname) {
FuncState *fs = ls->fs; FuncState *fs = ls->fs;
Proto *f = fs->f; Proto *f = fs->f;
luaM_growvector(ls->L, f->locvars, fs->nlocvars, f->sizelocvars, luaM_growvector(ls->L, f->locvars, fs->nlocvars, f->sizelocvars,
LocVar, MAX_INT, ""); LocVar, USHRT_MAX, "too many local variables");
f->locvars[fs->nlocvars].varname = varname; f->locvars[fs->nlocvars].varname = varname;
return fs->nlocvars++; return fs->nlocvars++;
} }
@ -148,7 +148,8 @@ static int luaI_registerlocalvar (LexState *ls, TString *varname) {
static void new_localvar (LexState *ls, TString *name, int n) { static void new_localvar (LexState *ls, TString *name, int n) {
FuncState *fs = ls->fs; FuncState *fs = ls->fs;
luaX_checklimit(ls, fs->nactvar+n+1, MAXVARS, "local variables"); luaX_checklimit(ls, fs->nactvar+n+1, MAXVARS, "local variables");
fs->actvar[fs->nactvar+n] = luaI_registerlocalvar(ls, name); fs->actvar[fs->nactvar+n] = cast(unsigned short,
luaI_registerlocalvar(ls, name));
} }
@ -187,8 +188,9 @@ static int indexupvalue (FuncState *fs, TString *name, expdesc *v) {
luaM_growvector(fs->L, fs->f->upvalues, f->nups, fs->f->sizeupvalues, luaM_growvector(fs->L, fs->f->upvalues, f->nups, fs->f->sizeupvalues,
TString *, MAX_INT, ""); TString *, MAX_INT, "");
fs->f->upvalues[f->nups] = name; fs->f->upvalues[f->nups] = name;
fs->upvalues[f->nups].k = v->k; lua_assert(v->k == VLOCAL || v->k == VUPVAL);
fs->upvalues[f->nups].info = v->info; fs->upvalues[f->nups].k = cast(lu_byte, v->k);
fs->upvalues[f->nups].info = cast(lu_byte, v->info);
return f->nups++; return f->nups++;
} }

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lparser.h,v 1.47 2003/02/11 10:46:24 roberto Exp roberto $ ** $Id: lparser.h,v 1.48 2003/07/09 15:36:38 roberto Exp roberto $
** Lua Parser ** Lua Parser
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -42,8 +42,8 @@ typedef struct expdesc {
typedef struct upvaldesc { typedef struct upvaldesc {
expkind k; lu_byte k;
int info; lu_byte info;
} upvaldesc; } upvaldesc;
@ -67,7 +67,7 @@ typedef struct FuncState {
int nlocvars; /* number of elements in `locvars' */ int nlocvars; /* number of elements in `locvars' */
lu_byte nactvar; /* number of active local variables */ lu_byte nactvar; /* number of active local variables */
upvaldesc upvalues[MAXUPVALUES]; /* upvalues */ upvaldesc upvalues[MAXUPVALUES]; /* upvalues */
int actvar[MAXVARS]; /* declared-variable stack */ unsigned short actvar[MAXVARS]; /* declared-variable stack */
} FuncState; } FuncState;