diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-05-24 10:54:49 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-05-24 10:54:49 -0300 |
commit | ef62b340e0a6b7b18931000dcbb19c4703bfe0e8 (patch) | |
tree | d9d995116a8a686b798d1b625b06ead26f28ba58 /lparser.c | |
parent | 5c2dd7a9e0a5b871a71ba66c4683cd88fe4f5aa4 (diff) | |
download | lua-ef62b340e0a6b7b18931000dcbb19c4703bfe0e8.tar.gz lua-ef62b340e0a6b7b18931000dcbb19c4703bfe0e8.tar.bz2 lua-ef62b340e0a6b7b18931000dcbb19c4703bfe0e8.zip |
code cleaner for 16 bits.
Diffstat (limited to 'lparser.c')
-rw-r--r-- | lparser.c | 30 |
1 files changed, 11 insertions, 19 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lparser.c,v 1.87 2000/05/15 19:48:04 roberto Exp roberto $ | 2 | ** $Id: lparser.c,v 1.88 2000/05/22 18:44:46 roberto Exp roberto $ |
3 | ** LL(1) Parser and code generator for Lua | 3 | ** LL(1) Parser and code generator for Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -79,19 +79,10 @@ static void check (LexState *ls, int c) { | |||
79 | } | 79 | } |
80 | 80 | ||
81 | 81 | ||
82 | static void checklimit (LexState *ls, int val, int limit, const char *msg) { | ||
83 | if (val > limit) { | ||
84 | char buff[100]; | ||
85 | sprintf(buff, "too many %.50s (limit=%d)", msg, limit); | ||
86 | luaK_error(ls, buff); | ||
87 | } | ||
88 | } | ||
89 | |||
90 | |||
91 | static void setline (LexState *ls) { | 82 | static void setline (LexState *ls) { |
92 | FuncState *fs = ls->fs; | 83 | FuncState *fs = ls->fs; |
93 | if (ls->L->debug && ls->linenumber != fs->lastsetline) { | 84 | if (ls->L->debug && ls->linenumber != fs->lastsetline) { |
94 | checklimit(ls, ls->linenumber, MAXARG_U, "lines in a chunk"); | 85 | luaX_checklimit(ls, ls->linenumber, MAXARG_U, "lines in a chunk"); |
95 | luaK_code1(fs, OP_SETLINE, ls->linenumber); | 86 | luaK_code1(fs, OP_SETLINE, ls->linenumber); |
96 | fs->lastsetline = ls->linenumber; | 87 | fs->lastsetline = ls->linenumber; |
97 | } | 88 | } |
@@ -142,7 +133,7 @@ static int string_constant (FuncState *fs, TString *s) { | |||
142 | int c = s->u.s.constindex; | 133 | int c = s->u.s.constindex; |
143 | if (c >= f->nkstr || f->kstr[c] != s) { | 134 | if (c >= f->nkstr || f->kstr[c] != s) { |
144 | luaM_growvector(fs->L, f->kstr, f->nkstr, 1, TString *, | 135 | luaM_growvector(fs->L, f->kstr, f->nkstr, 1, TString *, |
145 | constantEM, MAXARG_U); | 136 | "constant table overflow", MAXARG_U); |
146 | c = f->nkstr++; | 137 | c = f->nkstr++; |
147 | f->kstr[c] = s; | 138 | f->kstr[c] = s; |
148 | s->u.s.constindex = c; /* hint for next time */ | 139 | s->u.s.constindex = c; /* hint for next time */ |
@@ -200,7 +191,7 @@ static void luaI_unregisterlocalvar (LexState *ls, int line) { | |||
200 | 191 | ||
201 | static void store_localvar (LexState *ls, TString *name, int n) { | 192 | static void store_localvar (LexState *ls, TString *name, int n) { |
202 | FuncState *fs = ls->fs; | 193 | FuncState *fs = ls->fs; |
203 | checklimit(ls, fs->nlocalvar+n+1, MAXLOCALS, "local variables"); | 194 | luaX_checklimit(ls, fs->nlocalvar+n+1, MAXLOCALS, "local variables"); |
204 | fs->localvar[fs->nlocalvar+n] = name; | 195 | fs->localvar[fs->nlocalvar+n] = name; |
205 | } | 196 | } |
206 | 197 | ||
@@ -266,7 +257,7 @@ static int indexupvalue (LexState *ls, TString *n) { | |||
266 | } | 257 | } |
267 | /* new one */ | 258 | /* new one */ |
268 | ++(fs->nupvalues); | 259 | ++(fs->nupvalues); |
269 | checklimit(ls, fs->nupvalues, MAXUPVALUES, "upvalues"); | 260 | luaX_checklimit(ls, fs->nupvalues, MAXUPVALUES, "upvalues"); |
270 | fs->upvalues[i] = v; /* i = fs->nupvalues - 1 */ | 261 | fs->upvalues[i] = v; /* i = fs->nupvalues - 1 */ |
271 | return i; | 262 | return i; |
272 | } | 263 | } |
@@ -306,7 +297,7 @@ static void adjust_mult_assign (LexState *ls, int nvars, int nexps) { | |||
306 | static void code_args (LexState *ls, int nparams, int dots) { | 297 | static void code_args (LexState *ls, int nparams, int dots) { |
307 | FuncState *fs = ls->fs; | 298 | FuncState *fs = ls->fs; |
308 | adjustlocalvars(ls, nparams); | 299 | adjustlocalvars(ls, nparams); |
309 | checklimit(ls, fs->nlocalvar, MAXPARAMS, "parameters"); | 300 | luaX_checklimit(ls, fs->nlocalvar, MAXPARAMS, "parameters"); |
310 | nparams = fs->nlocalvar; /* `self' could be there already */ | 301 | nparams = fs->nlocalvar; /* `self' could be there already */ |
311 | fs->f->numparams = nparams; | 302 | fs->f->numparams = nparams; |
312 | fs->f->is_vararg = dots; | 303 | fs->f->is_vararg = dots; |
@@ -369,7 +360,7 @@ static void func_onstack (LexState *ls, FuncState *func) { | |||
369 | for (i=0; i<func->nupvalues; i++) | 360 | for (i=0; i<func->nupvalues; i++) |
370 | luaK_tostack(ls, &func->upvalues[i], 1); | 361 | luaK_tostack(ls, &func->upvalues[i], 1); |
371 | luaM_growvector(ls->L, f->kproto, f->nkproto, 1, Proto *, | 362 | luaM_growvector(ls->L, f->kproto, f->nkproto, 1, Proto *, |
372 | constantEM, MAXARG_A); | 363 | "constant table overflow", MAXARG_A); |
373 | f->kproto[f->nkproto++] = func->f; | 364 | f->kproto[f->nkproto++] = func->f; |
374 | luaK_code2(fs, OP_CLOSURE, f->nkproto-1, func->nupvalues); | 365 | luaK_code2(fs, OP_CLOSURE, f->nkproto-1, func->nupvalues); |
375 | } | 366 | } |
@@ -623,8 +614,8 @@ static int listfields (LexState *ls) { | |||
623 | break; | 614 | break; |
624 | exp1(ls); | 615 | exp1(ls); |
625 | n++; | 616 | n++; |
626 | checklimit(ls, n, MAXARG_A*LFIELDS_PER_FLUSH, | 617 | luaX_checklimit(ls, n/LFIELDS_PER_FLUSH, MAXARG_A, |
627 | "items in a list initializer"); | 618 | "`item groups' in a list initializer"); |
628 | if (++mod_n == LFIELDS_PER_FLUSH) { | 619 | if (++mod_n == LFIELDS_PER_FLUSH) { |
629 | luaK_code2(fs, OP_SETLIST, n/LFIELDS_PER_FLUSH - 1, LFIELDS_PER_FLUSH); | 620 | luaK_code2(fs, OP_SETLIST, n/LFIELDS_PER_FLUSH - 1, LFIELDS_PER_FLUSH); |
630 | mod_n = 0; | 621 | mod_n = 0; |
@@ -697,6 +688,7 @@ static void constructor (LexState *ls) { | |||
697 | } | 688 | } |
698 | check_match(ls, '}', '{', line); | 689 | check_match(ls, '}', '{', line); |
699 | /* set initial table size */ | 690 | /* set initial table size */ |
691 | luaX_checklimit(ls, nelems, MAXARG_U, "elements in a table constructor"); | ||
700 | SETARG_U(fs->f->code[pc], nelems); | 692 | SETARG_U(fs->f->code[pc], nelems); |
701 | } | 693 | } |
702 | 694 | ||
@@ -846,7 +838,7 @@ static void block (LexState *ls) { | |||
846 | 838 | ||
847 | static int assignment (LexState *ls, expdesc *v, int nvars) { | 839 | static int assignment (LexState *ls, expdesc *v, int nvars) { |
848 | int left = 0; | 840 | int left = 0; |
849 | checklimit(ls, nvars, MAXVARSLH, "variables in a multiple assignment"); | 841 | luaX_checklimit(ls, nvars, MAXVARSLH, "variables in a multiple assignment"); |
850 | if (ls->token == ',') { /* assignment -> ',' NAME assignment */ | 842 | if (ls->token == ',') { /* assignment -> ',' NAME assignment */ |
851 | expdesc nv; | 843 | expdesc nv; |
852 | next(ls); | 844 | next(ls); |