@@ -3,6 +3,7 @@ local guide = require 'parser.guide'
3
3
local globalBuilder = require ' vm.global'
4
4
local signMgr = require ' vm.sign'
5
5
local genericMgr = require ' vm.generic'
6
+ local localID = require ' vm.local-id'
6
7
--- @class vm
7
8
local vm = require ' vm.vm'
8
9
@@ -317,6 +318,43 @@ function m.compileObject(source)
317
318
compilerGlobalSwitch (source .type , source )
318
319
end
319
320
321
+ --- @param source parser.object
322
+ function m .compileSelf (source )
323
+ if source .parent .type ~= ' funcargs' then
324
+ return
325
+ end
326
+ --- @type parser.object
327
+ local node = source .parent .parent and source .parent .parent .parent and source .parent .parent .parent .node
328
+ if not node then
329
+ return
330
+ end
331
+ local fields = localID .getFields (source )
332
+ if not fields then
333
+ return
334
+ end
335
+ local nodeLocalID = localID .getID (node )
336
+ local globalNode = node ._globalNode
337
+ if not nodeLocalID and not globalNode then
338
+ return
339
+ end
340
+ for _ , field in ipairs (fields ) do
341
+ if field .type == ' setfield' then
342
+ local key = guide .getKeyName (field )
343
+ if key then
344
+ if nodeLocalID then
345
+ local myID = nodeLocalID .. vm .ID_SPLITE .. key
346
+ localID .insertLocalID (myID , field )
347
+ end
348
+ if globalNode then
349
+ local myID = globalNode :getName () .. vm .ID_SPLITE .. key
350
+ local myGlobal = m .declareGlobal (' variable' , myID , guide .getUri (node ))
351
+ myGlobal :addSet (guide .getUri (node ), field )
352
+ end
353
+ end
354
+ end
355
+ end
356
+ end
357
+
320
358
--- @param source parser.object
321
359
function m .compileAst (source )
322
360
local env = guide .getENV (source )
@@ -335,6 +373,18 @@ function m.compileAst(source)
335
373
}, function (src )
336
374
m .compileObject (src )
337
375
end )
376
+
377
+ --[[
378
+ local mt
379
+ function mt:xxx()
380
+ self.a = 1
381
+ end
382
+
383
+ mt.a --> find this definition
384
+ ]]
385
+ guide .eachSourceType (source , ' self' , function (src )
386
+ m .compileSelf (src )
387
+ end )
338
388
end
339
389
340
390
--- @return vm.global
0 commit comments