summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2023-03-24 15:52:03 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2023-03-24 15:52:03 -0300
commit94689ac3ad290caf3bada21c389a991f55391987 (patch)
treeaf0fc7e06ece8f9ad81f2a527428b02babd960ac
parentab859fe59b464a038a45552921cb2b23892343af (diff)
downloadlua-github-94689ac3ad290caf3bada21c389a991f55391987.tar.gz
More regularity in uses of enums in 'lcode.c'
-rw-r--r--lcode.c36
1 files changed, 18 insertions, 18 deletions
diff --git a/lcode.c b/lcode.c
index 911dbd5f..236ce05c 100644
--- a/lcode.c
+++ b/lcode.c
@@ -1389,15 +1389,16 @@ static void finishbinexpval (FuncState *fs, expdesc *e1, expdesc *e2,
** Emit code for binary expressions that "produce values" over
** two registers.
*/
-static void codebinexpval (FuncState *fs, OpCode op,
+static void codebinexpval (FuncState *fs, BinOpr opr,
expdesc *e1, expdesc *e2, int line) {
+ OpCode op = cast(OpCode, opr + OP_ADD);
int v2 = luaK_exp2anyreg(fs, e2); /* make sure 'e2' is in a register */
/* 'e1' must be already in a register or it is a constant */
lua_assert((VNIL <= e1->k && e1->k <= VKSTR) ||
e1->k == VNONRELOC || e1->k == VRELOC);
lua_assert(OP_ADD <= op && op <= OP_SHR);
finishbinexpval(fs, e1, e2, op, v2, 0, line, OP_MMBIN,
- cast(TMS, (op - OP_ADD) + TM_ADD));
+ cast(TMS, opr + TM_ADD));
}
@@ -1457,10 +1458,9 @@ static void swapexps (expdesc *e1, expdesc *e2) {
*/
static void codebinNoK (FuncState *fs, BinOpr opr,
expdesc *e1, expdesc *e2, int flip, int line) {
- OpCode op = cast(OpCode, opr + OP_ADD);
if (flip)
swapexps(e1, e2); /* back to original order */
- codebinexpval(fs, op, e1, e2, line); /* use standard operators */
+ codebinexpval(fs, opr, e1, e2, line); /* use standard operators */
}
@@ -1490,7 +1490,7 @@ static void codecommutative (FuncState *fs, BinOpr op,
flip = 1;
}
if (op == OPR_ADD && isSCint(e2)) /* immediate operand? */
- codebini(fs, cast(OpCode, OP_ADDI), e1, e2, flip, line, TM_ADD);
+ codebini(fs, OP_ADDI, e1, e2, flip, line, TM_ADD);
else
codearith(fs, op, e1, e2, flip, line);
}
@@ -1518,25 +1518,27 @@ static void codebitwise (FuncState *fs, BinOpr opr,
** Emit code for order comparisons. When using an immediate operand,
** 'isfloat' tells whether the original value was a float.
*/
-static void codeorder (FuncState *fs, OpCode op, expdesc *e1, expdesc *e2) {
+static void codeorder (FuncState *fs, BinOpr opr, expdesc *e1, expdesc *e2) {
int r1, r2;
int im;
int isfloat = 0;
+ OpCode op;
if (isSCnumber(e2, &im, &isfloat)) {
/* use immediate operand */
r1 = luaK_exp2anyreg(fs, e1);
r2 = im;
- op = cast(OpCode, (op - OP_LT) + OP_LTI);
+ op = cast(OpCode, (opr - OPR_LT) + OP_LTI);
}
else if (isSCnumber(e1, &im, &isfloat)) {
/* transform (A < B) to (B > A) and (A <= B) to (B >= A) */
r1 = luaK_exp2anyreg(fs, e2);
r2 = im;
- op = (op == OP_LT) ? OP_GTI : OP_GEI;
+ op = cast(OpCode, (opr - OPR_LT) + OP_GTI);
}
else { /* regular case, compare two registers */
r1 = luaK_exp2anyreg(fs, e1);
r2 = luaK_exp2anyreg(fs, e2);
+ op = cast(OpCode, (opr - OPR_EQ) + OP_EQ);
}
freeexps(fs, e1, e2);
e1->u.info = condjump(fs, op, r1, r2, isfloat, 1);
@@ -1579,16 +1581,16 @@ static void codeeq (FuncState *fs, BinOpr opr, expdesc *e1, expdesc *e2) {
/*
** Apply prefix operation 'op' to expression 'e'.
*/
-void luaK_prefix (FuncState *fs, UnOpr op, expdesc *e, int line) {
+void luaK_prefix (FuncState *fs, UnOpr opr, expdesc *e, int line) {
static const expdesc ef = {VKINT, {0}, NO_JUMP, NO_JUMP};
luaK_dischargevars(fs, e);
- switch (op) {
+ switch (opr) {
case OPR_MINUS: case OPR_BNOT: /* use 'ef' as fake 2nd operand */
- if (constfolding(fs, op + LUA_OPUNM, e, &ef))
+ if (constfolding(fs, opr + LUA_OPUNM, e, &ef))
break;
/* else */ /* FALLTHROUGH */
case OPR_LEN:
- codeunexpval(fs, cast(OpCode, op + OP_UNM), e, line);
+ codeunexpval(fs, cast(OpCode, opr + OP_UNM), e, line);
break;
case OPR_NOT: codenot(fs, e); break;
default: lua_assert(0);
@@ -1718,14 +1720,14 @@ void luaK_posfix (FuncState *fs, BinOpr opr,
/* coded as (r1 >> -I) */;
}
else /* regular case (two registers) */
- codebinexpval(fs, OP_SHL, e1, e2, line);
+ codebinexpval(fs, opr, e1, e2, line);
break;
}
case OPR_SHR: {
if (isSCint(e2))
codebini(fs, OP_SHRI, e1, e2, 0, line, TM_SHR); /* r1 >> I */
else /* regular case (two registers) */
- codebinexpval(fs, OP_SHR, e1, e2, line);
+ codebinexpval(fs, opr, e1, e2, line);
break;
}
case OPR_EQ: case OPR_NE: {
@@ -1733,15 +1735,13 @@ void luaK_posfix (FuncState *fs, BinOpr opr,
break;
}
case OPR_LT: case OPR_LE: {
- OpCode op = cast(OpCode, (opr - OPR_EQ) + OP_EQ);
- codeorder(fs, op, e1, e2);
+ codeorder(fs, opr, e1, e2);
break;
}
case OPR_GT: case OPR_GE: {
/* '(a > b)' <=> '(b < a)'; '(a >= b)' <=> '(b <= a)' */
- OpCode op = cast(OpCode, (opr - OPR_NE) + OP_EQ);
swapexps(e1, e2);
- codeorder(fs, op, e1, e2);
+ codeorder(fs, (opr - OPR_NE) + OPR_EQ, e1, e2);
break;
}
default: lua_assert(0);