summaryrefslogtreecommitdiff
path: root/src/lvm.js
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2017-05-24 16:48:20 +1000
committerdaurnimator <quae@daurnimator.com>2017-05-24 17:02:46 +1000
commit9bec9a5d038cfa488019e9370ff0b9ba785b313d (patch)
tree9ab1e449713d042cdc63c79a81549e4a7f7e2830 /src/lvm.js
parentb5ed872df1a418c6437dad8a80bfab75447c7dfb (diff)
downloadfengari-9bec9a5d038cfa488019e9370ff0b9ba785b313d.tar.gz
fengari-9bec9a5d038cfa488019e9370ff0b9ba785b313d.tar.bz2
fengari-9bec9a5d038cfa488019e9370ff0b9ba785b313d.zip
src/lvm.js: Factor out OP_CLOSURE to pushclosure
Diffstat (limited to 'src/lvm.js')
-rw-r--r--src/lvm.js34
1 files changed, 20 insertions, 14 deletions
diff --git a/src/lvm.js b/src/lvm.js
index 1f78dd3..e796e4e 100644
--- a/src/lvm.js
+++ b/src/lvm.js
@@ -607,20 +607,7 @@ const luaV_execute = function(L) {
}
case OCi.OP_CLOSURE: {
let p = cl.p.p[i.Bx];
- let nup = p.upvalues.length;
- let uv = p.upvalues;
- let ncl = new lobject.LClosure(L, nup);
- ncl.p = p;
-
- L.stack[ra] = new lobject.TValue(CT.LUA_TLCL, ncl);
-
- for (let i = 0; i < nup; i++) {
- if (uv[i].instack)
- ncl.upvals[i] = lfunc.luaF_findupval(L, base + uv[i].idx);
- else
- ncl.upvals[i] = cl.upvals[uv[i].idx];
- ncl.upvals[i].refcount++;
- }
+ pushclosure(L, p, cl.upvals, base, ra); /* create a new one */
break;
}
case OCi.OP_VARARG: {
@@ -948,6 +935,25 @@ const luaV_shiftl = function(x, y) {
}
};
+/*
+** create a new Lua closure, push it in the stack, and initialize
+** its upvalues.
+*/
+const pushclosure = function(L, p, encup, base, ra) {
+ let nup = p.upvalues.length;
+ let uv = p.upvalues;
+ let ncl = new lobject.LClosure(L, nup);
+ ncl.p = p;
+ L.stack[ra] = new lobject.TValue(CT.LUA_TLCL, ncl);
+ for (let i = 0; i < nup; i++) {
+ if (uv[i].instack)
+ ncl.upvals[i] = lfunc.luaF_findupval(L, base + uv[i].idx);
+ else
+ ncl.upvals[i] = encup[uv[i].idx];
+ ncl.upvals[i].refcount++;
+ }
+};
+
const cvt2str = function(o) {
return o.ttisnumber();
};