Showing the changes to src/lcode.c (1 of 15 files). Show all
Unified · Split
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lcode.c,v 2.25 2006/03/21 19:28:49 roberto Exp $ | |
| 2 | +** $Id: lcode.c,v 2.25a 2006/03/21 19:28:49 roberto Exp $ | |
| 3 | 3 | ** Code generator for Lua |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -35,15 +35,20 @@ static int isnumeral(expdesc *e) { · 29 unmodified lines | ||
| 35 | 35 | void luaK_nil (FuncState *fs, int from, int n) { |
| 36 | 36 | Instruction *previous; |
| 37 | 37 | if (fs->pc > fs->lasttarget) { /* no jumps to current position? */ |
| 38 | − if (fs->pc == 0) /* function start? */ | |
| 39 | − return; /* positions are already clean */ | |
| 40 | − if (GET_OPCODE(*(previous = &fs->f->code[fs->pc-1])) == OP_LOADNIL) { | |
| 41 | − int pfrom = GETARG_A(*previous); | |
| 42 | − int pto = GETARG_B(*previous); | |
| 43 | − if (pfrom <= from && from <= pto+1) { /* can connect both? */ | |
| 44 | − if (from+n-1 > pto) | |
| 45 | − SETARG_B(*previous, from+n-1); | |
| 46 | − return; | |
| 38 | + if (fs->pc == 0) { /* function start? */ | |
| 39 | + if (from >= fs->nactvar) | |
| 40 | + return; /* positions are already clean */ | |
| 41 | + } | |
| 42 | + else { | |
| 43 | + previous = &fs->f->code[fs->pc-1]; | |
| 44 | + if (GET_OPCODE(*previous) == OP_LOADNIL) { | |
| 45 | + int pfrom = GETARG_A(*previous); | |
| 46 | + int pto = GETARG_B(*previous); | |
| 47 | + if (pfrom <= from && from <= pto+1) { /* can connect both? */ | |
| 48 | + if (from+n-1 > pto) | |
| 49 | + SETARG_B(*previous, from+n-1); | |
| 50 | + return; | |
| 51 | + } | |
| 47 | 52 | } |
| 48 | 53 | } |
| 49 | 54 | } |
| @@ -657,10 +662,16 @@ static void codearith (FuncState *fs, OpCode op, expdesc *e1, expdesc *e2) { · 607 unmodified lines | ||
| 657 | 662 | if (constfolding(op, e1, e2)) |
| 658 | 663 | return; |
| 659 | 664 | else { |
| 660 | − int o1 = luaK_exp2RK(fs, e1); | |
| 661 | 665 | int o2 = (op != OP_UNM && op != OP_LEN) ? luaK_exp2RK(fs, e2) : 0; |
| 662 | − freeexp(fs, e2); | |
| 663 | − freeexp(fs, e1); | |
| 666 | + int o1 = luaK_exp2RK(fs, e1); | |
| 667 | + if (o1 > o2) { | |
| 668 | + freeexp(fs, e1); | |
| 669 | + freeexp(fs, e2); | |
| 670 | + } | |
| 671 | + else { | |
| 672 | + freeexp(fs, e2); | |
| 673 | + freeexp(fs, e1); | |
| 674 | + } | |
| 664 | 675 | e1->u.s.info = luaK_codeABC(fs, op, 0, o1, o2); |
| 665 | 676 | e1->k = VRELOCABLE; |
| 666 | 677 | } |
| @@ -718,10 +729,15 @@ void luaK_infix (FuncState *fs, BinOpr op, expdesc *v) { · 51 unmodified lines | ||
| 718 | 729 | luaK_exp2nextreg(fs, v); /* operand must be on the `stack' */ |
| 719 | 730 | break; |
| 720 | 731 | } |
| 721 | − default: { | |
| 732 | + case OPR_ADD: case OPR_SUB: case OPR_MUL: case OPR_DIV: | |
| 733 | + case OPR_MOD: case OPR_POW: { | |
| 722 | 734 | if (!isnumeral(v)) luaK_exp2RK(fs, v); |
| 723 | 735 | break; |
| 724 | 736 | } |
| 737 | + default: { | |
| 738 | + luaK_exp2RK(fs, v); | |
| 739 | + break; | |
| 740 | + } | |
| 725 | 741 | } |
| 726 | 742 | } |
| 727 | 743 | |