diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-02-17 21:03:42 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-02-17 21:03:42 +0800 |
commit | f8a6a73eaa1aa7915b296870f9a3862b429c7e74 (patch) | |
tree | da7637b772bfc44fe614b456dd04e16c34dea678 /script/vm | |
parent | 6e0a877b54dd66ce57f8fc07aeb11ee7ba48a907 (diff) | |
download | lua-language-server-f8a6a73eaa1aa7915b296870f9a3862b429c7e74.zip |
cleanup
Diffstat (limited to 'script/vm')
-rw-r--r-- | script/vm/getDef.lua | 16 | ||||
-rw-r--r-- | script/vm/global-node.lua (renamed from script/vm/global-id.lua) | 28 | ||||
-rw-r--r-- | script/vm/node/compiler.lua | 7 | ||||
-rw-r--r-- | script/vm/state.lua | 12 |
4 files changed, 30 insertions, 33 deletions
diff --git a/script/vm/getDef.lua b/script/vm/getDef.lua index 2741ae46..3cb33e69 100644 --- a/script/vm/getDef.lua +++ b/script/vm/getDef.lua @@ -1,9 +1,10 @@ ---@class vm -local vm = require 'vm.vm' -local util = require 'utility' -local compiler = require 'vm.node.compiler' -local guide = require 'parser.guide' -local localID = require 'vm.local-id' +local vm = require 'vm.vm' +local util = require 'utility' +local compiler = require 'vm.node.compiler' +local guide = require 'parser.guide' +local localID = require 'vm.local-id' +local globalNode = require 'vm.global-node' local simpleMap @@ -110,10 +111,7 @@ end ---@param source parser.object ---@param results parser.object[] local function searchByGlobal(source, results) - if source.type == 'field' then - source = source.parent - end - local global = source._globalID + local global = globalNode.getNode(source) if not global then return end diff --git a/script/vm/global-id.lua b/script/vm/global-node.lua index 614e28c5..107ea2e0 100644 --- a/script/vm/global-id.lua +++ b/script/vm/global-node.lua @@ -3,7 +3,7 @@ local guide = require 'parser.guide' local globalBuilder = require 'vm.node.global' ---@class parser.object ----@field _globalID vm.node.global +---@field _globalNode vm.node.global ---@class vm.global-id local m = {} @@ -31,14 +31,14 @@ local compilerGlobalMap = util.switch() : case 'setglobal' : call(function (uri, source) local name = guide.getKeyName(source) - source._globalID = m.declareGlobal(name, uri, source) + source._globalNode = m.declareGlobal(name, uri, source) end) : case 'getglobal' : call(function (uri, source) local name = guide.getKeyName(source) local global = m.getGlobal(name) global:addGet(uri, source) - source._globalID = global + source._globalNode = global local nxt = source.next if nxt then @@ -49,25 +49,25 @@ local compilerGlobalMap = util.switch() ---@param uri uri ---@param source parser.object : call(function (uri, source) - local parent = source.node._globalID + local parent = source.node._globalNode if not parent then return end local name = parent:getName() .. m.ID_SPLITE .. guide.getKeyName(source) - source._globalID = m.declareGlobal(name, uri, source) + source._globalNode = m.declareGlobal(name, uri, source) end) : case 'getfield' ---@param uri uri ---@param source parser.object : call(function (uri, source) - local parent = source.node._globalID + local parent = source.node._globalNode if not parent then return end local name = parent:getName() .. m.ID_SPLITE .. guide.getKeyName(source) local global = m.getGlobal(name) global:addGet(uri, source) - source._globalID = global + source._globalNode = global local nxt = source.next if nxt then @@ -100,10 +100,10 @@ end ---@param source parser.object function m.compileNode(uri, source) - if source._globalID ~= nil then + if source._globalNode ~= nil then return end - source._globalID = false + source._globalNode = false local compiler = compilerGlobalMap[source.type] if compiler then compiler(uri, source) @@ -117,10 +117,16 @@ function m.compileAst(source) m.compileNode(uri, env) end -function m.getID(source) - return source._globalID +---@return vm.node.global +function m.getNode(source) + if source.type == 'field' + or source.type == 'method' then + source = source.parent + end + return source._globalNode end +---@param uri uri function m.dropUri(uri) local globalSub = m.globalSubs[uri] m.globalSubs[uri] = nil diff --git a/script/vm/node/compiler.lua b/script/vm/node/compiler.lua index 296917d9..fefe4fb0 100644 --- a/script/vm/node/compiler.lua +++ b/script/vm/node/compiler.lua @@ -2,7 +2,6 @@ local guide = require 'parser.guide' local util = require 'utility' local state = require 'vm.state' local union = require 'vm.node.union' -local globalID = require 'vm.global-id' ---@class parser.object ---@field _compiledNodes boolean @@ -15,12 +14,6 @@ local m = {} ---@alias vm.node parser.object | vm.node.union | vm.node.cross ----@param ... string ----@return string -function m.getGlobalID(...) - return table.concat({...}, m.GLOBAL_SPLITE) -end - function m.setNode(source, node) if not node then return diff --git a/script/vm/state.lua b/script/vm/state.lua index 1eddc9db..83ce6084 100644 --- a/script/vm/state.lua +++ b/script/vm/state.lua @@ -1,6 +1,6 @@ -local util = require 'utility' -local files = require 'files' -local globalID = require 'vm.global-id' +local util = require 'utility' +local files = require 'files' +local globalNode = require 'vm.global-node' ---@class vm.state local m = {} @@ -58,7 +58,7 @@ end for uri in files.eachFile() do local state = files.getState(uri) if state then - globalID.compileAst(state.ast) + globalNode.compileAst(state.ast) end end @@ -66,12 +66,12 @@ files.watch(function (ev, uri) if ev == 'update' then local state = files.getState(uri) if state then - globalID.compileAst(state.ast) + globalNode.compileAst(state.ast) end end if ev == 'remove' then m.dropUri(uri) - globalID.dropUri(uri) + globalNode.dropUri(uri) end end) |