diff options
Diffstat (limited to 'lparser.c')
-rw-r--r-- | lparser.c | 58 |
1 files changed, 29 insertions, 29 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lparser.c,v 1.55 2000/01/25 13:57:18 roberto Exp roberto $ | 2 | ** $Id: lparser.c,v 1.56 2000/01/25 18:44:21 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 | */ |
@@ -150,7 +150,7 @@ static void deltastack (LexState *ls, int delta) { | |||
150 | fs->stacksize += delta; | 150 | fs->stacksize += delta; |
151 | if (fs->stacksize > fs->maxstacksize) { | 151 | if (fs->stacksize > fs->maxstacksize) { |
152 | if (fs->stacksize > MAX_BYTE) | 152 | if (fs->stacksize > MAX_BYTE) |
153 | luaY_error(ls, "function/expression too complex"); | 153 | luaY_error(ls, "function or expression too complex"); |
154 | fs->maxstacksize = fs->stacksize; | 154 | fs->maxstacksize = fs->stacksize; |
155 | } | 155 | } |
156 | } | 156 | } |
@@ -214,24 +214,24 @@ static void code_opcode (LexState *ls, OpCode op, int delta) { | |||
214 | } | 214 | } |
215 | 215 | ||
216 | 216 | ||
217 | static void code_strcnst (LexState *ls, int c) { | 217 | static void code_kstr (LexState *ls, int c) { |
218 | code_oparg(ls, PUSHSTRCNST, c, 1); | 218 | code_oparg(ls, PUSHSTRING, c, 1); |
219 | } | 219 | } |
220 | 220 | ||
221 | 221 | ||
222 | static void assertglobal (LexState *ls, int index) { | 222 | static void assertglobal (LexState *ls, int index) { |
223 | luaS_assertglobal(ls->L, ls->fs->f->strcnst[index]); | 223 | luaS_assertglobal(ls->L, ls->fs->f->kstr[index]); |
224 | } | 224 | } |
225 | 225 | ||
226 | 226 | ||
227 | static int string_constant (LexState *ls, FuncState *fs, TaggedString *s) { | 227 | static int string_constant (LexState *ls, FuncState *fs, TaggedString *s) { |
228 | TProtoFunc *f = fs->f; | 228 | TProtoFunc *f = fs->f; |
229 | int c = s->constindex; | 229 | int c = s->constindex; |
230 | if (c >= f->nstrcnst || f->strcnst[c] != s) { | 230 | if (c >= f->nkstr || f->kstr[c] != s) { |
231 | luaM_growvector(ls->L, f->strcnst, f->nstrcnst, 1, | 231 | luaM_growvector(ls->L, f->kstr, f->nkstr, 1, |
232 | TaggedString *, constantEM, MAX_ARG); | 232 | TaggedString *, constantEM, MAX_ARG); |
233 | c = f->nstrcnst++; | 233 | c = f->nkstr++; |
234 | f->strcnst[c] = s; | 234 | f->kstr[c] = s; |
235 | s->constindex = c; /* hint for next time */ | 235 | s->constindex = c; /* hint for next time */ |
236 | } | 236 | } |
237 | return c; | 237 | return c; |
@@ -239,7 +239,7 @@ static int string_constant (LexState *ls, FuncState *fs, TaggedString *s) { | |||
239 | 239 | ||
240 | 240 | ||
241 | static void code_string (LexState *ls, TaggedString *s) { | 241 | static void code_string (LexState *ls, TaggedString *s) { |
242 | code_strcnst(ls, string_constant(ls, ls->fs, s)); | 242 | code_kstr(ls, string_constant(ls, ls->fs, s)); |
243 | } | 243 | } |
244 | 244 | ||
245 | 245 | ||
@@ -247,15 +247,15 @@ static void code_string (LexState *ls, TaggedString *s) { | |||
247 | static int real_constant (LexState *ls, real r) { | 247 | static int real_constant (LexState *ls, real r) { |
248 | /* check whether `r' has appeared within the last LIM entries */ | 248 | /* check whether `r' has appeared within the last LIM entries */ |
249 | TProtoFunc *f = ls->fs->f; | 249 | TProtoFunc *f = ls->fs->f; |
250 | int c = f->nnumcnst; | 250 | int c = f->nknum; |
251 | int lim = c < LIM ? 0 : c-LIM; | 251 | int lim = c < LIM ? 0 : c-LIM; |
252 | while (--c >= lim) | 252 | while (--c >= lim) |
253 | if (f->numcnst[c] == r) return c; | 253 | if (f->knum[c] == r) return c; |
254 | /* not found; create a new entry */ | 254 | /* not found; create a new entry */ |
255 | luaM_growvector(ls->L, f->numcnst, f->nnumcnst, 1, | 255 | luaM_growvector(ls->L, f->knum, f->nknum, 1, |
256 | real, constantEM, MAX_ARG); | 256 | real, constantEM, MAX_ARG); |
257 | c = f->nnumcnst++; | 257 | c = f->nknum++; |
258 | f->numcnst[c] = r; | 258 | f->knum[c] = r; |
259 | return c; | 259 | return c; |
260 | } | 260 | } |
261 | 261 | ||
@@ -264,10 +264,10 @@ static void code_number (LexState *ls, real f) { | |||
264 | real af = (f<0) ? -f : f; | 264 | real af = (f<0) ? -f : f; |
265 | if (0 <= af && af <= (real)MAX_WORD && (int)af == af) { | 265 | if (0 <= af && af <= (real)MAX_WORD && (int)af == af) { |
266 | /* abs(f) has a short integer value */ | 266 | /* abs(f) has a short integer value */ |
267 | code_oparg(ls, (f<0) ? PUSHNUMBERNEG : PUSHNUMBER, (int)af, 1); | 267 | code_oparg(ls, (f<0) ? PUSHINTNEG : PUSHINT, (int)af, 1); |
268 | } | 268 | } |
269 | else | 269 | else |
270 | code_oparg(ls, PUSHNUMCNST, real_constant(ls, f), 1); | 270 | code_oparg(ls, PUSHNUMBER, real_constant(ls, f), 1); |
271 | } | 271 | } |
272 | 272 | ||
273 | 273 | ||
@@ -469,7 +469,7 @@ static void code_args (LexState *ls, int nparams, int dots) { | |||
469 | static void unloaddot (LexState *ls, vardesc *v) { | 469 | static void unloaddot (LexState *ls, vardesc *v) { |
470 | /* dotted variables <a.x> must be stored as regular indexed vars <a["x"]> */ | 470 | /* dotted variables <a.x> must be stored as regular indexed vars <a["x"]> */ |
471 | if (v->k == VDOT) { | 471 | if (v->k == VDOT) { |
472 | code_strcnst(ls, v->info); | 472 | code_kstr(ls, v->info); |
473 | v->k = VINDEXED; | 473 | v->k = VINDEXED; |
474 | } | 474 | } |
475 | } | 475 | } |
@@ -551,13 +551,13 @@ static void func_onstack (LexState *ls, FuncState *func) { | |||
551 | FuncState *fs = ls->fs; | 551 | FuncState *fs = ls->fs; |
552 | TProtoFunc *f = fs->f; | 552 | TProtoFunc *f = fs->f; |
553 | int i; | 553 | int i; |
554 | luaM_growvector(ls->L, f->protocnst, f->nprotocnst, 1, | 554 | luaM_growvector(ls->L, f->kproto, f->nkproto, 1, |
555 | TProtoFunc *, constantEM, MAX_ARG); | 555 | TProtoFunc *, constantEM, MAX_ARG); |
556 | f->protocnst[f->nprotocnst] = func->f; | 556 | f->kproto[f->nkproto] = func->f; |
557 | for (i=0; i<func->nupvalues; i++) | 557 | for (i=0; i<func->nupvalues; i++) |
558 | lua_pushvar(ls, &func->upvalues[i]); | 558 | lua_pushvar(ls, &func->upvalues[i]); |
559 | deltastack(ls, 1); /* CLOSURE puts one extra element (before poping) */ | 559 | deltastack(ls, 1); /* CLOSURE puts one extra element (before popping) */ |
560 | code_oparg(ls, CLOSURE, f->nprotocnst++, -func->nupvalues); | 560 | code_oparg(ls, CLOSURE, f->nkproto++, -func->nupvalues); |
561 | code_byte(ls, (Byte)func->nupvalues); | 561 | code_byte(ls, (Byte)func->nupvalues); |
562 | } | 562 | } |
563 | 563 | ||
@@ -592,9 +592,9 @@ static void close_func (LexState *ls) { | |||
592 | code_opcode(ls, ENDCODE, 0); | 592 | code_opcode(ls, ENDCODE, 0); |
593 | f->code[0] = (Byte)fs->maxstacksize; | 593 | f->code[0] = (Byte)fs->maxstacksize; |
594 | luaM_reallocvector(ls->L, f->code, fs->pc, Byte); | 594 | luaM_reallocvector(ls->L, f->code, fs->pc, Byte); |
595 | luaM_reallocvector(ls->L, f->strcnst, f->nstrcnst, TaggedString *); | 595 | luaM_reallocvector(ls->L, f->kstr, f->nkstr, TaggedString *); |
596 | luaM_reallocvector(ls->L, f->numcnst, f->nnumcnst, real); | 596 | luaM_reallocvector(ls->L, f->knum, f->nknum, real); |
597 | luaM_reallocvector(ls->L, f->protocnst, f->nprotocnst, TProtoFunc *); | 597 | luaM_reallocvector(ls->L, f->kproto, f->nkproto, TProtoFunc *); |
598 | if (fs->nvars != -1) { /* debug information? */ | 598 | if (fs->nvars != -1) { /* debug information? */ |
599 | luaI_registerlocalvar(ls, NULL, -1); /* flag end of vector */ | 599 | luaI_registerlocalvar(ls, NULL, -1); /* flag end of vector */ |
600 | luaM_reallocvector(ls->L, f->locvars, fs->nvars, LocVar); | 600 | luaM_reallocvector(ls->L, f->locvars, fs->nvars, LocVar); |
@@ -661,7 +661,7 @@ static int checkname (LexState *ls) { | |||
661 | 661 | ||
662 | static TaggedString *str_checkname (LexState *ls) { | 662 | static TaggedString *str_checkname (LexState *ls) { |
663 | int i = checkname(ls); /* this call may realloc `f->consts' */ | 663 | int i = checkname(ls); /* this call may realloc `f->consts' */ |
664 | return ls->fs->f->strcnst[i]; | 664 | return ls->fs->f->kstr[i]; |
665 | } | 665 | } |
666 | 666 | ||
667 | 667 | ||
@@ -853,7 +853,7 @@ static void recfield (LexState *ls) { | |||
853 | /* recfield -> (NAME | '['exp1']') = exp1 */ | 853 | /* recfield -> (NAME | '['exp1']') = exp1 */ |
854 | switch (ls->token) { | 854 | switch (ls->token) { |
855 | case NAME: | 855 | case NAME: |
856 | code_strcnst(ls, checkname(ls)); | 856 | code_kstr(ls, checkname(ls)); |
857 | break; | 857 | break; |
858 | 858 | ||
859 | case '[': | 859 | case '[': |
@@ -917,7 +917,7 @@ static void constructor_part (LexState *ls, constdesc *cd) { | |||
917 | if (ls->token == '=') { | 917 | if (ls->token == '=') { |
918 | switch (v.k) { | 918 | switch (v.k) { |
919 | case VGLOBAL: | 919 | case VGLOBAL: |
920 | code_strcnst(ls, v.info); | 920 | code_kstr(ls, v.info); |
921 | break; | 921 | break; |
922 | case VLOCAL: | 922 | case VLOCAL: |
923 | code_string(ls, ls->fs->localvar[v.info]); | 923 | code_string(ls, ls->fs->localvar[v.info]); |
@@ -1291,7 +1291,7 @@ static int funcname (LexState *ls, vardesc *v) { | |||
1291 | needself = (ls->token == ':'); | 1291 | needself = (ls->token == ':'); |
1292 | next(ls); | 1292 | next(ls); |
1293 | lua_pushvar(ls, v); | 1293 | lua_pushvar(ls, v); |
1294 | code_strcnst(ls, checkname(ls)); | 1294 | code_kstr(ls, checkname(ls)); |
1295 | v->k = VINDEXED; | 1295 | v->k = VINDEXED; |
1296 | } | 1296 | } |
1297 | return needself; | 1297 | return needself; |