Skip to content

Commit a3b5dcb

Browse files
committed
fix
1 parent 6c92b9a commit a3b5dcb

File tree

2 files changed

+31
-41
lines changed

2 files changed

+31
-41
lines changed

script/vm/compiler.lua

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ local vm = require 'vm.vm'
99
---@class parser.object
1010
---@field _compiledNodes boolean
1111
---@field _node vm.node
12-
---@field package _hasBindedDocs? boolean
1312
---@field cindex integer
1413
---@field func parser.object
1514

@@ -21,20 +20,14 @@ function vm.bindDocs(source)
2120
if not docs then
2221
return false
2322
end
24-
if source._hasBindedDocs ~= nil then
25-
return source._hasBindedDocs
26-
end
27-
source._hasBindedDocs = false
2823
for i = #docs, 1, -1 do
2924
local doc = docs[i]
3025
if doc.type == 'doc.type' then
3126
vm.setNode(source, vm.compileNode(doc))
32-
source._hasBindedDocs = true
3327
return true
3428
end
3529
if doc.type == 'doc.class' then
3630
vm.setNode(source, vm.compileNode(doc))
37-
source._hasBindedDocs = true
3831
return true
3932
end
4033
if doc.type == 'doc.param' then
@@ -43,28 +36,23 @@ function vm.bindDocs(source)
4336
node:addOptional()
4437
end
4538
vm.setNode(source, node)
46-
source._hasBindedDocs = true
4739
return true
4840
end
4941
if doc.type == 'doc.module' then
5042
local name = doc.module
5143
if not name then
52-
source._hasBindedDocs = true
5344
return true
5445
end
5546
local uri = rpath.findUrisByRequireName(guide.getUri(source), name)[1]
5647
if not uri then
57-
source._hasBindedDocs = true
5848
return true
5949
end
6050
local state = files.getState(uri)
6151
local ast = state and state.ast
6252
if not ast then
63-
source._hasBindedDocs = true
6453
return true
6554
end
6655
vm.setNode(source, vm.compileNode(ast))
67-
source._hasBindedDocs = true
6856
return true
6957
end
7058
end
@@ -594,7 +582,7 @@ end
594582

595583
---@param source parser.object
596584
---@return boolean
597-
local function bindAs(source)
585+
function vm.bindAs(source)
598586
local root = guide.getRoot(source)
599587
local docs = root.docs
600588
if not docs then
@@ -1195,7 +1183,7 @@ local compilerSwitch = util.switch()
11951183
end)
11961184
: case 'paren'
11971185
: call(function (source)
1198-
if bindAs(source) then
1186+
if vm.bindAs(source) then
11991187
return
12001188
end
12011189
if source.exp then
@@ -1232,7 +1220,7 @@ local compilerSwitch = util.switch()
12321220
: case 'getlocal'
12331221
---@async
12341222
: call(function (source)
1235-
if bindAs(source) then
1223+
if vm.bindAs(source) then
12361224
return
12371225
end
12381226
local node = vm.traceNode(source)
@@ -1251,7 +1239,7 @@ local compilerSwitch = util.switch()
12511239
if vm.bindDocs(source) then
12521240
return
12531241
end
1254-
if guide.isGet(source) and bindAs(source) then
1242+
if guide.isGet(source) and vm.bindAs(source) then
12551243
return
12561244
end
12571245
---@type (string|vm.node)?
@@ -1300,7 +1288,7 @@ local compilerSwitch = util.switch()
13001288
end)
13011289
: case 'getglobal'
13021290
: call(function (source)
1303-
if bindAs(source) then
1291+
if vm.bindAs(source) then
13041292
return
13051293
end
13061294
if source.node[1] ~= '_ENV' then
@@ -1441,7 +1429,7 @@ local compilerSwitch = util.switch()
14411429
: case 'call.return'
14421430
---@param source parser.object
14431431
: call(function (source)
1444-
if bindAs(source) then
1432+
if vm.bindAs(source) then
14451433
return
14461434
end
14471435
local func = source.func
@@ -1725,7 +1713,7 @@ local compilerSwitch = util.switch()
17251713
end)
17261714
: case 'unary'
17271715
: call(function (source)
1728-
if bindAs(source) then
1716+
if vm.bindAs(source) then
17291717
return
17301718
end
17311719
if not source[1] then
@@ -1735,7 +1723,7 @@ local compilerSwitch = util.switch()
17351723
end)
17361724
: case 'binary'
17371725
: call(function (source)
1738-
if bindAs(source) then
1726+
if vm.bindAs(source) then
17391727
return
17401728
end
17411729
if not source[1] or not source[2] then

script/vm/global.lua

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -546,31 +546,33 @@ function vm.compileByGlobal(source)
546546
if not global then
547547
return false
548548
end
549-
if global.cate == 'type' then
550-
vm.setNode(source, global)
551-
return false
552-
end
553549
vm.setNode(source, global)
554-
if guide.isAssign(source) then
555-
if vm.bindDocs(source) then
556-
return true
557-
end
558-
if source.value then
559-
vm.setNode(source, vm.compileNode(source.value))
550+
if global.cate == 'variable' then
551+
if guide.isAssign(source) then
552+
if vm.bindDocs(source) then
553+
return true
554+
end
555+
if source.value then
556+
vm.setNode(source, vm.compileNode(source.value))
557+
return true
558+
end
559+
else
560+
if vm.bindAs(source) then
561+
return true
562+
end
563+
local node = vm.traceNode(source)
564+
if node then
565+
vm.setNode(source, node, true)
566+
return true
567+
end
560568
end
561-
return true
562569
end
563-
local node = vm.traceNode(source)
564-
if node then
565-
vm.setNode(source, node, true)
566-
else
567-
local globalBase = vm.getGlobalBase(source)
568-
if not globalBase then
569-
return false
570-
end
571-
local globalNode = vm.compileNode(globalBase)
572-
vm.setNode(source, globalNode, true)
570+
local globalBase = vm.getGlobalBase(source)
571+
if not globalBase then
572+
return false
573573
end
574+
local globalNode = vm.compileNode(globalBase)
575+
vm.setNode(source, globalNode, true)
574576
return true
575577
end
576578

0 commit comments

Comments
 (0)