Skip to content

Commit 809fa70

Browse files
committed
stash
1 parent 5188c59 commit 809fa70

File tree

6 files changed

+90
-55
lines changed

6 files changed

+90
-55
lines changed

script/vm/compiler.lua

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -716,13 +716,13 @@ function vm.selectNode(list, index)
716716
local result
717717
if exp.type == 'call' then
718718
result = getReturn(exp.node, index, exp.args)
719-
if result:isEmpty() then
719+
if not result:isTyped() then
720720
result:merge(vm.declareGlobal('type', 'unknown'))
721721
end
722722
else
723723
---@type vm.node
724724
result = vm.compileNode(exp)
725-
if result:isEmpty() then
725+
if not result:isTyped() then
726726
result:merge(vm.declareGlobal('type', 'unknown'))
727727
end
728728
end
@@ -1526,7 +1526,7 @@ local compilerSwitch = util.switch()
15261526
if not node then
15271527
return
15281528
end
1529-
if node:isEmpty() then
1529+
if not node:isTyped() then
15301530
node = vm.runOperator('call', vararg.node) or node
15311531
end
15321532
vm.setNode(source, node)
@@ -1547,7 +1547,7 @@ local compilerSwitch = util.switch()
15471547
if not node then
15481548
return
15491549
end
1550-
if node:isEmpty() then
1550+
if not node:isTyped() then
15511551
node = vm.runOperator('call', source.node) or node
15521552
end
15531553
vm.setNode(source, node)
@@ -1829,15 +1829,15 @@ end
18291829

18301830
---@param source vm.object
18311831
local function compileByParentNode(source)
1832-
if not vm.getNode(source):isEmpty() then
1832+
if vm.getNode(source):isTyped() then
18331833
return
18341834
end
18351835
vm.compileByNodeChain(source, function (result)
18361836
vm.setNode(source, vm.compileNode(result))
18371837
end)
18381838
end
18391839

1840-
---@param source vm.object
1840+
---@param source vm.object | vm.variable
18411841
---@return vm.node
18421842
function vm.compileNode(source)
18431843
if not source then
@@ -1863,6 +1863,7 @@ function vm.compileNode(source)
18631863
---@cast source parser.object
18641864
vm.setNode(source, vm.createNode(), true)
18651865
vm.compileByGlobal(source)
1866+
vm.compileByVariable(source)
18661867
compileByNode(source)
18671868
compileByParentNode(source)
18681869
matchCall(source)

script/vm/generic.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,11 @@ function mt:resolve(uri, args)
124124
local protoNode = vm.compileNode(self.proto)
125125
local result = vm.createNode()
126126
for nd in protoNode:eachObject() do
127-
if nd.type == 'global' then
128-
---@cast nd vm.global
127+
if nd.type == 'global' or nd.type == 'variable' then
128+
---@cast nd vm.global | vm.variable
129129
result:merge(nd)
130130
else
131-
---@cast nd -vm.global
131+
---@cast nd -vm.global, -vm.variable
132132
local clonedObject = cloneObject(nd, resolved)
133133
if clonedObject then
134134
local clonedNode = vm.compileNode(clonedObject)

script/vm/node.lua

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ local util = require 'utility'
99
---@type table<vm.object, vm.node>
1010
vm.nodeCache = setmetatable({}, util.MODE_K)
1111

12-
---@alias vm.node.object vm.object | vm.global
12+
---@alias vm.node.object vm.object | vm.global | vm.variable
1313

1414
---@class vm.node
1515
---@field [integer] vm.node.object
@@ -58,6 +58,19 @@ function mt:isEmpty()
5858
return #self == 0
5959
end
6060

61+
---@return boolean
62+
function mt:isTyped()
63+
for _, c in ipairs(self) do
64+
if c.type == 'global' and c.cate == 'variable' then
65+
return true
66+
end
67+
if guide.isLiteral(c) then
68+
return true
69+
end
70+
end
71+
return false
72+
end
73+
6174
function mt:clear()
6275
self.optional = nil
6376
for i, c in ipairs(self) do
@@ -278,7 +291,7 @@ function mt:narrow(uri, name)
278291
return self
279292
end
280293

281-
---@param obj vm.object
294+
---@param obj vm.object | vm.variable
282295
function mt:removeObject(obj)
283296
for index, c in ipairs(self) do
284297
if c == obj then

