diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2007-03-09 15:50:56 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2007-03-09 15:50:56 -0300 |
commit | 3b19bd4d5768224b80fbc4983167821ada3f4485 (patch) | |
tree | 45b8e2500bf6ff51ed7d53bb34dfa6b43e68171a | |
parent | 08f902cf495752494088392a86f11a22755cc8cb (diff) | |
download | lua-3b19bd4d5768224b80fbc4983167821ada3f4485.tar.gz lua-3b19bd4d5768224b80fbc4983167821ada3f4485.tar.bz2 lua-3b19bd4d5768224b80fbc4983167821ada3f4485.zip |
bug: wrong code when constant is coded after it should be
-rw-r--r-- | lcode.c | 31 |
1 files changed, 22 insertions, 9 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lcode.c,v 2.30 2006/09/22 19:14:17 roberto Exp roberto $ | 2 | ** $Id: lcode.c,v 2.31 2006/10/10 17:39:00 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 | */ |
@@ -443,19 +443,21 @@ void luaK_exp2val (FuncState *fs, expdesc *e) { | |||
443 | int luaK_exp2RK (FuncState *fs, expdesc *e) { | 443 | int luaK_exp2RK (FuncState *fs, expdesc *e) { |
444 | luaK_exp2val(fs, e); | 444 | luaK_exp2val(fs, e); |
445 | switch (e->k) { | 445 | switch (e->k) { |
446 | case VKNUM: | ||
447 | case VTRUE: | 446 | case VTRUE: |
448 | case VFALSE: | 447 | case VFALSE: |
449 | case VNIL: { | 448 | case VNIL: { |
450 | if (fs->nk <= MAXINDEXRK) { /* constant fit in RK operand? */ | 449 | if (fs->nk <= MAXINDEXRK) { /* constant fit in RK operand? */ |
451 | e->u.s.info = (e->k == VNIL) ? nilK(fs) : | 450 | e->u.s.info = (e->k == VNIL) ? nilK(fs) : boolK(fs, (e->k == VTRUE)); |
452 | (e->k == VKNUM) ? luaK_numberK(fs, e->u.nval) : | ||
453 | boolK(fs, (e->k == VTRUE)); | ||
454 | e->k = VK; | 451 | e->k = VK; |
455 | return RKASK(e->u.s.info); | 452 | return RKASK(e->u.s.info); |
456 | } | 453 | } |
457 | else break; | 454 | else break; |
458 | } | 455 | } |
456 | case VKNUM: { | ||
457 | e->u.s.info = luaK_numberK(fs, e->u.nval); | ||
458 | e->k = VK; | ||
459 | /* go through */ | ||
460 | } | ||
459 | case VK: { | 461 | case VK: { |
460 | if (e->u.s.info <= MAXINDEXRK) /* constant fit in argC? */ | 462 | if (e->u.s.info <= MAXINDEXRK) /* constant fit in argC? */ |
461 | return RKASK(e->u.s.info); | 463 | return RKASK(e->u.s.info); |
@@ -661,10 +663,16 @@ static void codearith (FuncState *fs, OpCode op, expdesc *e1, expdesc *e2) { | |||
661 | if (constfolding(op, e1, e2)) | 663 | if (constfolding(op, e1, e2)) |
662 | return; | 664 | return; |
663 | else { | 665 | else { |
664 | int o1 = luaK_exp2RK(fs, e1); | ||
665 | int o2 = (op != OP_UNM && op != OP_LEN) ? luaK_exp2RK(fs, e2) : 0; | 666 | int o2 = (op != OP_UNM && op != OP_LEN) ? luaK_exp2RK(fs, e2) : 0; |
666 | freeexp(fs, e2); | 667 | int o1 = luaK_exp2RK(fs, e1); |
667 | freeexp(fs, e1); | 668 | if (o1 > o2) { |
669 | freeexp(fs, e1); | ||
670 | freeexp(fs, e2); | ||
671 | } | ||
672 | else { | ||
673 | freeexp(fs, e2); | ||
674 | freeexp(fs, e1); | ||
675 | } | ||
668 | e1->u.s.info = luaK_codeABC(fs, op, 0, o1, o2); | 676 | e1->u.s.info = luaK_codeABC(fs, op, 0, o1, o2); |
669 | e1->k = VRELOCABLE; | 677 | e1->k = VRELOCABLE; |
670 | } | 678 | } |
@@ -722,10 +730,15 @@ void luaK_infix (FuncState *fs, BinOpr op, expdesc *v) { | |||
722 | luaK_exp2nextreg(fs, v); /* operand must be on the `stack' */ | 730 | luaK_exp2nextreg(fs, v); /* operand must be on the `stack' */ |
723 | break; | 731 | break; |
724 | } | 732 | } |
725 | default: { | 733 | case OPR_ADD: case OPR_SUB: case OPR_MUL: case OPR_DIV: |
734 | case OPR_MOD: case OPR_POW: { | ||
726 | if (!isnumeral(v)) luaK_exp2RK(fs, v); | 735 | if (!isnumeral(v)) luaK_exp2RK(fs, v); |
727 | break; | 736 | break; |
728 | } | 737 | } |
738 | default: { | ||
739 | luaK_exp2RK(fs, v); | ||
740 | break; | ||
741 | } | ||
729 | } | 742 | } |
730 | } | 743 | } |
731 | 744 | ||