summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lcode.js12
-rw-r--r--tests/lexparse.js87
2 files changed, 97 insertions, 2 deletions
diff --git a/src/lcode.js b/src/lcode.js
index 7fd958e..c4b8b81 100644
--- a/src/lcode.js
+++ b/src/lcode.js
@@ -191,7 +191,7 @@ const fixjump = function(fs, pc, dest) {
** Concatenate jump-list 'l2' into jump-list 'l1'
*/
const luaK_concat = function(fs, l1, l2) {
- if (l2 === NO_JUMP) return; /* nothing to concatenate? */
+ if (l2 === NO_JUMP) return l1; /* nothing to concatenate? */
else if (l1 === NO_JUMP) /* no original list? */
l1 = l2;
else {
@@ -1063,7 +1063,15 @@ const codebinexpval = function(fs, op, e1, e2, line) {
*/
const codecomp = function(fs, opr, e1, e2) {
let ek = lparser.expkind;
- let rk1 = (e1.k === ek.VK) ? lopcode.RKASK(e1.u.info) : llimit.check_exp(e1.k === ek.VNONRELOC, e1.u.info);
+
+ let rk1;
+ if (e1.k === ek.VK)
+ rk1 = lopcode.RKASK(e1.u.info);
+ else {
+ assert(e1.k === ek.VNONRELOC);
+ rk1 = e1.u.info;
+ }
+
let rk2 = luaK_exp2RK(fs, e2);
freeexps(fs, e1, e2);
switch (opr) {
diff --git a/tests/lexparse.js b/tests/lexparse.js
index 36dbf97..2b0cc46 100644
--- a/tests/lexparse.js
+++ b/tests/lexparse.js
@@ -286,4 +286,91 @@ test('VARARG', function (t) {
[1, 2, 3],
"Program output is correct"
);
+});
+
+
+test('LE, JMP', function (t) {
+ let luaCode = `
+ local a, b = 1, 1
+
+ return a >= b
+ `, 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_toboolean(L, -1),
+ true,
+ "Program output is correct"
+ );
+});
+
+
+test('LT', function (t) {
+ let luaCode = `
+ local a, b = 1, 1
+
+ return a > b
+ `, 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_toboolean(L, -1),
+ false,
+ "Program output is correct"
+ );
+});
+
+
+test('EQ', function (t) {
+ let luaCode = `
+ local a, b = 1, 1
+
+ return a == b
+ `, 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_toboolean(L, -1),
+ true,
+ "Program output is correct"
+ );
}); \ No newline at end of file