diff options
Diffstat (limited to 'lvm.c')
-rw-r--r-- | lvm.c | 102 |
1 files changed, 40 insertions, 62 deletions
@@ -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 | |||
677 | lua_Integer luaV_shiftl (lua_Integer x, lua_Integer y) { | 679 | lua_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) { |