diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-04-07 16:35:20 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-04-07 16:35:20 -0300 |
commit | 54dd5cc7fd42a8b073f64b7d16efdb1ed01e2dd5 (patch) | |
tree | 01c0e573c486173dcafc3ea0d0d45185f52aa19a /lparser.c | |
parent | 031978798cc404c2c6757c564675d43a7da129ee (diff) | |
download | lua-54dd5cc7fd42a8b073f64b7d16efdb1ed01e2dd5.tar.gz lua-54dd5cc7fd42a8b073f64b7d16efdb1ed01e2dd5.tar.bz2 lua-54dd5cc7fd42a8b073f64b7d16efdb1ed01e2dd5.zip |
reorganization of lcode.c
Diffstat (limited to 'lparser.c')
-rw-r--r-- | lparser.c | 33 |
1 files changed, 15 insertions, 18 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lparser.c,v 1.77 2000/04/06 17:36:52 roberto Exp roberto $ | 2 | ** $Id: lparser.c,v 1.78 2000/04/07 13:13:11 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 | */ |
@@ -91,7 +91,7 @@ static void setline (LexState *ls) { | |||
91 | FuncState *fs = ls->fs; | 91 | FuncState *fs = ls->fs; |
92 | if (ls->L->debug && ls->linenumber != fs->lastsetline) { | 92 | if (ls->L->debug && ls->linenumber != fs->lastsetline) { |
93 | checklimit(ls, ls->linenumber, MAXARG_U, "lines in a chunk"); | 93 | checklimit(ls, ls->linenumber, MAXARG_U, "lines in a chunk"); |
94 | luaK_U(fs, OP_SETLINE, ls->linenumber, 0); | 94 | luaK_code1(fs, OP_SETLINE, ls->linenumber); |
95 | fs->lastsetline = ls->linenumber; | 95 | fs->lastsetline = ls->linenumber; |
96 | } | 96 | } |
97 | } | 97 | } |
@@ -260,7 +260,7 @@ static void pushupvalue (LexState *ls, TString *n) { | |||
260 | luaX_syntaxerror(ls, "cannot access upvalue in main", n->str); | 260 | luaX_syntaxerror(ls, "cannot access upvalue in main", n->str); |
261 | if (aux_localname(ls->fs, n) >= 0) | 261 | if (aux_localname(ls->fs, n) >= 0) |
262 | luaX_syntaxerror(ls, "cannot access an upvalue in current scope", n->str); | 262 | luaX_syntaxerror(ls, "cannot access an upvalue in current scope", n->str); |
263 | luaK_U(fs, OP_PUSHUPVALUE, indexupvalue(ls, n), 1); | 263 | luaK_code1(fs, OP_PUSHUPVALUE, indexupvalue(ls, n)); |
264 | } | 264 | } |
265 | 265 | ||
266 | 266 | ||
@@ -339,8 +339,7 @@ static void func_onstack (LexState *ls, FuncState *func) { | |||
339 | luaM_growvector(ls->L, f->kproto, f->nkproto, 1, Proto *, | 339 | luaM_growvector(ls->L, f->kproto, f->nkproto, 1, Proto *, |
340 | constantEM, MAXARG_A); | 340 | constantEM, MAXARG_A); |
341 | f->kproto[f->nkproto++] = func->f; | 341 | f->kproto[f->nkproto++] = func->f; |
342 | luaK_deltastack(fs, 1); /* CLOSURE puts one extra element before popping */ | 342 | luaK_code2(fs, OP_CLOSURE, f->nkproto-1, func->nupvalues); |
343 | luaK_AB(fs, OP_CLOSURE, f->nkproto-1, func->nupvalues, -func->nupvalues); | ||
344 | } | 343 | } |
345 | 344 | ||
346 | 345 | ||
@@ -373,7 +372,7 @@ static void close_func (LexState *ls) { | |||
373 | lua_State *L = ls->L; | 372 | lua_State *L = ls->L; |
374 | FuncState *fs = ls->fs; | 373 | FuncState *fs = ls->fs; |
375 | Proto *f = fs->f; | 374 | Proto *f = fs->f; |
376 | luaK_0(fs, OP_END, 0); | 375 | luaK_code0(fs, OP_END); |
377 | luaK_getlabel(fs); /* close eventual list of pending jumps */ | 376 | luaK_getlabel(fs); /* close eventual list of pending jumps */ |
378 | luaM_reallocvector(L, f->code, fs->pc, Instruction); | 377 | luaM_reallocvector(L, f->code, fs->pc, Instruction); |
379 | luaM_reallocvector(L, f->kstr, f->nkstr, TString *); | 378 | luaM_reallocvector(L, f->kstr, f->nkstr, TString *); |
@@ -469,7 +468,7 @@ static void funcargs (LexState *ls, int slf) { | |||
469 | break; | 468 | break; |
470 | } | 469 | } |
471 | fs->stacklevel = slevel; /* call will remove function and arguments */ | 470 | fs->stacklevel = slevel; /* call will remove function and arguments */ |
472 | luaK_AB(fs, OP_CALL, slevel, MULT_RET, 0); | 471 | luaK_code2(fs, OP_CALL, slevel, MULT_RET); |
473 | } | 472 | } |
474 | 473 | ||
475 | 474 | ||
@@ -496,7 +495,7 @@ static void var_or_func_tail (LexState *ls, expdesc *v) { | |||
496 | next(ls); | 495 | next(ls); |
497 | name = checkname(ls); | 496 | name = checkname(ls); |
498 | luaK_tostack(ls, v, 1); /* `v' must be on stack */ | 497 | luaK_tostack(ls, v, 1); /* `v' must be on stack */ |
499 | luaK_U(ls->fs, OP_PUSHSELF, name, 1); | 498 | luaK_code1(ls->fs, OP_PUSHSELF, name); |
500 | funcargs(ls, 1); | 499 | funcargs(ls, 1); |
501 | v->k = VEXP; | 500 | v->k = VEXP; |
502 | v->u.l.t = v->u.l.f = NO_JUMP; | 501 | v->u.l.t = v->u.l.f = NO_JUMP; |
@@ -569,12 +568,12 @@ static int recfields (LexState *ls) { | |||
569 | recfield(ls); | 568 | recfield(ls); |
570 | n++; | 569 | n++; |
571 | if (++mod_n == RFIELDS_PER_FLUSH) { | 570 | if (++mod_n == RFIELDS_PER_FLUSH) { |
572 | luaK_U(fs, OP_SETMAP, RFIELDS_PER_FLUSH-1, -2*RFIELDS_PER_FLUSH); | 571 | luaK_code1(fs, OP_SETMAP, RFIELDS_PER_FLUSH-1); |
573 | mod_n = 0; | 572 | mod_n = 0; |
574 | } | 573 | } |
575 | } | 574 | } |
576 | if (mod_n) | 575 | if (mod_n) |
577 | luaK_U(fs, OP_SETMAP, mod_n-1, -2*mod_n); | 576 | luaK_code1(fs, OP_SETMAP, mod_n-1); |
578 | return n; | 577 | return n; |
579 | } | 578 | } |
580 | 579 | ||
@@ -593,13 +592,12 @@ static int listfields (LexState *ls) { | |||
593 | checklimit(ls, n, MAXARG_A*LFIELDS_PER_FLUSH, | 592 | checklimit(ls, n, MAXARG_A*LFIELDS_PER_FLUSH, |
594 | "items in a list initializer"); | 593 | "items in a list initializer"); |
595 | if (++mod_n == LFIELDS_PER_FLUSH) { | 594 | if (++mod_n == LFIELDS_PER_FLUSH) { |
596 | luaK_AB(fs, OP_SETLIST, n/LFIELDS_PER_FLUSH - 1, LFIELDS_PER_FLUSH-1, | 595 | luaK_code2(fs, OP_SETLIST, n/LFIELDS_PER_FLUSH - 1, LFIELDS_PER_FLUSH-1); |
597 | -LFIELDS_PER_FLUSH); | ||
598 | mod_n = 0; | 596 | mod_n = 0; |
599 | } | 597 | } |
600 | } | 598 | } |
601 | if (mod_n > 0) | 599 | if (mod_n > 0) |
602 | luaK_AB(fs, OP_SETLIST, n/LFIELDS_PER_FLUSH, mod_n-1, -mod_n); | 600 | luaK_code2(fs, OP_SETLIST, n/LFIELDS_PER_FLUSH, mod_n-1); |
603 | return n; | 601 | return n; |
604 | } | 602 | } |
605 | 603 | ||
@@ -649,7 +647,7 @@ static void constructor (LexState *ls) { | |||
649 | /* constructor -> '{' constructor_part [';' constructor_part] '}' */ | 647 | /* constructor -> '{' constructor_part [';' constructor_part] '}' */ |
650 | FuncState *fs = ls->fs; | 648 | FuncState *fs = ls->fs; |
651 | int line = ls->linenumber; | 649 | int line = ls->linenumber; |
652 | int pc = luaK_U(fs, OP_CREATETABLE, 0, 1); | 650 | int pc = luaK_code1(fs, OP_CREATETABLE, 0); |
653 | int nelems; | 651 | int nelems; |
654 | Constdesc cd; | 652 | Constdesc cd; |
655 | check(ls, '{'); | 653 | check(ls, '{'); |
@@ -835,7 +833,7 @@ static int assignment (LexState *ls, expdesc *v, int nvars) { | |||
835 | if (v->k != VINDEXED) | 833 | if (v->k != VINDEXED) |
836 | luaK_storevar(ls, v); | 834 | luaK_storevar(ls, v); |
837 | else { /* there may be garbage between table-index and value */ | 835 | else { /* there may be garbage between table-index and value */ |
838 | luaK_AB(ls->fs, OP_SETTABLE, left+nvars+2, 1, -1); | 836 | luaK_code2(ls->fs, OP_SETTABLE, left+nvars+2, 1); |
839 | left += 2; | 837 | left += 2; |
840 | } | 838 | } |
841 | return left; | 839 | return left; |
@@ -1099,10 +1097,9 @@ static void ret (LexState *ls) { | |||
1099 | FuncState *fs = ls->fs; | 1097 | FuncState *fs = ls->fs; |
1100 | switch (ls->token) { | 1098 | switch (ls->token) { |
1101 | case TK_RETURN: { | 1099 | case TK_RETURN: { |
1102 | int nexps; /* number of expressions returned */ | ||
1103 | setline_and_next(ls); /* skip RETURN */ | 1100 | setline_and_next(ls); /* skip RETURN */ |
1104 | nexps = explist(ls); | 1101 | explist(ls); |
1105 | luaK_retcode(fs, ls->fs->nlocalvar, nexps); | 1102 | luaK_code1(fs, OP_RETURN, ls->fs->nlocalvar); |
1106 | fs->stacklevel = fs->nlocalvar; /* removes all temp values */ | 1103 | fs->stacklevel = fs->nlocalvar; /* removes all temp values */ |
1107 | optional(ls, ';'); | 1104 | optional(ls, ';'); |
1108 | break; | 1105 | break; |