aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--luac.outbin203 -> 221 bytes
-rw-r--r--sandbox/helloworld.lua1
-rw-r--r--src/lvm.js7
-rw-r--r--tests/lvm.js24
4 files changed, 28 insertions, 4 deletions
diff --git a/luac.out b/luac.out
index 1c971ab..eb528fa 100644
--- a/luac.out
+++ b/luac.out
Binary files differ
diff --git a/sandbox/helloworld.lua b/sandbox/helloworld.lua
deleted file mode 100644
index 7785fb9..0000000
--- a/sandbox/helloworld.lua
+++ /dev/null
@@ -1 +0,0 @@
-local a = "hello world"
diff --git a/src/lvm.js b/src/lvm.js
index 7a65d74..964abe7 100644
--- a/src/lvm.js
+++ b/src/lvm.js
@@ -42,11 +42,10 @@ class LuaVM {
let i = ci.savedpc[ci.pcOff++];
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);
+ L.stack[ra] = L.stack[this.RB(base, i.opcode, i.B)];
break;
case "OP_LOADK":
L.stack[ra] = k[i.Bx];
@@ -131,6 +130,8 @@ class LuaVM {
}
L.ci = ci.previous;
+ // TODO what to return when end of program ?
+ console.log(L.stack);
if (L.ci === null) return;
if (i.B !== 0) L.top = ci.top;
diff --git a/tests/lvm.js b/tests/lvm.js
index 6ee348d..ffd128d 100644
--- a/tests/lvm.js
+++ b/tests/lvm.js
@@ -63,4 +63,28 @@ test('LOADK, RETURN', function (t) {
"hello world",
"Program output is correct"
);
+});
+
+
+test('MOV', function (t) {
+ let luaCode = `
+ local a = "hello world"
+ local b = a
+ return b
+ `, vm;
+
+ t.plan(1);
+
+ t.comment("Running following code: \n" + luaCode);
+
+ // t.doesNotThrow(function () {
+ vm = getVM(luaCode);
+ vm.execute();
+ // }, "Program executed without errors");
+
+ t.strictEqual(
+ vm.L.stack[0].value,
+ "hello world",
+ "Program output is correct"
+ );
}); \ No newline at end of file