From 0652fa586d62408e28d8f7d253aa96381d357bc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Sat, 23 Apr 2022 23:36:30 +0800 Subject: infer by `if not x then return end` --- script/vm/runner.lua | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) (limited to 'script/vm/runner.lua') diff --git a/script/vm/runner.lua b/script/vm/runner.lua index 9384ec01..5c92dcbe 100644 --- a/script/vm/runner.lua +++ b/script/vm/runner.lua @@ -180,19 +180,28 @@ function mt:_compileBlock(block) order = 3, } self:_compileNarrowByFilter(childBlock.filter, childBlock[1].start - 1) - local finalState = { - type = 'save', - pos = childBlock.finish, - order = 1, - } - finals[#finals+1] = finalState - self.steps[#self.steps+1] = finalState - self.steps[#self.steps+1] = { - type = 'load', - ref1 = outState, - pos = childBlock.finish, - order = 2, - } + if childBlock.returns then + self.steps[#self.steps+1] = { + type = 'load', + ref1 = outState, + pos = childBlock.finish, + order = 1, + } + else + local finalState = { + type = 'save', + pos = childBlock.finish, + order = 1, + } + finals[#finals+1] = finalState + self.steps[#self.steps+1] = finalState + self.steps[#self.steps+1] = { + type = 'load', + ref1 = outState, + pos = childBlock.finish, + order = 2, + } + end end end for i, final in ipairs(finals) do -- cgit v1.2.3