diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-02-25 16:32:40 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-02-25 16:32:40 +0800 |
commit | 32dcf712ce2b08a124718c519e43dd327a15d748 (patch) | |
tree | 06acc3d8c6759516e4cccad881a66b6915e37f80 /script/vm | |
parent | ee408986c37082c981cb2689d71e4d77d4079a23 (diff) | |
download | lua-language-server-32dcf712ce2b08a124718c519e43dd327a15d748.zip |
cleanup
Diffstat (limited to 'script/vm')
-rw-r--r-- | script/vm/literal-manager.lua | 57 | ||||
-rw-r--r-- | script/vm/local-manager.lua | 57 | ||||
-rw-r--r-- | script/vm/manager.lua | 4 | ||||
-rw-r--r-- | script/vm/node/compiler.lua | 16 | ||||
-rw-r--r-- | script/vm/node/union.lua | 8 |
5 files changed, 71 insertions, 71 deletions
diff --git a/script/vm/literal-manager.lua b/script/vm/literal-manager.lua deleted file mode 100644 index 9c1f70a8..00000000 --- a/script/vm/literal-manager.lua +++ /dev/null @@ -1,57 +0,0 @@ -local util = require 'utility' -local guide = require 'parser.guide' - ----@class vm.literal-node -local m = {} ----@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) ----@type table<parser.object, boolean> -m.allLiterals = {} - ----@param source parser.object -function m.declareLiteral(source) - if m.allLiterals[source] then - return - end - m.allLiterals[source] = true - local uri = guide.getUri(source) - local literals = m.literals[uri] - literals[#literals+1] = source -end - ----@param source parser.object ----@param node vm.node -function m.subscribeLiteral(source, node) - if not node then - return - end - if node.type == 'union' - or node.type == 'cross' then - node:subscribeLiteral(source) - return - end - if not m.allLiterals[source] then - return - end - m.literalSubs[node][source] = true -end - ----@param uri uri -function m.dropUri(uri) - local literals = m.literals[uri] - m.literals[uri] = nil - for _, literal in ipairs(literals) do - m.allLiterals[literal] = nil - local literalSubs = m.literalSubs[literal] - m.literalSubs[literal] = nil - for source in pairs(literalSubs) do - source._node = nil - end - end -end - -return m diff --git a/script/vm/local-manager.lua b/script/vm/local-manager.lua new file mode 100644 index 00000000..bae22318 --- /dev/null +++ b/script/vm/local-manager.lua @@ -0,0 +1,57 @@ +local util = require 'utility' +local guide = require 'parser.guide' + +---@class vm.local-node +local m = {} +---@type table<uri, parser.object[]> +m.locals = util.multiTable(2) +---@type table<parser.object, table<parser.object, boolean>> +m.localSubs = util.multiTable(2, function () + return setmetatable({}, util.MODE_K) +end) +---@type table<parser.object, boolean> +m.allLocals = {} + +---@param source parser.object +function m.declareLocal(source) + if m.allLocals[source] then + return + end + m.allLocals[source] = true + local uri = guide.getUri(source) + local locals = m.locals[uri] + locals[#locals+1] = source +end + +---@param source parser.object +---@param node vm.node +function m.subscribeLocal(source, node) + if not node then + return + end + if node.type == 'union' + or node.type == 'cross' then + node:subscribeLocal(source) + return + end + if not m.allLocals[source] then + return + end + m.localSubs[node][source] = true +end + +---@param uri uri +function m.dropUri(uri) + local locals = m.locals[uri] + m.locals[uri] = nil + for _, loc in ipairs(locals) do + m.allLocals[loc] = nil + local localSubs = m.localSubs[loc] + m.localSubs[loc] = nil + for source in pairs(localSubs) do + source._node = nil + end + end +end + +return m diff --git a/script/vm/manager.lua b/script/vm/manager.lua index b80cfb43..2068507f 100644 --- a/script/vm/manager.lua +++ b/script/vm/manager.lua @@ -1,7 +1,7 @@ local files = require 'files' local globalManager = require 'vm.global-manager' -local literalManager = require 'vm.literal-manager' +local localManager = require 'vm.local-manager' ---@class vm.state local m = {} @@ -21,7 +21,7 @@ files.watch(function (ev, uri) end if ev == 'remove' then globalManager.dropUri(uri) - literalManager.dropUri(uri) + localManager.dropUri(uri) end end) diff --git a/script/vm/node/compiler.lua b/script/vm/node/compiler.lua index 3a51fc4c..9d86768f 100644 --- a/script/vm/node/compiler.lua +++ b/script/vm/node/compiler.lua @@ -1,9 +1,9 @@ -local guide = require 'parser.guide' -local util = require 'utility' -local union = require 'vm.node.union' -local localID = require 'vm.local-id' -local literalMgr = require 'vm.literal-manager' -local globalMgr = require 'vm.global-manager' +local guide = require 'parser.guide' +local util = require 'utility' +local union = require 'vm.node.union' +local localID = require 'vm.local-id' +local localMgr = require 'vm.local-manager' +local globalMgr = require 'vm.global-manager' ---@class parser.object ---@field _compiledNodes boolean @@ -131,7 +131,7 @@ local compilerMap = util.switch() : case 'string' : case 'function' : call(function (source) - literalMgr.declareLiteral(source) + localMgr.declareLocal(source) m.setNode(source, source) end) : case 'local' @@ -206,7 +206,7 @@ function m.compileNode(source) if compiler then compiler(source) end - literalMgr.subscribeLiteral(source, source._node) + localMgr.subscribeLocal(source, source._node) if source._globalNode then m.setNode(source, source._globalNode) end diff --git a/script/vm/node/union.lua b/script/vm/node/union.lua index 47b9c63a..b944b92d 100644 --- a/script/vm/node/union.lua +++ b/script/vm/node/union.lua @@ -1,4 +1,4 @@ -local literalMgr = require 'vm.literal-manager' +local localMgr = require 'vm.local-manager' ---@class vm.node.union local mt = {} @@ -26,11 +26,11 @@ function mt:merge(node) end ---@param source parser.object -function mt:subscribeLiteral(source) +function mt:subscribeLocal(source) for _, c in ipairs(self) do - literalMgr.subscribeLiteral(source, c) + localMgr.subscribeLocal(source, c) if c.type == 'cross' then - c:subscribeLiteral(source) + c:subscribeLocal(source) end end end |