From 2620918840cb28fdd641fa986367ad9e8175a730 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, 29 Oct 2020 20:58:47 +0800 Subject: =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=80=A7=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script-beta/vm/eachDef.lua | 4 ++++ script-beta/vm/eachField.lua | 4 ++++ script-beta/vm/eachRef.lua | 4 ++++ script-beta/vm/getInfer.lua | 46 +++++++++++++++++++++++++++++++++++++------- 4 files changed, 51 insertions(+), 7 deletions(-) (limited to 'script-beta/vm') diff --git a/script-beta/vm/eachDef.lua b/script-beta/vm/eachDef.lua index 5d1aa566..0cd3c6ca 100644 --- a/script-beta/vm/eachDef.lua +++ b/script-beta/vm/eachDef.lua @@ -26,12 +26,16 @@ local function eachDef(source, deep) end function vm.getDefs(source, deep) + if ALL_DEEP then + deep = 'deep' + end if guide.isGlobal(source) then local name = guide.getKeyName(source) local cache = vm.getCache('eachDefOfGlobal')[name] or vm.getCache('eachDef')[source] or eachDef(source, 'deep') vm.getCache('eachDefOfGlobal')[name] = cache + vm.getCache('eachDef')[source] = cache return cache else local cache = vm.getCache('eachDef')[source] diff --git a/script-beta/vm/eachField.lua b/script-beta/vm/eachField.lua index 90892f03..798566b4 100644 --- a/script-beta/vm/eachField.lua +++ b/script-beta/vm/eachField.lua @@ -47,12 +47,16 @@ local function eachField(source, deep) end function vm.getFields(source, deep) + if ALL_DEEP then + deep = 'deep' + end if guide.isGlobal(source) then local name = guide.getKeyName(source) local cache = vm.getCache('eachFieldOfGlobal')[name] or vm.getCache('eachField')[source] or eachField(source, 'deep') vm.getCache('eachFieldOfGlobal')[name] = cache + vm.getCache('eachField')[source] = cache return cache else local cache = vm.getCache('eachField')[source] diff --git a/script-beta/vm/eachRef.lua b/script-beta/vm/eachRef.lua index ea46c9ee..cd003443 100644 --- a/script-beta/vm/eachRef.lua +++ b/script-beta/vm/eachRef.lua @@ -25,12 +25,16 @@ local function getRefs(source, deep) end function vm.getRefs(source, deep) + if ALL_DEEP then + deep = 'deep' + end if guide.isGlobal(source) then local name = guide.getKeyName(source) local cache = vm.getCache('eachRefOfGlobal')[name] or vm.getCache('eachRef')[source] or getRefs(source, 'deep') vm.getCache('eachRefOfGlobal')[name] = cache + vm.getCache('eachRef')[source] = cache return cache else local cache = vm.getCache('eachRef')[source] diff --git a/script-beta/vm/getInfer.lua b/script-beta/vm/getInfer.lua index c0f2d118..c7c422f4 100644 --- a/script-beta/vm/getInfer.lua +++ b/script-beta/vm/getInfer.lua @@ -1,6 +1,7 @@ local vm = require 'vm.vm' local guide = require 'parser.guide' local util = require 'utility' +local await = require 'await' NIL = setmetatable({''}, { __tostring = function () return 'nil' end }) @@ -52,16 +53,47 @@ function vm.getInferLiteral(source, deep) return table.concat(literals, '|') end +local function getInfers(source, deep) + local results = {} + local lock = vm.lock('getInfers', source) + if not lock then + return results + end + + await.delay() + + local clock = os.clock() + local myResults, count = guide.requestInfer(source, vm.interface, deep) + if DEVELOP and os.clock() - clock > 0.1 then + log.warn('requestInfer', count, os.clock() - clock, guide.getUri(source), util.dump(source, { deep = 1 })) + end + vm.mergeResults(results, myResults) + + lock() + + return results +end + --- 获取对象的值 --- 会尝试穿透函数调用 function vm.getInfers(source, deep) - if not source then - return + if ALL_DEEP then + deep = 'deep' end - local clock = os.clock() - local infers = guide.requestInfer(source, vm.interface, deep) - if os.clock() - clock > 0.1 then - log.warn(('Request infer takes [%.3f]sec! %s %s'):format(os.clock() - clock, guide.getUri(source), util.dump(source, { deep = 1 }))) + if guide.isGlobal(source) then + local name = guide.getKeyName(source) + local cache = vm.getCache('getInfersOfGlobal')[name] + or vm.getCache('getInfers')[source] + or getInfers(source, 'deep') + vm.getCache('getInfersOfGlobal')[name] = cache + vm.getCache('getInfers')[source] = cache + return cache + else + local cache = vm.getCache('getInfers')[source] + or getInfers(source, deep) + if deep then + vm.getCache('getInfers')[source] = cache + end + return cache end - return infers end -- cgit v1.2.3