Skip to content

Commit 09b57f6

Browse files
committed
fix runner
1 parent 6fc0ad3 commit 09b57f6

File tree

1 file changed

+21
-22
lines changed

1 file changed

+21
-22
lines changed

script/vm/runner.lua

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function mt:_collect()
5757
end
5858

5959
table.sort(self._objs, function (a, b)
60-
return (a.range or a.start) < (b.range or b.start)
60+
return a.start < b.start
6161
end)
6262
end
6363

@@ -69,17 +69,12 @@ end
6969
function mt:_fastWard(pos, node)
7070
for i = self._index, #self._objs do
7171
local obj = self._objs[i]
72-
if (obj.range or obj.finish) > pos then
72+
if obj.finish > pos then
7373
self._index = i
7474
return node, obj
7575
end
7676
if obj.type == 'getlocal' then
7777
self._callback(obj, node)
78-
elseif obj.type == 'setlocal' then
79-
local newNode = self._callback(obj, node)
80-
if newNode then
81-
node = newNode:copy()
82-
end
8378
elseif obj.type == 'doc.cast' then
8479
node = node:copy()
8580
for _, cast in ipairs(obj.casts) do
@@ -178,13 +173,13 @@ function mt:_lookIntoExp(exp, topNode, outNode)
178173
outNode = checkerNode
179174
end
180175
end
181-
elseif exp.type == 'call'
176+
elseif handler.type == 'call'
182177
and checker.type == 'string'
183-
and exp.node.special == 'type'
184-
and exp.args
185-
and exp.args[1]
186-
and exp.args[1].type == 'getlocal'
187-
and exp.args[1].node == self._loc then
178+
and handler.node.special == 'type'
179+
and handler.args
180+
and handler.args[1]
181+
and handler.args[1].type == 'getlocal'
182+
and handler.args[1].node == self._loc then
188183
-- if type(x) == 'string' then
189184
self:_fastWard(exp.finish, topNode:copy())
190185
if exp.op.type == '==' then
@@ -198,9 +193,9 @@ function mt:_lookIntoExp(exp, topNode, outNode)
198193
outNode:narrow(checker[1])
199194
end
200195
end
201-
elseif exp.type == 'getlocal'
196+
elseif handler.type == 'getlocal'
202197
and checker.type == 'string' then
203-
local nodeValue = vm.getObjectValue(exp.node)
198+
local nodeValue = vm.getObjectValue(handler.node)
204199
if nodeValue
205200
and nodeValue.type == 'select'
206201
and nodeValue.sindex == 1 then
@@ -242,7 +237,7 @@ function mt:_lookIntoExp(exp, topNode, outNode)
242237
self:_lookIntoExp(exp.index, topNode)
243238
elseif exp.type == 'table' then
244239
for _, field in ipairs(exp) do
245-
self:_lookIntoExp(field, topNode)
240+
self:_lookIntoAction(field, topNode)
246241
end
247242
end
248243
::RETURN::
@@ -272,9 +267,14 @@ function mt:_lookIntoAction(action, topNode)
272267
end
273268
local value = vm.getObjectValue(action)
274269
if value then
275-
topNode = self:_lookIntoExp(value, topNode:copy())
270+
self:_lookIntoExp(value, topNode:copy())
276271
end
277-
if action.type == 'function' then
272+
if action.type == 'setlocal' then
273+
local newTopNode = self._callback(action, topNode)
274+
if newTopNode then
275+
topNode = newTopNode
276+
end
277+
elseif action.type == 'function' then
278278
self:_launchBlock(action, topNode:copy())
279279
elseif action.type == 'loop'
280280
or action.type == 'in'
@@ -345,18 +345,17 @@ function mt:_launchBlock(block, node)
345345
return topNode
346346
end
347347
for _, action in ipairs(block) do
348-
if (action.range or action.finish) < (top.range or top.finish) then
348+
if (action.range or action.finish) < top.finish then
349349
goto CONTINUE
350350
end
351351
topNode = self:_lookIntoAction(action, topNode)
352-
topNode, top = self:_fastWard(action.range or action.finish, topNode)
352+
topNode, top = self:_fastWard(action.finish, topNode)
353353
if not top then
354354
return topNode
355355
end
356356
::CONTINUE::
357357
end
358-
-- `x = function () end`: don't touch `x` in the end of function
359-
topNode = self:_fastWard(block.finish - 1, topNode)
358+
topNode = self:_fastWard(block.finish, topNode)
360359
return topNode
361360
end
362361

0 commit comments

Comments
 (0)