diff options
-rw-r--r-- | src/lfunc.js | 1 | ||||
-rw-r--r-- | src/lstate.js | 6 | ||||
-rw-r--r-- | src/lvm.js | 4 | ||||
-rw-r--r-- | tests/lvm.js | 12 |
4 files changed, 12 insertions, 11 deletions
diff --git a/src/lfunc.js b/src/lfunc.js index abc87e8..929dae8 100644 --- a/src/lfunc.js +++ b/src/lfunc.js @@ -17,7 +17,6 @@ class Proto { this.linedefined = 0; // debug information this.lastlinedefined = 0; // debug information this.source = null; // used for debug information - this.nresults = 0; // expected number of results from this function } } diff --git a/src/lstate.js b/src/lstate.js index bf49b42..ef84e07 100644 --- a/src/lstate.js +++ b/src/lstate.js @@ -4,8 +4,9 @@ class CallInfo { - constructor(func, top, base, previous, next) { + constructor(funcOff, func, top, base, previous, next) { this.func = func; + this.funcOff = funcOff; this.top = top; this.previous = previous; this.next = next; @@ -16,6 +17,7 @@ class CallInfo { savedpc: [] } }; + this.nresults = 0; } } @@ -24,7 +26,7 @@ class lua_State { constructor(cl) { this.top = 1; - this.ci = new CallInfo(cl, 1, 1, null, null); + this.ci = new CallInfo(0, cl, 1, 1, null, null); this.ci.u.l.savedpc = cl.p.code; this.ciOff = 0; this.stack = [ @@ -450,7 +450,7 @@ class LuaVM { if (L.ci.next) { L.ci = L.ci.next; } else { - ci = new CallInfo(); + ci = new CallInfo(off); L.ci.next = ci; ci.previous = L.ci; ci.next = null; @@ -473,7 +473,7 @@ class LuaVM { postcall(ci, firstResult, nres) { let wanted = ci.nresults; - let res = ci.func; + let res = ci.funcOff; this.L.ci = ci.previous; this.L.ciOff--; return this.moveresults(firstResult, res, nres, wanted); diff --git a/tests/lvm.js b/tests/lvm.js index d328b6b..729a66d 100644 --- a/tests/lvm.js +++ b/tests/lvm.js @@ -61,7 +61,7 @@ test('LOADK, RETURN', function (t) { }, "Program executed without errors"); t.strictEqual( - vm.L.stack[vm.L.top].value, + vm.L.stack[vm.L.stack.length - 1].value, "hello world", "Program output is correct" ); @@ -85,7 +85,7 @@ test('MOV', function (t) { }, "Program executed without errors"); t.strictEqual( - vm.L.stack[vm.L.top].value, + vm.L.stack[vm.L.stack.length - 1].value, "hello world", "Program output is correct" ); @@ -108,7 +108,7 @@ test('Binary op', function (t) { }, "Program executed without errors"); t.deepEqual( - vm.L.stack.slice(vm.L.top, vm.L.top + 12).map(function (e) { return e.value; }), + vm.L.stack.slice(vm.L.stack.length - 12).map(function (e) { return e.value; }), [15, -5, 50, 0.5, 5, 9765625.0, 0, 0, 15, 15, 5120, 0], "Program output is correct" ); @@ -132,7 +132,7 @@ test('Unary op, LOADBOOL', function (t) { }, "Program executed without errors"); t.deepEqual( - vm.L.stack.slice(vm.L.top - 3, vm.L.top).map(function (e) { return e.value; }), + vm.L.stack.slice(vm.L.stack.length - 3).map(function (e) { return e.value; }), [-5, true, -6], "Program output is correct" ); @@ -155,7 +155,7 @@ test('NEWTABLE', function (t) { }, "Program executed without errors"); t.ok( - vm.L.stack[vm.L.top] instanceof Table, + vm.L.stack[vm.L.stack.length - 1] instanceof Table, "Program output is correct" ); }); @@ -182,7 +182,7 @@ test('CALL', function (t) { }, "Program executed without errors"); t.strictEqual( - vm.L.stack[vm.L.top].value, + vm.L.stack[vm.L.stack.length - 1].value, 3, "Program output is correct" ); |