summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-06-14 16:22:09 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-06-14 16:22:09 +0800
commit840054f13235d2e24a9ff90edc64c0325331818c (patch)
tree44826a694638c3ba2d6bc38a8a5dbd722d9a71ec /script
parent72d3060bc60847d47d17fab4ff1b65bf0c3a1b8e (diff)
downloadlua-language-server-840054f13235d2e24a9ff90edc64c0325331818c.zip
update runner
Diffstat (limited to 'script')
-rw-r--r--script/vm/node.lua8
-rw-r--r--script/vm/runner.lua37
2 files changed, 44 insertions, 1 deletions
diff --git a/script/vm/node.lua b/script/vm/node.lua
index 7964c442..76e61192 100644
--- a/script/vm/node.lua
+++ b/script/vm/node.lua
@@ -216,6 +216,14 @@ function mt:removeNode(node)
for _, c in ipairs(node) do
if c.type == 'global' and c.cate == 'type' then
self:remove(c.name)
+ elseif c.type == 'nil' then
+ self:remove 'nil'
+ elseif c.type == 'boolean' then
+ if c[1] == true then
+ self:remove 'true'
+ else
+ self:remove 'false'
+ end
end
end
end
diff --git a/script/vm/runner.lua b/script/vm/runner.lua
index df5b4ed1..90b388f1 100644
--- a/script/vm/runner.lua
+++ b/script/vm/runner.lua
@@ -118,13 +118,47 @@ function mt:_lookInto(action, topNode, outNode)
end
end
elseif action.type == 'unary' then
+ if not action[1] then
+ return topNode, outNode
+ end
if action.op.type == 'not' then
outNode, topNode = self:_lookInto(action[1], topNode, outNode)
end
elseif action.type == 'binary' then
+ if not action[1] or not action[2] then
+ return topNode, outNode
+ end
if action.op.type == 'and' then
topNode = self:_lookInto(action[1], topNode)
topNode = self:_lookInto(action[2], topNode)
+ elseif action.op.type == '=='
+ or action.op.type == '~=' then
+ local loc, checker
+ for i = 1, 2 do
+ if action[i].type == 'getlocal' and action[i].node == self._loc then
+ loc = action[i]
+ checker = action[3-i] -- Copilot tells me use `3-i` instead of `i%2+1`
+ else
+ loc = action[3-i]
+ checker = action[i]
+ end
+ end
+ if loc then
+ if guide.isLiteral(checker) then
+ local checkerNode = vm.compileNode(checker)
+ if action.op.type == '==' then
+ topNode = checkerNode
+ if outNode then
+ outNode:removeNode(topNode)
+ end
+ else
+ topNode:removeNode(checkerNode)
+ if outNode then
+ outNode = checkerNode
+ end
+ end
+ end
+ end
end
end
return topNode, outNode
@@ -141,7 +175,8 @@ function mt:_launchBlock(block, node)
return topNode, neverReturn
end
for _, action in ipairs(block) do
- if action.type == 'return' then
+ if action.type == 'return'
+ or action.type == 'goto' then
neverReturn = true
end
local finish = action.range or action.finish