diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-06-12 11:36:48 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-06-12 11:36:48 -0300 |
| commit | 89c301d180ef4ef3887fbf54fe2fd43a5c8d183a (patch) | |
| tree | 6598d32655d3dc34ec27c2c100c5ea13d6a96c86 | |
| parent | 186111dc011a37d915c4550c7d716feefd2e7dce (diff) | |
| download | lua-89c301d180ef4ef3887fbf54fe2fd43a5c8d183a.tar.gz lua-89c301d180ef4ef3887fbf54fe2fd43a5c8d183a.tar.bz2 lua-89c301d180ef4ef3887fbf54fe2fd43a5c8d183a.zip | |
`(exp)' adjusts exp to 1 result
Diffstat (limited to '')
| -rw-r--r-- | lcode.c | 22 | ||||
| -rw-r--r-- | lcode.h | 3 | ||||
| -rw-r--r-- | lparser.c | 3 |
3 files changed, 15 insertions, 13 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lcode.c,v 1.73 2001/06/08 19:00:57 roberto Exp roberto $ | 2 | ** $Id: lcode.c,v 1.74 2001/06/11 14:56:42 roberto Exp roberto $ |
| 3 | ** Code generator for Lua | 3 | ** Code generator for Lua |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -271,7 +271,7 @@ void luaK_setcallreturns (FuncState *fs, expdesc *e, int nresults) { | |||
| 271 | } | 271 | } |
| 272 | 272 | ||
| 273 | 273 | ||
| 274 | static void dischargevars (FuncState *fs, expdesc *e) { | 274 | void luaK_dischargevars (FuncState *fs, expdesc *e) { |
| 275 | switch (e->k) { | 275 | switch (e->k) { |
| 276 | case VLOCAL: { | 276 | case VLOCAL: { |
| 277 | e->k = VNONRELOC; | 277 | e->k = VNONRELOC; |
| @@ -325,7 +325,7 @@ static void dischargejumps (FuncState *fs, expdesc *e, int reg) { | |||
| 325 | 325 | ||
| 326 | 326 | ||
| 327 | static void discharge2reg (FuncState *fs, expdesc *e, int reg) { | 327 | static void discharge2reg (FuncState *fs, expdesc *e, int reg) { |
| 328 | dischargevars(fs, e); | 328 | luaK_dischargevars(fs, e); |
| 329 | switch (e->k) { | 329 | switch (e->k) { |
| 330 | case VNIL: { | 330 | case VNIL: { |
| 331 | luaK_nil(fs, reg, 1); | 331 | luaK_nil(fs, reg, 1); |
| @@ -392,7 +392,7 @@ static void luaK_exp2reg (FuncState *fs, expdesc *e, int reg) { | |||
| 392 | 392 | ||
| 393 | void luaK_exp2nextreg (FuncState *fs, expdesc *e) { | 393 | void luaK_exp2nextreg (FuncState *fs, expdesc *e) { |
| 394 | int reg; | 394 | int reg; |
| 395 | dischargevars(fs, e); | 395 | luaK_dischargevars(fs, e); |
| 396 | freeexp(fs, e); | 396 | freeexp(fs, e); |
| 397 | reg = fs->freereg; | 397 | reg = fs->freereg; |
| 398 | luaK_reserveregs(fs, 1); | 398 | luaK_reserveregs(fs, 1); |
| @@ -401,7 +401,7 @@ void luaK_exp2nextreg (FuncState *fs, expdesc *e) { | |||
| 401 | 401 | ||
| 402 | 402 | ||
| 403 | int luaK_exp2anyreg (FuncState *fs, expdesc *e) { | 403 | int luaK_exp2anyreg (FuncState *fs, expdesc *e) { |
| 404 | dischargevars(fs, e); | 404 | luaK_dischargevars(fs, e); |
| 405 | if (e->k == VNONRELOC) { | 405 | if (e->k == VNONRELOC) { |
| 406 | if (!hasjumps(e)) return e->u.i.info; /* exp is already in a register */ | 406 | if (!hasjumps(e)) return e->u.i.info; /* exp is already in a register */ |
| 407 | if (e->u.i.info >= fs->nactloc) { /* reg. is not a local? */ | 407 | if (e->u.i.info >= fs->nactloc) { /* reg. is not a local? */ |
| @@ -418,7 +418,7 @@ void luaK_exp2val (FuncState *fs, expdesc *e) { | |||
| 418 | if (hasjumps(e)) | 418 | if (hasjumps(e)) |
| 419 | luaK_exp2anyreg(fs, e); | 419 | luaK_exp2anyreg(fs, e); |
| 420 | else | 420 | else |
| 421 | dischargevars(fs, e); | 421 | luaK_dischargevars(fs, e); |
| 422 | } | 422 | } |
| 423 | 423 | ||
| 424 | 424 | ||
| @@ -510,7 +510,7 @@ static int jumponcond (FuncState *fs, expdesc *e, OpCode op) { | |||
| 510 | 510 | ||
| 511 | void luaK_goiftrue (FuncState *fs, expdesc *e) { | 511 | void luaK_goiftrue (FuncState *fs, expdesc *e) { |
| 512 | int pc; /* pc of last jump */ | 512 | int pc; /* pc of last jump */ |
| 513 | dischargevars(fs, e); | 513 | luaK_dischargevars(fs, e); |
| 514 | switch (e->k) { | 514 | switch (e->k) { |
| 515 | case VK: case VNUMBER: { | 515 | case VK: case VNUMBER: { |
| 516 | pc = NO_JUMP; /* always true; do nothing */ | 516 | pc = NO_JUMP; /* always true; do nothing */ |
| @@ -544,7 +544,7 @@ void luaK_goiftrue (FuncState *fs, expdesc *e) { | |||
| 544 | 544 | ||
| 545 | static void luaK_goiffalse (FuncState *fs, expdesc *e) { | 545 | static void luaK_goiffalse (FuncState *fs, expdesc *e) { |
| 546 | int pc; /* pc of last jump */ | 546 | int pc; /* pc of last jump */ |
| 547 | dischargevars(fs, e); | 547 | luaK_dischargevars(fs, e); |
| 548 | switch (e->k) { | 548 | switch (e->k) { |
| 549 | case VNIL: { | 549 | case VNIL: { |
| 550 | pc = NO_JUMP; /* always false; do nothing */ | 550 | pc = NO_JUMP; /* always false; do nothing */ |
| @@ -573,7 +573,7 @@ static void luaK_goiffalse (FuncState *fs, expdesc *e) { | |||
| 573 | 573 | ||
| 574 | 574 | ||
| 575 | static void codenot (FuncState *fs, expdesc *e) { | 575 | static void codenot (FuncState *fs, expdesc *e) { |
| 576 | dischargevars(fs, e); | 576 | luaK_dischargevars(fs, e); |
| 577 | switch (e->k) { | 577 | switch (e->k) { |
| 578 | case VNIL: { | 578 | case VNIL: { |
| 579 | e->u.n = 1; | 579 | e->u.n = 1; |
| @@ -680,14 +680,14 @@ void luaK_posfix (FuncState *fs, BinOpr op, expdesc *e1, expdesc *e2) { | |||
| 680 | switch (op) { | 680 | switch (op) { |
| 681 | case OPR_AND: { | 681 | case OPR_AND: { |
| 682 | lua_assert(e1->t == NO_JUMP); /* list must be closed */ | 682 | lua_assert(e1->t == NO_JUMP); /* list must be closed */ |
| 683 | dischargevars(fs, e2); | 683 | luaK_dischargevars(fs, e2); |
| 684 | luaK_concat(fs, &e1->f, e2->f); | 684 | luaK_concat(fs, &e1->f, e2->f); |
| 685 | e1->k = e2->k; e1->u = e2->u; e1->t = e2->t; | 685 | e1->k = e2->k; e1->u = e2->u; e1->t = e2->t; |
| 686 | break; | 686 | break; |
| 687 | } | 687 | } |
| 688 | case OPR_OR: { | 688 | case OPR_OR: { |
| 689 | lua_assert(e1->f == NO_JUMP); /* list must be closed */ | 689 | lua_assert(e1->f == NO_JUMP); /* list must be closed */ |
| 690 | dischargevars(fs, e2); | 690 | luaK_dischargevars(fs, e2); |
| 691 | luaK_concat(fs, &e1->t, e2->t); | 691 | luaK_concat(fs, &e1->t, e2->t); |
| 692 | e1->k = e2->k; e1->u = e2->u; e1->f = e2->f; | 692 | e1->k = e2->k; e1->u = e2->u; e1->f = e2->f; |
| 693 | break; | 693 | break; |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lcode.h,v 1.21 2001/02/23 17:17:25 roberto Exp roberto $ | 2 | ** $Id: lcode.h,v 1.22 2001/06/05 18:17:01 roberto Exp roberto $ |
| 3 | ** Code generator for Lua | 3 | ** Code generator for Lua |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -44,6 +44,7 @@ int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C); | |||
| 44 | void luaK_nil (FuncState *fs, int from, int n); | 44 | void luaK_nil (FuncState *fs, int from, int n); |
| 45 | void luaK_reserveregs (FuncState *fs, int n); | 45 | void luaK_reserveregs (FuncState *fs, int n); |
| 46 | int luaK_stringk (FuncState *fs, TString *s); | 46 | int luaK_stringk (FuncState *fs, TString *s); |
| 47 | void luaK_dischargevars (FuncState *fs, expdesc *e); | ||
| 47 | int luaK_exp2anyreg (FuncState *fs, expdesc *e); | 48 | int luaK_exp2anyreg (FuncState *fs, expdesc *e); |
| 48 | void luaK_exp2nextreg (FuncState *fs, expdesc *e); | 49 | void luaK_exp2nextreg (FuncState *fs, expdesc *e); |
| 49 | void luaK_exp2val (FuncState *fs, expdesc *e); | 50 | void luaK_exp2val (FuncState *fs, expdesc *e); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lparser.c,v 1.147 2001/06/08 19:00:57 roberto Exp roberto $ | 2 | ** $Id: lparser.c,v 1.148 2001/06/11 14:56:42 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 | */ |
| @@ -636,6 +636,7 @@ static void primaryexp (LexState *ls, expdesc *v) { | |||
| 636 | next(ls); | 636 | next(ls); |
| 637 | expr(ls, v); | 637 | expr(ls, v); |
| 638 | check(ls, l_c(')')); | 638 | check(ls, l_c(')')); |
| 639 | luaK_dischargevars(ls->fs, v); | ||
| 639 | return; | 640 | return; |
| 640 | } | 641 | } |
| 641 | case TK_NAME: { | 642 | case TK_NAME: { |
