summaryrefslogtreecommitdiff
path: root/script/vm
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-04-24 05:05:39 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-04-24 05:05:39 +0800
commitafbe46c3090e55ff08302b5306ce6dae99f09c54 (patch)
tree250d17bd9c841fc8ceb78de58637c7f555482471 /script/vm
parente76e59948ff86f37a7b17fa79ca7041a1dae1bf8 (diff)
downloadlua-language-server-afbe46c3090e55ff08302b5306ce6dae99f09c54.zip
infer by `if not x or x.y then`
Diffstat (limited to 'script/vm')
-rw-r--r--script/vm/node.lua8
-rw-r--r--script/vm/runner.lua32
2 files changed, 18 insertions, 22 deletions
diff --git a/script/vm/node.lua b/script/vm/node.lua
index 204a149d..d3e407b6 100644
--- a/script/vm/node.lua
+++ b/script/vm/node.lua
@@ -10,6 +10,7 @@ vm.nodeCache = {}
---@field [integer] vm.object
local mt = {}
mt.__index = mt
+mt.id = 0
mt.type = 'vm.node'
mt.optional = nil
mt.lastInfer = nil
@@ -273,11 +274,16 @@ function vm.clearNodeCache()
vm.nodeCache = {}
end
+local ID = 0
+
---@param a? vm.node | vm.object
---@param b? vm.node | vm.object
---@return vm.node
function vm.createNode(a, b)
- local node = setmetatable({}, mt)
+ ID = ID + 1
+ local node = setmetatable({
+ id = ID,
+ }, mt)
if a then
node:merge(a)
end
diff --git a/script/vm/runner.lua b/script/vm/runner.lua
index 0d8d023e..2be187c9 100644
--- a/script/vm/runner.lua
+++ b/script/vm/runner.lua
@@ -72,35 +72,29 @@ function mt:_compileNarrowByFilter(filter, outStep, blockStep)
self:_compileNarrowByFilter(filter[2], outStep, blockStep)
end
if filter.op.type == 'or' then
- local orRightStep = {
+ local dummyStep = {
type = 'load',
- tag = 'orRight',
+ tag = 'dummy',
copy = true,
ref1 = outStep,
pos = filter.start - 1,
}
- local orLeftStep = {
+ self.steps[#self.steps+1] = dummyStep
+ self:_compileNarrowByFilter(filter[1], outStep, dummyStep)
+ dummyStep = {
type = 'load',
- tag = 'orLeft',
+ tag = 'dummy',
copy = true,
ref1 = outStep,
- pos = filter.start - 1,
- }
- self.steps[#self.steps+1] = orRightStep
- self.steps[#self.steps+1] = orLeftStep
- self:_compileNarrowByFilter(filter[1], orRightStep, orLeftStep)
- self.steps[#self.steps+1] = {
- type = 'load',
- tag = 'orReset',
- ref1 = orRightStep,
- pos = filter.op.start
+ pos = filter.op.finish,
}
- self:_compileNarrowByFilter(filter[2], orLeftStep, orRightStep)
+ self.steps[#self.steps+1] = dummyStep
+ self:_compileNarrowByFilter(filter[2], outStep, dummyStep)
self.steps[#self.steps+1] = {
type = 'load',
tag = 'reset',
ref1 = blockStep,
- pos = filter.finish
+ pos = filter.finish,
}
end
if filter.op.type == '=='
@@ -339,11 +333,7 @@ function mt:launch(callback)
elseif step.type == 'save' then
step.node = node
elseif step.type == 'load' then
- if step.ref1 then
- step.node = step.ref1.node
- else
- step.node = node
- end
+ step.node = node
context = step
elseif step.type == 'merge' then
node:merge(step.ref2.node)