diff options
author | daurnimator <quae@daurnimator.com> | 2017-05-30 16:02:52 +1000 |
---|---|---|
committer | daurnimator <quae@daurnimator.com> | 2017-05-30 16:02:52 +1000 |
commit | e602b73c35b74178a1dc36e4b0d0b442e63264d5 (patch) | |
tree | d39036ef867c252150e5a3824cc6caf48d7a1c36 /src/ldo.js | |
parent | aef4fa0614a7984b5382b47302f3248032197d5a (diff) | |
download | fengari-e602b73c35b74178a1dc36e4b0d0b442e63264d5.tar.gz fengari-e602b73c35b74178a1dc36e4b0d0b442e63264d5.tar.bz2 fengari-e602b73c35b74178a1dc36e4b0d0b442e63264d5.zip |
Introduce function to adjust L.top
Diffstat (limited to 'src/ldo.js')
-rw-r--r-- | src/ldo.js | 27 |
1 files changed, 13 insertions, 14 deletions
@@ -21,6 +21,16 @@ const lzio = require('./lzio.js'); const CT = defs.constant_types; const TS = defs.thread_status; +const adjust_top = function(L, newtop) { + if (L.top < newtop) { + while (L.top < newtop) + L.stack[L.top++] = new lobject.TValue(CT.LUA_TNIL, null); + } else { + while (L.top > newtop) + delete L.stack[--L.top]; + } +}; + const seterrorobj = function(L, errcode, oldtop) { let current_top = L.top; @@ -159,13 +169,7 @@ const luaD_precall = function(L, off, nresults) { ci.func = func; ci.l_base = base; ci.top = base + fsize; - if (L.top < ci.top) { - while (L.top < ci.top) - L.stack[L.top++] = new lobject.TValue(CT.LUA_TNIL, null); - } else { - while (L.top > ci.top) - delete L.stack[--L.top]; - } + adjust_top(L, ci.top); ci.l_code = p.code; ci.l_savedpc = 0; ci.callstatus = lstate.CIST_LUA; @@ -263,13 +267,7 @@ const luaD_hook = function(L, event, line) { assert(!L.allowhook); L.allowhook = 1; ci.top = ci_top; - if (L.top < top) { - while (L.top < top) - L.stack[L.top++] = new lobject.TValue(CT.LUA_TNIL, null); - } else { - while (L.top > top) - delete L.stack[--L.top]; - } + adjust_top(L, top); ci.callstatus &= ~lstate.CIST_HOOKED; } }; @@ -693,6 +691,7 @@ const luaD_protectedparser = function(L, z, name, mode) { return status; }; +module.exports.adjust_top = adjust_top; module.exports.luaD_call = luaD_call; module.exports.luaD_callnoyield = luaD_callnoyield; module.exports.luaD_checkstack = luaD_checkstack; |