aboutsummaryrefslogtreecommitdiff
path: root/src/3rdParty/lua/lcode.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/3rdParty/lua/lcode.c')
-rw-r--r--src/3rdParty/lua/lcode.c70
1 files changed, 41 insertions, 29 deletions
diff --git a/src/3rdParty/lua/lcode.c b/src/3rdParty/lua/lcode.c
index 06425a1..911dbd5 100644
--- a/src/3rdParty/lua/lcode.c
+++ b/src/3rdParty/lua/lcode.c
@@ -1391,7 +1391,10 @@ static void finishbinexpval (FuncState *fs, expdesc *e1, expdesc *e2,
1391*/ 1391*/
1392static void codebinexpval (FuncState *fs, OpCode op, 1392static void codebinexpval (FuncState *fs, OpCode op,
1393 expdesc *e1, expdesc *e2, int line) { 1393 expdesc *e1, expdesc *e2, int line) {
1394 int v2 = luaK_exp2anyreg(fs, e2); /* both operands are in registers */ 1394 int v2 = luaK_exp2anyreg(fs, e2); /* make sure 'e2' is in a register */
1395 /* 'e1' must be already in a register or it is a constant */
1396 lua_assert((VNIL <= e1->k && e1->k <= VKSTR) ||
1397 e1->k == VNONRELOC || e1->k == VRELOC);
1395 lua_assert(OP_ADD <= op && op <= OP_SHR); 1398 lua_assert(OP_ADD <= op && op <= OP_SHR);
1396 finishbinexpval(fs, e1, e2, op, v2, 0, line, OP_MMBIN, 1399 finishbinexpval(fs, e1, e2, op, v2, 0, line, OP_MMBIN,
1397 cast(TMS, (op - OP_ADD) + TM_ADD)); 1400 cast(TMS, (op - OP_ADD) + TM_ADD));
@@ -1410,6 +1413,18 @@ static void codebini (FuncState *fs, OpCode op,
1410} 1413}
1411 1414
1412 1415
1416/*
1417** Code binary operators with K operand.
1418*/
1419static void codebinK (FuncState *fs, BinOpr opr,
1420 expdesc *e1, expdesc *e2, int flip, int line) {
1421 TMS event = cast(TMS, opr + TM_ADD);
1422 int v2 = e2->u.info; /* K index */
1423 OpCode op = cast(OpCode, opr + OP_ADDK);
1424 finishbinexpval(fs, e1, e2, op, v2, flip, line, OP_MMBINK, event);
1425}
1426
1427
1413/* Try to code a binary operator negating its second operand. 1428/* Try to code a binary operator negating its second operand.
1414** For the metamethod, 2nd operand must keep its original value. 1429** For the metamethod, 2nd operand must keep its original value.
1415*/ 1430*/
@@ -1438,23 +1453,27 @@ static void swapexps (expdesc *e1, expdesc *e2) {
1438 1453
1439 1454
1440/* 1455/*
1456** Code binary operators with no constant operand.
1457*/
1458static void codebinNoK (FuncState *fs, BinOpr opr,
1459 expdesc *e1, expdesc *e2, int flip, int line) {
1460 OpCode op = cast(OpCode, opr + OP_ADD);
1461 if (flip)
1462 swapexps(e1, e2); /* back to original order */
1463 codebinexpval(fs, op, e1, e2, line); /* use standard operators */
1464}
1465
1466
1467/*
1441** Code arithmetic operators ('+', '-', ...). If second operand is a 1468** Code arithmetic operators ('+', '-', ...). If second operand is a
1442** constant in the proper range, use variant opcodes with K operands. 1469** constant in the proper range, use variant opcodes with K operands.
1443*/ 1470*/
1444static void codearith (FuncState *fs, BinOpr opr, 1471static void codearith (FuncState *fs, BinOpr opr,
1445 expdesc *e1, expdesc *e2, int flip, int line) { 1472 expdesc *e1, expdesc *e2, int flip, int line) {
1446 TMS event = cast(TMS, opr + TM_ADD); 1473 if (tonumeral(e2, NULL) && luaK_exp2K(fs, e2)) /* K operand? */
1447 if (tonumeral(e2, NULL) && luaK_exp2K(fs, e2)) { /* K operand? */ 1474 codebinK(fs, opr, e1, e2, flip, line);
1448 int v2 = e2->u.info; /* K index */ 1475 else /* 'e2' is neither an immediate nor a K operand */
1449 OpCode op = cast(OpCode, opr + OP_ADDK); 1476 codebinNoK(fs, opr, e1, e2, flip, line);
1450 finishbinexpval(fs, e1, e2, op, v2, flip, line, OP_MMBINK, event);
1451 }
1452 else { /* 'e2' is neither an immediate nor a K operand */
1453 OpCode op = cast(OpCode, opr + OP_ADD);
1454 if (flip)
1455 swapexps(e1, e2); /* back to original order */
1456 codebinexpval(fs, op, e1, e2, line); /* use standard operators */
1457 }
1458} 1477}
1459 1478
1460 1479
@@ -1478,28 +1497,20 @@ static void codecommutative (FuncState *fs, BinOpr op,
1478 1497
1479 1498
1480/* 1499/*
1481** Code bitwise operations; they are all associative, so the function 1500** Code bitwise operations; they are all commutative, so the function
1482** tries to put an integer constant as the 2nd operand (a K operand). 1501** tries to put an integer constant as the 2nd operand (a K operand).
1483*/ 1502*/
1484static void codebitwise (FuncState *fs, BinOpr opr, 1503static void codebitwise (FuncState *fs, BinOpr opr,
1485 expdesc *e1, expdesc *e2, int line) { 1504 expdesc *e1, expdesc *e2, int line) {
1486 int flip = 0; 1505 int flip = 0;
1487 int v2; 1506 if (e1->k == VKINT) {
1488 OpCode op;
1489 if (e1->k == VKINT && luaK_exp2RK(fs, e1)) {
1490 swapexps(e1, e2); /* 'e2' will be the constant operand */ 1507 swapexps(e1, e2); /* 'e2' will be the constant operand */
1491 flip = 1; 1508 flip = 1;
1492 } 1509 }
1493 else if (!(e2->k == VKINT && luaK_exp2RK(fs, e2))) { /* no constants? */ 1510 if (e2->k == VKINT && luaK_exp2K(fs, e2)) /* K operand? */
1494 op = cast(OpCode, opr + OP_ADD); 1511 codebinK(fs, opr, e1, e2, flip, line);
1495 codebinexpval(fs, op, e1, e2, line); /* all-register opcodes */ 1512 else /* no constants */
1496 return; 1513 codebinNoK(fs, opr, e1, e2, flip, line);
1497 }
1498 v2 = e2->u.info; /* index in K array */
1499 op = cast(OpCode, opr + OP_ADDK);
1500 lua_assert(ttisinteger(&fs->f->k[v2]));
1501 finishbinexpval(fs, e1, e2, op, v2, flip, line, OP_MMBINK,
1502 cast(TMS, opr + TM_ADD));
1503} 1514}
1504 1515
1505 1516
@@ -1551,7 +1562,7 @@ static void codeeq (FuncState *fs, BinOpr opr, expdesc *e1, expdesc *e2) {
1551 op = OP_EQI; 1562 op = OP_EQI;
1552 r2 = im; /* immediate operand */ 1563 r2 = im; /* immediate operand */
1553 } 1564 }
1554 else if (luaK_exp2RK(fs, e2)) { /* 1st expression is constant? */ 1565 else if (luaK_exp2RK(fs, e2)) { /* 2nd expression is constant? */
1555 op = OP_EQK; 1566 op = OP_EQK;
1556 r2 = e2->u.info; /* constant index */ 1567 r2 = e2->u.info; /* constant index */
1557 } 1568 }
@@ -1611,7 +1622,8 @@ void luaK_infix (FuncState *fs, BinOpr op, expdesc *v) {
1611 case OPR_SHL: case OPR_SHR: { 1622 case OPR_SHL: case OPR_SHR: {
1612 if (!tonumeral(v, NULL)) 1623 if (!tonumeral(v, NULL))
1613 luaK_exp2anyreg(fs, v); 1624 luaK_exp2anyreg(fs, v);
1614 /* else keep numeral, which may be folded with 2nd operand */ 1625 /* else keep numeral, which may be folded or used as an immediate
1626 operand */
1615 break; 1627 break;
1616 } 1628 }
1617 case OPR_EQ: case OPR_NE: { 1629 case OPR_EQ: case OPR_NE: {