@@ -5,7 +5,7 @@ local vm = require 'vm.vm'
55
66--- @class parser.object
77--- @field _localID string
8- --- @field _localIDs table<string , parser.object[]>
8+ --- @field _localIDs table<string , { sets : parser.object[] , gets : parser.object[] } []>
99
1010local compileLocalID , getLocal
1111
@@ -114,10 +114,19 @@ end
114114function vm .insertLocalID (id , source )
115115 local root = guide .getRoot (source )
116116 if not root ._localIDs then
117- root ._localIDs = util .multiTable (2 )
117+ root ._localIDs = util .multiTable (2 , function ()
118+ return {
119+ sets = {},
120+ gets = {},
121+ }
122+ end )
118123 end
119124 local sources = root ._localIDs [id ]
120- sources [# sources + 1 ] = source
125+ if guide .isSet (source ) then
126+ sources .sets [# sources .sets + 1 ] = source
127+ else
128+ sources .gets [# sources .gets + 1 ] = source
129+ end
121130end
122131
123132function compileLocalID (source )
154163--- @param source parser.object
155164--- @param key ? string
156165--- @return parser.object[] ?
157- function vm .getLocalSources (source , key )
166+ function vm .getLocalSourcesSets (source , key )
158167 local id = vm .getLocalID (source )
159168 if not id then
160169 return nil
@@ -169,12 +178,34 @@ function vm.getLocalSources(source, key)
169178 end
170179 id = id .. vm .ID_SPLITE .. key
171180 end
172- return root ._localIDs [id ]
181+ return root ._localIDs [id ]. sets
173182end
174183
175184--- @param source parser.object
185+ --- @param key ? string
186+ --- @return parser.object[] ?
187+ function vm .getLocalSourcesGets (source , key )
188+ local id = vm .getLocalID (source )
189+ if not id then
190+ return nil
191+ end
192+ local root = guide .getRoot (source )
193+ if not root ._localIDs then
194+ return nil
195+ end
196+ if key then
197+ if type (key ) ~= ' string' then
198+ return nil
199+ end
200+ id = id .. vm .ID_SPLITE .. key
201+ end
202+ return root ._localIDs [id ].gets
203+ end
204+
205+ --- @param source parser.object
206+ --- @param includeGets boolean
176207--- @return parser.object[]
177- function vm .getLocalFields (source )
208+ function vm .getLocalFields (source , includeGets )
178209 local id = vm .getLocalID (source )
179210 if not id then
180211 return nil
@@ -192,9 +223,14 @@ function vm.getLocalFields(source)
192223 and lid :sub (# id + 1 , # id + 1 ) == vm .ID_SPLITE
193224 -- only one field
194225 and not lid :find (vm .ID_SPLITE , # id + 2 ) then
195- for _ , src in ipairs (sources ) do
226+ for _ , src in ipairs (sources . sets ) do
196227 fields [# fields + 1 ] = src
197228 end
229+ if includeGets then
230+ for _ , src in ipairs (sources .gets ) do
231+ fields [# fields + 1 ] = src
232+ end
233+ end
198234 end
199235 end
200236 local cost = os.clock () - clock
0 commit comments