script/vm/tracer.lua

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ local util = require 'utility'
1313
---@field mode tracer.mode
1414
---@field name string
1515
---@field source parser.object
16+
---@field variable vm.variable
1617
---@field assigns parser.object[]
1718
---@field assignMap table<parser.object, true>
1819
---@field getMap table<parser.object, true>
@@ -94,10 +95,7 @@ function mt:collectLocal()
9495
local startPos = self.source.start
9596
local finishPos = 0
9697

97-
self.assigns[#self.assigns+1] = self.source
98-
self.assignMap[self.source] = true
99-
100-
local variable = vm.getVariableInfoByCodeName(self.source, self.name)
98+
local variable = self.variable
10199

102100
assert(variable)
103101

@@ -131,6 +129,10 @@ function mt:collectLocal()
131129
if #self.casts > 0 then
132130
self.fastCalc = false
133131
end
132+
133+
if variable ~= vm.getVariable(self.source) then
134+
self.fastCalc = false
135+
end
134136
end
135137

136138
function mt:collectGlobal()
@@ -171,8 +173,13 @@ end
171173
---@param finish integer
172174
---@return parser.object?
173175
function mt:getLastAssign(start, finish)
174-
local assign = self.assigns[1]
176+
local assign
175177
for _, obj in ipairs(self.assigns) do
178+
if obj.type == 'local'
179+
or obj.type == 'self' then
180+
assign = obj
181+
break
182+
end
176183
if obj.start < start then
177184
goto CONTINUE
178185
end
@@ -742,7 +749,9 @@ end
742749
function mt:calcNode(source)
743750
if self.getMap[source] then
744751
local lastAssign = self:getLastAssign(0, source.finish)
745-
assert(lastAssign)
752+
if not lastAssign then
753+
return
754+
end
746755
if self.fastCalc then
747756
self.nodes[source] = vm.compileNode(lastAssign)
748757
return
@@ -783,9 +792,10 @@ end
783792
---@param mode tracer.mode
784793
---@param source parser.object
785794
---@param name string
795+
---@param variable vm.variable?
786796
---@return vm.tracer?
787-
local function createTracer(mode, source, name)
788-
local node = vm.compileNode(source)
797+
local function createTracer(mode, source, name, variable)
798+
local node = vm.compileNode(variable or source)
789799
local tracer = node._tracer
790800
if tracer then
791801
return tracer
@@ -796,6 +806,7 @@ local function createTracer(mode, source, name)
796806
end
797807
tracer = setmetatable({
798808
source = source,
809+
variable = variable,
799810
mode = mode,
800811
name = name,
801812
assigns = {},
@@ -806,7 +817,7 @@ local function createTracer(mode, source, name)
806817
casts = {},
807818
nodes = {},
808819
main = main,
809-
uri = guide.getUri(source),
820+
uri = guide.getUri(main),
810821
}, mt)
811822
node._tracer = tracer
812823

@@ -822,7 +833,7 @@ end
822833
---@param source parser.object
823834
---@return vm.node?
824835
function vm.traceNode(source)
825-
local mode, base, name
836+
local mode, base, name, variable
826837
if vm.getGlobalNode(source) then
827838
base = vm.getGlobalBase(source)
828839
if not base then
@@ -831,15 +842,15 @@ function vm.traceNode(source)
831842
mode = 'global'
832843
name = base.global:getCodeName()
833844
else
834-
local variable = vm.getVariable(source)
845+
variable = vm.getVariable(source)
835846
if not variable then
836847
return nil
837848
end
838-
base = variable.base
849+
base = variable:getBase()
839850
name = variable:getCodeName()
840851
mode = 'local'
841852
end
842-
local tracer = createTracer(mode, base, name)
853+
local tracer = createTracer(mode, base, name, variable)
843854
if not tracer then
844855
return nil
845856
end

script/vm/type.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,8 +721,9 @@ function vm.viewTypeErrorMessage(uri, errs)
721721
elseif value.type == 'generic' then
722722
---@cast value vm.generic
723723
lparams[paramName] = vm.viewObject(value, uri)
724+
elseif value.type == 'variable' then
724725
else
725-
---@cast value -string, -vm.global, -vm.node, -vm.generic
726+
---@cast value -string, -vm.global, -vm.node, -vm.generic, -vm.variable
726727
if paramName == 'key' then
727728
lparams[paramName] = vm.viewKey(value, uri)
728729
else

0 commit comments

Comments
 (0)