From 32fd9f2cef67919ef37d7a6396ae0a8c7d7f224f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Thu, 10 Mar 2022 17:54:42 +0800 Subject: update --- script/vm/compiler.lua | 18 ++++++++++++++++++ script/vm/infer.lua | 27 ++++++++++++++++++++------- 2 files changed, 38 insertions(+), 7 deletions(-) (limited to 'script/vm') diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index bdd228e0..f0735ad3 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -236,6 +236,20 @@ local function getReturn(func, index, args) if func.special == 'setmetatable' then return getReturnOfSetMetaTable(args) end + if func.special == 'pcall' and index > 1 then + local newArgs = {} + for i = 2, #args do + newArgs[#newArgs+1] = args[i] + end + return getReturn(args[1], index - 1, newArgs) + end + if func.special == 'xpcall' and index > 1 then + local newArgs = {} + for i = 3, #args do + newArgs[#newArgs+1] = args[i] + end + return getReturn(args[1], index - 1, newArgs) + end local node = m.compileNode(func) ---@type vm.node.union local result @@ -534,6 +548,10 @@ local compilerMap = util.switch() nodeMgr.setNode(source, m.compileNode(typeUnit)) end end) + : case 'doc.type.enum' + : call(function (source) + nodeMgr.setNode(source, source) + end) : case 'doc.generic.name' : call(function (source) nodeMgr.setNode(source, source) diff --git a/script/vm/infer.lua b/script/vm/infer.lua index 90c10145..95a01658 100644 --- a/script/vm/infer.lua +++ b/script/vm/infer.lua @@ -12,16 +12,20 @@ local viewNodeMap = util.switch() : case 'nil' : case 'boolean' : case 'string' - : case 'table' : case 'function' - : case 'number' : case 'integer' : call(function (source, options) - if source.type == 'number' then - options['hasNumber'] = true - end return source.type end) + : case 'number' + : call(function (source, options) + options['hasNumber'] = true + return source.type + end) + : case 'table' + : call(function (source, options) + options['hasTable'] = true + end) : case 'global' : call(function (source, options) if source.cate == 'type' then @@ -29,6 +33,15 @@ local viewNodeMap = util.switch() return source.name end end) + : case 'doc.type.array' + : call(function (source, options) + options['hasClass'] = true + return m.viewType(source.node) .. '[]' + end) + : case 'doc.type.enum' + : call(function (source, options) + return source[1] + end) : getMap() ---@param node vm.node @@ -54,8 +67,8 @@ function m.viewType(source) if options['hasNumber'] then views['integer'] = nil end - if options['hasClass'] then - views['table'] = nil + if options['hasTable'] and not options['hasClass'] then + views['table'] = true end local array = {} for view in pairs(views) do -- cgit v1.2.3