aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-03-01 15:59:14 +0100
committerBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-03-02 07:38:57 +0100
commit0989db69a5c0b36b7b5c39f57510da879a0076b5 (patch)
treed835b16950636161319f423dea14f89aef0958d9
parent19005492cf3b3597492e4fab9a2893dbdba1d42a (diff)
downloadfengari-0989db69a5c0b36b7b5c39f57510da879a0076b5.tar.gz
fengari-0989db69a5c0b36b7b5c39f57510da879a0076b5.tar.bz2
fengari-0989db69a5c0b36b7b5c39f57510da879a0076b5.zip
[Parsing tests] TAILCALL
-rw-r--r--.vscode/launch.json27
-rw-r--r--.vscode/settings.json3
-rw-r--r--src/lopcodes.js6
-rw-r--r--tests/lexparse.js31
4 files changed, 67 insertions, 0 deletions
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