diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-06-14 00:38:53 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-06-14 00:38:53 +0800 |
commit | 0691911c68f777559599b997f85c83407b9f3d6b (patch) | |
tree | 64e0f111dc4999537c406b13a733249eca3df51f /script/vm/runner.lua | |
parent | a02828b3c1d3582d73e44f36bc34e8d86f9b0295 (diff) | |
download | lua-language-server-0691911c68f777559599b997f85c83407b9f3d6b.zip |
update
Diffstat (limited to 'script/vm/runner.lua')
-rw-r--r-- | script/vm/runner.lua | 51 |
1 files changed, 40 insertions, 11 deletions
diff --git a/script/vm/runner.lua b/script/vm/runner.lua index 87630512..65992bea 100644 --- a/script/vm/runner.lua +++ b/script/vm/runner.lua @@ -63,14 +63,14 @@ end ---@param pos integer ---@param node vm.node ----@return parser.object ---@return vm.node +---@return parser.object? function mt:_fastWard(pos, node) for i = self._index, #self._objs do local obj = self._objs[i] if obj.start > pos then self._index = i - return obj, node + return node, obj end if obj.type == 'getlocal' then self._callback(obj, node) @@ -83,37 +83,66 @@ function mt:_fastWard(pos, node) error('unexpected type: ' .. obj.type) end end + self._index = math.huge + return node, nil end ----@param action parser.object ----@param topNode vm.node -function mt:_lookInto(action, topNode) +---@param action parser.object +---@param topNode vm.node +---@param outNode? vm.node +---@return vm.node +function mt:_lookInto(action, topNode, outNode) action = vm.getObjectValue(action) or action if action.type == 'function' then self:_launchBlock(action, topNode:copy()) + elseif action.type == 'if' then + local mainNode = topNode:copy() + local blockNode = topNode:copy() + for _, subBlock in ipairs(action) do + if subBlock.type == 'ifblock' then + blockNode, mainNode = self:_lookInto(subBlock.filter, blockNode, mainNode) + blockNode = self:_launchBlock(subBlock, blockNode) + mainNode:merge(blockNode) + end + end + elseif action.type == 'getlocal' then + if action.node == self._loc then + topNode = self:_fastWard(action.finish, topNode) + topNode = topNode:copy():setTruthy() + if outNode then + outNode:setFalsy() + end + end + elseif action.type == 'unary' then + if action.op.type == 'not' then + outNode, topNode = self:_lookInto(action[1], topNode, outNode) + end end + return topNode, outNode end ---@param block parser.object ---@param node vm.node +---@return vm.node function mt:_launchBlock(block, node) - local top, topNode = self:_fastWard(block.start, node) + local topNode, top = self:_fastWard(block.start, node) if not top then - return + return topNode end for _, action in ipairs(block) do local finish = action.range or action.finish if finish < top.start then goto CONTINUE end - self:_lookInto(action, topNode) - top, topNode = self:_fastWard(action.finish, topNode) + topNode = self:_lookInto(action, topNode) + topNode, top = self:_fastWard(action.finish, topNode) if not top then - return + return topNode end ::CONTINUE:: end - self:_fastWard(block.finish, topNode) + topNode = self:_fastWard(block.finish, topNode) + return topNode end ---@param loc parser.object |