From 0989db69a5c0b36b7b5c39f57510da879a0076b5 Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Wed, 1 Mar 2017 15:59:14 +0100 Subject: [Parsing tests] TAILCALL --- .vscode/launch.json | 27 +++++++++++++++++++++++++++ .vscode/settings.json | 3 +++ src/lopcodes.js | 6 ++++++ tests/lexparse.js | 31 +++++++++++++++++++++++++++++++ 4 files changed, 67 insertions(+) create mode 100644 .vscode/launch.json create mode 100644 .vscode/settings.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..8d42b62 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,27 @@ +{ + // Use IntelliSense to learn about possible Node.js debug attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "Launch Program", + "program": "${workspaceRoot}/index.js" + }, + { + "type": "node", + "request": "launch", + "name": "Tests", + "program": "${workspaceRoot}/tests/lexparse.js" + }, + { + "type": "node", + "request": "attach", + "name": "Attach to Process", + "address": "localhost", + "port": 5858 + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..0c4a669 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "vsicons.presets.angular": false +} \ No newline at end of file diff --git a/src/lopcodes.js b/src/lopcodes.js index bfcd993..f679f85 100644 --- a/src/lopcodes.js +++ b/src/lopcodes.js @@ -243,6 +243,11 @@ const MASK0 = function(n, p) { return (~MASK1(n, p)); }; +const SET_OPCODE = function(i, o) { + i.code = (i.code & MASK0(SIZE_OP, POS_OP)) | ((o << POS_OP) & MASK1(SIZE_OP, POS_OP)); + fullins(i); +}; + const setarg = function(i, v, pos, size) { i.code = (i.code & MASK0(size, pos)) | ((v << pos) & MASK1(size, pos)); fullins(i); @@ -348,6 +353,7 @@ module.exports.SETARG_B = SETARG_B; module.exports.SETARG_Bx = SETARG_Bx; module.exports.SETARG_C = SETARG_C; module.exports.SETARG_sBx = SETARG_sBx; +module.exports.SET_OPCODE = SET_OPCODE; module.exports.SIZE_A = SIZE_A; module.exports.SIZE_Ax = SIZE_Ax; module.exports.SIZE_B = SIZE_B; diff --git a/tests/lexparse.js b/tests/lexparse.js index 1271a36..4747724 100644 --- a/tests/lexparse.js +++ b/tests/lexparse.js @@ -224,4 +224,35 @@ test('Multiple return', function (t) { [3, -1, 2], "Program output is correct" ); +}); + + +test('TAILCALL', function (t) { + let luaCode = ` + local f = function (a, b) + return a + b + end + + return f(1,2) + `, 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 -- cgit v1.2.3-70-g09d2