diff options
Diffstat (limited to 'script/vm/state.lua')
-rw-r--r-- | script/vm/state.lua | 46 |
1 files changed, 36 insertions, 10 deletions
diff --git a/script/vm/state.lua b/script/vm/state.lua index cec9eb6f..0048649e 100644 --- a/script/vm/state.lua +++ b/script/vm/state.lua @@ -6,11 +6,15 @@ local global = require 'vm.node.global' local m = {} ---@type table<string, vm.node.global> m.globals = util.defaultTable(global) ----@type table<uri, { globals: table }> -m.subscriptions = util.defaultTable(function () - return { - globals = {}, - } +---@type table<uri, table<string, boolean>> +m.globalSubs = util.defaultTable(function () + return {} +end) +---@type table<uri, parser.object[]> +m.literals = util.multiTable(2) +---@type table<parser.object, table<parser.object, boolean>> +m.literalSubs = util.multiTable(2, function () + return setmetatable({}, util.MODE_K) end) ---@param name string @@ -18,7 +22,7 @@ end) ---@param source parser.object ---@return vm.node.global function m.declareGlobal(name, uri, source) - m.subscriptions[uri].globals[name] = true + m.globalSubs[uri][name] = true local node = m.globals[name] node:addSet(uri, source) return node @@ -29,18 +33,40 @@ end ---@return vm.node.global function m.getGlobal(name, uri) if uri then - m.subscriptions[uri].globals[name] = true + m.globalSubs[uri][name] = true end return m.globals[name] end +---@param uri uri +---@param source parser.object +function m.declareLiteral(uri, source) + local literals = m.literals[uri] + literals[#literals+1] = source +end + +---@param literal parser.object +---@param source parser.object +function m.subscribeLiteral(literal, source) + m.literalSubs[literal][source] = true +end + ---@param uri uri function m.dropUri(uri) - local subscription = m.subscriptions[uri] - m.subscriptions[uri] = nil - for name in pairs(subscription.globals) do + local globalSub = m.globalSubs[uri] + m.globalSubs[uri] = nil + for name in pairs(globalSub) do m.globals[name]:dropUri(uri) end + local literals = m.literals[uri] + m.literals[uri] = nil + for _, literal in ipairs(literals) do + local literalSubs = m.literalSubs[literal] + m.literalSubs[literal] = nil + for source in pairs(literalSubs) do + source._compiled = nil + end + end end return m |