diff options
Diffstat (limited to 'lcode.c')
-rw-r--r-- | lcode.c | 19 |
1 files changed, 11 insertions, 8 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lcode.c,v 2.44 2010/02/26 20:40:29 roberto Exp roberto $ | 2 | ** $Id: lcode.c,v 2.45 2010/03/12 19:14:06 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 | */ |
@@ -719,7 +719,8 @@ static int constfolding (OpCode op, expdesc *e1, expdesc *e2) { | |||
719 | } | 719 | } |
720 | 720 | ||
721 | 721 | ||
722 | static void codearith (FuncState *fs, OpCode op, expdesc *e1, expdesc *e2) { | 722 | static void codearith (FuncState *fs, OpCode op, |
723 | expdesc *e1, expdesc *e2, int line) { | ||
723 | if (constfolding(op, e1, e2)) | 724 | if (constfolding(op, e1, e2)) |
724 | return; | 725 | return; |
725 | else { | 726 | else { |
@@ -735,6 +736,7 @@ static void codearith (FuncState *fs, OpCode op, expdesc *e1, expdesc *e2) { | |||
735 | } | 736 | } |
736 | e1->u.s.info = luaK_codeABC(fs, op, 0, o1, o2); | 737 | e1->u.s.info = luaK_codeABC(fs, op, 0, o1, o2); |
737 | e1->k = VRELOCABLE; | 738 | e1->k = VRELOCABLE; |
739 | luaK_fixline(fs, line); | ||
738 | } | 740 | } |
739 | } | 741 | } |
740 | 742 | ||
@@ -755,7 +757,7 @@ static void codecomp (FuncState *fs, OpCode op, int cond, expdesc *e1, | |||
755 | } | 757 | } |
756 | 758 | ||
757 | 759 | ||
758 | void luaK_prefix (FuncState *fs, UnOpr op, expdesc *e) { | 760 | void luaK_prefix (FuncState *fs, UnOpr op, expdesc *e, int line) { |
759 | expdesc e2; | 761 | expdesc e2; |
760 | e2.t = e2.f = NO_JUMP; e2.k = VKNUM; e2.u.nval = 0; | 762 | e2.t = e2.f = NO_JUMP; e2.k = VKNUM; e2.u.nval = 0; |
761 | switch (op) { | 763 | switch (op) { |
@@ -764,14 +766,14 @@ void luaK_prefix (FuncState *fs, UnOpr op, expdesc *e) { | |||
764 | e->u.nval = luai_numunm(NULL, e->u.nval); /* fold it */ | 766 | e->u.nval = luai_numunm(NULL, e->u.nval); /* fold it */ |
765 | else { | 767 | else { |
766 | luaK_exp2anyreg(fs, e); | 768 | luaK_exp2anyreg(fs, e); |
767 | codearith(fs, OP_UNM, e, &e2); | 769 | codearith(fs, OP_UNM, e, &e2, line); |
768 | } | 770 | } |
769 | break; | 771 | break; |
770 | } | 772 | } |
771 | case OPR_NOT: codenot(fs, e); break; | 773 | case OPR_NOT: codenot(fs, e); break; |
772 | case OPR_LEN: { | 774 | case OPR_LEN: { |
773 | luaK_exp2anyreg(fs, e); /* cannot operate on constants */ | 775 | luaK_exp2anyreg(fs, e); /* cannot operate on constants */ |
774 | codearith(fs, OP_LEN, e, &e2); | 776 | codearith(fs, OP_LEN, e, &e2, line); |
775 | break; | 777 | break; |
776 | } | 778 | } |
777 | default: lua_assert(0); | 779 | default: lua_assert(0); |
@@ -806,7 +808,8 @@ void luaK_infix (FuncState *fs, BinOpr op, expdesc *v) { | |||
806 | } | 808 | } |
807 | 809 | ||
808 | 810 | ||
809 | void luaK_posfix (FuncState *fs, BinOpr op, expdesc *e1, expdesc *e2) { | 811 | void luaK_posfix (FuncState *fs, BinOpr op, |
812 | expdesc *e1, expdesc *e2, int line) { | ||
810 | switch (op) { | 813 | switch (op) { |
811 | case OPR_AND: { | 814 | case OPR_AND: { |
812 | lua_assert(e1->t == NO_JUMP); /* list must be closed */ | 815 | lua_assert(e1->t == NO_JUMP); /* list must be closed */ |
@@ -832,13 +835,13 @@ void luaK_posfix (FuncState *fs, BinOpr op, expdesc *e1, expdesc *e2) { | |||
832 | } | 835 | } |
833 | else { | 836 | else { |
834 | luaK_exp2nextreg(fs, e2); /* operand must be on the 'stack' */ | 837 | luaK_exp2nextreg(fs, e2); /* operand must be on the 'stack' */ |
835 | codearith(fs, OP_CONCAT, e1, e2); | 838 | codearith(fs, OP_CONCAT, e1, e2, line); |
836 | } | 839 | } |
837 | break; | 840 | break; |
838 | } | 841 | } |
839 | case OPR_ADD: case OPR_SUB: case OPR_MUL: case OPR_DIV: | 842 | case OPR_ADD: case OPR_SUB: case OPR_MUL: case OPR_DIV: |
840 | case OPR_MOD: case OPR_POW: { | 843 | case OPR_MOD: case OPR_POW: { |
841 | codearith(fs, cast(OpCode, op - OPR_ADD + OP_ADD), e1, e2); | 844 | codearith(fs, cast(OpCode, op - OPR_ADD + OP_ADD), e1, e2, line); |
842 | break; | 845 | break; |
843 | } | 846 | } |
844 | case OPR_EQ: case OPR_LT: case OPR_LE: { | 847 | case OPR_EQ: case OPR_LT: case OPR_LE: { |