summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-03-01 15:16:07 +0100
committerBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-03-01 15:16:07 +0100
commit6d3c16cb0b7a859ff45e62ed83252f667d3b74d5 (patch)
tree86357ed832a1c022921e5fce106b7eadd9350add
parent3da8070fa77b518baeba0cdea7265f7d41f497fe (diff)
downloadfengari-6d3c16cb0b7a859ff45e62ed83252f667d3b74d5.tar.gz
fengari-6d3c16cb0b7a859ff45e62ed83252f667d3b74d5.tar.bz2
fengari-6d3c16cb0b7a859ff45e62ed83252f667d3b74d5.zip
[Parsing tests] CALL
-rw-r--r--src/lcode.js2
-rw-r--r--src/lvm.js1
-rw-r--r--tests/lexparse.js33
3 files changed, 35 insertions, 1 deletions
diff --git a/src/lcode.js b/src/lcode.js
index f69bc34..7fd958e 100644
--- a/src/lcode.js
+++ b/src/lcode.js
@@ -359,7 +359,7 @@ const luaK_patchclose = function(fs, list, level) {
** line information. Return 'i' position.
*/
const luaK_code = function(fs, i) {
- console.log(OpCodes[i.opcode]);
+ // console.log(OpCodes[i.opcode]);
let f = fs.f;
dischargejpc(fs); /* 'pc' will change */
/* put new instruction in code array */
diff --git a/src/lvm.js b/src/lvm.js
index 0ff433e..75fe44c 100644
--- a/src/lvm.js
+++ b/src/lvm.js
@@ -128,6 +128,7 @@ const luaV_execute = function(L) {
if (i.breakpoint) // TODO: remove, used until lapi
return;
+ console.log(`> ${opcode}`);
switch (opcode) {
case "OP_MOVE": {
L.stack[ra] = L.stack[RB(L, base, i)];
diff --git a/tests/lexparse.js b/tests/lexparse.js
index 1132ef1..98f55bb 100644
--- a/tests/lexparse.js
+++ b/tests/lexparse.js
@@ -155,4 +155,37 @@ test('NEWTABLE', function (t) {
L.stack[lapi.index2addr_(L, -1)] instanceof Table,
"Program output is correct"
);
+});
+
+
+test('CALL', function (t) {
+ let luaCode = `
+ local f = function (a, b)
+ return a + b
+ end
+
+ local c = f(1, 2)
+
+ return c
+ `, L;
+
+ t.plan(2);
+
+ t.doesNotThrow(function () {
+
+ L = lauxlib.luaL_newstate();
+
+ linit.luaL_openlibs(L);
+
+ lapi.lua_load(L, null, luaCode, "test", "text");
+
+ lapi.lua_call(L, 0, -1);
+
+ }, "JS Lua program ran without error");
+
+ t.strictEqual(
+ lapi.lua_tointeger(L, -1),
+ 3,
+ "Program output is correct"
+ );
}); \ No newline at end of file