diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-02-21 12:49:32 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-02-21 12:49:32 -0300 |
commit | 212095a601ee68e99065b553f7b6bc216056d82e (patch) | |
tree | 3843f9dde40eeb71c56ac8a0be8d77c78272f6ef /lvm.c | |
parent | c67603fafba7f982e92eb870ff4da6c6433c2a85 (diff) | |
download | lua-212095a601ee68e99065b553f7b6bc216056d82e.tar.gz lua-212095a601ee68e99065b553f7b6bc216056d82e.tar.bz2 lua-212095a601ee68e99065b553f7b6bc216056d82e.zip |
new opcodes OP_GTI/OP_GEI
Diffstat (limited to 'lvm.c')
-rw-r--r-- | lvm.c | 45 |
1 files changed, 28 insertions, 17 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 2.343 2018/02/21 12:54:26 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 2.344 2018/02/21 13:47:03 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 | */ |
@@ -731,18 +731,15 @@ void luaV_finishOp (lua_State *L) { | |||
731 | } | 731 | } |
732 | case OP_LT: case OP_LE: | 732 | case OP_LT: case OP_LE: |
733 | case OP_LTI: case OP_LEI: | 733 | case OP_LTI: case OP_LEI: |
734 | case OP_GTI: case OP_GEI: | ||
734 | case OP_EQ: { /* note that 'OP_EQI'/'OP_EQK' cannot yield */ | 735 | case OP_EQ: { /* note that 'OP_EQI'/'OP_EQK' cannot yield */ |
735 | int res = !l_isfalse(s2v(L->top - 1)); | 736 | int res = !l_isfalse(s2v(L->top - 1)); |
736 | L->top--; | 737 | L->top--; |
737 | if (ci->callstatus & CIST_LEQ) { /* "<=" using "<" instead? */ | 738 | if (ci->callstatus & CIST_LEQ) { /* "<=" using "<" instead? */ |
738 | lua_assert(op == OP_LE || | ||
739 | (op == OP_LTI && GETARG_C(inst)) || | ||
740 | (op == OP_LEI && !GETARG_C(inst))); | ||
741 | ci->callstatus ^= CIST_LEQ; /* clear mark */ | 739 | ci->callstatus ^= CIST_LEQ; /* clear mark */ |
742 | res = !res; /* negate result */ | 740 | res = !res; /* negate result */ |
743 | } | 741 | } |
744 | lua_assert(GET_OPCODE(*ci->u.l.savedpc) == OP_JMP); | 742 | lua_assert(GET_OPCODE(*ci->u.l.savedpc) == OP_JMP); |
745 | if (GETARG_C(inst)) res = !res; | ||
746 | if (res != GETARG_k(inst)) /* condition failed? */ | 743 | if (res != GETARG_k(inst)) /* condition failed? */ |
747 | ci->u.l.savedpc++; /* skip jump instruction */ | 744 | ci->u.l.savedpc++; /* skip jump instruction */ |
748 | break; | 745 | break; |
@@ -1473,26 +1470,40 @@ void luaV_execute (lua_State *L, CallInfo *ci) { | |||
1473 | int im = GETARG_sB(i); | 1470 | int im = GETARG_sB(i); |
1474 | if (ttisinteger(vra)) | 1471 | if (ttisinteger(vra)) |
1475 | cond = (ivalue(vra) < im); | 1472 | cond = (ivalue(vra) < im); |
1476 | else if (ttisfloat(vra)) { | 1473 | else if (ttisfloat(vra)) |
1477 | lua_Number f = fltvalue(vra); | 1474 | cond = luai_numlt(fltvalue(vra), cast_num(im)); |
1478 | cond = (!luai_numisnan(f)) ? luai_numlt(f, cast_num(im)) | ||
1479 | : GETARG_C(i); /* NaN */ | ||
1480 | } | ||
1481 | else | 1475 | else |
1482 | Protect(cond = luaT_callorderiTM(L, vra, im, GETARG_C(i), TM_LT)); | 1476 | Protect(cond = luaT_callorderiTM(L, vra, im, 0, TM_LT)); |
1483 | goto condjump; | 1477 | goto condjump; |
1484 | } | 1478 | } |
1485 | vmcase(OP_LEI) { | 1479 | vmcase(OP_LEI) { |
1486 | int im = GETARG_sB(i); | 1480 | int im = GETARG_sB(i); |
1487 | if (ttisinteger(vra)) | 1481 | if (ttisinteger(vra)) |
1488 | cond = (ivalue(vra) <= im); | 1482 | cond = (ivalue(vra) <= im); |
1489 | else if (ttisfloat(vra)) { | 1483 | else if (ttisfloat(vra)) |
1490 | lua_Number f = fltvalue(vra); | 1484 | cond = luai_numle(fltvalue(vra), cast_num(im)); |
1491 | cond = (!luai_numisnan(f)) ? luai_numle(f, cast_num(im)) | 1485 | else |
1492 | : GETARG_C(i); /* NaN? */ | 1486 | Protect(cond = luaT_callorderiTM(L, vra, im, 0, TM_LE)); |
1493 | } | 1487 | goto condjump; |
1488 | } | ||
1489 | vmcase(OP_GTI) { | ||
1490 | int im = GETARG_sB(i); | ||
1491 | if (ttisinteger(vra)) | ||
1492 | cond = (im < ivalue(vra)); | ||
1493 | else if (ttisfloat(vra)) | ||
1494 | cond = luai_numlt(cast_num(im), fltvalue(vra)); | ||
1495 | else | ||
1496 | Protect(cond = luaT_callorderiTM(L, vra, im, 1, TM_LT)); | ||
1497 | goto condjump; | ||
1498 | } | ||
1499 | vmcase(OP_GEI) { | ||
1500 | int im = GETARG_sB(i); | ||
1501 | if (ttisinteger(vra)) | ||
1502 | cond = (im <= ivalue(vra)); | ||
1503 | else if (ttisfloat(vra)) | ||
1504 | cond = luai_numle(cast_num(im), fltvalue(vra)); | ||
1494 | else | 1505 | else |
1495 | Protect(cond = luaT_callorderiTM(L, vra, im, GETARG_C(i), TM_LE)); | 1506 | Protect(cond = luaT_callorderiTM(L, vra, im, 1, TM_LE)); |
1496 | goto condjump; | 1507 | goto condjump; |
1497 | } | 1508 | } |
1498 | vmcase(OP_TEST) { | 1509 | vmcase(OP_TEST) { |