reducing even more use of C stack by the parser: struct 'FuncState'
does not need field 'L' + number of labels/gotos in a chunk may be limited to SHRT_MAX. (Also removed some non-needed 'unsigned's.)
This commit is contained in:
22
lparser.c
22
lparser.c
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lparser.c,v 2.113 2011/07/02 15:58:14 roberto Exp roberto $
|
** $Id: lparser.c,v 2.114 2011/07/15 12:50:29 roberto Exp roberto $
|
||||||
** Lua Parser
|
** Lua Parser
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@@ -41,8 +41,8 @@
|
|||||||
*/
|
*/
|
||||||
typedef struct BlockCnt {
|
typedef struct BlockCnt {
|
||||||
struct BlockCnt *previous; /* chain */
|
struct BlockCnt *previous; /* chain */
|
||||||
int firstlabel; /* index of first label in this block */
|
short firstlabel; /* index of first label in this block */
|
||||||
int firstgoto; /* index of first pending goto in this block */
|
short firstgoto; /* index of first pending goto in this block */
|
||||||
lu_byte nactvar; /* # active locals outside the block */
|
lu_byte nactvar; /* # active locals outside the block */
|
||||||
lu_byte upval; /* true if some variable in the block is an upvalue */
|
lu_byte upval; /* true if some variable in the block is an upvalue */
|
||||||
lu_byte isloop; /* true if `block' is a loop */
|
lu_byte isloop; /* true if `block' is a loop */
|
||||||
@@ -81,12 +81,13 @@ static void error_expected (LexState *ls, int token) {
|
|||||||
|
|
||||||
|
|
||||||
static void errorlimit (FuncState *fs, int limit, const char *what) {
|
static void errorlimit (FuncState *fs, int limit, const char *what) {
|
||||||
|
lua_State *L = fs->ls->L;
|
||||||
const char *msg;
|
const char *msg;
|
||||||
int line = fs->f->linedefined;
|
int line = fs->f->linedefined;
|
||||||
const char *where = (line == 0)
|
const char *where = (line == 0)
|
||||||
? "main function"
|
? "main function"
|
||||||
: luaO_pushfstring(fs->L, "function at line %d", line);
|
: luaO_pushfstring(L, "function at line %d", line);
|
||||||
msg = luaO_pushfstring(fs->L, "too many %s (limit is %d) in %s",
|
msg = luaO_pushfstring(L, "too many %s (limit is %d) in %s",
|
||||||
what, limit, where);
|
what, limit, where);
|
||||||
luaX_syntaxerror(fs->ls, msg);
|
luaX_syntaxerror(fs->ls, msg);
|
||||||
}
|
}
|
||||||
@@ -182,7 +183,7 @@ static void new_localvar (LexState *ls, TString *name) {
|
|||||||
MAXVARS, "local variables");
|
MAXVARS, "local variables");
|
||||||
luaM_growvector(ls->L, dyd->actvar.arr, dyd->actvar.n + 1,
|
luaM_growvector(ls->L, dyd->actvar.arr, dyd->actvar.n + 1,
|
||||||
dyd->actvar.size, Vardesc, MAX_INT, "local variables");
|
dyd->actvar.size, Vardesc, MAX_INT, "local variables");
|
||||||
dyd->actvar.arr[dyd->actvar.n++].idx = cast(unsigned short, reg);
|
dyd->actvar.arr[dyd->actvar.n++].idx = cast(short, reg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -231,13 +232,13 @@ static int newupvalue (FuncState *fs, TString *name, expdesc *v) {
|
|||||||
Proto *f = fs->f;
|
Proto *f = fs->f;
|
||||||
int oldsize = f->sizeupvalues;
|
int oldsize = f->sizeupvalues;
|
||||||
checklimit(fs, fs->nups + 1, MAXUPVAL, "upvalues");
|
checklimit(fs, fs->nups + 1, MAXUPVAL, "upvalues");
|
||||||
luaM_growvector(fs->L, f->upvalues, fs->nups, f->sizeupvalues,
|
luaM_growvector(fs->ls->L, f->upvalues, fs->nups, f->sizeupvalues,
|
||||||
Upvaldesc, MAXUPVAL, "upvalues");
|
Upvaldesc, MAXUPVAL, "upvalues");
|
||||||
while (oldsize < f->sizeupvalues) f->upvalues[oldsize++].name = NULL;
|
while (oldsize < f->sizeupvalues) f->upvalues[oldsize++].name = NULL;
|
||||||
f->upvalues[fs->nups].instack = (v->k == VLOCAL);
|
f->upvalues[fs->nups].instack = (v->k == VLOCAL);
|
||||||
f->upvalues[fs->nups].idx = cast_byte(v->u.info);
|
f->upvalues[fs->nups].idx = cast_byte(v->u.info);
|
||||||
f->upvalues[fs->nups].name = name;
|
f->upvalues[fs->nups].name = name;
|
||||||
luaC_objbarrier(fs->L, f, name);
|
luaC_objbarrier(fs->ls->L, f, name);
|
||||||
return fs->nups++;
|
return fs->nups++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -382,7 +383,7 @@ static int findlabel (LexState *ls, int g) {
|
|||||||
static int newlabelentry (LexState *ls, Labellist *l, TString *name,
|
static int newlabelentry (LexState *ls, Labellist *l, TString *name,
|
||||||
int line, int pc) {
|
int line, int pc) {
|
||||||
int n = l->n;
|
int n = l->n;
|
||||||
luaM_growvector(ls->L, l->arr, n, l->size, Labeldesc, MAX_INT, "labels");
|
luaM_growvector(ls->L, l->arr, n, l->size, Labeldesc, SHRT_MAX, "labels");
|
||||||
l->arr[n].name = name;
|
l->arr[n].name = name;
|
||||||
l->arr[n].line = line;
|
l->arr[n].line = line;
|
||||||
l->arr[n].nactvar = ls->fs->nactvar;
|
l->arr[n].nactvar = ls->fs->nactvar;
|
||||||
@@ -514,7 +515,6 @@ static void open_func (LexState *ls, FuncState *fs, BlockCnt *bl) {
|
|||||||
Proto *f;
|
Proto *f;
|
||||||
fs->prev = ls->fs; /* linked list of funcstates */
|
fs->prev = ls->fs; /* linked list of funcstates */
|
||||||
fs->ls = ls;
|
fs->ls = ls;
|
||||||
fs->L = L;
|
|
||||||
ls->fs = fs;
|
ls->fs = fs;
|
||||||
fs->pc = 0;
|
fs->pc = 0;
|
||||||
fs->lasttarget = 0;
|
fs->lasttarget = 0;
|
||||||
@@ -1039,7 +1039,7 @@ static const struct {
|
|||||||
** subexpr -> (simpleexp | unop subexpr) { binop subexpr }
|
** subexpr -> (simpleexp | unop subexpr) { binop subexpr }
|
||||||
** where `binop' is any binary operator with a priority higher than `limit'
|
** where `binop' is any binary operator with a priority higher than `limit'
|
||||||
*/
|
*/
|
||||||
static BinOpr subexpr (LexState *ls, expdesc *v, unsigned int limit) {
|
static BinOpr subexpr (LexState *ls, expdesc *v, int limit) {
|
||||||
BinOpr op;
|
BinOpr op;
|
||||||
UnOpr uop;
|
UnOpr uop;
|
||||||
enterlevel(ls);
|
enterlevel(ls);
|
||||||
|
|||||||
13
lparser.h
13
lparser.h
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lparser.h,v 1.67 2011/02/07 17:14:50 roberto Exp roberto $
|
** $Id: lparser.h,v 1.68 2011/02/23 13:13:10 roberto Exp roberto $
|
||||||
** Lua Parser
|
** Lua Parser
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@@ -55,7 +55,7 @@ typedef struct expdesc {
|
|||||||
|
|
||||||
/* description of active local variable */
|
/* description of active local variable */
|
||||||
typedef struct Vardesc {
|
typedef struct Vardesc {
|
||||||
unsigned short idx; /* variable index in stack */
|
short idx; /* variable index in stack */
|
||||||
} Vardesc;
|
} Vardesc;
|
||||||
|
|
||||||
|
|
||||||
@@ -98,18 +98,17 @@ typedef struct FuncState {
|
|||||||
Table *h; /* table to find (and reuse) elements in `k' */
|
Table *h; /* table to find (and reuse) elements in `k' */
|
||||||
struct FuncState *prev; /* enclosing function */
|
struct FuncState *prev; /* enclosing function */
|
||||||
struct LexState *ls; /* lexical state */
|
struct LexState *ls; /* lexical state */
|
||||||
struct lua_State *L; /* copy of the Lua state */
|
|
||||||
struct BlockCnt *bl; /* chain of current blocks */
|
struct BlockCnt *bl; /* chain of current blocks */
|
||||||
int pc; /* next position to code (equivalent to `ncode') */
|
int pc; /* next position to code (equivalent to `ncode') */
|
||||||
int lasttarget; /* `pc' of last `jump target' */
|
int lasttarget; /* 'label' of last 'jump label' */
|
||||||
int jpc; /* list of pending jumps to `pc' */
|
int jpc; /* list of pending jumps to `pc' */
|
||||||
int freereg; /* first free register */
|
|
||||||
int nk; /* number of elements in `k' */
|
int nk; /* number of elements in `k' */
|
||||||
int np; /* number of elements in `p' */
|
int np; /* number of elements in `p' */
|
||||||
int firstlocal; /* index of first local var of this function */
|
int firstlocal; /* index of first local var (in Dyndata array) */
|
||||||
short nlocvars; /* number of elements in `locvars' */
|
short nlocvars; /* number of elements in 'f->locvars' */
|
||||||
lu_byte nactvar; /* number of active local variables */
|
lu_byte nactvar; /* number of active local variables */
|
||||||
lu_byte nups; /* number of upvalues */
|
lu_byte nups; /* number of upvalues */
|
||||||
|
lu_byte freereg; /* first free register */
|
||||||
} FuncState;
|
} FuncState;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user