From 3f56e35738ecc1d8765dfb6fc89522c1a8481095 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Tue, 5 Apr 2022 03:16:46 +0800 Subject: update --- script/vm/compiler.lua | 28 ++++++++++++++++++++++++++-- script/vm/infer.lua | 11 +++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) (limited to 'script/vm') diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index b496d9cc..31713f36 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -20,17 +20,29 @@ local m = {} local searchFieldSwitch = util.switch() : case 'table' : call(function (node, key, pushResult) + local hasFiled = false for _, field in ipairs(node) do if field.type == 'tablefield' or field.type == 'tableindex' then if not key or key == guide.getKeyName(field) then + hasFiled = true pushResult(field) end end if field.type == 'tableexp' then if not key or key == field.tindex then + hasFiled = true + pushResult(field) + end + end + if field.type == 'varargs' then + if not hasFiled + and key + and key >= 1 + and math.tointeger(key) then + hasFiled = true pushResult(field) end end @@ -432,8 +444,6 @@ local function selectNode(source, list, index) local result if exp.type == 'call' then result = getReturn(exp.node, index, exp.args) - elseif exp.type == '...' then - -- TODO else result = m.compileNode(exp) end @@ -748,6 +758,13 @@ local compilerSwitch = util.switch() local node = getReturn(vararg.node, source.sindex, vararg.args) nodeMgr.setNode(source, node) end + if vararg.type == 'varargs' then + nodeMgr.setNode(source, m.compileNode(vararg)) + end + end) + : case 'varargs' + : call(function (source) + nodeMgr.setNode(source, m.compileNode(source.node)) end) : case 'call' : call(function (source) @@ -872,6 +889,10 @@ local compilerSwitch = util.switch() nodeMgr.setNode(source, globalMgr.getGlobal('type', 'any')) end end) + : case 'generic' + : call(function (source) + nodeMgr.setNode(source, source) + end) : case 'unary' : call(function (source) local valueMgr = require 'vm.value' @@ -1295,6 +1316,9 @@ end ---@param source parser.object ---@return vm.node function m.compileNode(source) + if not source then + return false + end if nodeMgr.nodeCache[source] ~= nil then return nodeMgr.nodeCache[source] end diff --git a/script/vm/infer.lua b/script/vm/infer.lua index 1b0ff800..bf6df2fb 100644 --- a/script/vm/infer.lua +++ b/script/vm/infer.lua @@ -50,6 +50,13 @@ local viewNodeSwitch = util.switch() end) : case 'table' : call(function (source, infer) + if source.type == 'table' then + if #source == 1 and source[1].type == 'varargs' then + local node = m.getInfer(source[1]):view() + return ('%s[]'):format(node) + end + end + infer._hasTable = true end) : case 'function' @@ -92,6 +99,10 @@ local viewNodeSwitch = util.switch() return source[1] end end) + : case 'generic' + : call(function (source, infer) + return ('<%s>'):format(source.proto[1]) + end) : case 'doc.generic.name' : call(function (source, infer) return ('<%s>'):format(source[1]) -- cgit v1.2.3