aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2010-01-05 16:46:58 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2010-01-05 16:46:58 -0200
commite3866afa97c7cc0d0fce9277b13136f86d16e26c (patch)
tree5be6a04f912087d6e157cc2114f6616c5582a271
parent25189b420de22d9088229989de265f1b81872fa8 (diff)
downloadlua-e3866afa97c7cc0d0fce9277b13136f86d16e26c.tar.gz
lua-e3866afa97c7cc0d0fce9277b13136f86d16e26c.tar.bz2
lua-e3866afa97c7cc0d0fce9277b13136f86d16e26c.zip
macro 'luaY_checklimit' changed into a function (and renamed 'checklimit').
It makes no sense to trade space for time in the parser.
-rw-r--r--lparser.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/lparser.c b/lparser.c
index 55fe9352..2fb6f970 100644
--- a/lparser.c
+++ b/lparser.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lparser.c,v 2.72 2009/11/17 16:33:38 roberto Exp roberto $ 2** $Id: lparser.c,v 2.73 2009/11/26 11:39:20 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*/
@@ -36,9 +36,6 @@
36 36
37 37
38 38
39#define luaY_checklimit(fs,v,l,m) if ((v)>(l)) errorlimit(fs,l,m)
40
41
42/* 39/*
43** nodes for block list (list of active blocks) 40** nodes for block list (list of active blocks)
44*/ 41*/
@@ -86,6 +83,11 @@ static void errorlimit (FuncState *fs, int limit, const char *what) {
86} 83}
87 84
88 85
86static void checklimit (FuncState *fs, int v, int l, const char *what) {
87 if (v > l) errorlimit(fs, l, what);
88}
89
90
89static int testnext (LexState *ls, int c) { 91static int testnext (LexState *ls, int c) {
90 if (ls->t.token == c) { 92 if (ls->t.token == c) {
91 luaX_next(ls); 93 luaX_next(ls);
@@ -170,7 +172,7 @@ static void new_localvar (LexState *ls, TString *name) {
170 FuncState *fs = ls->fs; 172 FuncState *fs = ls->fs;
171 Varlist *vl = ls->varl; 173 Varlist *vl = ls->varl;
172 int reg = registerlocalvar(ls, name); 174 int reg = registerlocalvar(ls, name);
173 luaY_checklimit(fs, vl->nactvar + 1 - fs->firstlocal, 175 checklimit(fs, vl->nactvar + 1 - fs->firstlocal,
174 MAXVARS, "local variables"); 176 MAXVARS, "local variables");
175 luaM_growvector(ls->L, vl->actvar, vl->nactvar + 1, 177 luaM_growvector(ls->L, vl->actvar, vl->nactvar + 1,
176 vl->actvarsize, vardesc, MAX_INT, "local variables"); 178 vl->actvarsize, vardesc, MAX_INT, "local variables");
@@ -214,7 +216,7 @@ static int indexupvalue (FuncState *fs, TString *name, expdesc *v) {
214 } 216 }
215 } 217 }
216 /* new one */ 218 /* new one */
217 luaY_checklimit(fs, fs->nups + 1, UCHAR_MAX, "upvalues"); 219 checklimit(fs, fs->nups + 1, UCHAR_MAX, "upvalues");
218 luaM_growvector(fs->L, f->upvalues, fs->nups, f->sizeupvalues, 220 luaM_growvector(fs->L, f->upvalues, fs->nups, f->sizeupvalues,
219 Upvaldesc, UCHAR_MAX, "upvalues"); 221 Upvaldesc, UCHAR_MAX, "upvalues");
220 while (oldsize < f->sizeupvalues) f->upvalues[oldsize++].name = NULL; 222 while (oldsize < f->sizeupvalues) f->upvalues[oldsize++].name = NULL;
@@ -304,7 +306,7 @@ static void adjust_assign (LexState *ls, int nvars, int nexps, expdesc *e) {
304static void enterlevel (LexState *ls) { 306static void enterlevel (LexState *ls) {
305 global_State *g = G(ls->L); 307 global_State *g = G(ls->L);
306 ++g->nCcalls; 308 ++g->nCcalls;
307 luaY_checklimit(ls->fs, g->nCcalls, LUAI_MAXCCALLS, "syntax levels"); 309 checklimit(ls->fs, g->nCcalls, LUAI_MAXCCALLS, "syntax levels");
308} 310}
309 311
310 312
@@ -485,7 +487,7 @@ static void recfield (LexState *ls, struct ConsControl *cc) {
485 expdesc key, val; 487 expdesc key, val;
486 int rkkey; 488 int rkkey;
487 if (ls->t.token == TK_NAME) { 489 if (ls->t.token == TK_NAME) {
488 luaY_checklimit(fs, cc->nh, MAX_INT, "items in a constructor"); 490 checklimit(fs, cc->nh, MAX_INT, "items in a constructor");
489 checkname(ls, &key); 491 checkname(ls, &key);
490 } 492 }
491 else /* ls->t.token == '[' */ 493 else /* ls->t.token == '[' */
@@ -528,7 +530,7 @@ static void lastlistfield (FuncState *fs, struct ConsControl *cc) {
528static void listfield (LexState *ls, struct ConsControl *cc) { 530static void listfield (LexState *ls, struct ConsControl *cc) {
529 /* listfield -> exp */ 531 /* listfield -> exp */
530 expr(ls, &cc->v); 532 expr(ls, &cc->v);
531 luaY_checklimit(ls->fs, cc->na, MAX_INT, "items in a constructor"); 533 checklimit(ls->fs, cc->na, MAX_INT, "items in a constructor");
532 cc->na++; 534 cc->na++;
533 cc->tostore++; 535 cc->tostore++;
534} 536}
@@ -978,7 +980,7 @@ static void assignment (LexState *ls, struct LHS_assign *lh, int nvars) {
978 primaryexp(ls, &nv.v); 980 primaryexp(ls, &nv.v);
979 if (nv.v.k == VLOCAL) 981 if (nv.v.k == VLOCAL)
980 check_conflict(ls, lh, &nv.v); 982 check_conflict(ls, lh, &nv.v);
981 luaY_checklimit(ls->fs, nvars, LUAI_MAXCCALLS - G(ls->L)->nCcalls, 983 checklimit(ls->fs, nvars, LUAI_MAXCCALLS - G(ls->L)->nCcalls,
982 "variable names"); 984 "variable names");
983 assignment(ls, &nv, nvars+1); 985 assignment(ls, &nv, nvars+1);
984 } 986 }