History

Lua 5.1.2-rc1

Lua Team committed 19 years ago

Commit ce51ee41 parent 954596315 files · +362 −206Browse files

Showing the changes to src/lcode.c (1 of 15 files). Show all

Unified · Split

src/lcode.c+30−14
@@ -1,5 +1,5 @@
11 /*
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 $
33 ** Code generator for Lua
44 ** See Copyright Notice in lua.h
55 */
@@ -35,15 +35,20 @@ static int isnumeral(expdesc *e) { · 29 unmodified lines
3535 void luaK_nil (FuncState *fs, int from, int n) {
3636 Instruction *previous;
3737 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+ }
4752 }
4853 }
4954 }
@@ -657,10 +662,16 @@ static void codearith (FuncState *fs, OpCode op, expdesc *e1, expdesc *e2) { · 607 unmodified lines
657662 if (constfolding(op, e1, e2))
658663 return;
659664 else {
660− int o1 = luaK_exp2RK(fs, e1);
661665 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+ }
664675 e1->u.s.info = luaK_codeABC(fs, op, 0, o1, o2);
665676 e1->k = VRELOCABLE;
666677 }
@@ -718,10 +729,15 @@ void luaK_infix (FuncState *fs, BinOpr op, expdesc *v) { · 51 unmodified lines
718729 luaK_exp2nextreg(fs, v); /* operand must be on the `stack' */
719730 break;
720731 }
721− default: {
732+ case OPR_ADD: case OPR_SUB: case OPR_MUL: case OPR_DIV:
733+ case OPR_MOD: case OPR_POW: {
722734 if (!isnumeral(v)) luaK_exp2RK(fs, v);
723735 break;
724736 }
737+ default: {
738+ luaK_exp2RK(fs, v);
739+ break;
740+ }
725741 }
726742 }
727743