aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2009-06-18 13:35:05 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2009-06-18 13:35:05 -0300
commitd7872dcf91eb2075312a03973a6cdb489610c796 (patch)
treed07d6d33355ad2c56dc6343317c3021294cf49f7
parent14115170bc9411e1c13871b87e50d83d60a4bb1c (diff)
downloadlua-d7872dcf91eb2075312a03973a6cdb489610c796.tar.gz
lua-d7872dcf91eb2075312a03973a6cdb489610c796.tar.bz2
lua-d7872dcf91eb2075312a03973a6cdb489610c796.zip
small optimization (reorder of BinOpr enum to unify some cases
in switches)
-rw-r--r--lcode.c27
-rw-r--r--lcode.h8
-rw-r--r--lparser.c10
3 files changed, 23 insertions, 22 deletions
diff --git a/lcode.c b/lcode.c
index bbf4e813..3371b71c 100644
--- a/lcode.c
+++ b/lcode.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lcode.c,v 2.38 2009/06/15 13:52:08 roberto Exp roberto $ 2** $Id: lcode.c,v 2.39 2009/06/17 17:49:09 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*/
@@ -766,18 +766,19 @@ void luaK_posfix (FuncState *fs, BinOpr op, expdesc *e1, expdesc *e2) {
766 } 766 }
767 break; 767 break;
768 } 768 }
769 case OPR_ADD: codearith(fs, OP_ADD, e1, e2); break; 769 case OPR_ADD: case OPR_SUB: case OPR_MUL: case OPR_DIV:
770 case OPR_SUB: codearith(fs, OP_SUB, e1, e2); break; 770 case OPR_MOD: case OPR_POW: {
771 case OPR_MUL: codearith(fs, OP_MUL, e1, e2); break; 771 codearith(fs, op - OPR_ADD + OP_ADD, e1, e2);
772 case OPR_DIV: codearith(fs, OP_DIV, e1, e2); break; 772 break;
773 case OPR_MOD: codearith(fs, OP_MOD, e1, e2); break; 773 }
774 case OPR_POW: codearith(fs, OP_POW, e1, e2); break; 774 case OPR_EQ: case OPR_LT: case OPR_LE: {
775 case OPR_EQ: codecomp(fs, OP_EQ, 1, e1, e2); break; 775 codecomp(fs, op - OPR_EQ + OP_EQ, 1, e1, e2);
776 case OPR_NE: codecomp(fs, OP_EQ, 0, e1, e2); break; 776 break;
777 case OPR_LT: codecomp(fs, OP_LT, 1, e1, e2); break; 777 }
778 case OPR_LE: codecomp(fs, OP_LE, 1, e1, e2); break; 778 case OPR_NE: case OPR_GT: case OPR_GE: {
779 case OPR_GT: codecomp(fs, OP_LT, 0, e1, e2); break; 779 codecomp(fs, op - OPR_NE + OP_EQ, 0, e1, e2);
780 case OPR_GE: codecomp(fs, OP_LE, 0, e1, e2); break; 780 break;
781 }
781 default: lua_assert(0); 782 default: lua_assert(0);
782 } 783 }
783} 784}
diff --git a/lcode.h b/lcode.h
index 77f1450a..55426417 100644
--- a/lcode.h
+++ b/lcode.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lcode.h,v 1.49 2008/10/28 12:55:00 roberto Exp roberto $ 2** $Id: lcode.h,v 1.50 2009/06/10 16:52:03 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*/
@@ -21,13 +21,13 @@
21 21
22 22
23/* 23/*
24** grep "ORDER OPR" if you change these enums 24** grep "ORDER OPR" if you change these enums (ORDER OP)
25*/ 25*/
26typedef enum BinOpr { 26typedef enum BinOpr {
27 OPR_ADD, OPR_SUB, OPR_MUL, OPR_DIV, OPR_MOD, OPR_POW, 27 OPR_ADD, OPR_SUB, OPR_MUL, OPR_DIV, OPR_MOD, OPR_POW,
28 OPR_CONCAT, 28 OPR_CONCAT,
29 OPR_NE, OPR_EQ, 29 OPR_EQ, OPR_LT, OPR_LE,
30 OPR_LT, OPR_LE, OPR_GT, OPR_GE, 30 OPR_NE, OPR_GT, OPR_GE,
31 OPR_AND, OPR_OR, 31 OPR_AND, OPR_OR,
32 OPR_NOBINOPR 32 OPR_NOBINOPR
33} BinOpr; 33} BinOpr;
diff --git a/lparser.c b/lparser.c
index 753dbce2..d1016473 100644
--- a/lparser.c
+++ b/lparser.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lparser.c,v 2.62 2009/04/30 17:42:21 roberto Exp roberto $ 2** $Id: lparser.c,v 2.63 2009/06/10 16:52:03 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*/
@@ -813,10 +813,10 @@ static const struct {
813 lu_byte right; /* right priority */ 813 lu_byte right; /* right priority */
814} priority[] = { /* ORDER OPR */ 814} priority[] = { /* ORDER OPR */
815 {6, 6}, {6, 6}, {7, 7}, {7, 7}, {7, 7}, /* `+' `-' `*' `/' `%' */ 815 {6, 6}, {6, 6}, {7, 7}, {7, 7}, {7, 7}, /* `+' `-' `*' `/' `%' */
816 {10, 9}, {5, 4}, /* power and concat (right associative) */ 816 {10, 9}, {5, 4}, /* ^, .. (right associative) */
817 {3, 3}, {3, 3}, /* equality and inequality */ 817 {3, 3}, {3, 3}, {3, 3}, /* ==, <, <= */
818 {3, 3}, {3, 3}, {3, 3}, {3, 3}, /* order */ 818 {3, 3}, {3, 3}, {3, 3}, /* ~=, >, >= */
819 {2, 2}, {1, 1} /* logical (and/or) */ 819 {2, 2}, {1, 1} /* and, or */
820}; 820};
821 821
822#define UNARY_PRIORITY 8 /* priority for unary operators */ 822#define UNARY_PRIORITY 8 /* priority for unary operators */