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 @@
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** Code generator for Lua3** Code generator for Lua
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -35,15 +35,20 @@ static int isnumeral(expdesc *e) { · 29 unmodified lines
35void luaK_nil (FuncState *fs, int from, int n) {35void luaK_nil (FuncState *fs, int from, int n) {
36 Instruction *previous;36 Instruction *previous;
37 if (fs->pc > fs->lasttarget) { /* no jumps to current position? */37 if (fs->pc > fs->lasttarget) { /* no jumps to current position? */
38 if (fs->pc == 0) /* function start? */38 if (fs->pc == 0) { /* function start? */
39 return; /* positions are already clean */39 if (from >= fs->nactvar)
40 if (GET_OPCODE(*(previous = &fs->f->code[fs->pc-1])) == OP_LOADNIL) {40 return; /* positions are already clean */
41 int pfrom = GETARG_A(*previous);41 }
42 int pto = GETARG_B(*previous);42 else {
43 if (pfrom <= from && from <= pto+1) { /* can connect both? */43 previous = &fs->f->code[fs->pc-1];
44 if (from+n-1 > pto)44 if (GET_OPCODE(*previous) == OP_LOADNIL) {
45 SETARG_B(*previous, from+n-1);45 int pfrom = GETARG_A(*previous);
46 return;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 if (constfolding(op, e1, e2))662 if (constfolding(op, e1, e2))
658 return;663 return;
659 else {664 else {
660 int o1 = luaK_exp2RK(fs, e1);
661 int o2 = (op != OP_UNM && op != OP_LEN) ? luaK_exp2RK(fs, e2) : 0;665 int o2 = (op != OP_UNM && op != OP_LEN) ? luaK_exp2RK(fs, e2) : 0;
662 freeexp(fs, e2);666 int o1 = luaK_exp2RK(fs, e1);
663 freeexp(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 e1->u.s.info = luaK_codeABC(fs, op, 0, o1, o2);675 e1->u.s.info = luaK_codeABC(fs, op, 0, o1, o2);
665 e1->k = VRELOCABLE;676 e1->k = VRELOCABLE;
666 }677 }
@@ -718,10 +729,15 @@ void luaK_infix (FuncState *fs, BinOpr op, expdesc *v) { · 51 unmodified lines
718 luaK_exp2nextreg(fs, v); /* operand must be on the `stack' */729 luaK_exp2nextreg(fs, v); /* operand must be on the `stack' */
719 break;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 if (!isnumeral(v)) luaK_exp2RK(fs, v);734 if (!isnumeral(v)) luaK_exp2RK(fs, v);
723 break;735 break;
724 }736 }
737 default: {
738 luaK_exp2RK(fs, v);
739 break;
740 }
725 }741 }
726}742}
727 743