aboutsummaryrefslogtreecommitdiff
path: root/lvm.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2017-11-27 15:44:31 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2017-11-27 15:44:31 -0200
commit093c16b67b263e334600ed306310b9015f65fa8b (patch)
tree5ed17cb52078eddcc9b6b051e102839194ad4ba8 /lvm.c
parent599f1742c628db70ef84794b3b8b25fdef9e5004 (diff)
downloadlua-093c16b67b263e334600ed306310b9015f65fa8b.tar.gz
lua-093c16b67b263e334600ed306310b9015f65fa8b.tar.bz2
lua-093c16b67b263e334600ed306310b9015f65fa8b.zip
new opcodes 'OP_LTI' and 'OP_LEI'
Diffstat (limited to 'lvm.c')
-rw-r--r--lvm.c53
1 files changed, 45 insertions, 8 deletions
diff --git a/lvm.c b/lvm.c
index 5d9440a6..364c64dd 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,9 +1,5 @@
1/* 1/*
2<<<<<<< lvm.c 2** $Id: lvm.c,v 2.317 2017/11/23 19:18:10 roberto Exp roberto $
3** $Id: lvm.c,v 2.316 2017/11/23 16:41:16 roberto Exp roberto $
4=======
5** $Id: lvm.c,v 2.316 2017/11/23 16:41:16 roberto Exp roberto $
6>>>>>>> 2.315
7** Lua virtual machine 3** Lua virtual machine
8** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
9*/ 5*/
@@ -699,16 +695,21 @@ void luaV_finishOp (lua_State *L) {
699 setobjs2s(L, base + GETARG_A(inst), --L->top); 695 setobjs2s(L, base + GETARG_A(inst), --L->top);
700 break; 696 break;
701 } 697 }
702 case OP_LE: case OP_LT: case OP_EQ: { 698 case OP_LT: case OP_LE:
699 case OP_LTI: case OP_LEI:
700 case OP_EQ: { /* note that 'OP_EQI'/'OP_EQK' cannot yield */
703 int res = !l_isfalse(s2v(L->top - 1)); 701 int res = !l_isfalse(s2v(L->top - 1));
704 L->top--; 702 L->top--;
705 if (ci->callstatus & CIST_LEQ) { /* "<=" using "<" instead? */ 703 if (ci->callstatus & CIST_LEQ) { /* "<=" using "<" instead? */
706 lua_assert(op == OP_LE); 704 lua_assert(op == OP_LE ||
705 (op == OP_LEI && !(GETARG_B(inst) & 2)) ||
706 (op == OP_LTI && GETARG_B(inst) & 2));
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 (res != GETARG_B(inst)) /* condition failed? */ 711 if (GETARG_B(inst) & 2) res = !res;
712 if (res != (GETARG_B(inst) & 1)) /* condition failed? */
712 ci->u.l.savedpc++; /* skip jump instruction */ 713 ci->u.l.savedpc++; /* skip jump instruction */
713 break; 714 break;
714 } 715 }
@@ -1383,6 +1384,42 @@ void luaV_execute (lua_State *L) {
1383 donextjump(ci); 1384 donextjump(ci);
1384 vmbreak; 1385 vmbreak;
1385 } 1386 }
1387 vmcase(OP_LTI) {
1388 int res;
1389 int ic = GETARG_sC(i);
1390 if (ttisinteger(s2v(ra)))
1391 res = (ivalue(s2v(ra)) < ic);
1392 else if (ttisfloat(s2v(ra))) {
1393 lua_Number f = fltvalue(s2v(ra));
1394 res = (!luai_numisnan(f)) ? luai_numlt(f, cast_num(ic))
1395 : GETARG_B(i) >> 1; /* NaN? */
1396 }
1397 else
1398 Protect(res = luaT_callorderiTM(L, s2v(ra), ic, GETARG_B(i) >> 1, TM_LT));
1399 if (res != (GETARG_B(i) & 1))
1400 pc++;
1401 else
1402 donextjump(ci);
1403 vmbreak;
1404 }
1405 vmcase(OP_LEI) {
1406 int res;
1407 int ic = GETARG_sC(i);
1408 if (ttisinteger(s2v(ra)))
1409 res = (ivalue(s2v(ra)) <= ic);
1410 else if (ttisfloat(s2v(ra))) {
1411 lua_Number f = fltvalue(s2v(ra));
1412 res = (!luai_numisnan(f)) ? luai_numle(f, cast_num(ic))
1413 : GETARG_B(i) >> 1; /* NaN? */
1414 }
1415 else
1416 Protect(res = luaT_callorderiTM(L, s2v(ra), ic, GETARG_B(i) >> 1, TM_LE));
1417 if (res != (GETARG_B(i) & 1))
1418 pc++;
1419 else
1420 donextjump(ci);
1421 vmbreak;
1422 }
1386 vmcase(OP_TEST) { 1423 vmcase(OP_TEST) {
1387 if (GETARG_C(i) ? l_isfalse(s2v(ra)) : !l_isfalse(s2v(ra))) 1424 if (GETARG_C(i) ? l_isfalse(s2v(ra)) : !l_isfalse(s2v(ra)))
1388 pc++; 1425 pc++;