diff options
author | Benoit Giannangeli <benoit.giannangeli@boursorama.fr> | 2017-02-13 11:39:43 +0100 |
---|---|---|
committer | Benoit Giannangeli <benoit.giannangeli@boursorama.fr> | 2017-02-13 11:44:08 +0100 |
commit | 7236b4bf648ba2fffc83d0b031766208a183e52b (patch) | |
tree | d9963576bd6cb16a72601bb92d194e9fbc33d3a4 | |
parent | 4627bb4b5c3ccc8431fbba68a78efd50ebb13909 (diff) | |
download | fengari-7236b4bf648ba2fffc83d0b031766208a183e52b.tar.gz fengari-7236b4bf648ba2fffc83d0b031766208a183e52b.tar.bz2 fengari-7236b4bf648ba2fffc83d0b031766208a183e52b.zip |
l_isfalse as TValue method
-rw-r--r-- | src/lobject.js | 4 | ||||
-rw-r--r-- | src/ltm.js | 2 | ||||
-rw-r--r-- | src/lvm.js | 13 | ||||
-rw-r--r-- | tests/lvm.js | 2 |
4 files changed, 10 insertions, 11 deletions
diff --git a/src/lobject.js b/src/lobject.js index 7b39668..385ac9c 100644 --- a/src/lobject.js +++ b/src/lobject.js @@ -102,6 +102,10 @@ class TValue { return this.checktag(CT.LUA_TDEADKEY); } + l_isfalse() { + return this.ttisnil() || (this.ttisboolean() && this.value === false); + } + } const nil = new TValue(CT.LUA_TNIL, null); @@ -79,7 +79,7 @@ const luaT_callorderTM = function(L, p1, p2, event) { if (!luaT_callbinTM(L, p2, p2, L.top, event)) return -1; else - return !l_isfalse(L.stack[L.top]) ? 1 : 0; + return !L.stack[L.top].l_isfalse() ? 1 : 0; }; const luaT_gettmbyobj = function(L, o, event) { @@ -372,7 +372,7 @@ const luaV_execute = function(L) { } case "OP_NOT": { let op = L.stack[RB(L, base, i)]; - L.stack[ra] = new TValue(CT.LUA_TBOOLEAN, l_isfalse(op)); + L.stack[ra] = new TValue(CT.LUA_TBOOLEAN, op.l_isfalse()); break; } case "OP_LEN": { @@ -412,7 +412,7 @@ const luaV_execute = function(L) { break; } case "OP_TEST": { - if (i.C ? l_isfalse(L.stack[ra]) : !l_isfalse(L.stack[ra])) + if (i.C ? L.stack[ra].l_isfalse() : !L.stack[ra].l_isfalse()) ci.pcOff++; else donextjump(L, ci); @@ -420,7 +420,7 @@ const luaV_execute = function(L) { } case "OP_TESTSET": { let rb = L.stack[RB(L, base, i)]; - if (i.C ? l_isfalse(rb) : !l_isfalse(rb)) + if (i.C ? rb.l_isfalse() : !rb.l_isfalse()) ci.pcOff++; else { L.stack[ra] = rb; @@ -731,7 +731,7 @@ const luaV_equalobj = function(L, t1, t2) { return 0; ltm.luaT_callTM(L, tm, t1, t2, L.top, 1); - return !l_isfalse(L.stack[L.top]); + return !L.stack[L.top].l_isfalse(); }; const forlimit = function(obj, step) { @@ -846,10 +846,6 @@ const l_strcmp = function(ls, rs) { return ls.value === rs.value ? 0 : (ls.value < rs.value ? -1 : 1); }; -const l_isfalse = function(o) { - return o.ttisnil() || (o.ttisboolean() && o.value === false); -}; - /* ** Main operation 'ra' = #rb'. */ @@ -942,7 +938,6 @@ module.exports = { LEintfloat: LEintfloat, LTintfloat: LTintfloat, l_strcmp: l_strcmp, - l_isfalse: l_isfalse, luaV_objlen: luaV_objlen, stackerror: stackerror, luaD_call: luaD_call, diff --git a/tests/lvm.js b/tests/lvm.js index 5de8b31..d11eb9d 100644 --- a/tests/lvm.js +++ b/tests/lvm.js @@ -747,7 +747,7 @@ test('LEN', function (t) { return #t, #t2, #s `, L; - t.plan(3); + t.plan(4); t.comment("Running following code: \n" + luaCode); |