diff options
author | daurnimator <quae@daurnimator.com> | 2017-05-24 16:48:20 +1000 |
---|---|---|
committer | daurnimator <quae@daurnimator.com> | 2017-05-24 17:02:46 +1000 |
commit | 9bec9a5d038cfa488019e9370ff0b9ba785b313d (patch) | |
tree | 9ab1e449713d042cdc63c79a81549e4a7f7e2830 | |
parent | b5ed872df1a418c6437dad8a80bfab75447c7dfb (diff) | |
download | fengari-9bec9a5d038cfa488019e9370ff0b9ba785b313d.tar.gz fengari-9bec9a5d038cfa488019e9370ff0b9ba785b313d.tar.bz2 fengari-9bec9a5d038cfa488019e9370ff0b9ba785b313d.zip |
src/lvm.js: Factor out OP_CLOSURE to pushclosure
-rw-r--r-- | src/lvm.js | 34 |
1 files changed, 20 insertions, 14 deletions
@@ -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(); }; |