diff options
Diffstat (limited to 'lvm.c')
-rw-r--r-- | lvm.c | 88 |
1 files changed, 44 insertions, 44 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 2.317 2017/11/23 19:18:10 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 2.318 2017/11/27 17:44:31 roberto Exp roberto $ |
3 | ** Lua virtual machine | 3 | ** Lua virtual machine |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -702,14 +702,14 @@ void luaV_finishOp (lua_State *L) { | |||
702 | L->top--; | 702 | L->top--; |
703 | if (ci->callstatus & CIST_LEQ) { /* "<=" using "<" instead? */ | 703 | if (ci->callstatus & CIST_LEQ) { /* "<=" using "<" instead? */ |
704 | lua_assert(op == OP_LE || | 704 | lua_assert(op == OP_LE || |
705 | (op == OP_LEI && !(GETARG_B(inst) & 2)) || | 705 | (op == OP_LTI && GETARG_C(inst)) || |
706 | (op == OP_LTI && GETARG_B(inst) & 2)); | 706 | (op == OP_LEI && !GETARG_C(inst))); |
707 | ci->callstatus ^= CIST_LEQ; /* clear mark */ | 707 | ci->callstatus ^= CIST_LEQ; /* clear mark */ |
708 | res = !res; /* negate result */ | 708 | res = !res; /* negate result */ |
709 | } | 709 | } |
710 | lua_assert(GET_OPCODE(*ci->u.l.savedpc) == OP_JMP); | 710 | lua_assert(GET_OPCODE(*ci->u.l.savedpc) == OP_JMP); |
711 | if (GETARG_B(inst) & 2) res = !res; | 711 | if (GETARG_C(inst)) res = !res; |
712 | if (res != (GETARG_B(inst) & 1)) /* condition failed? */ | 712 | if (res != GETARG_k(inst)) /* condition failed? */ |
713 | ci->u.l.savedpc++; /* skip jump instruction */ | 713 | ci->u.l.savedpc++; /* skip jump instruction */ |
714 | break; | 714 | break; |
715 | } | 715 | } |
@@ -766,7 +766,7 @@ void luaV_finishOp (lua_State *L) { | |||
766 | #define RC(i) (base+GETARG_C(i)) | 766 | #define RC(i) (base+GETARG_C(i)) |
767 | #define vRC(i) s2v(RC(i)) | 767 | #define vRC(i) s2v(RC(i)) |
768 | #define KC(i) (k+GETARG_C(i)) | 768 | #define KC(i) (k+GETARG_C(i)) |
769 | #define RKC(i) ((GETARG_k(i)) ? k + GETARG_C(i) : s2v(base + GETARG_C(i))) | 769 | #define RKC(i) ((TESTARG_k(i)) ? k + GETARG_C(i) : s2v(base + GETARG_C(i))) |
770 | 770 | ||
771 | 771 | ||
772 | 772 | ||
@@ -1326,59 +1326,59 @@ void luaV_execute (lua_State *L) { | |||
1326 | vmbreak; | 1326 | vmbreak; |
1327 | } | 1327 | } |
1328 | vmcase(OP_EQ) { | 1328 | vmcase(OP_EQ) { |
1329 | TValue *rc = vRC(i); | 1329 | TValue *rb = vRB(i); |
1330 | int res; | 1330 | int res; |
1331 | Protect(res = luaV_equalobj(L, s2v(ra), rc)); | 1331 | Protect(res = luaV_equalobj(L, s2v(ra), rb)); |
1332 | if (res != GETARG_B(i)) | 1332 | if (res != GETARG_k(i)) |
1333 | pc++; | 1333 | pc++; |
1334 | else | 1334 | else |
1335 | donextjump(ci); | 1335 | donextjump(ci); |
1336 | vmbreak; | 1336 | vmbreak; |
1337 | } | 1337 | } |
1338 | vmcase(OP_LT) { | 1338 | vmcase(OP_LT) { |
1339 | TValue *rc = vRC(i); | 1339 | TValue *rb = vRB(i); |
1340 | int res; | 1340 | int res; |
1341 | if (ttisinteger(s2v(ra)) && ttisinteger(rc)) | 1341 | if (ttisinteger(s2v(ra)) && ttisinteger(rb)) |
1342 | res = (ivalue(s2v(ra)) < ivalue(rc)); | 1342 | res = (ivalue(s2v(ra)) < ivalue(rb)); |
1343 | else if (ttisnumber(s2v(ra)) && ttisnumber(rc)) | 1343 | else if (ttisnumber(s2v(ra)) && ttisnumber(rb)) |
1344 | res = LTnum(s2v(ra), rc); | 1344 | res = LTnum(s2v(ra), rb); |
1345 | else | 1345 | else |
1346 | Protect(res = lessthanothers(L, s2v(ra), rc)); | 1346 | Protect(res = lessthanothers(L, s2v(ra), rb)); |
1347 | if (res != GETARG_B(i)) | 1347 | if (res != GETARG_k(i)) |
1348 | pc++; | 1348 | pc++; |
1349 | else | 1349 | else |
1350 | donextjump(ci); | 1350 | donextjump(ci); |
1351 | vmbreak; | 1351 | vmbreak; |
1352 | } | 1352 | } |
1353 | vmcase(OP_LE) { | 1353 | vmcase(OP_LE) { |
1354 | TValue *rc = vRC(i); | 1354 | TValue *rb = vRB(i); |
1355 | int res; | 1355 | int res; |
1356 | if (ttisinteger(s2v(ra)) && ttisinteger(rc)) | 1356 | if (ttisinteger(s2v(ra)) && ttisinteger(rb)) |
1357 | res = (ivalue(s2v(ra)) <= ivalue(rc)); | 1357 | res = (ivalue(s2v(ra)) <= ivalue(rb)); |
1358 | else if (ttisnumber(s2v(ra)) && ttisnumber(rc)) | 1358 | else if (ttisnumber(s2v(ra)) && ttisnumber(rb)) |
1359 | res = LEnum(s2v(ra), rc); | 1359 | res = LEnum(s2v(ra), rb); |
1360 | else | 1360 | else |
1361 | Protect(res = lessequalothers(L, s2v(ra), rc)); | 1361 | Protect(res = lessequalothers(L, s2v(ra), rb)); |
1362 | if (res != GETARG_B(i)) | 1362 | if (res != GETARG_k(i)) |
1363 | pc++; | 1363 | pc++; |
1364 | else | 1364 | else |
1365 | donextjump(ci); | 1365 | donextjump(ci); |
1366 | vmbreak; | 1366 | vmbreak; |
1367 | } | 1367 | } |
1368 | vmcase(OP_EQK) { | 1368 | vmcase(OP_EQK) { |
1369 | TValue *rc = KC(i); | 1369 | TValue *rb = KB(i); |
1370 | /* basic types do not use '__eq'; we can use raw equality */ | 1370 | /* basic types do not use '__eq'; we can use raw equality */ |
1371 | if (luaV_equalobj(NULL, s2v(ra), rc) != GETARG_B(i)) | 1371 | if (luaV_equalobj(NULL, s2v(ra), rb) != GETARG_k(i)) |
1372 | pc++; | 1372 | pc++; |
1373 | else | 1373 | else |
1374 | donextjump(ci); | 1374 | donextjump(ci); |
1375 | vmbreak; | 1375 | vmbreak; |
1376 | } | 1376 | } |
1377 | vmcase(OP_EQI) { | 1377 | vmcase(OP_EQI) { |
1378 | int ic = GETARG_sC(i); | 1378 | int im = GETARG_sB(i); |
1379 | if ((ttisinteger(s2v(ra)) ? (ivalue(s2v(ra)) == ic) | 1379 | if ((ttisinteger(s2v(ra)) ? (ivalue(s2v(ra)) == im) |
1380 | :ttisfloat(s2v(ra)) ? luai_numeq(fltvalue(s2v(ra)), cast_num(ic)) | 1380 | :ttisfloat(s2v(ra)) ? luai_numeq(fltvalue(s2v(ra)), cast_num(im)) |
1381 | : 0) != GETARG_B(i)) | 1381 | : 0) != GETARG_k(i)) |
1382 | pc++; | 1382 | pc++; |
1383 | else | 1383 | else |
1384 | donextjump(ci); | 1384 | donextjump(ci); |
@@ -1386,17 +1386,17 @@ void luaV_execute (lua_State *L) { | |||
1386 | } | 1386 | } |
1387 | vmcase(OP_LTI) { | 1387 | vmcase(OP_LTI) { |
1388 | int res; | 1388 | int res; |
1389 | int ic = GETARG_sC(i); | 1389 | int im = GETARG_sB(i); |
1390 | if (ttisinteger(s2v(ra))) | 1390 | if (ttisinteger(s2v(ra))) |
1391 | res = (ivalue(s2v(ra)) < ic); | 1391 | res = (ivalue(s2v(ra)) < im); |
1392 | else if (ttisfloat(s2v(ra))) { | 1392 | else if (ttisfloat(s2v(ra))) { |
1393 | lua_Number f = fltvalue(s2v(ra)); | 1393 | lua_Number f = fltvalue(s2v(ra)); |
1394 | res = (!luai_numisnan(f)) ? luai_numlt(f, cast_num(ic)) | 1394 | res = (!luai_numisnan(f)) ? luai_numlt(f, cast_num(im)) |
1395 | : GETARG_B(i) >> 1; /* NaN? */ | 1395 | : GETARG_C(i); /* NaN? */ |
1396 | } | 1396 | } |
1397 | else | 1397 | else |
1398 | Protect(res = luaT_callorderiTM(L, s2v(ra), ic, GETARG_B(i) >> 1, TM_LT)); | 1398 | Protect(res = luaT_callorderiTM(L, s2v(ra), im, GETARG_C(i), TM_LT)); |
1399 | if (res != (GETARG_B(i) & 1)) | 1399 | if (res != GETARG_k(i)) |
1400 | pc++; | 1400 | pc++; |
1401 | else | 1401 | else |
1402 | donextjump(ci); | 1402 | donextjump(ci); |
@@ -1404,32 +1404,32 @@ void luaV_execute (lua_State *L) { | |||
1404 | } | 1404 | } |
1405 | vmcase(OP_LEI) { | 1405 | vmcase(OP_LEI) { |
1406 | int res; | 1406 | int res; |
1407 | int ic = GETARG_sC(i); | 1407 | int im = GETARG_sB(i); |
1408 | if (ttisinteger(s2v(ra))) | 1408 | if (ttisinteger(s2v(ra))) |
1409 | res = (ivalue(s2v(ra)) <= ic); | 1409 | res = (ivalue(s2v(ra)) <= im); |
1410 | else if (ttisfloat(s2v(ra))) { | 1410 | else if (ttisfloat(s2v(ra))) { |
1411 | lua_Number f = fltvalue(s2v(ra)); | 1411 | lua_Number f = fltvalue(s2v(ra)); |
1412 | res = (!luai_numisnan(f)) ? luai_numle(f, cast_num(ic)) | 1412 | res = (!luai_numisnan(f)) ? luai_numle(f, cast_num(im)) |
1413 | : GETARG_B(i) >> 1; /* NaN? */ | 1413 | : GETARG_C(i); /* NaN? */ |
1414 | } | 1414 | } |
1415 | else | 1415 | else |
1416 | Protect(res = luaT_callorderiTM(L, s2v(ra), ic, GETARG_B(i) >> 1, TM_LE)); | 1416 | Protect(res = luaT_callorderiTM(L, s2v(ra), im, GETARG_C(i), TM_LE)); |
1417 | if (res != (GETARG_B(i) & 1)) | 1417 | if (res != GETARG_k(i)) |
1418 | pc++; | 1418 | pc++; |
1419 | else | 1419 | else |
1420 | donextjump(ci); | 1420 | donextjump(ci); |
1421 | vmbreak; | 1421 | vmbreak; |
1422 | } | 1422 | } |
1423 | vmcase(OP_TEST) { | 1423 | vmcase(OP_TEST) { |
1424 | if (GETARG_C(i) ? l_isfalse(s2v(ra)) : !l_isfalse(s2v(ra))) | 1424 | if (l_isfalse(s2v(ra)) == GETARG_k(i)) |
1425 | pc++; | 1425 | pc++; |
1426 | else | 1426 | else |
1427 | donextjump(ci); | 1427 | donextjump(ci); |
1428 | vmbreak; | 1428 | vmbreak; |
1429 | } | 1429 | } |
1430 | vmcase(OP_TESTSET) { | 1430 | vmcase(OP_TESTSET) { |
1431 | TValue *rb = vRB(i); | 1431 | TValue *rb = vRB(i); |
1432 | if (GETARG_C(i) ? l_isfalse(rb) : !l_isfalse(rb)) | 1432 | if (l_isfalse(rb) == GETARG_k(i)) |
1433 | pc++; | 1433 | pc++; |
1434 | else { | 1434 | else { |
1435 | setobj2s(L, ra, rb); | 1435 | setobj2s(L, ra, rb); |