diff options
author | Benoit Giannangeli <benoit.giannangeli@boursorama.fr> | 2017-02-03 11:24:18 +0100 |
---|---|---|
committer | Benoit Giannangeli <benoit.giannangeli@boursorama.fr> | 2017-02-03 11:24:18 +0100 |
commit | 3e7c7039680f80f3fa90cf357e5448d42397ea16 (patch) | |
tree | db633c610c9644c05f67739252abc068a2213409 /src/lvm.js | |
parent | 9fbe044cbff12b635e535a36abcf2fb2a03dee11 (diff) | |
download | fengari-3e7c7039680f80f3fa90cf357e5448d42397ea16.tar.gz fengari-3e7c7039680f80f3fa90cf357e5448d42397ea16.tar.bz2 fengari-3e7c7039680f80f3fa90cf357e5448d42397ea16.zip |
VM Tests, OP_MOVE, OP_LOAK, partial OP_RETURN
Diffstat (limited to 'src/lvm.js')
-rw-r--r-- | src/lvm.js | 27 |
1 files changed, 21 insertions, 6 deletions
@@ -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; |