summaryrefslogtreecommitdiff
path: root/script/vm/compiler.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2023-01-04 20:56:29 +0800
committer最萌小汐 <sumneko@hotmail.com>2023-01-04 20:56:29 +0800
commit1befa0b9aa893ad11acb858df5e3c636b05435c0 (patch)
tree1bc30f319b73cc28cf30f9e3d1275cc3aafccc96 /script/vm/compiler.lua
parent702b0e7abe33f099e26ce48fdd4d82d6c8d7af0e (diff)
downloadlua-language-server-1befa0b9aa893ad11acb858df5e3c636b05435c0.zip
fix removing dead nodes
Diffstat (limited to 'script/vm/compiler.lua')
-rw-r--r--script/vm/compiler.lua36
1 files changed, 19 insertions, 17 deletions
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua
index 43c372a0..325c75e2 100644
--- a/script/vm/compiler.lua
+++ b/script/vm/compiler.lua
@@ -1235,27 +1235,29 @@ local compilerSwitch = util.switch()
end
---@type vm.node, boolean
- local cacheNode, needCompile
+ local variableNode, needCompile
do
local localInfo = vm.getVariableInfo(source)
if localInfo then
- cacheNode = localInfo.node
- if not cacheNode then
+ local lastCacheNode = vm.getNode(localInfo)
+ if lastCacheNode then
+ variableNode = lastCacheNode
+ else
needCompile = true
- cacheNode = vm.createNode()
- localInfo.node = cacheNode
+ variableNode = vm.createNode()
+ vm.setNode(localInfo, variableNode, true)
end
else
local parentNode = vm.compileNode(source.node)
if not parentNode.fields then
parentNode.fields = {}
end
- cacheNode = parentNode.fields[key]
- if not cacheNode then
+ variableNode = parentNode.fields[key]
+ if not variableNode then
needCompile = true
- cacheNode = vm.createNode()
- parentNode.fields[key] = cacheNode
+ variableNode = vm.createNode()
+ parentNode.fields[key] = variableNode
end
end
end
@@ -1266,15 +1268,15 @@ local compilerSwitch = util.switch()
local uri = guide.getUri(source)
local value = vm.getTableValue(uri, vm.compileNode(source.node), key)
if value then
- cacheNode:merge(value)
+ variableNode:merge(value)
end
for k in key:eachObject() do
if k.type == 'global' and k.cate == 'type' then
---@cast k vm.global
vm.compileByParentNode(source.node, k, function (src)
- cacheNode:merge(vm.compileNode(src))
+ variableNode:merge(vm.compileNode(src))
if src.value then
- cacheNode:merge(vm.compileNode(src.value))
+ variableNode:merge(vm.compileNode(src.value))
end
end)
end
@@ -1284,21 +1286,21 @@ local compilerSwitch = util.switch()
vm.compileByParentNode(source.node, key, function (src)
if src.value then
if bindDocs(src) then
- cacheNode:merge(vm.compileNode(src))
+ variableNode:merge(vm.compileNode(src))
elseif src.value.type ~= 'nil' then
- cacheNode:merge(vm.compileNode(src.value))
+ variableNode:merge(vm.compileNode(src.value))
local node = vm.getNode(src)
if node then
- cacheNode:merge(node)
+ variableNode:merge(node)
end
end
else
- cacheNode:merge(vm.compileNode(src))
+ variableNode:merge(vm.compileNode(src))
end
end)
end
end
- vm.setNode(source, cacheNode)
+ vm.setNode(source, variableNode)
end)
: case 'setglobal'
: call(function (source)