11local util = require ' utility'
22local guide = require ' parser.guide'
3+ --- @class vm
34local vm = require ' vm.vm'
45
56--- @class parser.object
67--- @field _localID string
78--- @field _localIDs table<string , parser.object[]>
89
9- --- @class vm.local-id
10- local m = {}
10+ local compileLocalID , getLocal
1111
1212local compileSwitch = util .switch ()
1313 : case ' local'
@@ -18,13 +18,13 @@ local compileSwitch = util.switch()
1818 return
1919 end
2020 for _ , ref in ipairs (source .ref ) do
21- m . compileLocalID (ref )
21+ compileLocalID (ref )
2222 end
2323 end )
2424 : case ' getlocal'
2525 : call (function (source )
2626 source ._localID = (' %d' ):format (source .node .start )
27- m . compileLocalID (source .next )
27+ compileLocalID (source .next )
2828 end )
2929 : case ' getfield'
3030 : case ' setfield'
@@ -40,7 +40,7 @@ local compileSwitch = util.switch()
4040 source ._localID = parentID .. vm .ID_SPLITE .. key
4141 source .field ._localID = source ._localID
4242 if source .type == ' getfield' then
43- m . compileLocalID (source .next )
43+ compileLocalID (source .next )
4444 end
4545 end )
4646 : case ' getmethod'
@@ -57,7 +57,7 @@ local compileSwitch = util.switch()
5757 source ._localID = parentID .. vm .ID_SPLITE .. key
5858 source .method ._localID = source ._localID
5959 if source .type == ' getmethod' then
60- m . compileLocalID (source .next )
60+ compileLocalID (source .next )
6161 end
6262 end )
6363 : case ' getindex'
@@ -74,15 +74,15 @@ local compileSwitch = util.switch()
7474 source ._localID = parentID .. vm .ID_SPLITE .. key
7575 source .index ._localID = source ._localID
7676 if source .type == ' setindex' then
77- m . compileLocalID (source .next )
77+ compileLocalID (source .next )
7878 end
7979 end )
8080
8181local leftSwitch = util .switch ()
8282 : case ' field'
8383 : case ' method'
8484 : call (function (source )
85- return m . getLocal (source .parent )
85+ return getLocal (source .parent )
8686 end )
8787 : case ' getfield'
8888 : case ' setfield'
@@ -91,7 +91,7 @@ local leftSwitch = util.switch()
9191 : case ' getindex'
9292 : case ' setindex'
9393 : call (function (source )
94- return m . getLocal (source .node )
94+ return getLocal (source .node )
9595 end )
9696 : case ' getlocal'
9797 : call (function (source )
@@ -105,13 +105,13 @@ local leftSwitch = util.switch()
105105
106106--- @param source parser.object
107107--- @return parser.object ?
108- function m . getLocal (source )
108+ function getLocal (source )
109109 return leftSwitch (source .type , source )
110110end
111111
112112--- @param id string
113113--- @param source parser.object
114- function m .insertLocalID (id , source )
114+ function vm .insertLocalID (id , source )
115115 local root = guide .getRoot (source )
116116 if not root ._localIDs then
117117 root ._localIDs = util .multiTable (2 )
@@ -120,7 +120,7 @@ function m.insertLocalID(id, source)
120120 sources [# sources + 1 ] = source
121121end
122122
123- function m . compileLocalID (source )
123+ function compileLocalID (source )
124124 if not source then
125125 return
126126 end
@@ -133,29 +133,29 @@ function m.compileLocalID(source)
133133 if not id then
134134 return
135135 end
136- m .insertLocalID (id , source )
136+ vm .insertLocalID (id , source )
137137end
138138
139139--- @param source parser.object
140140--- @return string ?
141- function m . getID (source )
141+ function vm . getLocalID (source )
142142 if source ._localID ~= nil then
143143 return source ._localID
144144 end
145145 source ._localID = false
146- local loc = m . getLocal (source )
146+ local loc = getLocal (source )
147147 if not loc then
148148 return source ._localID
149149 end
150- m . compileLocalID (loc )
150+ compileLocalID (loc )
151151 return source ._localID
152152end
153153
154154--- @param source parser.object
155155--- @param key ? string
156156--- @return parser.object[] ?
157- function m . getSources (source , key )
158- local id = m . getID (source )
157+ function vm . getLocalSources (source , key )
158+ local id = vm . getLocalID (source )
159159 if not id then
160160 return nil
161161 end
174174
175175--- @param source parser.object
176176--- @return parser.object[]
177- function m . getFields (source )
178- local id = m . getID (source )
177+ function vm . getLocalFields (source )
178+ local id = vm . getLocalID (source )
179179 if not id then
180180 return nil
181181 end
@@ -203,5 +203,3 @@ function m.getFields(source)
203203 end
204204 return fields
205205end
206-
207- return m
0 commit comments