diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2011-07-27 15:09:01 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2011-07-27 15:09:01 -0300 |
commit | 59bcd137ae09456d9315b5c9b0cce520230423a7 (patch) | |
tree | 8b9a1a1650016cab52c93a6932428d564b51002a /lparser.c | |
parent | 5ab6d36d99a30cadeff18a9467ac88c114973554 (diff) | |
download | lua-59bcd137ae09456d9315b5c9b0cce520230423a7.tar.gz lua-59bcd137ae09456d9315b5c9b0cce520230423a7.tar.bz2 lua-59bcd137ae09456d9315b5c9b0cce520230423a7.zip |
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.)
Diffstat (limited to 'lparser.c')
-rw-r--r-- | lparser.c | 24 |
1 files changed, 12 insertions, 12 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lparser.c,v 2.113 2011/07/02 15:58:14 roberto Exp roberto $ | 2 | ** $Id: lparser.c,v 2.114 2011/07/15 12:50:29 roberto Exp roberto $ |
3 | ** Lua Parser | 3 | ** Lua Parser |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -41,8 +41,8 @@ | |||
41 | */ | 41 | */ |
42 | typedef struct BlockCnt { | 42 | typedef struct BlockCnt { |
43 | struct BlockCnt *previous; /* chain */ | 43 | struct BlockCnt *previous; /* chain */ |
44 | int firstlabel; /* index of first label in this block */ | 44 | short firstlabel; /* index of first label in this block */ |
45 | int firstgoto; /* index of first pending goto in this block */ | 45 | short firstgoto; /* index of first pending goto in this block */ |
46 | lu_byte nactvar; /* # active locals outside the block */ | 46 | lu_byte nactvar; /* # active locals outside the block */ |
47 | lu_byte upval; /* true if some variable in the block is an upvalue */ | 47 | lu_byte upval; /* true if some variable in the block is an upvalue */ |
48 | lu_byte isloop; /* true if `block' is a loop */ | 48 | lu_byte isloop; /* true if `block' is a loop */ |
@@ -81,13 +81,14 @@ static void error_expected (LexState *ls, int token) { | |||
81 | 81 | ||
82 | 82 | ||
83 | static void errorlimit (FuncState *fs, int limit, const char *what) { | 83 | static void errorlimit (FuncState *fs, int limit, const char *what) { |
84 | lua_State *L = fs->ls->L; | ||
84 | const char *msg; | 85 | const char *msg; |
85 | int line = fs->f->linedefined; | 86 | int line = fs->f->linedefined; |
86 | const char *where = (line == 0) | 87 | const char *where = (line == 0) |
87 | ? "main function" | 88 | ? "main function" |
88 | : luaO_pushfstring(fs->L, "function at line %d", line); | 89 | : luaO_pushfstring(L, "function at line %d", line); |
89 | msg = luaO_pushfstring(fs->L, "too many %s (limit is %d) in %s", | 90 | msg = luaO_pushfstring(L, "too many %s (limit is %d) in %s", |
90 | what, limit, where); | 91 | what, limit, where); |
91 | luaX_syntaxerror(fs->ls, msg); | 92 | luaX_syntaxerror(fs->ls, msg); |
92 | } | 93 | } |
93 | 94 | ||
@@ -182,7 +183,7 @@ static void new_localvar (LexState *ls, TString *name) { | |||
182 | MAXVARS, "local variables"); | 183 | MAXVARS, "local variables"); |
183 | luaM_growvector(ls->L, dyd->actvar.arr, dyd->actvar.n + 1, | 184 | luaM_growvector(ls->L, dyd->actvar.arr, dyd->actvar.n + 1, |
184 | dyd->actvar.size, Vardesc, MAX_INT, "local variables"); | 185 | dyd->actvar.size, Vardesc, MAX_INT, "local variables"); |
185 | dyd->actvar.arr[dyd->actvar.n++].idx = cast(unsigned short, reg); | 186 | dyd->actvar.arr[dyd->actvar.n++].idx = cast(short, reg); |
186 | } | 187 | } |
187 | 188 | ||
188 | 189 | ||
@@ -231,13 +232,13 @@ static int newupvalue (FuncState *fs, TString *name, expdesc *v) { | |||
231 | Proto *f = fs->f; | 232 | Proto *f = fs->f; |
232 | int oldsize = f->sizeupvalues; | 233 | int oldsize = f->sizeupvalues; |
233 | checklimit(fs, fs->nups + 1, MAXUPVAL, "upvalues"); | 234 | checklimit(fs, fs->nups + 1, MAXUPVAL, "upvalues"); |
234 | luaM_growvector(fs->L, f->upvalues, fs->nups, f->sizeupvalues, | 235 | luaM_growvector(fs->ls->L, f->upvalues, fs->nups, f->sizeupvalues, |
235 | Upvaldesc, MAXUPVAL, "upvalues"); | 236 | Upvaldesc, MAXUPVAL, "upvalues"); |
236 | while (oldsize < f->sizeupvalues) f->upvalues[oldsize++].name = NULL; | 237 | while (oldsize < f->sizeupvalues) f->upvalues[oldsize++].name = NULL; |
237 | f->upvalues[fs->nups].instack = (v->k == VLOCAL); | 238 | f->upvalues[fs->nups].instack = (v->k == VLOCAL); |
238 | f->upvalues[fs->nups].idx = cast_byte(v->u.info); | 239 | f->upvalues[fs->nups].idx = cast_byte(v->u.info); |
239 | f->upvalues[fs->nups].name = name; | 240 | f->upvalues[fs->nups].name = name; |
240 | luaC_objbarrier(fs->L, f, name); | 241 | luaC_objbarrier(fs->ls->L, f, name); |
241 | return fs->nups++; | 242 | return fs->nups++; |
242 | } | 243 | } |
243 | 244 | ||
@@ -382,7 +383,7 @@ static int findlabel (LexState *ls, int g) { | |||
382 | static int newlabelentry (LexState *ls, Labellist *l, TString *name, | 383 | static int newlabelentry (LexState *ls, Labellist *l, TString *name, |
383 | int line, int pc) { | 384 | int line, int pc) { |
384 | int n = l->n; | 385 | int n = l->n; |
385 | luaM_growvector(ls->L, l->arr, n, l->size, Labeldesc, MAX_INT, "labels"); | 386 | luaM_growvector(ls->L, l->arr, n, l->size, Labeldesc, SHRT_MAX, "labels"); |
386 | l->arr[n].name = name; | 387 | l->arr[n].name = name; |
387 | l->arr[n].line = line; | 388 | l->arr[n].line = line; |
388 | l->arr[n].nactvar = ls->fs->nactvar; | 389 | l->arr[n].nactvar = ls->fs->nactvar; |
@@ -514,7 +515,6 @@ static void open_func (LexState *ls, FuncState *fs, BlockCnt *bl) { | |||
514 | Proto *f; | 515 | Proto *f; |
515 | fs->prev = ls->fs; /* linked list of funcstates */ | 516 | fs->prev = ls->fs; /* linked list of funcstates */ |
516 | fs->ls = ls; | 517 | fs->ls = ls; |
517 | fs->L = L; | ||
518 | ls->fs = fs; | 518 | ls->fs = fs; |
519 | fs->pc = 0; | 519 | fs->pc = 0; |
520 | fs->lasttarget = 0; | 520 | fs->lasttarget = 0; |
@@ -1039,7 +1039,7 @@ static const struct { | |||
1039 | ** subexpr -> (simpleexp | unop subexpr) { binop subexpr } | 1039 | ** subexpr -> (simpleexp | unop subexpr) { binop subexpr } |
1040 | ** where `binop' is any binary operator with a priority higher than `limit' | 1040 | ** where `binop' is any binary operator with a priority higher than `limit' |
1041 | */ | 1041 | */ |
1042 | static BinOpr subexpr (LexState *ls, expdesc *v, unsigned int limit) { | 1042 | static BinOpr subexpr (LexState *ls, expdesc *v, int limit) { |
1043 | BinOpr op; | 1043 | BinOpr op; |
1044 | UnOpr uop; | 1044 | UnOpr uop; |
1045 | enterlevel(ls); | 1045 | enterlevel(ls); |