diff options
Diffstat (limited to 'lcode.c')
-rw-r--r-- | lcode.c | 16 |
1 files changed, 8 insertions, 8 deletions
@@ -1342,7 +1342,7 @@ static void finishbinexpval (FuncState *fs, expdesc *e1, expdesc *e2, | |||
1342 | OpCode op, int v2, int flip, int line, | 1342 | OpCode op, int v2, int flip, int line, |
1343 | OpCode mmop, TMS event) { | 1343 | OpCode mmop, TMS event) { |
1344 | int v1 = luaK_exp2anyreg(fs, e1); | 1344 | int v1 = luaK_exp2anyreg(fs, e1); |
1345 | int pc = luaK_codeABCk(fs, op, 0, v1, v2, flip); | 1345 | int pc = luaK_codeABCk(fs, op, 0, v1, v2, 0); |
1346 | freeexps(fs, e1, e2); | 1346 | freeexps(fs, e1, e2); |
1347 | e1->u.info = pc; | 1347 | e1->u.info = pc; |
1348 | e1->k = VRELOC; /* all those operations are relocatable */ | 1348 | e1->k = VRELOC; /* all those operations are relocatable */ |
@@ -1372,7 +1372,7 @@ static void codebinexpval (FuncState *fs, OpCode op, | |||
1372 | 1372 | ||
1373 | 1373 | ||
1374 | /* | 1374 | /* |
1375 | ** Code binary operators ('+', '-', ...) with immediate operands. | 1375 | ** Code binary operators with immediate operands. |
1376 | */ | 1376 | */ |
1377 | static void codebini (FuncState *fs, OpCode op, | 1377 | static void codebini (FuncState *fs, OpCode op, |
1378 | expdesc *e1, expdesc *e2, int flip, int line, | 1378 | expdesc *e1, expdesc *e2, int flip, int line, |
@@ -1389,15 +1389,12 @@ static void swapexps (expdesc *e1, expdesc *e2) { | |||
1389 | 1389 | ||
1390 | /* | 1390 | /* |
1391 | ** Code arithmetic operators ('+', '-', ...). If second operand is a | 1391 | ** Code arithmetic operators ('+', '-', ...). If second operand is a |
1392 | ** constant in the proper range, use variant opcodes with immediate | 1392 | ** constant in the proper range, use variant opcodes with K operands. |
1393 | ** operands or K operands. | ||
1394 | */ | 1393 | */ |
1395 | static void codearith (FuncState *fs, BinOpr opr, | 1394 | static void codearith (FuncState *fs, BinOpr opr, |
1396 | expdesc *e1, expdesc *e2, int flip, int line) { | 1395 | expdesc *e1, expdesc *e2, int flip, int line) { |
1397 | TMS event = cast(TMS, opr + TM_ADD); | 1396 | TMS event = cast(TMS, opr + TM_ADD); |
1398 | if (isSCint(e2)) /* immediate operand? */ | 1397 | if (tonumeral(e2, NULL) && luaK_exp2K(fs, e2)) { /* K operand? */ |
1399 | codebini(fs, cast(OpCode, opr + OP_ADDI), e1, e2, flip, line, event); | ||
1400 | else if (tonumeral(e2, NULL) && luaK_exp2K(fs, e2)) { /* K operand? */ | ||
1401 | int v2 = e2->u.info; /* K index */ | 1398 | int v2 = e2->u.info; /* K index */ |
1402 | OpCode op = cast(OpCode, opr + OP_ADDK); | 1399 | OpCode op = cast(OpCode, opr + OP_ADDK); |
1403 | finishbinexpval(fs, e1, e2, op, v2, flip, line, OP_MMBINK, event); | 1400 | finishbinexpval(fs, e1, e2, op, v2, flip, line, OP_MMBINK, event); |
@@ -1423,7 +1420,10 @@ static void codecommutative (FuncState *fs, BinOpr op, | |||
1423 | swapexps(e1, e2); /* change order */ | 1420 | swapexps(e1, e2); /* change order */ |
1424 | flip = 1; | 1421 | flip = 1; |
1425 | } | 1422 | } |
1426 | codearith(fs, op, e1, e2, flip, line); | 1423 | if (op == OPR_ADD && isSCint(e2)) /* immediate operand? */ |
1424 | codebini(fs, cast(OpCode, OP_ADDI), e1, e2, flip, line, TM_ADD); | ||
1425 | else | ||
1426 | codearith(fs, op, e1, e2, flip, line); | ||
1427 | } | 1427 | } |
1428 | 1428 | ||
1429 | 1429 | ||