diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-06-14 21:01:25 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-06-14 21:01:25 +0800 |
commit | d1567d7e47a7c418d7fa072e41e78b2c8cbf29a5 (patch) | |
tree | 89abe580e7b61aae80b916ee83cfaf0d71f6ade9 /script/vm/node.lua | |
parent | 11085b8e4172f054191d3cb9cffac3cbce1803f5 (diff) | |
parent | 329cd44aedec15f1048742d98baacdd71d434a6e (diff) | |
download | lua-language-server-d1567d7e47a7c418d7fa072e41e78b2c8cbf29a5.zip |
Merge branch 'runner'
Diffstat (limited to 'script/vm/node.lua')
-rw-r--r-- | script/vm/node.lua | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/script/vm/node.lua b/script/vm/node.lua index 6a86350a..5086f66d 100644 --- a/script/vm/node.lua +++ b/script/vm/node.lua @@ -2,6 +2,7 @@ local files = require 'files' ---@class vm local vm = require 'vm.vm' local ws = require 'workspace.workspace' +local guide = require 'parser.guide' ---@type table<vm.object, vm.node> vm.nodeCache = {} @@ -105,6 +106,18 @@ function mt:hasFalsy() return false end +function mt:hasKnownType() + for _, c in ipairs(self) do + if c.type == 'global' and c.cate == 'type' then + return true + end + if guide.isLiteral(c) then + return true + end + end + return false +end + ---@return boolean function mt:isNullable() if self.optional then @@ -152,6 +165,7 @@ function mt:setTruthy() if hasBoolean then self[#self+1] = vm.declareGlobal('type', 'true') end + return self end ---@return vm.node @@ -174,12 +188,19 @@ function mt:setFalsy() hasBoolean = true table.remove(self, index) self[c] = nil + goto CONTINUE + end + if (c.type == 'global' and c.cate == 'type') then + table.remove(self, index) + self[c] = nil + goto CONTINUE end ::CONTINUE:: end if hasBoolean then self[#self+1] = vm.declareGlobal('type', 'false') end + return self end ---@param name string @@ -200,6 +221,7 @@ function mt:remove(name) self[c] = nil end end + return self end ---@param node vm.node @@ -207,6 +229,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 |