From c706c851f52c0b56a65dbaf74bafb66f36a9c521 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Fri, 5 May 2017 17:57:45 +1000 Subject: Always pass lua_State to Proto constructor --- src/lparser.js | 4 ++-- src/lundump.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/lparser.js b/src/lparser.js index f0f1d87..566576a 100644 --- a/src/lparser.js +++ b/src/lparser.js @@ -504,8 +504,8 @@ const undefgoto = function(ls, gt) { ** adds a new prototype into list of prototypes */ const addprototype = function(ls) { - let clp = new Proto(); let L = ls.L; + let clp = new Proto(L); let fs = ls.fs; let f = fs.f; /* prototype of current function */ f.p[fs.np++] = clp; @@ -536,7 +536,7 @@ const open_func = function(ls, fs, bl) { fs.nactvar = 0; fs.firstlocal = ls.dyd.actvar.n; fs.bl = null; - let f = new Proto(); + let f = new Proto(ls.L); f = fs.f; f.source = ls.source; f.maxstacksize = 2; /* registers 0/1 are always valid */ diff --git a/src/lundump.js b/src/lundump.js index 5d158bd..541adbb 100644 --- a/src/lundump.js +++ b/src/lundump.js @@ -285,7 +285,7 @@ class BytecodeParser { this.L.stack[this.L.top] = new lobject.TValue(defs.CT.LUA_TLCL, cl); this.L.top++; - cl.p = new lfunc.Proto(); + cl.p = new lfunc.Proto(this.L); this.readFunction(cl.p); -- cgit v1.2.3-54-g00ecf From f6a4dcf3871c6c5a4f9bdbfe699042dddbb8a62a Mon Sep 17 00:00:00 2001 From: daurnimator Date: Fri, 5 May 2017 18:04:06 +1000 Subject: src/lvm.js: Remove special case This makes it faster on my computer --- src/lvm.js | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/lvm.js b/src/lvm.js index 9e280c9..7c827a8 100644 --- a/src/lvm.js +++ b/src/lvm.js @@ -100,34 +100,27 @@ const RKC = function(L, base, k, i) { const luaV_execute = function(L) { let OCi = OC.OpCodesI; let ci = L.ci; - let specialCase = null; // To enable jump to specific opcode without reading current op/ra let opcode, k, base, i, ra; var cl; ci.callstatus |= lstate.CIST_FRESH; newframe: for (;;) { - if (specialCase) { - opcode = specialCase; - specialCase = null; - } else { - ci = L.ci; - cl = ci.func.value; - k = cl.p.k; - base = ci.l_base; - - i = ci.l_savedpc[ci.pcOff++]; + assert(ci === L.ci); + cl = ci.func.value; + k = cl.p.k; + base = ci.l_base; - if (L.hookmask & (defs.LUA_MASKLINE | defs.LUA_MASKCOUNT)) { - ldebug.luaG_traceexec(L); - base = ci.l_base; - } + i = ci.l_savedpc[ci.pcOff++]; - - ra = RA(L, base, i); - opcode = i.opcode; + if (L.hookmask & (defs.LUA_MASKLINE | defs.LUA_MASKCOUNT)) { + ldebug.luaG_traceexec(L); + base = ci.l_base; } + ra = RA(L, base, i); + opcode = i.opcode; + if (i.breakpoint) // TODO: remove, used until lapi return; @@ -629,13 +622,13 @@ const luaV_execute = function(L) { L.stack[cb] = L.stack[ra]; L.top = cb + 3; /* func. + 2 args (state and index) */ ldo.luaD_call(L, cb, i.C); + /* go straight to OP_TFORLOOP */ base = ci.l_base; L.top = ci.top; i = ci.l_savedpc[ci.pcOff++]; ra = RA(L, base, i); assert(i.opcode === OCi.OP_TFORLOOP); - specialCase = OCi.OP_TFORLOOP; - break; + /* fall through */ } case OCi.OP_TFORLOOP: { if (!L.stack[ra + 1].ttisnil()) { /* continue loop? */ -- cgit v1.2.3-54-g00ecf From c7b6fa63459d411cd7b20ea0de3dc2f4cf7e2a2f Mon Sep 17 00:00:00 2001 From: daurnimator Date: Fri, 5 May 2017 18:05:02 +1000 Subject: src/lvm.js: Optimise variable declarations Oddly 'const' on OCi helps, but on anything else dramatically increases runtime Otherwise the reduced scope for other variables is a tiny bit faster --- src/lvm.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/lvm.js b/src/lvm.js index 7c827a8..41b17c8 100644 --- a/src/lvm.js +++ b/src/lvm.js @@ -98,28 +98,26 @@ const RKC = function(L, base, k, i) { }; const luaV_execute = function(L) { - let OCi = OC.OpCodesI; + const OCi = OC.OpCodesI; let ci = L.ci; - let opcode, k, base, i, ra; - var cl; ci.callstatus |= lstate.CIST_FRESH; newframe: for (;;) { assert(ci === L.ci); - cl = ci.func.value; - k = cl.p.k; - base = ci.l_base; + let cl = ci.func.value; + let k = cl.p.k; + let base = ci.l_base; - i = ci.l_savedpc[ci.pcOff++]; + let i = ci.l_savedpc[ci.pcOff++]; if (L.hookmask & (defs.LUA_MASKLINE | defs.LUA_MASKCOUNT)) { ldebug.luaG_traceexec(L); base = ci.l_base; } - ra = RA(L, base, i); - opcode = i.opcode; + let ra = RA(L, base, i); + let opcode = i.opcode; if (i.breakpoint) // TODO: remove, used until lapi return; -- cgit v1.2.3-54-g00ecf