From 70e485206d08913cf9709db8e6b589b3df34711e Mon Sep 17 00:00:00 2001 From: daurnimator Date: Mon, 22 May 2017 12:16:46 +1000 Subject: Add TMcache --- src/lapi.js | 1 + src/ltable.js | 6 ++++++ src/ltm.js | 17 +++++++++++++++++ src/lvm.js | 25 +++++++++++++------------ 4 files changed, 37 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/lapi.js b/src/lapi.js index d2f5c95..9aacb10 100644 --- a/src/lapi.js +++ b/src/lapi.js @@ -424,6 +424,7 @@ const lua_rawset = function(L, idx) { let slot = ltable.luaH_set(o.value, k); slot.setfrom(v); } + ltable.invalidateTMcache(o.value); L.top -= 2; }; diff --git a/src/ltable.js b/src/ltable.js index e4d21e2..0ed56ab 100644 --- a/src/ltable.js +++ b/src/ltable.js @@ -39,9 +39,14 @@ class Table { this.f = void 0; /* first entry */ this.l = void 0; /* last entry */ this.metatable = null; + this.flags = ~0; } } +const invalidateTMcache = function(t) { + t.flags = 0; +}; + const add = function(t, hash, key, value) { t.dead_strong.clear(); t.dead_weak = void 0; @@ -204,6 +209,7 @@ const luaH_next = function(L, table, keyI) { return true; }; +module.exports.invalidateTMcache = invalidateTMcache; module.exports.luaH_delete = luaH_delete; module.exports.luaH_get = luaH_get; module.exports.luaH_getint = luaH_getint; diff --git a/src/ltm.js b/src/ltm.js index 3e24c9c..ad09c26 100644 --- a/src/ltm.js +++ b/src/ltm.js @@ -166,6 +166,21 @@ const luaT_callorderTM = function(L, p1, p2, event) { return !L.stack[L.top].l_isfalse() ? 1 : 0; }; +const fasttm = function(l, et, e) { + return et === null ? null : + (et.flags & (1 << e)) ? null : luaT_gettm(et, e, l.l_G.tmname[e]); +}; + +const luaT_gettm = function(events, event, ename) { + const tm = ltable.luaH_getstr(events, ename); + assert(event <= TMS.TM_EQ); + if (tm.ttisnil()) { /* no tag method? */ + events.flags |= 1<