@@ -3,6 +3,7 @@ local guide = require 'parser.guide'
33local globalBuilder = require ' vm.global'
44local signMgr = require ' vm.sign'
55local genericMgr = require ' vm.generic'
6+ local localID = require ' vm.local-id'
67--- @class vm
78local vm = require ' vm.vm'
89
@@ -317,6 +318,43 @@ function m.compileObject(source)
317318 compilerGlobalSwitch (source .type , source )
318319end
319320
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+
320358--- @param source parser.object
321359function m .compileAst (source )
322360 local env = guide .getENV (source )
@@ -335,6 +373,18 @@ function m.compileAst(source)
335373 }, function (src )
336374 m .compileObject (src )
337375 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 )
338388end
339389
340390--- @return vm.global
0 commit comments