From 3e7c7039680f80f3fa90cf357e5448d42397ea16 Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Fri, 3 Feb 2017 11:24:18 +0100 Subject: VM Tests, OP_MOVE, OP_LOAK, partial OP_RETURN --- src/lstate.js | 11 ++++++++--- src/lvm.js | 27 +++++++++++++++++++++------ 2 files changed, 29 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/lstate.js b/src/lstate.js index 9c7eec3..15dedcb 100644 --- a/src/lstate.js +++ b/src/lstate.js @@ -21,14 +21,19 @@ class lua_State { constructor(cl) { this.top = 1; this.ci = [ - new CallInfo(0, 1, 1, null, null); + new CallInfo(0, 1, 1, null, null) ]; this.ci[0].savedpc = cl.p.code; this.ciOff = 0; this.stack = [ - closure + cl ]; this.openupval = []; } -} \ No newline at end of file +} + +module.exports = { + lua_State: lua_State, + CallInfo: CallInfo +}; \ No newline at end of file diff --git a/src/lvm.js b/src/lvm.js index 349cccf..7a65d74 100644 --- a/src/lvm.js +++ b/src/lvm.js @@ -14,7 +14,7 @@ class LuaVM { return base + a; } - RB(base, opcode, base, b) { + RB(base, opcode, b) { return base + b; } @@ -35,18 +35,21 @@ class LuaVM { let ci = L.ci[this.L.ciOff]; newframe: - let cl = ci.func; - let k = cl.p.k; - let base = ci.base; - for (;;) { + var cl = L.stack[ci.func]; + let k = cl.p.k; + let base = ci.base; + let i = ci.savedpc[ci.pcOff++]; - let ra = this.RA(base, i.a); + let ra = this.RA(base, i.A); + console.log(OC.OpCodes[i.opcode]); switch (OC.OpCodes[i.opcode]) { case "OP_MOVE": + L.stack[ra] = RB(base, i.opcode, i.B); break; case "OP_LOADK": + L.stack[ra] = k[i.Bx]; break; case "OP_LOADKX": break; @@ -121,6 +124,18 @@ class LuaVM { case "OP_TAILCALL": break; case "OP_RETURN": + if (i.B >= 2) { + for (let j = 0; j <= i.B-2; j++) { + L.stack[L.ciOff + j] = L.stack[ra + j]; + } + } + L.ci = ci.previous; + + if (L.ci === null) return; + + if (i.B !== 0) L.top = ci.top; + + continue newframe; break; case "OP_FORLOOP": break; -- cgit v1.2.3-54-g00ecf