From afbe46c3090e55ff08302b5306ce6dae99f09c54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Sun, 24 Apr 2022 05:05:39 +0800 Subject: infer by `if not x or x.y then` --- script/vm/runner.lua | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) (limited to 'script/vm/runner.lua') 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) -- cgit v1.2.3