small optimization (reorder of BinOpr enum to unify some cases
in switches)
This commit is contained in:
27
lcode.c
27
lcode.c
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lcode.c,v 2.38 2009/06/15 13:52:08 roberto Exp roberto $
|
** $Id: lcode.c,v 2.39 2009/06/17 17:49:09 roberto Exp roberto $
|
||||||
** Code generator for Lua
|
** Code generator for Lua
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@@ -766,18 +766,19 @@ void luaK_posfix (FuncState *fs, BinOpr op, expdesc *e1, expdesc *e2) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case OPR_ADD: codearith(fs, OP_ADD, e1, e2); break;
|
case OPR_ADD: case OPR_SUB: case OPR_MUL: case OPR_DIV:
|
||||||
case OPR_SUB: codearith(fs, OP_SUB, e1, e2); break;
|
case OPR_MOD: case OPR_POW: {
|
||||||
case OPR_MUL: codearith(fs, OP_MUL, e1, e2); break;
|
codearith(fs, op - OPR_ADD + OP_ADD, e1, e2);
|
||||||
case OPR_DIV: codearith(fs, OP_DIV, e1, e2); break;
|
break;
|
||||||
case OPR_MOD: codearith(fs, OP_MOD, e1, e2); break;
|
}
|
||||||
case OPR_POW: codearith(fs, OP_POW, e1, e2); break;
|
case OPR_EQ: case OPR_LT: case OPR_LE: {
|
||||||
case OPR_EQ: codecomp(fs, OP_EQ, 1, e1, e2); break;
|
codecomp(fs, op - OPR_EQ + OP_EQ, 1, e1, e2);
|
||||||
case OPR_NE: codecomp(fs, OP_EQ, 0, e1, e2); break;
|
break;
|
||||||
case OPR_LT: codecomp(fs, OP_LT, 1, e1, e2); break;
|
}
|
||||||
case OPR_LE: codecomp(fs, OP_LE, 1, e1, e2); break;
|
case OPR_NE: case OPR_GT: case OPR_GE: {
|
||||||
case OPR_GT: codecomp(fs, OP_LT, 0, e1, e2); break;
|
codecomp(fs, op - OPR_NE + OP_EQ, 0, e1, e2);
|
||||||
case OPR_GE: codecomp(fs, OP_LE, 0, e1, e2); break;
|
break;
|
||||||
|
}
|
||||||
default: lua_assert(0);
|
default: lua_assert(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
8
lcode.h
8
lcode.h
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lcode.h,v 1.49 2008/10/28 12:55:00 roberto Exp roberto $
|
** $Id: lcode.h,v 1.50 2009/06/10 16:52:03 roberto Exp roberto $
|
||||||
** Code generator for Lua
|
** Code generator for Lua
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@@ -21,13 +21,13 @@
|
|||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** grep "ORDER OPR" if you change these enums
|
** grep "ORDER OPR" if you change these enums (ORDER OP)
|
||||||
*/
|
*/
|
||||||
typedef enum BinOpr {
|
typedef enum BinOpr {
|
||||||
OPR_ADD, OPR_SUB, OPR_MUL, OPR_DIV, OPR_MOD, OPR_POW,
|
OPR_ADD, OPR_SUB, OPR_MUL, OPR_DIV, OPR_MOD, OPR_POW,
|
||||||
OPR_CONCAT,
|
OPR_CONCAT,
|
||||||
OPR_NE, OPR_EQ,
|
OPR_EQ, OPR_LT, OPR_LE,
|
||||||
OPR_LT, OPR_LE, OPR_GT, OPR_GE,
|
OPR_NE, OPR_GT, OPR_GE,
|
||||||
OPR_AND, OPR_OR,
|
OPR_AND, OPR_OR,
|
||||||
OPR_NOBINOPR
|
OPR_NOBINOPR
|
||||||
} BinOpr;
|
} BinOpr;
|
||||||
|
|||||||
10
lparser.c
10
lparser.c
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lparser.c,v 2.62 2009/04/30 17:42:21 roberto Exp roberto $
|
** $Id: lparser.c,v 2.63 2009/06/10 16:52:03 roberto Exp roberto $
|
||||||
** Lua Parser
|
** Lua Parser
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@@ -813,10 +813,10 @@ static const struct {
|
|||||||
lu_byte right; /* right priority */
|
lu_byte right; /* right priority */
|
||||||
} priority[] = { /* ORDER OPR */
|
} priority[] = { /* ORDER OPR */
|
||||||
{6, 6}, {6, 6}, {7, 7}, {7, 7}, {7, 7}, /* `+' `-' `*' `/' `%' */
|
{6, 6}, {6, 6}, {7, 7}, {7, 7}, {7, 7}, /* `+' `-' `*' `/' `%' */
|
||||||
{10, 9}, {5, 4}, /* power and concat (right associative) */
|
{10, 9}, {5, 4}, /* ^, .. (right associative) */
|
||||||
{3, 3}, {3, 3}, /* equality and inequality */
|
{3, 3}, {3, 3}, {3, 3}, /* ==, <, <= */
|
||||||
{3, 3}, {3, 3}, {3, 3}, {3, 3}, /* order */
|
{3, 3}, {3, 3}, {3, 3}, /* ~=, >, >= */
|
||||||
{2, 2}, {1, 1} /* logical (and/or) */
|
{2, 2}, {1, 1} /* and, or */
|
||||||
};
|
};
|
||||||
|
|
||||||
#define UNARY_PRIORITY 8 /* priority for unary operators */
|
#define UNARY_PRIORITY 8 /* priority for unary operators */
|
||||||
|
|||||||
Reference in New Issue
Block a user