summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lfunc.js34
-rw-r--r--src/lobject.js6
-rw-r--r--src/lvm.js4
3 files changed, 22 insertions, 22 deletions
diff --git a/src/lfunc.js b/src/lfunc.js
index 7e324da..663f614 100644
--- a/src/lfunc.js
+++ b/src/lfunc.js
@@ -54,28 +54,26 @@ const luaF_newLclosure = function(L, n) {
const luaF_findupval = function(L, level) {
- let pp = L.openupval;
- let p = pp;
- while (pp !== null && pp.v >= level) {
- p = pp;
+ let prevp;
+ let p = L.openupval;
+ while (p !== null && p.v >= level) {
assert(p.isopen());
- if (p.v === level)
- return p;
-
- pp = p.open_next;
+ if (p.v === level) /* found a corresponding upvalue? */
+ return p; /* return it */
+ prevp = p;
+ p = p.open_next;
}
-
+ /* not found: create a new upvalue */
let uv = new UpVal();
-
- if (p) { /* The openupval list is not empty */
- uv.open_next = p; /* link it to list of open upvalues */
- }
-
- L.openupval = uv;
-
+ /* link it to list of open upvalues */
+ uv.open_next = p;
+ if (prevp)
+ prevp.open_next = uv;
+ else
+ L.openupval = uv;
+ /* current value lives in the stack */
uv.L = L;
- uv.v = level; /* current value lives in the stack */
-
+ uv.v = level;
return uv;
};
diff --git a/src/lobject.js b/src/lobject.js
index 9790d23..680e293 100644
--- a/src/lobject.js
+++ b/src/lobject.js
@@ -523,7 +523,7 @@ const intarith = function(L, op, v1, v2) {
case defs.LUA_OPSUB: return (v1 - v2)|0;
case defs.LUA_OPMUL: return (v1 * v2)|0;
case defs.LUA_OPMOD: return (v1 - Math.floor(v1 / v2) * v2)|0; // % semantic on negative numbers is different in js
- case defs.LUA_OPIDIV: return (v1 / v2)|0;
+ case defs.LUA_OPIDIV: return Math.floor(v1 / v2)|0;
case defs.LUA_OPBAND: return (v1 & v2);
case defs.LUA_OPBOR: return (v1 | v2);
case defs.LUA_OPBXOR: return (v1 ^ v2);
@@ -531,6 +531,7 @@ const intarith = function(L, op, v1, v2) {
case defs.LUA_OPSHR: return (v1 >> v2);
case defs.LUA_OPUNM: return (0 - v1)|0;
case defs.LUA_OPBNOT: return (~0 ^ v1);
+ default: assert(0);
}
};
@@ -542,9 +543,10 @@ const numarith = function(L, op, v1, v2) {
case defs.LUA_OPMUL: return v1 * v2;
case defs.LUA_OPDIV: return v1 / v2;
case defs.LUA_OPPOW: return Math.pow(v1, v2);
- case defs.LUA_OPIDIV: return (v1 / v2);
+ case defs.LUA_OPIDIV: return Math.floor(v1 / v2);
case defs.LUA_OPUNM: return -v1;
case defs.LUA_OPMOD: return v1 % v2;
+ default: assert(0);
}
};
diff --git a/src/lvm.js b/src/lvm.js
index d48610c..df4f62f 100644
--- a/src/lvm.js
+++ b/src/lvm.js
@@ -713,8 +713,8 @@ const luaV_equalobj = function(L, t1, t2) {
if (t1.ttnov() !== t2.ttnov() || t1.ttnov() !== CT.LUA_TNUMBER)
return 0; /* only numbers can be equal with different variants */
else { /* two numbers with different variants */
- /* compare them as integers */
- return Math.floor(t1.value) === Math.floor(t2.value) ? 1 : 0; // TODO: tointeger
+ /* OPTIMIZATION: instead of calling luaV_tointeger we can just let JS do the comparison */
+ return (t1.value === t2.value) ? 1 : 0;
}
}