aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lcode.c19
-rw-r--r--lcode.h7
-rw-r--r--lparser.c21
3 files changed, 27 insertions, 20 deletions
diff --git a/lcode.c b/lcode.c
index 5458d766..debb26e1 100644
--- a/lcode.c
+++ b/lcode.c
@@ -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
722static void codearith (FuncState *fs, OpCode op, expdesc *e1, expdesc *e2) { 722static 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
758void luaK_prefix (FuncState *fs, UnOpr op, expdesc *e) { 760void 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
809void luaK_posfix (FuncState *fs, BinOpr op, expdesc *e1, expdesc *e2) { 811void 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: {
diff --git a/lcode.h b/lcode.h
index 44996a43..f081022a 100644
--- a/lcode.h
+++ b/lcode.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lcode.h,v 1.52 2009/09/23 20:33:05 roberto Exp roberto $ 2** $Id: lcode.h,v 1.53 2010/02/26 20:40:29 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*/
@@ -73,9 +73,10 @@ LUAI_FUNC void luaK_patchlist (FuncState *fs, int list, int target);
73LUAI_FUNC void luaK_patchtohere (FuncState *fs, int list); 73LUAI_FUNC void luaK_patchtohere (FuncState *fs, int list);
74LUAI_FUNC void luaK_concat (FuncState *fs, int *l1, int l2); 74LUAI_FUNC void luaK_concat (FuncState *fs, int *l1, int l2);
75LUAI_FUNC int luaK_getlabel (FuncState *fs); 75LUAI_FUNC int luaK_getlabel (FuncState *fs);
76LUAI_FUNC void luaK_prefix (FuncState *fs, UnOpr op, expdesc *v); 76LUAI_FUNC void luaK_prefix (FuncState *fs, UnOpr op, expdesc *v, int line);
77LUAI_FUNC void luaK_infix (FuncState *fs, BinOpr op, expdesc *v); 77LUAI_FUNC void luaK_infix (FuncState *fs, BinOpr op, expdesc *v);
78LUAI_FUNC void luaK_posfix (FuncState *fs, BinOpr op, expdesc *v1, expdesc *v2); 78LUAI_FUNC void luaK_posfix (FuncState *fs, BinOpr op, expdesc *v1,
79 expdesc *v2, int line);
79LUAI_FUNC void luaK_setlist (FuncState *fs, int base, int nelems, int tostore); 80LUAI_FUNC void luaK_setlist (FuncState *fs, int base, int nelems, int tostore);
80 81
81 82
diff --git a/lparser.c b/lparser.c
index 62c88fdb..1d603544 100644
--- a/lparser.c
+++ b/lparser.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lparser.c,v 2.81 2010/04/05 16:26:37 roberto Exp roberto $ 2** $Id: lparser.c,v 2.82 2010/04/05 16:35:37 roberto Exp roberto $
3** Lua Parser 3** Lua Parser
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -670,15 +670,12 @@ static int explist1 (LexState *ls, expdesc *v) {
670} 670}
671 671
672 672
673static void funcargs (LexState *ls, expdesc *f) { 673static void funcargs (LexState *ls, expdesc *f, int line) {
674 FuncState *fs = ls->fs; 674 FuncState *fs = ls->fs;
675 expdesc args; 675 expdesc args;
676 int base, nparams; 676 int base, nparams;
677 int line = ls->linenumber;
678 switch (ls->t.token) { 677 switch (ls->t.token) {
679 case '(': { /* funcargs -> `(' [ explist1 ] `)' */ 678 case '(': { /* funcargs -> `(' [ explist1 ] `)' */
680 if (line != ls->lastline)
681 luaX_syntaxerror(ls,"ambiguous syntax (function call x new statement)");
682 luaX_next(ls); 679 luaX_next(ls);
683 if (ls->t.token == ')') /* arg list is empty? */ 680 if (ls->t.token == ')') /* arg list is empty? */
684 args.k = VVOID; 681 args.k = VVOID;
@@ -755,6 +752,7 @@ static void primaryexp (LexState *ls, expdesc *v) {
755 /* primaryexp -> 752 /* primaryexp ->
756 prefixexp { `.' NAME | `[' exp `]' | `:' NAME funcargs | funcargs } */ 753 prefixexp { `.' NAME | `[' exp `]' | `:' NAME funcargs | funcargs } */
757 FuncState *fs = ls->fs; 754 FuncState *fs = ls->fs;
755 int line = ls->linenumber;
758 prefixexp(ls, v); 756 prefixexp(ls, v);
759 for (;;) { 757 for (;;) {
760 switch (ls->t.token) { 758 switch (ls->t.token) {
@@ -774,12 +772,12 @@ static void primaryexp (LexState *ls, expdesc *v) {
774 luaX_next(ls); 772 luaX_next(ls);
775 checkname(ls, &key); 773 checkname(ls, &key);
776 luaK_self(fs, v, &key); 774 luaK_self(fs, v, &key);
777 funcargs(ls, v); 775 funcargs(ls, v, line);
778 break; 776 break;
779 } 777 }
780 case '(': case TK_STRING: case '{': { /* funcargs */ 778 case '(': case TK_STRING: case '{': { /* funcargs */
781 luaK_exp2nextreg(fs, v); 779 luaK_exp2nextreg(fs, v);
782 funcargs(ls, v); 780 funcargs(ls, v, line);
783 break; 781 break;
784 } 782 }
785 default: return; 783 default: return;
@@ -894,9 +892,10 @@ static BinOpr subexpr (LexState *ls, expdesc *v, unsigned int limit) {
894 enterlevel(ls); 892 enterlevel(ls);
895 uop = getunopr(ls->t.token); 893 uop = getunopr(ls->t.token);
896 if (uop != OPR_NOUNOPR) { 894 if (uop != OPR_NOUNOPR) {
895 int line = ls->linenumber;
897 luaX_next(ls); 896 luaX_next(ls);
898 subexpr(ls, v, UNARY_PRIORITY); 897 subexpr(ls, v, UNARY_PRIORITY);
899 luaK_prefix(ls->fs, uop, v); 898 luaK_prefix(ls->fs, uop, v, line);
900 } 899 }
901 else simpleexp(ls, v); 900 else simpleexp(ls, v);
902 /* expand while operators have priorities higher than `limit' */ 901 /* expand while operators have priorities higher than `limit' */
@@ -904,11 +903,12 @@ static BinOpr subexpr (LexState *ls, expdesc *v, unsigned int limit) {
904 while (op != OPR_NOBINOPR && priority[op].left > limit) { 903 while (op != OPR_NOBINOPR && priority[op].left > limit) {
905 expdesc v2; 904 expdesc v2;
906 BinOpr nextop; 905 BinOpr nextop;
906 int line = ls->linenumber;
907 luaX_next(ls); 907 luaX_next(ls);
908 luaK_infix(ls->fs, op, v); 908 luaK_infix(ls->fs, op, v);
909 /* read sub-expression with higher priority */ 909 /* read sub-expression with higher priority */
910 nextop = subexpr(ls, &v2, priority[op].right); 910 nextop = subexpr(ls, &v2, priority[op].right);
911 luaK_posfix(ls->fs, op, v, &v2); 911 luaK_posfix(ls->fs, op, v, &v2, line);
912 op = nextop; 912 op = nextop;
913 } 913 }
914 leavelevel(ls); 914 leavelevel(ls);
@@ -1346,6 +1346,9 @@ static void retstat (LexState *ls) {
1346static int statement (LexState *ls) { 1346static int statement (LexState *ls) {
1347 int line = ls->linenumber; /* may be needed for error messages */ 1347 int line = ls->linenumber; /* may be needed for error messages */
1348 switch (ls->t.token) { 1348 switch (ls->t.token) {
1349 case ';': { /* stat -> <empty statement> */
1350 return 0;
1351 }
1349 case TK_IF: { /* stat -> ifstat */ 1352 case TK_IF: { /* stat -> ifstat */
1350 ifstat(ls, line); 1353 ifstat(ls, line);
1351 return 0; 1354 return 0;