Skip to content

Commit 5188c59

Browse files
committed
stash
1 parent 709ec79 commit 5188c59

File tree

7 files changed

+412
-379
lines changed

7 files changed

+412
-379
lines changed

script/parser/guide.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,7 @@ function m.getLineRange(state, row)
884884
return 0
885885
end
886886

887-
local isSetMap = {
887+
local assignTypeMap = {
888888
['setglobal'] = true,
889889
['local'] = true,
890890
['self'] = true,
@@ -908,7 +908,7 @@ local isSetMap = {
908908
}
909909
function m.isAssign(source)
910910
local tp = source.type
911-
if isSetMap[tp] then
911+
if assignTypeMap[tp] then
912912
return true
913913
end
914914
if tp == 'call' then
@@ -920,7 +920,7 @@ function m.isAssign(source)
920920
return false
921921
end
922922

923-
local isGetMap = {
923+
local getTypeMap = {
924924
['getglobal'] = true,
925925
['getlocal'] = true,
926926
['getfield'] = true,
@@ -929,7 +929,7 @@ local isGetMap = {
929929
}
930930
function m.isGet(source)
931931
local tp = source.type
932-
if isGetMap[tp] then
932+
if getTypeMap[tp] then
933933
return true
934934
end
935935
if tp == 'call' then

script/vm/global.lua

Lines changed: 4 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
local util = require 'utility'
22
local scope = require 'workspace.scope'
33
local guide = require 'parser.guide'
4-
local files = require 'files'
54
---@class vm
65
local vm = require 'vm.vm'
76

@@ -569,43 +568,6 @@ function vm.getGlobalBase(source)
569568
return source._globalBase
570569
end
571570

572-
---@param source parser.object
573-
local function compileSelf(source)
574-
if source.parent.type ~= 'funcargs' then
575-
return
576-
end
577-
---@type parser.object
578-
local node = source.parent.parent and source.parent.parent.parent and source.parent.parent.parent.node
579-
if not node then
580-
return
581-
end
582-
local fields = vm.getVariableFields(source, false)
583-
if not fields then
584-
return
585-
end
586-
local nodeLocalID = vm.getVariableID(node)
587-
local globalNode = node._globalNode
588-
if not nodeLocalID and not globalNode then
589-
return
590-
end
591-
for _, field in ipairs(fields) do
592-
if field.type == 'setfield' then
593-
local key = guide.getKeyName(field)
594-
if key then
595-
if nodeLocalID then
596-
local myID = nodeLocalID .. vm.ID_SPLITE .. key
597-
vm.insertVariableID(myID, field)
598-
end
599-
if globalNode then
600-
local myID = globalNode:getName() .. vm.ID_SPLITE .. key
601-
local myGlobal = vm.declareGlobal('variable', myID, guide.getUri(node))
602-
myGlobal:addSet(guide.getUri(node), field)
603-
end
604-
end
605-
end
606-
end
607-
end
608-
609571
---@param source parser.object
610572
local function compileAst(source)
611573
local env = guide.getENV(source)
@@ -628,18 +590,6 @@ local function compileAst(source)
628590
}, function (src)
629591
compileObject(src)
630592
end)
631-
632-
--[[
633-
local mt
634-
function mt:xxx()
635-
self.a = 1
636-
end
637-
638-
mt.a --> find this definition
639-
]]
640-
guide.eachSourceType(source, 'self', function (src)
641-
compileSelf(src)
642-
end)
643593
end
644594

645595
---@param uri uri
@@ -657,18 +607,7 @@ local function dropUri(uri)
657607
end
658608
end
659609

660-
---@async
661-
files.watch(function (ev, uri)
662-
if ev == 'update' then
663-
dropUri(uri)
664-
end
665-
if ev == 'remove' then
666-
dropUri(uri)
667-
end
668-
if ev == 'compile' then
669-
local state = files.getLastState(uri)
670-
if state then
671-
compileAst(state.ast)
672-
end
673-
end
674-
end)
610+
return {
611+
compileAst = compileAst,
612+
dropUri = dropUri,
613+
}

script/vm/init.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ require 'vm.tracer'
1515
require 'vm.infer'
1616
require 'vm.generic'
1717
require 'vm.sign'
18-
require 'vm.variable-id'
18+
require 'vm.variable'
1919
require 'vm.global'
2020
require 'vm.function'
2121
require 'vm.operator'
2222
require 'vm.visible'
23+
require 'vm.precompile'
2324

2425
return vm

script/vm/precompile.lua

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
local files = require 'files'
2+
local global = require 'vm.global'
3+
local variable = require 'vm.variable'
4+
5+
---@async
6+
files.watch(function (ev, uri)
7+
if ev == 'update' then
8+
global.dropUri(uri)
9+
end
10+
if ev == 'remove' then
11+
global.dropUri(uri)
12+
end
13+
if ev == 'compile' then
14+
local state = files.getLastState(uri)
15+
if state then
16+
global.compileAst(state.ast)
17+
variable.compileAst(state.ast)
18+
end
19+
end
20+
end)

script/vm/tracer.lua

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,11 @@ function mt:collectLocal()
9797
self.assigns[#self.assigns+1] = self.source
9898
self.assignMap[self.source] = true
9999

100-
local varInfo = vm.getVariableInfoByName(self.source, self.name)
100+
local variable = vm.getVariableInfoByCodeName(self.source, self.name)
101101

102-
assert(varInfo)
102+
assert(variable)
103103

104-
for _, set in ipairs(varInfo.sets) do
104+
for _, set in ipairs(variable.sets) do
105105
self.assigns[#self.assigns+1] = set
106106
self.assignMap[set] = true
107107
self:collectCare(set)
@@ -110,7 +110,7 @@ function mt:collectLocal()
110110
end
111111
end
112112

113-
for _, get in ipairs(varInfo.gets) do
113+
for _, get in ipairs(variable.gets) do
114114
self:collectCare(get)
115115
self.getMap[get] = true
116116
if get.finish > finishPos then
@@ -831,14 +831,12 @@ function vm.traceNode(source)
831831
mode = 'global'
832832
name = base.global:getCodeName()
833833
else
834-
base = vm.getVariableHead(source)
835-
if not base then
836-
return nil
837-
end
838-
name = vm.getVariableName(source)
839-
if not name then
834+
local variable = vm.getVariable(source)
835+
if not variable then
840836
return nil
841837
end
838+
base = variable.base
839+
name = variable:getCodeName()
842840
mode = 'local'
843841
end
844842
local tracer = createTracer(mode, base, name)

0 commit comments

Comments
 (0)