aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-03-01 15:07:02 +0100
committerBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-03-01 15:07:02 +0100
commit699630a97161ef970c40af073f2943c7d90043e7 (patch)
tree284880debd33973254520ea8690aa28ac88ead1c
parent69a7af7a8af1e737fe6afe47998b90c8fd778998 (diff)
downloadfengari-699630a97161ef970c40af073f2943c7d90043e7.tar.gz
fengari-699630a97161ef970c40af073f2943c7d90043e7.tar.bz2
fengari-699630a97161ef970c40af073f2943c7d90043e7.zip
[Parsing tests] Unary op, LOADBOOL
-rw-r--r--src/lcode.js8
-rw-r--r--src/lparser.js1
-rw-r--r--tests/lexparse.js32
3 files changed, 36 insertions, 5 deletions
diff --git a/src/lcode.js b/src/lcode.js
index 3c6500d..f69bc34 100644
--- a/src/lcode.js
+++ b/src/lcode.js
@@ -1092,16 +1092,16 @@ const codecomp = function(fs, opr, e1, e2) {
const luaK_prefix = function(fs, op, e, line) {
let ef = new lparser.expdesc();
ef.k = lparser.expkind.VKINT;
- ef.u.ival = e.u.nval = e.u.info = 0;
- e.t = NO_JUMP;
- e.f = NO_JUMP;
+ ef.u.ival = ef.u.nval = ef.u.info = 0;
+ ef.t = NO_JUMP;
+ ef.f = NO_JUMP;
switch (op) {
case UnOpr.OPR_MINUS: case UnOpr.OPR_BNOT: /* use 'ef' as fake 2nd operand */
if (constfolding(fs, op + lua.LUA_OPUNM, e, ef))
break;
/* FALLTHROUGH */
case UnOpr.OPR_LEN:
- codeunexpval(fs, op + UnOpr.OP_UNM, e, line);
+ codeunexpval(fs, op + OpCodesI.OP_UNM, e, line);
break;
case UnOpr.OPR_NOT: codenot(fs, e); break;
}
diff --git a/src/lparser.js b/src/lparser.js
index 1e454e0..86f32f8 100644
--- a/src/lparser.js
+++ b/src/lparser.js
@@ -1556,5 +1556,6 @@ const luaY_parser = function(L, z, buff, dyd, name, firstchar) {
module.exports.Dyndata = Dyndata;
module.exports.expkind = expkind;
+module.exports.expdesc = expdesc;
module.exports.luaY_parser = luaY_parser;
module.exports.vkisinreg = vkisinreg; \ No newline at end of file
diff --git a/tests/lexparse.js b/tests/lexparse.js
index 2604e72..1a1a7b3 100644
--- a/tests/lexparse.js
+++ b/tests/lexparse.js
@@ -10,6 +10,7 @@ const lapi = require("../src/lapi.js");
const lauxlib = require("../src/lauxlib.js");
const linit = require('../src/linit.js');
+// Roughly the same tests as test/lvm.js to cover all opcodes
test('LOADK, RETURN', function (t) {
let luaCode = `
@@ -97,4 +98,33 @@ test('Binary op', function (t) {
"Program output is correct"
);
-}); \ No newline at end of file
+});
+
+
+test('Unary op, LOADBOOL', function (t) {
+ let luaCode = `
+ local a = 5
+ local b = false
+ return -a, not b, ~a
+ `, L;
+
+ t.plan(1);
+
+ // 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.deepEqual(
+ L.stack.slice(L.top - 3, L.top).map(e => e.value),
+ [-5, true, -6],
+ "Program output is correct"
+ );
+});