From 13328c5bee9b847317313491c3eb9f6f66766de7 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Mon, 22 May 2017 23:26:44 +1000 Subject: Add luaD_inctop calls where appropriate --- src/ldo.js | 6 ++++++ src/lobject.js | 9 ++++++--- src/lparser.js | 7 +++++-- src/lundump.js | 3 ++- 4 files changed, 19 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/ldo.js b/src/ldo.js index 83f26cf..fbef68f 100644 --- a/src/ldo.js +++ b/src/ldo.js @@ -89,6 +89,11 @@ const luaD_shrinkstack = function(L) { luaD_reallocstack(L, goodsize); }; +const luaD_inctop = function(L) { + luaD_checkstack(L, 1); + L.top++; +}; + /* ** Prepares a function call: checks the stack, creates a new CallInfo ** entry, fills in the relevant information, calls hook if needed. @@ -653,6 +658,7 @@ module.exports.luaD_callnoyield = luaD_callnoyield; module.exports.luaD_checkstack = luaD_checkstack; module.exports.luaD_growstack = luaD_growstack; module.exports.luaD_hook = luaD_hook; +module.exports.luaD_inctop = luaD_inctop; module.exports.luaD_pcall = luaD_pcall; module.exports.luaD_poscall = luaD_poscall; module.exports.luaD_precall = luaD_precall; diff --git a/src/lobject.js b/src/lobject.js index e7b716e..fad3b73 100644 --- a/src/lobject.js +++ b/src/lobject.js @@ -461,7 +461,8 @@ const luaO_tostring = function(L, obj) { }; const pushstr = function(L, str) { - L.stack[L.top++] = new TValue(CT.LUA_TLNGSTR, lstring.luaS_new(L, str)); + ldo.luaD_inctop(L); + L.stack[L.top-1] = new TValue(CT.LUA_TLNGSTR, lstring.luaS_new(L, str)); }; const luaO_pushvfstring = function(L, fmt, argp) { @@ -488,10 +489,12 @@ const luaO_pushvfstring = function(L, fmt, argp) { break; case char['d']: case char['I']: - L.stack[L.top++] = luaO_tostring(L, new TValue(CT.LUA_TNUMINT, argp[a++])); + ldo.luaD_inctop(L); + L.stack[L.top-1] = luaO_tostring(L, new TValue(CT.LUA_TNUMINT, argp[a++])); break; case char['f']: - L.stack[L.top++] = luaO_tostring(L, new TValue(CT.LUA_TNUMFLT, argp[a++])); + ldo.luaD_inctop(L); + L.stack[L.top-1] = luaO_tostring(L, new TValue(CT.LUA_TNUMFLT, argp[a++])); break; // case char['p']: case char['U']: diff --git a/src/lparser.js b/src/lparser.js index 100342a..13f75c9 100644 --- a/src/lparser.js +++ b/src/lparser.js @@ -4,6 +4,7 @@ const assert = require('assert'); const defs = require('./defs.js'); const lcode = require('./lcode.js'); +const ldo = require('./ldo.js'); const lfunc = require('./lfunc.js'); const llex = require('./llex.js'); const llimit = require('./llimit.js'); @@ -1563,9 +1564,11 @@ const luaY_parser = function(L, z, buff, dyd, name, firstchar) { let lexstate = new llex.LexState(); let funcstate = new FuncState(); let cl = lfunc.luaF_newLclosure(L, 1); /* create main closure */ - L.stack[L.top++] = new TValue(defs.CT.LUA_TLCL, cl); + ldo.luaD_inctop(L); + L.stack[L.top-1] = new TValue(defs.CT.LUA_TLCL, cl); lexstate.h = ltable.luaH_new(L); /* create table for scanner */ - L.stack[L.top++] = new TValue(defs.CT.LUA_TTABLE, lexstate.h); + ldo.luaD_inctop(L); + L.stack[L.top-1] = new TValue(defs.CT.LUA_TTABLE, lexstate.h); funcstate.f = cl.p = new Proto(L); funcstate.f.source = lstring.luaS_new(L, name); lexstate.buff = buff; diff --git a/src/lundump.js b/src/lundump.js index 1891451..4931fe8 100644 --- a/src/lundump.js +++ b/src/lundump.js @@ -265,7 +265,8 @@ const luaU_undump = function(L, Z, name) { let S = new BytecodeParser(L, Z, name); S.checkHeader(); let cl = lfunc.luaF_newLclosure(L, S.readByte()); - L.stack[L.top++] = new lobject.TValue(defs.CT.LUA_TLCL, cl); + ldo.luaD_inctop(L); + L.stack[L.top-1] = new lobject.TValue(defs.CT.LUA_TLCL, cl); cl.p = new lfunc.Proto(L); S.readFunction(cl.p, null); assert(cl.nupvalues === cl.p.upvalues.length); -- cgit v1.2.3-54-g00ecf