aboutsummaryrefslogtreecommitdiff
path: root/lparser.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-03-08 21:19:22 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-03-08 21:19:22 -0300
commit88b306f495fa7034c708c6b75a355a6deee51c58 (patch)
tree7d8faaacd1f5c753ed9e77f0e2c8e27b9a002635 /lparser.c
parent563de491be90601f23a735aede89ea9a3ef86ee9 (diff)
downloadlua-88b306f495fa7034c708c6b75a355a6deee51c58.tar.gz
lua-88b306f495fa7034c708c6b75a355a6deee51c58.tar.bz2
lua-88b306f495fa7034c708c6b75a355a6deee51c58.zip
some optimizations
Diffstat (limited to 'lparser.c')
-rw-r--r--lparser.c20
1 files changed, 9 insertions, 11 deletions
diff --git a/lparser.c b/lparser.c
index 4c1eeb80..7fb5a0d7 100644
--- a/lparser.c
+++ b/lparser.c
@@ -716,7 +716,7 @@ static int get_priority (int op, int *rp) {
716 716
717 case '+': case '-': *rp = 5; return 5; 717 case '+': case '-': *rp = 5; return 5;
718 718
719 case CONC: *rp = 4; return 4; /* left associative (?) */ 719 case CONC: *rp = 3; return 4; /* right associative (?) */
720 720
721 case EQ: case NE: case '>': case '<': case LE: case GE: 721 case EQ: case NE: case '>': case '<': case LE: case GE:
722 *rp = 2; return 2; 722 *rp = 2; return 2;
@@ -941,18 +941,17 @@ static void namestat (LexState *ls) {
941 941
942 942
943static void ifpart (LexState *ls, int line) { 943static void ifpart (LexState *ls, int line) {
944 /* ifpart -> cond THEN block [ELSE block | ELSEIF ifpart] */ 944 /* ifpart -> cond THEN block (ELSEIF ifpart | [ELSE block] END) */
945 FuncState *fs = ls->fs; 945 FuncState *fs = ls->fs;
946 int c; /* address of the conditional jump */ 946 int c; /* address of the conditional jump */
947 int je; /* address of the unconditional jump (to skip `else' part) */
948 int elseinit; 947 int elseinit;
949 next(ls); /* skip IF or ELSEIF */ 948 next(ls); /* skip IF or ELSEIF */
950 exp1(ls); /* cond */ 949 exp1(ls); /* cond */
951 c = luaK_S(ls, IFFJMP, 0, -1); /* jump over `then' part if `cond' is false */ 950 c = luaK_S(ls, IFFJMP, 0, -1); /* 1st jump: over `then' part */
952 check(ls, THEN); 951 check(ls, THEN);
953 block(ls); /* `then' part */ 952 block(ls); /* `then' part */
954 je = luaK_S(ls, JMP, 0, 0); /* jump over `else' part after `then' */ 953 luaK_S(ls, JMP, 0, 0); /* 2nd jump: over `else' part */
955 elseinit = luaK_getlabel(ls); 954 elseinit = luaK_getlabel(ls); /* address of 2nd jump == elseinit-1 */
956 if (ls->token == ELSEIF) 955 if (ls->token == ELSEIF)
957 ifpart(ls, line); 956 ifpart(ls, line);
958 else { 957 else {
@@ -961,13 +960,12 @@ static void ifpart (LexState *ls, int line) {
961 check_match(ls, END, IF, line); 960 check_match(ls, END, IF, line);
962 } 961 }
963 if (fs->pc > elseinit) { /* is there an `else' part? */ 962 if (fs->pc > elseinit) { /* is there an `else' part? */
964 luaK_fixjump(ls, je, luaK_getlabel(ls)); /* last jump jumps over it */ 963 luaK_fixjump(ls, c, elseinit); /* fix 1st jump to `else' part */
965 luaK_fixjump(ls, c, elseinit); /* fix first jump to `else' part */ 964 luaK_fixjump(ls, elseinit-1, luaK_getlabel(ls)); /* fix 2nd jump */
966 } 965 }
967 else { /* no else part */ 966 else { /* no else part */
968 fs->pc--; /* remove last jump */ 967 fs->pc--; /* remove 2nd jump */
969 LUA_ASSERT(L, fs->pc == je, "jump out of place"); 968 luaK_fixjump(ls, c, luaK_getlabel(ls)); /* fix 1st jump to `if' end */
970 luaK_fixjump(ls, c, luaK_getlabel(ls)); /* fix first jump to `if' end */
971 } 969 }
972} 970}
973 971