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 | |
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.)
-rw-r--r-- | lparser.c | 24 | ||||
-rw-r--r-- | lparser.h | 13 |
2 files changed, 18 insertions, 19 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); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lparser.h,v 1.67 2011/02/07 17:14:50 roberto Exp roberto $ | 2 | ** $Id: lparser.h,v 1.68 2011/02/23 13:13:10 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 | */ |
@@ -55,7 +55,7 @@ typedef struct expdesc { | |||
55 | 55 | ||
56 | /* description of active local variable */ | 56 | /* description of active local variable */ |
57 | typedef struct Vardesc { | 57 | typedef struct Vardesc { |
58 | unsigned short idx; /* variable index in stack */ | 58 | short idx; /* variable index in stack */ |
59 | } Vardesc; | 59 | } Vardesc; |
60 | 60 | ||
61 | 61 | ||
@@ -98,18 +98,17 @@ typedef struct FuncState { | |||
98 | Table *h; /* table to find (and reuse) elements in `k' */ | 98 | Table *h; /* table to find (and reuse) elements in `k' */ |
99 | struct FuncState *prev; /* enclosing function */ | 99 | struct FuncState *prev; /* enclosing function */ |
100 | struct LexState *ls; /* lexical state */ | 100 | struct LexState *ls; /* lexical state */ |
101 | struct lua_State *L; /* copy of the Lua state */ | ||
102 | struct BlockCnt *bl; /* chain of current blocks */ | 101 | struct BlockCnt *bl; /* chain of current blocks */ |
103 | int pc; /* next position to code (equivalent to `ncode') */ | 102 | int pc; /* next position to code (equivalent to `ncode') */ |
104 | int lasttarget; /* `pc' of last `jump target' */ | 103 | int lasttarget; /* 'label' of last 'jump label' */ |
105 | int jpc; /* list of pending jumps to `pc' */ | 104 | int jpc; /* list of pending jumps to `pc' */ |
106 | int freereg; /* first free register */ | ||
107 | int nk; /* number of elements in `k' */ | 105 | int nk; /* number of elements in `k' */ |
108 | int np; /* number of elements in `p' */ | 106 | int np; /* number of elements in `p' */ |
109 | int firstlocal; /* index of first local var of this function */ | 107 | int firstlocal; /* index of first local var (in Dyndata array) */ |
110 | short nlocvars; /* number of elements in `locvars' */ | 108 | short nlocvars; /* number of elements in 'f->locvars' */ |
111 | lu_byte nactvar; /* number of active local variables */ | 109 | lu_byte nactvar; /* number of active local variables */ |
112 | lu_byte nups; /* number of upvalues */ | 110 | lu_byte nups; /* number of upvalues */ |
111 | lu_byte freereg; /* first free register */ | ||
113 | } FuncState; | 112 | } FuncState; |
114 | 113 | ||
115 | 114 | ||