summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-08-28 09:58:03 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-08-28 09:58:03 -0300
commit46b84580d6d7890f4ba813f312e52514fffc38a7 (patch)
tree764855657253d0b7d2a83c810d5f3bd3493c5ed1
parentdf13f259487459f3a28d31d76c890aa6c2d061e0 (diff)
downloadlua-46b84580d6d7890f4ba813f312e52514fffc38a7.tar.gz
lua-46b84580d6d7890f4ba813f312e52514fffc38a7.tar.bz2
lua-46b84580d6d7890f4ba813f312e52514fffc38a7.zip
Use of 'MMBIN' opcodes extended to shift operators
Plus, this commit removes useless 'tm' parameters in 'op_*' macros.
-rw-r--r--lcode.c26
-rw-r--r--ldebug.c8
-rw-r--r--lvm.c102
-rw-r--r--testes/code.lua8
-rw-r--r--testes/db.lua3
5 files changed, 60 insertions, 87 deletions
diff --git a/lcode.c b/lcode.c
index a1b27a00..2c08409b 100644
--- a/lcode.c
+++ b/lcode.c
@@ -1339,19 +1339,23 @@ static void codeunexpval (FuncState *fs, OpCode op, expdesc *e, int line) {
1339** Expression to produce final result will be encoded in 'e1'. 1339** Expression to produce final result will be encoded in 'e1'.
1340*/ 1340*/
1341static void finishbinexpval (FuncState *fs, expdesc *e1, expdesc *e2, 1341static void finishbinexpval (FuncState *fs, expdesc *e1, expdesc *e2,
1342 OpCode op, int v2, int k, 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, k); 1345 int pc = luaK_codeABCk(fs, op, 0, v1, v2, flip);
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 */
1349 luaK_fixline(fs, line); 1349 luaK_fixline(fs, line);
1350if (event != TM_SHL && event != TM_SHR) { 1350 if (op == OP_SHRI && flip) {
1351 luaK_codeABCk(fs, mmop, v1, v2, event, k); /* to call metamethod */ 1351 /* For the metamethod, undo the "changedir" did by 'codeshift' */
1352 event = TM_SHL;
1353 v2 = -(v2 - OFFSET_sC) + OFFSET_sC;
1354 flip = 0;
1355 }
1356 luaK_codeABCk(fs, mmop, v1, v2, event, flip); /* to call metamethod */
1352 luaK_fixline(fs, line); 1357 luaK_fixline(fs, line);
1353} 1358}
1354}
1355 1359
1356 1360
1357/* 1361/*
@@ -1371,10 +1375,10 @@ static void codebinexpval (FuncState *fs, OpCode op,
1371** Code binary operators ('+', '-', ...) with immediate operands. 1375** Code binary operators ('+', '-', ...) with immediate operands.
1372*/ 1376*/
1373static void codebini (FuncState *fs, OpCode op, 1377static void codebini (FuncState *fs, OpCode op,
1374 expdesc *e1, expdesc *e2, int k, int line, 1378 expdesc *e1, expdesc *e2, int flip, int line,
1375 TMS event) { 1379 TMS event) {
1376 int v2 = cast_int(e2->u.ival) + OFFSET_sC; /* immediate operand */ 1380 int v2 = cast_int(e2->u.ival) + OFFSET_sC; /* immediate operand */
1377 finishbinexpval(fs, e1, e2, op, v2, k, line, OP_MMBINI, event); 1381 finishbinexpval(fs, e1, e2, op, v2, flip, line, OP_MMBINI, event);
1378} 1382}
1379 1383
1380 1384
@@ -1429,12 +1433,12 @@ static void codecommutative (FuncState *fs, BinOpr op,
1429*/ 1433*/
1430static void codebitwise (FuncState *fs, BinOpr opr, 1434static void codebitwise (FuncState *fs, BinOpr opr,
1431 expdesc *e1, expdesc *e2, int line) { 1435 expdesc *e1, expdesc *e2, int line) {
1432 int inv = 0; 1436 int flip = 0;
1433 int v2; 1437 int v2;
1434 OpCode op; 1438 OpCode op;
1435 if (e1->k == VKINT && luaK_exp2RK(fs, e1)) { 1439 if (e1->k == VKINT && luaK_exp2RK(fs, e1)) {
1436 swapexps(e1, e2); /* 'e2' will be the constant operand */ 1440 swapexps(e1, e2); /* 'e2' will be the constant operand */
1437 inv = 1; 1441 flip = 1;
1438 } 1442 }
1439 else if (!(e2->k == VKINT && luaK_exp2RK(fs, e2))) { /* no constants? */ 1443 else if (!(e2->k == VKINT && luaK_exp2RK(fs, e2))) { /* no constants? */
1440 op = cast(OpCode, opr + OP_ADD); 1444 op = cast(OpCode, opr + OP_ADD);
@@ -1444,7 +1448,7 @@ static void codebitwise (FuncState *fs, BinOpr opr,
1444 v2 = e2->u.info; /* index in K array */ 1448 v2 = e2->u.info; /* index in K array */
1445 op = cast(OpCode, opr + OP_ADDK); 1449 op = cast(OpCode, opr + OP_ADDK);
1446 lua_assert(ttisinteger(&fs->f->k[v2])); 1450 lua_assert(ttisinteger(&fs->f->k[v2]));
1447 finishbinexpval(fs, e1, e2, op, v2, inv, line, OP_MMBINK, 1451 finishbinexpval(fs, e1, e2, op, v2, flip, line, OP_MMBINK,
1448 cast(TMS, opr + TM_ADD)); 1452 cast(TMS, opr + TM_ADD));
1449} 1453}
1450 1454
@@ -1461,7 +1465,7 @@ static void codeshift (FuncState *fs, OpCode op,
1461 changedir = 1; 1465 changedir = 1;
1462 e2->u.ival = -(e2->u.ival); 1466 e2->u.ival = -(e2->u.ival);
1463 } 1467 }
1464 codebini(fs, OP_SHRI, e1, e2, changedir, line, TM_SHL); 1468 codebini(fs, OP_SHRI, e1, e2, changedir, line, TM_SHR);
1465 } 1469 }
1466 else 1470 else
1467 codebinexpval(fs, op, e1, e2, line); 1471 codebinexpval(fs, op, e1, e2, line);
diff --git a/ldebug.c b/ldebug.c
index 4e1dc6b9..aef52e15 100644
--- a/ldebug.c
+++ b/ldebug.c
@@ -628,11 +628,6 @@ static const char *funcnamefromcode (lua_State *L, CallInfo *ci,
628 tm = cast(TMS, GETARG_C(i)); 628 tm = cast(TMS, GETARG_C(i));
629 break; 629 break;
630 } 630 }
631 case OP_SHL: case OP_SHR: {
632 int offset = GET_OPCODE(i) - OP_ADD; /* ORDER OP */
633 tm = cast(TMS, offset + TM_ADD); /* ORDER TM */
634 break;
635 }
636 case OP_UNM: tm = TM_UNM; break; 631 case OP_UNM: tm = TM_UNM; break;
637 case OP_BNOT: tm = TM_BNOT; break; 632 case OP_BNOT: tm = TM_BNOT; break;
638 case OP_LEN: tm = TM_LEN; break; 633 case OP_LEN: tm = TM_LEN; break;
@@ -641,9 +636,6 @@ static const char *funcnamefromcode (lua_State *L, CallInfo *ci,
641 case OP_LT: case OP_LE: case OP_LTI: case OP_LEI: 636 case OP_LT: case OP_LE: case OP_LTI: case OP_LEI:
642 *name = "order"; /* '<=' can call '__lt', etc. */ 637 *name = "order"; /* '<=' can call '__lt', etc. */
643 return "metamethod"; 638 return "metamethod";
644 case OP_SHRI: case OP_SHLI:
645 *name = "shift";
646 return "metamethod";
647 case OP_CLOSE: case OP_RETURN: 639 case OP_CLOSE: case OP_RETURN:
648 *name = "close"; 640 *name = "close";
649 return "metamethod"; 641 return "metamethod";
diff --git a/lvm.c b/lvm.c
index a9e8455e..71f6ae0d 100644
--- a/lvm.c
+++ b/lvm.c
@@ -674,6 +674,8 @@ lua_Number luaV_modf (lua_State *L, lua_Number m, lua_Number n) {
674/* 674/*
675** Shift left operation. (Shift right just negates 'y'.) 675** Shift left operation. (Shift right just negates 'y'.)
676*/ 676*/
677#define luaV_shiftr(x,y) luaV_shiftl(x,-(y))
678
677lua_Integer luaV_shiftl (lua_Integer x, lua_Integer y) { 679lua_Integer luaV_shiftl (lua_Integer x, lua_Integer y) {
678 if (y < 0) { /* shift right? */ 680 if (y < 0) { /* shift right? */
679 if (y <= -NBITS) return 0; 681 if (y <= -NBITS) return 0;
@@ -721,7 +723,6 @@ void luaV_finishOp (lua_State *L) {
721 setobjs2s(L, base + GETARG_A(*(ci->u.l.savedpc - 2)), --L->top); 723 setobjs2s(L, base + GETARG_A(*(ci->u.l.savedpc - 2)), --L->top);
722 break; 724 break;
723 } 725 }
724 case OP_SHLI: case OP_SHRI: case OP_SHL: case OP_SHR:
725 case OP_UNM: case OP_BNOT: case OP_LEN: 726 case OP_UNM: case OP_BNOT: case OP_LEN:
726 case OP_GETTABUP: case OP_GETTABLE: case OP_GETI: 727 case OP_GETTABUP: case OP_GETTABLE: case OP_GETI:
727 case OP_GETFIELD: case OP_SELF: { 728 case OP_GETFIELD: case OP_SELF: {
@@ -778,9 +779,9 @@ void luaV_finishOp (lua_State *L) {
778#define l_addi(L,a,b) intop(+, a, b) 779#define l_addi(L,a,b) intop(+, a, b)
779#define l_subi(L,a,b) intop(-, a, b) 780#define l_subi(L,a,b) intop(-, a, b)
780#define l_muli(L,a,b) intop(*, a, b) 781#define l_muli(L,a,b) intop(*, a, b)
781#define l_band(L,a,b) intop(&, a, b) 782#define l_band(a,b) intop(&, a, b)
782#define l_bor(L,a,b) intop(|, a, b) 783#define l_bor(a,b) intop(|, a, b)
783#define l_bxor(L,a,b) intop(^, a, b) 784#define l_bxor(a,b) intop(^, a, b)
784 785
785#define l_lti(a,b) (a < b) 786#define l_lti(a,b) (a < b)
786#define l_lei(a,b) (a <= b) 787#define l_lei(a,b) (a <= b)
@@ -827,7 +828,7 @@ void luaV_finishOp (lua_State *L) {
827** Auxiliary function for arithmetic operations over floats and others 828** Auxiliary function for arithmetic operations over floats and others
828** with two register operands. 829** with two register operands.
829*/ 830*/
830#define op_arithf_aux(L,v1,v2,fop,tm) { \ 831#define op_arithf_aux(L,v1,v2,fop) { \
831 lua_Number n1; lua_Number n2; \ 832 lua_Number n1; lua_Number n2; \
832 if (tonumberns(v1, n1) && tonumberns(v2, n2)) { \ 833 if (tonumberns(v1, n1) && tonumberns(v2, n2)) { \
833 pc++; setfltvalue(s2v(ra), fop(L, n1, n2)); \ 834 pc++; setfltvalue(s2v(ra), fop(L, n1, n2)); \
@@ -837,29 +838,29 @@ void luaV_finishOp (lua_State *L) {
837/* 838/*
838** Arithmetic operations over floats and others with register operands. 839** Arithmetic operations over floats and others with register operands.
839*/ 840*/
840#define op_arithf(L,fop,tm) { \ 841#define op_arithf(L,fop) { \
841 TValue *v1 = vRB(i); \ 842 TValue *v1 = vRB(i); \
842 TValue *v2 = vRC(i); \ 843 TValue *v2 = vRC(i); \
843 op_arithf_aux(L, v1, v2, fop, tm); } 844 op_arithf_aux(L, v1, v2, fop); }
844 845
845 846
846/* 847/*
847** Arithmetic operations with register operands. 848** Arithmetic operations with register operands.
848*/ 849*/
849#define op_arith(L,iop,fop,tm) { \ 850#define op_arith(L,iop,fop) { \
850 TValue *v1 = vRB(i); \ 851 TValue *v1 = vRB(i); \
851 TValue *v2 = vRC(i); \ 852 TValue *v2 = vRC(i); \
852 if (ttisinteger(v1) && ttisinteger(v2)) { \ 853 if (ttisinteger(v1) && ttisinteger(v2)) { \
853 lua_Integer i1 = ivalue(v1); lua_Integer i2 = ivalue(v2); \ 854 lua_Integer i1 = ivalue(v1); lua_Integer i2 = ivalue(v2); \
854 pc++; setivalue(s2v(ra), iop(L, i1, i2)); \ 855 pc++; setivalue(s2v(ra), iop(L, i1, i2)); \
855 } \ 856 } \
856 else op_arithf_aux(L, v1, v2, fop, tm); } 857 else op_arithf_aux(L, v1, v2, fop); }
857 858
858 859
859/* 860/*
860** Arithmetic operations with K operands. 861** Arithmetic operations with K operands.
861*/ 862*/
862#define op_arithK(L,iop,fop,tm,flip) { \ 863#define op_arithK(L,iop,fop,flip) { \
863 TValue *v1 = vRB(i); \ 864 TValue *v1 = vRB(i); \
864 TValue *v2 = KC(i); \ 865 TValue *v2 = KC(i); \
865 if (ttisinteger(v1) && ttisinteger(v2)) { \ 866 if (ttisinteger(v1) && ttisinteger(v2)) { \
@@ -876,7 +877,7 @@ void luaV_finishOp (lua_State *L) {
876/* 877/*
877** Arithmetic operations with K operands for floats. 878** Arithmetic operations with K operands for floats.
878*/ 879*/
879#define op_arithfK(L,fop,tm) { \ 880#define op_arithfK(L,fop) { \
880 TValue *v1 = vRB(i); \ 881 TValue *v1 = vRB(i); \
881 TValue *v2 = KC(i); \ 882 TValue *v2 = KC(i); \
882 lua_Number n1; lua_Number n2; \ 883 lua_Number n1; lua_Number n2; \
@@ -888,25 +889,25 @@ void luaV_finishOp (lua_State *L) {
888/* 889/*
889** Bitwise operations with constant operand. 890** Bitwise operations with constant operand.
890*/ 891*/
891#define op_bitwiseK(L,op,tm) { \ 892#define op_bitwiseK(L,op) { \
892 TValue *v1 = vRB(i); \ 893 TValue *v1 = vRB(i); \
893 TValue *v2 = KC(i); \ 894 TValue *v2 = KC(i); \
894 lua_Integer i1; \ 895 lua_Integer i1; \
895 lua_Integer i2 = ivalue(v2); \ 896 lua_Integer i2 = ivalue(v2); \
896 if (tointegerns(v1, &i1)) { \ 897 if (tointegerns(v1, &i1)) { \
897 pc++; setivalue(s2v(ra), op(L, i1, i2)); \ 898 pc++; setivalue(s2v(ra), op(i1, i2)); \
898 }} 899 }}
899 900
900 901
901/* 902/*
902** Bitwise operations with register operands. 903** Bitwise operations with register operands.
903*/ 904*/
904#define op_bitwise(L,op,tm) { \ 905#define op_bitwise(L,op) { \
905 TValue *v1 = vRB(i); \ 906 TValue *v1 = vRB(i); \
906 TValue *v2 = vRC(i); \ 907 TValue *v2 = vRC(i); \
907 lua_Integer i1; lua_Integer i2; \ 908 lua_Integer i1; lua_Integer i2; \
908 if (tointegerns(v1, &i1) && tointegerns(v2, &i2)) { \ 909 if (tointegerns(v1, &i1) && tointegerns(v2, &i2)) { \
909 pc++; setivalue(s2v(ra), op(L, i1, i2)); \ 910 pc++; setivalue(s2v(ra), op(i1, i2)); \
910 }} 911 }}
911 912
912 913
@@ -1296,43 +1297,43 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
1296 vmbreak; 1297 vmbreak;
1297 } 1298 }
1298 vmcase(OP_ADDK) { 1299 vmcase(OP_ADDK) {
1299 op_arithK(L, l_addi, luai_numadd, TM_ADD, GETARG_k(i)); 1300 op_arithK(L, l_addi, luai_numadd, GETARG_k(i));
1300 vmbreak; 1301 vmbreak;
1301 } 1302 }
1302 vmcase(OP_SUBK) { 1303 vmcase(OP_SUBK) {
1303 op_arithK(L, l_subi, luai_numsub, TM_SUB, 0); 1304 op_arithK(L, l_subi, luai_numsub, 0);
1304 vmbreak; 1305 vmbreak;
1305 } 1306 }
1306 vmcase(OP_MULK) { 1307 vmcase(OP_MULK) {
1307 op_arithK(L, l_muli, luai_nummul, TM_MUL, GETARG_k(i)); 1308 op_arithK(L, l_muli, luai_nummul, GETARG_k(i));
1308 vmbreak; 1309 vmbreak;
1309 } 1310 }
1310 vmcase(OP_MODK) { 1311 vmcase(OP_MODK) {
1311 op_arithK(L, luaV_mod, luaV_modf, TM_MOD, 0); 1312 op_arithK(L, luaV_mod, luaV_modf, 0);
1312 vmbreak; 1313 vmbreak;
1313 } 1314 }
1314 vmcase(OP_POWK) { 1315 vmcase(OP_POWK) {
1315 op_arithfK(L, luai_numpow, TM_POW); 1316 op_arithfK(L, luai_numpow);
1316 vmbreak; 1317 vmbreak;
1317 } 1318 }
1318 vmcase(OP_DIVK) { 1319 vmcase(OP_DIVK) {
1319 op_arithfK(L, luai_numdiv, TM_DIV); 1320 op_arithfK(L, luai_numdiv);
1320 vmbreak; 1321 vmbreak;
1321 } 1322 }
1322 vmcase(OP_IDIVK) { 1323 vmcase(OP_IDIVK) {
1323 op_arithK(L, luaV_idiv, luai_numidiv, TM_IDIV, 0); 1324 op_arithK(L, luaV_idiv, luai_numidiv, 0);
1324 vmbreak; 1325 vmbreak;
1325 } 1326 }
1326 vmcase(OP_BANDK) { 1327 vmcase(OP_BANDK) {
1327 op_bitwiseK(L, l_band, TM_BAND); 1328 op_bitwiseK(L, l_band);
1328 vmbreak; 1329 vmbreak;
1329 } 1330 }
1330 vmcase(OP_BORK) { 1331 vmcase(OP_BORK) {
1331 op_bitwiseK(L, l_bor, TM_BOR); 1332 op_bitwiseK(L, l_bor);
1332 vmbreak; 1333 vmbreak;
1333 } 1334 }
1334 vmcase(OP_BXORK) { 1335 vmcase(OP_BXORK) {
1335 op_bitwiseK(L, l_bxor, TM_BXOR); 1336 op_bitwiseK(L, l_bxor);
1336 vmbreak; 1337 vmbreak;
1337 } 1338 }
1338 vmcase(OP_SHRI) { 1339 vmcase(OP_SHRI) {
@@ -1340,14 +1341,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
1340 int ic = GETARG_sC(i); 1341 int ic = GETARG_sC(i);
1341 lua_Integer ib; 1342 lua_Integer ib;
1342 if (tointegerns(rb, &ib)) { 1343 if (tointegerns(rb, &ib)) {
1343 setivalue(s2v(ra), luaV_shiftl(ib, -ic)); 1344 pc++; setivalue(s2v(ra), luaV_shiftl(ib, -ic));
1344 }
1345 else {
1346 TMS ev = TM_SHR;
1347 if (TESTARG_k(i)) {
1348 ic = -ic; ev = TM_SHL;
1349 }
1350 ProtectNT(luaT_trybiniTM(L, rb, ic, 0, ra, ev));
1351 } 1345 }
1352 vmbreak; 1346 vmbreak;
1353 } 1347 }
@@ -1356,72 +1350,56 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
1356 int ic = GETARG_sC(i); 1350 int ic = GETARG_sC(i);
1357 lua_Integer ib; 1351 lua_Integer ib;
1358 if (tointegerns(rb, &ib)) { 1352 if (tointegerns(rb, &ib)) {
1359 setivalue(s2v(ra), luaV_shiftl(ic, ib)); 1353 pc++; setivalue(s2v(ra), luaV_shiftl(ic, ib));
1360 } 1354 }
1361 else
1362 ProtectNT(luaT_trybiniTM(L, rb, ic, 1, ra, TM_SHL));
1363 vmbreak; 1355 vmbreak;
1364 } 1356 }
1365 vmcase(OP_ADD) { 1357 vmcase(OP_ADD) {
1366 op_arith(L, l_addi, luai_numadd, TM_ADD); 1358 op_arith(L, l_addi, luai_numadd);
1367 vmbreak; 1359 vmbreak;
1368 } 1360 }
1369 vmcase(OP_SUB) { 1361 vmcase(OP_SUB) {
1370 op_arith(L, l_subi, luai_numsub, TM_SUB); 1362 op_arith(L, l_subi, luai_numsub);
1371 vmbreak; 1363 vmbreak;
1372 } 1364 }
1373 vmcase(OP_MUL) { 1365 vmcase(OP_MUL) {
1374 op_arith(L, l_muli, luai_nummul, TM_MUL); 1366 op_arith(L, l_muli, luai_nummul);
1375 vmbreak; 1367 vmbreak;
1376 } 1368 }
1377 vmcase(OP_MOD) { 1369 vmcase(OP_MOD) {
1378 op_arith(L, luaV_mod, luaV_modf, TM_MOD); 1370 op_arith(L, luaV_mod, luaV_modf);
1379 vmbreak; 1371 vmbreak;
1380 } 1372 }
1381 vmcase(OP_POW) { 1373 vmcase(OP_POW) {
1382 op_arithf(L, luai_numpow, TM_POW); 1374 op_arithf(L, luai_numpow);
1383 vmbreak; 1375 vmbreak;
1384 } 1376 }
1385 vmcase(OP_DIV) { /* float division (always with floats) */ 1377 vmcase(OP_DIV) { /* float division (always with floats) */
1386 op_arithf(L, luai_numdiv, TM_DIV); 1378 op_arithf(L, luai_numdiv);
1387 vmbreak; 1379 vmbreak;
1388 } 1380 }
1389 vmcase(OP_IDIV) { /* floor division */ 1381 vmcase(OP_IDIV) { /* floor division */
1390 op_arith(L, luaV_idiv, luai_numidiv, TM_IDIV); 1382 op_arith(L, luaV_idiv, luai_numidiv);
1391 vmbreak; 1383 vmbreak;
1392 } 1384 }
1393 vmcase(OP_BAND) { 1385 vmcase(OP_BAND) {
1394 op_bitwise(L, l_band, TM_BAND); 1386 op_bitwise(L, l_band);
1395 vmbreak; 1387 vmbreak;
1396 } 1388 }
1397 vmcase(OP_BOR) { 1389 vmcase(OP_BOR) {
1398 op_bitwise(L, l_bor, TM_BOR); 1390 op_bitwise(L, l_bor);
1399 vmbreak; 1391 vmbreak;
1400 } 1392 }
1401 vmcase(OP_BXOR) { 1393 vmcase(OP_BXOR) {
1402 op_bitwise(L, l_bxor, TM_BXOR); 1394 op_bitwise(L, l_bxor);
1403 vmbreak; 1395 vmbreak;
1404 } 1396 }
1405 vmcase(OP_SHR) { 1397 vmcase(OP_SHR) {
1406 TValue *rb = vRB(i); 1398 op_bitwise(L, luaV_shiftr);
1407 TValue *rc = vRC(i);
1408 lua_Integer ib; lua_Integer ic;
1409 if (tointegerns(rb, &ib) && tointegerns(rc, &ic)) {
1410 setivalue(s2v(ra), luaV_shiftl(ib, -ic));
1411 }
1412 else
1413 ProtectNT(luaT_trybinTM(L, rb, rc, ra, TM_SHR));
1414 vmbreak; 1399 vmbreak;
1415 } 1400 }
1416 vmcase(OP_SHL) { 1401 vmcase(OP_SHL) {
1417 TValue *rb = vRB(i); 1402 op_bitwise(L, luaV_shiftl);
1418 TValue *rc = vRC(i);
1419 lua_Integer ib; lua_Integer ic;
1420 if (tointegerns(rb, &ib) && tointegerns(rc, &ic)) {
1421 setivalue(s2v(ra), luaV_shiftl(ib, ic));
1422 }
1423 else
1424 ProtectNT(luaT_trybinTM(L, rb, rc, ra, TM_SHL));
1425 vmbreak; 1403 vmbreak;
1426 } 1404 }
1427 vmcase(OP_MMBIN) { 1405 vmcase(OP_MMBIN) {
diff --git a/testes/code.lua b/testes/code.lua
index fcb5c309..96560166 100644
--- a/testes/code.lua
+++ b/testes/code.lua
@@ -304,9 +304,9 @@ checkR(function (x) return x // 1 end, 10.0, 10.0,
304 'IDIVI', 'MMBINI', 'RETURN1') 304 'IDIVI', 'MMBINI', 'RETURN1')
305checkR(function (x) return x % (100 - 10) end, 91, 1, 305checkR(function (x) return x % (100 - 10) end, 91, 1,
306 'MODI', 'MMBINI', 'RETURN1') 306 'MODI', 'MMBINI', 'RETURN1')
307checkR(function (x) return k1 << x end, 3, 8, 'SHLI', 'RETURN1') 307checkR(function (x) return k1 << x end, 3, 8, 'SHLI', 'MMBINI', 'RETURN1')
308checkR(function (x) return x << 2 end, 10, 40, 'SHRI', 'RETURN1') 308checkR(function (x) return x << 2 end, 10, 40, 'SHRI', 'MMBINI', 'RETURN1')
309checkR(function (x) return x >> 2 end, 8, 2, 'SHRI', 'RETURN1') 309checkR(function (x) return x >> 2 end, 8, 2, 'SHRI', 'MMBINI', 'RETURN1')
310checkR(function (x) return x & 1 end, 9, 1, 'BANDK', 'MMBINK', 'RETURN1') 310checkR(function (x) return x & 1 end, 9, 1, 'BANDK', 'MMBINK', 'RETURN1')
311checkR(function (x) return 10 | x end, 1, 11, 'BORK', 'MMBINK', 'RETURN1') 311checkR(function (x) return 10 | x end, 1, 11, 'BORK', 'MMBINK', 'RETURN1')
312checkR(function (x) return -10 ~ x end, -1, 9, 'BXORK', 'MMBINK', 'RETURN1') 312checkR(function (x) return -10 ~ x end, -1, 9, 'BXORK', 'MMBINK', 'RETURN1')
@@ -329,7 +329,7 @@ check(function () return -0.0 end, 'LOADF', 'UNM', 'RETURN1')
329check(function () return k3/0 end, 'LOADI', 'DIVI', 'MMBINI', 'RETURN1') 329check(function () return k3/0 end, 'LOADI', 'DIVI', 'MMBINI', 'RETURN1')
330check(function () return 0%0 end, 'LOADI', 'MODI', 'MMBINI', 'RETURN1') 330check(function () return 0%0 end, 'LOADI', 'MODI', 'MMBINI', 'RETURN1')
331check(function () return -4//0 end, 'LOADI', 'IDIVI', 'MMBINI', 'RETURN1') 331check(function () return -4//0 end, 'LOADI', 'IDIVI', 'MMBINI', 'RETURN1')
332check(function (x) return x >> 2.0 end, 'LOADF', 'SHR', 'RETURN1') 332check(function (x) return x >> 2.0 end, 'LOADF', 'SHR', 'MMBIN', 'RETURN1')
333check(function (x) return x & 2.0 end, 'LOADF', 'BAND', 'MMBIN', 'RETURN1') 333check(function (x) return x & 2.0 end, 'LOADF', 'BAND', 'MMBIN', 'RETURN1')
334 334
335-- basic 'for' loops 335-- basic 'for' loops
diff --git a/testes/db.lua b/testes/db.lua
index c43243a6..074a6d0b 100644
--- a/testes/db.lua
+++ b/testes/db.lua
@@ -806,8 +806,7 @@ assert(a+3 == "add" and 3-a == "sub" and a*3 == "mul" and
806 -a == "unm" and #a == "len" and a&3 == "band") 806 -a == "unm" and #a == "len" and a&3 == "band")
807assert(a + 30000 == "add" and a - 3.0 == "sub" and a * 3.0 == "mul" and 807assert(a + 30000 == "add" and a - 3.0 == "sub" and a * 3.0 == "mul" and
808 -a == "unm" and #a == "len" and a & 3 == "band") 808 -a == "unm" and #a == "len" and a & 3 == "band")
809assert(a|3 == "bor" and 3~a == "bxor" and a<<3 == "shift" and 809assert(a|3 == "bor" and 3~a == "bxor" and a<<3 == "shl" and a>>1 == "shr")
810 a>>1 == "shift")
811assert (a==b and a.op == "eq") 810assert (a==b and a.op == "eq")
812assert (a>=b and a.op == "order") 811assert (a>=b and a.op == "order")
813assert (a>b and a.op == "order") 812assert (a>b and a.op == "order")