diff options
Diffstat (limited to 'script-beta')
-rw-r--r-- | script-beta/core/hover/table.lua | 15 | ||||
-rw-r--r-- | script-beta/vm/getClass.lua | 14 | ||||
-rw-r--r-- | script-beta/vm/getLibrary.lua | 43 |
3 files changed, 47 insertions, 25 deletions
diff --git a/script-beta/core/hover/table.lua b/script-beta/core/hover/table.lua index b098ad35..f845c335 100644 --- a/script-beta/core/hover/table.lua +++ b/script-beta/core/hover/table.lua @@ -173,6 +173,7 @@ return function (source) local literals = {} local classes = {} local clock = os.clock() + local timeUp for _, src in ipairs(vm.getFields(source, 'deep')) do local key = getKey(src) if not key then @@ -184,10 +185,12 @@ return function (source) if not literals[key] then literals[key] = {} end - if os.clock() - clock <= 1 then + if os.clock() - clock <= 5 then local class, literal = getField(src) classes[key][#classes[key]+1] = class literals[key][#literals[key]+1] = literal + else + timeUp = true end ::CONTINUE:: end @@ -210,9 +213,15 @@ return function (source) break end end + local result if intValue then - return buildAsConst(classes, literals) + result = buildAsConst(classes, literals) else - return buildAsHash(classes, literals) + result = buildAsHash(classes, literals) + end + -- TODO + if timeUp then + result = '\n-- TODO: Too much time has been spent, type inference has been abandoned. Optimize later.\n' .. result end + return result end diff --git a/script-beta/vm/getClass.lua b/script-beta/vm/getClass.lua index ec86e0cf..2a507b12 100644 --- a/script-beta/vm/getClass.lua +++ b/script-beta/vm/getClass.lua @@ -11,8 +11,8 @@ local function lookUpDocClass(source) end end -local function getClass(source, classes, deep, simple) - local lib = vm.getLibrary(source, simple) +local function getClass(source, classes, depth, deep) + local lib = vm.getLibrary(source, deep) if lib then if lib.value.type == 'table' then classes[#classes+1] = lib.value.name @@ -26,11 +26,11 @@ local function getClass(source, classes, deep, simple) classes[#classes+1] = docClass return end - if deep > 3 then + if depth > 3 then return end local value = guide.getObjectValue(source) or source - if simple and value == source then + if deep and value == source then if value and value.type == 'string' then classes[#classes+1] = value[1] end @@ -56,13 +56,13 @@ local function getClass(source, classes, deep, simple) return end vm.eachMeta(source, function (mt) - getClass(mt, classes, deep + 1, simple) + getClass(mt, classes, depth + 1, deep) end) end -function vm.getClass(source, simple) +function vm.getClass(source, deep) local classes = {} - getClass(source, classes, 1, simple) + getClass(source, classes, 1, deep) if #classes == 0 then return nil end diff --git a/script-beta/vm/getLibrary.lua b/script-beta/vm/getLibrary.lua index 3a3c1baf..f5c643e9 100644 --- a/script-beta/vm/getLibrary.lua +++ b/script-beta/vm/getLibrary.lua @@ -2,7 +2,7 @@ local vm = require 'vm.vm' local guide = require 'parser.guide' local library = require 'library' -local function getLibrary(source, simple) +local function getLibrary(source, deep) if source.type == 'library' then return source end @@ -18,29 +18,42 @@ local function getLibrary(source, simple) end end end - local defs = vm.getDefs(source, simple) + + local unlock = vm.lock('getLibrary', source) + if not unlock then + return + end + + local defs = vm.getDefs(source, deep) + unlock() + for _, def in ipairs(defs) do if def.type == 'library' then return def end end + return nil end -function vm.getLibrary(source, simple) - if simple then - return getLibrary(source, simple) or false +function vm.getLibrary(source, deep) + if ALL_DEEP then + deep = 'deep' end - local cache = vm.getCache('getLibrary')[source] - if cache ~= nil then + if guide.isGlobal(source) then + local name = guide.getKeyName(source) + local cache = vm.getCache('getLibraryOfGlobal')[name] + or vm.getCache('getLibrary')[source] + or getLibrary(source, 'deep') + vm.getCache('getLibraryOfGlobal')[name] = cache + vm.getCache('getLibrary')[source] = cache + return cache + else + local cache = vm.getCache('getLibrary')[source] + or getLibrary(source, deep) + if deep then + vm.getCache('getLibrary')[source] = cache + end return cache end - local unlock = vm.lock('getLibrary', source) - if not unlock then - return - end - cache = getLibrary(source) or false - vm.getCache('getLibrary')[source] = cache - unlock() - return cache end |