From 01d7a43f5ef8e7a74bad9b39916d553d61b29fc3 Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Wed, 8 Feb 2017 10:29:20 +0100 Subject: TEST, TESTSET --- src/lvm.js | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/lvm.js b/src/lvm.js index 1673db7..bf74f24 100644 --- a/src/lvm.js +++ b/src/lvm.js @@ -333,7 +333,7 @@ class LuaVM { } case "OP_NOT": { let op = L.stack[this.RB(base, i)]; - L.stack[ra] = new TValue(CT.LUA_TBOOLEAN, !!((op.type === CT.LUA_TBOOLEAN && !op.value) || op.type === CT.LUA_TNIL)); + L.stack[ra] = new TValue(CT.LUA_TBOOLEAN, LuaVM.l_isfalse(op)); break; } case "OP_LEN": { @@ -371,9 +371,20 @@ class LuaVM { break; } case "OP_TEST": { + if (i.C ? LuaVM.l_isfalse(L.stack[ra]) : !LuaVM.l_isfalse(L.stack[ra])) + ci.pcOff++; + else + this.donextjump(ci); break; } case "OP_TESTSET": { + let rb = L.stack[this.RB(base, i)]; + if (i.C ? LuaVM.l_isfalse(rb) : !LuaVM.l_isfalse(rb)) + ci.pcOff++; + else { + L.stack[ra] = rb; + this.donextjump(ci); + } break; } case "OP_CALL": { @@ -747,12 +758,12 @@ class LuaVM { } static LEintfloat(l, r) { - // TODO + // TODO: LEintfloat return l <= r ? 1 : 0; } static LTintfloat(l, r) { - // TODO + // TODO: LTintfloat return l < r ? 1 : 0; } @@ -761,6 +772,10 @@ class LuaVM { return ls.value === rs.value ? 0 : (ls.value < rs.value ? -1 : 1); } + static l_isfalse(o) { + return o.ttisnil() || (o.ttisboolean() && o.value === false) + } + } module.exports = { -- cgit v1.2.3-70-g09d2