summaryrefslogtreecommitdiff
path: root/script/vm
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-04-23 20:52:10 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-04-23 20:52:10 +0800
commit317c856fa0f04472c7b6a4febae2b813657ca9c2 (patch)
tree534f9a3b495cce2406e9e4d18255318cdb9503c8 /script/vm
parent4cbbe55a5944e6c4dcaea7028cab65648251951e (diff)
downloadlua-language-server-317c856fa0f04472c7b6a4febae2b813657ca9c2.zip
cleanup
Diffstat (limited to 'script/vm')
-rw-r--r--script/vm/compiler.lua39
-rw-r--r--script/vm/node.lua28
-rw-r--r--script/vm/value.lua2
3 files changed, 32 insertions, 37 deletions
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua
index b3c9d950..4917d33a 100644
--- a/script/vm/compiler.lua
+++ b/script/vm/compiler.lua
@@ -982,6 +982,13 @@ local compilerSwitch = util.switch()
else
vm.setNode(src, vm.compileNode(src.value), true)
end
+ elseif src.value
+ and src.value.type == 'binary'
+ and src.value.op and src.value.op.type == 'or'
+ and src.value[1] and src.value[1].type == 'getlocal' and src.value[1].node == source
+ and src.value[2] and guide.isLiteral(src.value[2]) then
+ -- x = x or 1
+ vm.setNode(src, vm.compileNode(src.value))
else
vm.setNode(src, node, true)
end
@@ -1420,28 +1427,32 @@ local compilerSwitch = util.switch()
return
end
if source.op.type == 'and' then
+ local node1 = vm.compileNode(source[1])
+ local node2 = vm.compileNode(source[2])
local r1 = vm.test(source[1])
if r1 == true then
- vm.setNode(source, vm.compileNode(source[2]))
- return
- end
- if r1 == false then
- vm.setNode(source, vm.compileNode(source[1]))
- return
+ vm.setNode(source, node2)
+ elseif r1 == false then
+ vm.setNode(source, node1)
+ else
+ vm.getNode(source):merge(node1)
+ vm.getNode(source):setTruly()
+ vm.getNode(source):merge(node2)
end
- return
end
if source.op.type == 'or' then
+ local node1 = vm.compileNode(source[1])
+ local node2 = vm.compileNode(source[2])
local r1 = vm.test(source[1])
if r1 == true then
- vm.setNode(source, vm.compileNode(source[1]))
- return
- end
- if r1 == false then
- vm.setNode(source, vm.compileNode(source[2]))
- return
+ vm.setNode(source, node1)
+ elseif r1 == false then
+ vm.setNode(source, node2)
+ else
+ vm.getNode(source):merge(node1)
+ vm.getNode(source):setTruly()
+ vm.getNode(source):merge(node2)
end
- return
end
if source.op.type == '==' then
local result = vm.equal(source[1], source[2])
diff --git a/script/vm/node.lua b/script/vm/node.lua
index 8dd0c7f7..d52c2a84 100644
--- a/script/vm/node.lua
+++ b/script/vm/node.lua
@@ -119,27 +119,23 @@ function mt:setTruly()
self.optional = nil
end
local hasBoolean
- local index = 0
- while true do
- index = index + 1
+ for index = #self, 1, -1 do
local c = self[index]
- if not c then
- break
- end
if c.type == 'nil'
or (c.type == 'boolean' and c[1] == false)
or (c.type == 'doc.type.boolean' and c[1] == false) then
table.remove(self, index)
self[c] = nil
- index = index - 1
+ goto CONTINUE
end
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
table.remove(self, index)
self[c] = nil
- index = index - 1
+ goto CONTINUE
end
+ ::CONTINUE::
end
if hasBoolean then
self[#self+1] = {
@@ -155,13 +151,8 @@ function mt:setFalsy()
self.optional = nil
end
local hasBoolean
- local index = 0
- while true do
- index = index + 1
+ for index = #self, 1, -1 do
local c = self[index]
- if not c then
- break
- end
if c.type == 'nil'
or (c.type == 'boolean' and c[1] == true)
or (c.type == 'doc.type.boolean' and c[1] == true) then
@@ -174,7 +165,6 @@ function mt:setFalsy()
end
table.remove(self, index)
self[c] = nil
- index = index - 1
::CONTINUE::
end
if hasBoolean then
@@ -190,13 +180,8 @@ function mt:remove(name)
if name == 'nil' and self.optional == true then
self.optional = nil
end
- local index = 0
- while true do
- index = index + 1
+ for index = #self, 1, -1 do
local c = self[index]
- if not c then
- break
- end
if (c.type == 'global' and c.cate == 'type' and c.name == name)
or (c.type == name)
or (c.type == 'doc.type.integer' and (name == 'number' or name == 'integer'))
@@ -206,7 +191,6 @@ function mt:remove(name)
or (c.type == 'doc.type.function' and name == 'function') then
table.remove(self, index)
self[c] = nil
- index = index - 1
end
end
end
diff --git a/script/vm/value.lua b/script/vm/value.lua
index 1a2b5722..aa314875 100644
--- a/script/vm/value.lua
+++ b/script/vm/value.lua
@@ -17,7 +17,7 @@ function vm.test(source)
hasTrue = true
end
if n[1] == false then
- hasTrue = false
+ hasFalse = true
end
end
if n.type == 'nil' then