diff options
Diffstat (limited to 'script')
-rw-r--r-- | script/vm/generic-manager.lua | 36 | ||||
-rw-r--r-- | script/vm/generic.lua | 12 | ||||
-rw-r--r-- | script/vm/getDef.lua | 2 | ||||
-rw-r--r-- | script/vm/type.lua | 16 |
4 files changed, 43 insertions, 23 deletions
diff --git a/script/vm/generic-manager.lua b/script/vm/generic-manager.lua index 76bdd9c5..cad0e48d 100644 --- a/script/vm/generic-manager.lua +++ b/script/vm/generic-manager.lua @@ -4,14 +4,15 @@ local nodeMgr = require 'vm.node' ---@class vm.node.generic-manager ---@field parent parser.object ----@field signList parser.object[] +---@field signList vm.node[] local mt = {} mt.__index = mt mt.type = 'generic-manager' ---@param key parser.object function mt:addSign(key) - self.signList[#self.signList+1] = key + local compiler = require 'vm.compiler' + self.signList[#self.signList+1] = compiler.compileNode(key) end ---@param node vm.node @@ -61,14 +62,22 @@ function mt:resolve(argNodes) for _, ufield in ipairs(typeUnit.fields) do local ufieldNode = compiler.compileNode(ufield.name) local uvalueNode = compiler.compileNode(ufield.extends) - if ufieldNode.type == 'doc.generic.name' then - -- { [number]: number}|number[] -> { [K]: number } - local tnode = typeMgr.getTableKey(node, uvalueNode) - resolve(ufieldNode, tnode) + if ufieldNode.type == 'doc.generic.name' and uvalueNode.type == 'doc.generic.name' then + -- { [number]: number} -> { [K]: V } + local tfieldNode = typeMgr.getTableKey(node, 'any') + local tvalueNode = typeMgr.getTableValue(node, 'any') + resolve(ufieldNode, tfieldNode) + resolve(uvalueNode, tvalueNode) else - -- { [number]: number}|number[] -> { [number]: V } - local tnode = typeMgr.getTableValue(node, ufieldNode) - resolve(uvalueNode, tnode) + if ufieldNode.type == 'doc.generic.name' then + -- { [number]: number}|number[] -> { [K]: number } + local tnode = typeMgr.getTableKey(node, uvalueNode) + resolve(ufieldNode, tnode) + else + -- { [number]: number}|number[] -> { [number]: V } + local tnode = typeMgr.getTableValue(node, ufieldNode) + resolve(uvalueNode, tnode) + end end end end @@ -79,13 +88,8 @@ function mt:resolve(argNodes) if not sign then break end - if sign.type == 'doc.type' then - for _, typeUnit in ipairs(sign.types) do - resolve(typeUnit, compiler.compileNode(node)) - end - end - if sign.type == 'doc.generic.name' then - resolve(sign, compiler.compileNode(node)) + for n in nodeMgr.eachNode(sign) do + resolve(n, compiler.compileNode(node)) end end diff --git a/script/vm/generic.lua b/script/vm/generic.lua index 7b0eb120..e0096e30 100644 --- a/script/vm/generic.lua +++ b/script/vm/generic.lua @@ -67,12 +67,12 @@ local function cloneObject(node, resolved) } for i, field in ipairs(node.fields) do local newField = { - type = field.type, - start = field.start, - finish = field.finish, - parent = newTable, - name = field.name, - extends = cloneObject(field.extends, resolved) + type = field.type, + start = field.start, + finish = field.finish, + parent = newTable, + name = cloneObject(field.name, resolved), + extends = cloneObject(field.extends, resolved), } newField.name.parent = newField newField.extends.parent = newField diff --git a/script/vm/getDef.lua b/script/vm/getDef.lua index 2105eeb6..5edc6c67 100644 --- a/script/vm/getDef.lua +++ b/script/vm/getDef.lua @@ -118,7 +118,7 @@ local searchFieldMap = util.switch() local fieldKey = field.name if fieldKey.type == 'doc.field.name' then if fieldKey[1] == key then - pushResult(fieldKey) + pushResult(field) end end end diff --git a/script/vm/type.lua b/script/vm/type.lua index a0f923ae..5bdc975b 100644 --- a/script/vm/type.lua +++ b/script/vm/type.lua @@ -9,6 +9,17 @@ local m = {} ---@param parent vm.node ---@return boolean function m.isSubType(child, parent, mark) + if type(parent) == 'string' then + parent = globalMgr.getGlobal('type', parent) + end + if type(child) == 'string' then + child = globalMgr.getGlobal('type', child) + end + + if parent.type == 'global' and parent.cate == 'type' and parent.name == 'any' then + return true + end + if child.type == 'doc.type' then for _, typeUnit in ipairs(child.types) do if not m.isSubType(typeUnit, parent) then @@ -17,9 +28,11 @@ function m.isSubType(child, parent, mark) end return true end + if child.type == 'doc.type.name' then child = globalMgr.getGlobal('type', child[1]) end + if child.type == 'global' and child.cate == 'type' then if parent.type == 'doc.type' then for _, typeUnit in ipairs(parent.types) do @@ -28,9 +41,11 @@ function m.isSubType(child, parent, mark) end end end + if parent.type == 'doc.type.name' then parent = globalMgr.getGlobal('type', parent[1]) end + if parent.type == 'global' and parent.cate == 'type' then if parent.name == child.name then return true @@ -51,6 +66,7 @@ function m.isSubType(child, parent, mark) end end end + return false end |