summaryrefslogtreecommitdiff
path: root/script/vm
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-05-01 00:38:06 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-05-01 00:38:06 +0800
commit9baa655e26a4091bb9a34457a98a6c3bb8da5c77 (patch)
tree4a4532fffbccda94363c30e1bea3bae44d2ddad9 /script/vm
parent25a1c462dfcba4a308de325396aece29a6c7198d (diff)
downloadlua-language-server-9baa655e26a4091bb9a34457a98a6c3bb8da5c77.zip
fix #1107
Diffstat (limited to 'script/vm')
-rw-r--r--script/vm/node.lua18
-rw-r--r--script/vm/value.lua9
2 files changed, 16 insertions, 11 deletions
diff --git a/script/vm/node.lua b/script/vm/node.lua
index 6023b1c3..e76542aa 100644
--- a/script/vm/node.lua
+++ b/script/vm/node.lua
@@ -96,6 +96,7 @@ function mt:hasFalsy()
for _, c in ipairs(self) do
if c.type == 'nil'
or (c.type == 'global' and c.cate == 'type' and c.name == 'nil')
+ or (c.type == 'global' and c.cate == 'type' and c.name == 'false')
or (c.type == 'boolean' and c[1] == false)
or (c.type == 'doc.type.boolean' and c[1] == false) then
return true
@@ -132,6 +133,7 @@ function mt:setTruthy()
local c = self[index]
if c.type == 'nil'
or (c.type == 'global' and c.cate == 'type' and c.name == 'nil')
+ or (c.type == 'global' and c.cate == 'type' and c.name == 'false')
or (c.type == 'boolean' and c[1] == false)
or (c.type == 'doc.type.boolean' and c[1] == false) then
table.remove(self, index)
@@ -148,10 +150,7 @@ function mt:setTruthy()
::CONTINUE::
end
if hasBoolean then
- self[#self+1] = {
- type = 'doc.type.boolean',
- [1] = true,
- }
+ self[#self+1] = vm.declareGlobal('type', 'true')
end
end
@@ -165,6 +164,7 @@ function mt:setFalsy()
local c = self[index]
if c.type == 'nil'
or (c.type == 'global' and c.cate == 'type' and c.name == 'nil')
+ or (c.type == 'global' and c.cate == 'type' and c.name == 'false')
or (c.type == 'boolean' and c[1] == true)
or (c.type == 'doc.type.boolean' and c[1] == true) then
goto CONTINUE
@@ -172,17 +172,13 @@ function mt:setFalsy()
if (c.type == 'global' and c.cate == 'type' and c.name == 'boolean')
or (c.type == 'boolean' or c.type == 'doc.type.boolean') then
hasBoolean = true
- goto CONTINUE
+ table.remove(self, index)
+ self[c] = nil
end
- table.remove(self, index)
- self[c] = nil
::CONTINUE::
end
if hasBoolean then
- self[#self+1] = {
- type = 'doc.type.boolean',
- [1] = false,
- }
+ self[#self+1] = vm.declareGlobal('type', 'false')
end
end
diff --git a/script/vm/value.lua b/script/vm/value.lua
index aa314875..d29ca9d0 100644
--- a/script/vm/value.lua
+++ b/script/vm/value.lua
@@ -20,6 +20,15 @@ function vm.test(source)
hasFalse = true
end
end
+ if n.type == 'global' and n.cate == 'type' then
+ if n.name == 'true' then
+ hasTrue = true
+ end
+ if n.name == 'false'
+ or n.name == 'nil' then
+ hasFalse = true
+ end
+ end
if n.type == 'nil' then
hasFalse = true
end