summaryrefslogtreecommitdiff
path: root/script/vm/compiler.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-04-13 19:59:45 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-04-13 19:59:45 +0800
commitb3b71716f689be9115cdde8d6caf0314e76ae523 (patch)
treed1859d7a80d635b6157a431c1ef6f51c8a4484f0 /script/vm/compiler.lua
parent43ef5d13ab20b77da3e4f7626116f0580aa1377e (diff)
downloadlua-language-server-b3b71716f689be9115cdde8d6caf0314e76ae523.zip
cleanup
Diffstat (limited to 'script/vm/compiler.lua')
-rw-r--r--script/vm/compiler.lua345
1 files changed, 179 insertions, 166 deletions
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua
index 2af4f61f..3c0a2dcb 100644
--- a/script/vm/compiler.lua
+++ b/script/vm/compiler.lua
@@ -2,10 +2,8 @@ local guide = require 'parser.guide'
local util = require 'utility'
local localID = require 'vm.local-id'
local globalMgr = require 'vm.global-manager'
-local nodeMgr = require 'vm.node'
local signMgr = require 'vm.sign'
local config = require 'config'
-local union = require 'vm.union'
local genericMgr = require 'vm.generic'
local rpath = require 'workspace.require-path'
local files = require 'files'
@@ -112,7 +110,7 @@ local searchFieldSwitch = util.switch()
local fieldKey = field.name
if fieldKey.type == 'doc.type' then
local fieldNode = vm.compileNode(fieldKey)
- for fn in nodeMgr.eachObject(fieldNode) do
+ for fn in fieldNode:eachObject() do
if fn.type == 'global' and fn.cate == 'type' then
if key == nil
or fn.name == 'any'
@@ -237,7 +235,7 @@ local function getObjectSign(source)
for _, arg in ipairs(source.args) do
local argNode = vm.compileNode(arg)
if arg.optional then
- argNode = nodeMgr.addOptional(argNode)
+ argNode:addOptional()
end
source._sign:addSign(argNode)
end
@@ -257,7 +255,7 @@ local function getObjectSign(source)
for _, arg in ipairs(source.args) do
local argNode = vm.compileNode(arg.extends)
if arg.optional then
- argNode = nodeMgr.addOptional(argNode)
+ argNode:addOptional()
end
source._sign:addSign(argNode)
end
@@ -296,16 +294,17 @@ function vm.getReturnOfFunction(func, index)
end
end
+---@return vm.node
local function getReturnOfSetMetaTable(args)
local tbl = args[1]
local mt = args[2]
- local node = union()
+ local node = vm.createNode()
if tbl then
node:merge(vm.compileNode(tbl))
end
if mt then
vm.compileByParentNode(mt, '__index', function (src)
- for n in nodeMgr.eachObject(vm.compileNode(src)) do
+ for n in vm.compileNode(src):eachObject() do
if n.type == 'global'
or n.type == 'local'
or n.type == 'table'
@@ -318,6 +317,7 @@ local function getReturnOfSetMetaTable(args)
return node
end
+---@return vm.node?
local function getReturn(func, index, args)
if func.special == 'setmetatable' then
if not args then
@@ -369,29 +369,27 @@ local function getReturn(func, index, args)
return vm.compileNode(ast)
end
local node = vm.compileNode(func)
- ---@type vm.union
+ ---@type vm.node?
local result
- if node then
- for cnode in nodeMgr.eachObject(node) do
- if cnode.type == 'function'
- or cnode.type == 'doc.type.function' then
- local returnObject = vm.getReturnOfFunction(cnode, index)
- local returnNode = vm.compileNode(returnObject)
- if returnNode then
- for rnode in nodeMgr.eachObject(returnNode) do
- if rnode.type == 'generic' then
- returnNode = rnode:resolve(guide.getUri(func), args)
- break
- end
+ for cnode in node:eachObject() do
+ if cnode.type == 'function'
+ or cnode.type == 'doc.type.function' then
+ local returnObject = vm.getReturnOfFunction(cnode, index)
+ local returnNode = vm.compileNode(returnObject)
+ if returnNode then
+ for rnode in returnNode:eachObject() do
+ if rnode.type == 'generic' then
+ returnNode = rnode:resolve(guide.getUri(func), args)
+ break
end
end
- if returnNode then
- for rnode in nodeMgr.eachObject(returnNode) do
- -- TODO: narrow type
- if rnode.type ~= 'doc.generic.name' then
- result = result or union()
- result:merge(rnode)
- end
+ end
+ if returnNode then
+ for rnode in returnNode:eachObject() do
+ -- TODO: narrow type
+ if rnode.type ~= 'doc.generic.name' then
+ result = result or vm.createNode()
+ result:merge(rnode)
end
end
end
@@ -408,7 +406,7 @@ local function bindDocs(source)
local doc = docs[i]
if doc.type == 'doc.type' then
if not isParam then
- nodeMgr.setNode(source, vm.compileNode(doc))
+ vm.setNode(source, vm.compileNode(doc))
return true
end
end
@@ -417,13 +415,13 @@ local function bindDocs(source)
or (source._globalNode and guide.isSet(source))
or source.type == 'tablefield'
or source.type == 'tableindex' then
- nodeMgr.setNode(source, vm.compileNode(doc))
+ vm.setNode(source, vm.compileNode(doc))
return true
end
end
if doc.type == 'doc.param' then
if isParam and source[1] == doc.param[1] then
- nodeMgr.setNode(source, vm.compileNode(doc))
+ vm.setNode(source, vm.compileNode(doc))
return true
end
end
@@ -438,7 +436,7 @@ local function bindDocs(source)
if not ast then
return nil
end
- nodeMgr.setNode(source, vm.compileNode(ast))
+ vm.setNode(source, vm.compileNode(ast))
return true
end
end
@@ -455,14 +453,14 @@ local function compileByLocalID(source)
if src.bindDocs then
if bindDocs(src) then
hasMarkDoc = true
- nodeMgr.setNode(source, vm.compileNode(src))
+ vm.setNode(source, vm.compileNode(src))
end
end
end
for _, src in ipairs(sources) do
if src.value then
if not hasMarkDoc or guide.isLiteral(src.value) then
- nodeMgr.setNode(source, vm.compileNode(src.value))
+ vm.setNode(source, vm.compileNode(src.value))
end
end
end
@@ -477,11 +475,12 @@ function vm.compileByParentNode(source, key, pushResult)
return
end
local suri = guide.getUri(source)
- for node in nodeMgr.eachObject(parentNode) do
+ for node in parentNode:eachObject() do
searchFieldSwitch(node.type, suri, node, key, pushResult)
end
end
+---@return vm.node?
local function selectNode(source, list, index)
if not list then
return nil
@@ -508,14 +507,17 @@ local function selectNode(source, list, index)
local result
if exp.type == 'call' then
result = getReturn(exp.node, index, exp.args)
+ if not result then
+ return nil
+ end
else
result = vm.compileNode(exp)
end
if source.type == 'function.return' then
-- remove any for returns
- local rtnNode = union()
+ local rtnNode = vm.createNode()
local hasKnownType
- for n in nodeMgr.eachObject(result) do
+ for n in result:eachObject() do
if guide.isLiteral(n) then
hasKnownType = true
rtnNode:merge(n)
@@ -533,9 +535,11 @@ local function selectNode(source, list, index)
if not hasKnownType then
rtnNode:merge(globalMgr.getGlobal('type', 'unknown'))
end
- return nodeMgr.setNode(source, rtnNode)
+ vm.setNode(source, rtnNode)
+ return rtnNode
end
- return nodeMgr.setNode(source, result)
+ vm.setNode(source, result)
+ return result
end
---@param source parser.object
@@ -583,6 +587,9 @@ local function compileCallArgNode(arg, call, callNode, fixIndex, myIndex)
if call.args then
for i = 1, 2 do
local eventArg = call.args[i + fixIndex]
+ if not eventArg then
+ break
+ end
eventMap = vm.getLiterals(eventArg)
if eventMap then
eventIndex = i
@@ -591,27 +598,29 @@ local function compileCallArgNode(arg, call, callNode, fixIndex, myIndex)
end
end
- for n in nodeMgr.eachObject(callNode) do
+ for n in callNode:eachObject() do
if n.type == 'function' then
local farg = getFuncArg(n, myIndex)
- for fn in nodeMgr.eachObject(vm.compileNode(farg)) do
+ for fn in vm.compileNode(farg):eachObject() do
if isValidCallArgNode(arg, fn) then
- nodeMgr.setNode(arg, fn)
+ vm.setNode(arg, fn)
end
end
end
if n.type == 'doc.type.function' then
- local argNode = vm.compileNode(n.args[eventIndex])
- local event = argNode and argNode[1]
- if not event
- or not eventMap
- or myIndex <= eventIndex
- or event.type ~= 'doc.type.string'
- or eventMap[event[1]] then
- local farg = getFuncArg(n, myIndex)
- for fn in nodeMgr.eachObject(vm.compileNode(farg)) do
- if isValidCallArgNode(arg, fn) then
- nodeMgr.setNode(arg, fn)
+ if n.args[eventIndex] then
+ local argNode = vm.compileNode(n.args[eventIndex])
+ local event = argNode and argNode[1]
+ if not event
+ or not eventMap
+ or myIndex <= eventIndex
+ or event.type ~= 'doc.type.string'
+ or eventMap[event[1]] then
+ local farg = getFuncArg(n, myIndex)
+ for fn in vm.compileNode(farg):eachObject() do
+ if isValidCallArgNode(arg, fn) then
+ vm.setNode(arg, fn)
+ end
end
end
end
@@ -641,7 +650,7 @@ function vm.compileCallArg(arg, call, index)
callNode = vm.compileNode(call.args[1])
compileCallArgNode(arg, call, callNode, fixIndex, index - fixIndex)
end
- return nodeMgr.getNode(arg)
+ return vm.getNode(arg)
end
local compilerSwitch = util.switch()
@@ -654,11 +663,11 @@ local compilerSwitch = util.switch()
: case 'doc.type.table'
: case 'doc.type.array'
: call(function (source)
- nodeMgr.setNode(source, source)
+ vm.setNode(source, source)
end)
: case 'table'
: call(function (source)
- nodeMgr.setNode(source, source)
+ vm.setNode(source, source)
if source.parent.type == 'callargs' then
local call = source.parent.parent
@@ -672,17 +681,17 @@ local compilerSwitch = util.switch()
or source.parent.type == 'tableindex'
or source.parent.type == 'setfield'
or source.parent.type == 'setindex' then
- nodeMgr.setNode(source, vm.compileNode(source.parent))
+ vm.setNode(source, vm.compileNode(source.parent))
end
end)
: case 'function'
: call(function (source)
- nodeMgr.setNode(source, source)
+ vm.setNode(source, source)
if source.bindDocs then
for _, doc in ipairs(source.bindDocs) do
if doc.type == 'doc.overload' then
- nodeMgr.setNode(source, vm.compileNode(doc))
+ vm.setNode(source, vm.compileNode(doc))
end
end
end
@@ -695,12 +704,11 @@ local compilerSwitch = util.switch()
end)
: case 'paren'
: call(function (source)
- nodeMgr.setNode(source, vm.compileNode(source.exp))
+ vm.setNode(source, vm.compileNode(source.exp))
end)
: case 'local'
: call(function (source)
- --localMgr.declareLocal(source)
- nodeMgr.setNode(source, source)
+ vm.setNode(source, source)
local hasMarkDoc
if source.bindDocs then
hasMarkDoc = bindDocs(source)
@@ -708,14 +716,14 @@ local compilerSwitch = util.switch()
local hasMarkParam
if source.dummy and not hasMarkDoc then
hasMarkParam = true
- nodeMgr.setNode(source, vm.compileNode(source.method.node))
+ vm.setNode(source, vm.compileNode(source.method.node))
end
if source.value then
if not hasMarkDoc or guide.isLiteral(source.value) then
if source.value and source.value.type == 'table' then
- nodeMgr.setNode(source, source.value)
+ vm.setNode(source, source.value)
else
- nodeMgr.setNode(source, vm.compileNode(source.value))
+ vm.setNode(source, vm.compileNode(source.value))
end
end
end
@@ -726,9 +734,9 @@ local compilerSwitch = util.switch()
for _, ref in ipairs(source.ref) do
if ref.type == 'setlocal' then
if ref.value and ref.value.type == 'table' then
- nodeMgr.setNode(source, ref.value)
+ vm.setNode(source, ref.value)
else
- nodeMgr.setNode(source, vm.compileNode(ref.value))
+ vm.setNode(source, vm.compileNode(ref.value))
end
end
end
@@ -742,25 +750,25 @@ local compilerSwitch = util.switch()
local setfield = source.parent.parent.parent
if setfield.type == 'setfield' then
hasMarkParam = true
- nodeMgr.setNode(source, vm.compileNode(setfield.node))
+ vm.setNode(source, vm.compileNode(setfield.node))
end
end
if source.parent.type == 'funcargs' and not hasMarkDoc and not hasMarkParam then
local func = source.parent.parent
local funcNode = vm.compileNode(func)
local hasDocArg
- for n in nodeMgr.eachObject(funcNode) do
+ for n in funcNode:eachObject() do
if n.type == 'doc.type.function' then
for index, arg in ipairs(n.args) do
if func.args[index] == source then
- nodeMgr.setNode(source, vm.compileNode(arg))
+ vm.setNode(source, vm.compileNode(arg))
hasDocArg = true
end
end
end
end
if not hasDocArg then
- nodeMgr.setNode(source, globalMgr.getGlobal('type', 'any'))
+ vm.setNode(source, globalMgr.getGlobal('type', 'any'))
end
end
-- for x in ... do
@@ -770,13 +778,13 @@ local compilerSwitch = util.switch()
-- for x = ... do
if source.parent.type == 'loop' then
- nodeMgr.setNode(source, globalMgr.getGlobal('type', 'integer'))
+ vm.setNode(source, globalMgr.getGlobal('type', 'integer'))
end
end)
: case 'setlocal'
: case 'getlocal'
: call(function (source)
- nodeMgr.setNode(source, vm.compileNode(source.node), true)
+ vm.setNode(source, vm.compileNode(source.node), true)
end)
: case 'setfield'
: case 'setmethod'
@@ -790,7 +798,7 @@ local compilerSwitch = util.switch()
vm.compileByParentNode(source.node, key, function (src)
if src.type == 'doc.type.field'
or src.type == 'doc.field' then
- nodeMgr.setNode(source, vm.compileNode(src))
+ vm.setNode(source, vm.compileNode(src))
end
end)
end)
@@ -809,10 +817,12 @@ local compilerSwitch = util.switch()
if type(key) == 'table' then
local uri = guide.getUri(source)
local value = vm.getTableValue(uri, vm.compileNode(source.node), key)
- nodeMgr.setNode(source, value)
+ if value then
+ vm.setNode(source, value)
+ end
else
vm.compileByParentNode(source.node, key, function (src)
- nodeMgr.setNode(source, vm.compileNode(src))
+ vm.setNode(source, vm.compileNode(src))
end)
end
end)
@@ -825,7 +835,7 @@ local compilerSwitch = util.switch()
vm.compileByParentNode(source.node, key, function (src)
if src.type == 'doc.type.field'
or src.type == 'doc.field' then
- nodeMgr.setNode(source, vm.compileNode(src))
+ vm.setNode(source, vm.compileNode(src))
end
end)
end)
@@ -836,7 +846,7 @@ local compilerSwitch = util.switch()
end
local key = guide.getKeyName(source)
vm.compileByParentNode(source.node, key, function (src)
- nodeMgr.setNode(source, vm.compileNode(src))
+ vm.setNode(source, vm.compileNode(src))
end)
end)
: case 'tablefield'
@@ -850,27 +860,27 @@ local compilerSwitch = util.switch()
if source.value then
if not hasMarkDoc or guide.isLiteral(source.value) then
if source.value and source.value.type == 'table' then
- nodeMgr.setNode(source, source.value)
+ vm.setNode(source, source.value)
else
- nodeMgr.setNode(source, vm.compileNode(source.value))
+ vm.setNode(source, vm.compileNode(source.value))
end
end
end
if not hasMarkDoc then
vm.compileByParentNode(source.parent, guide.getKeyName(source), function (src)
- nodeMgr.setNode(source, vm.compileNode(src))
+ vm.setNode(source, vm.compileNode(src))
end)
end
end)
: case 'field'
: case 'method'
: call(function (source)
- nodeMgr.setNode(source, vm.compileNode(source.parent))
+ vm.setNode(source, vm.compileNode(source.parent))
end)
: case 'tableexp'
: call(function (source)
- nodeMgr.setNode(source, vm.compileNode(source.value))
+ vm.setNode(source, vm.compileNode(source.value))
end)
: case 'function.return'
: call(function (source)
@@ -891,9 +901,9 @@ local compilerSwitch = util.switch()
end)
end
if hasGeneric then
- nodeMgr.setNode(source, genericMgr(rtn, sign))
+ vm.setNode(source, genericMgr(rtn, sign))
else
- nodeMgr.setNode(source, vm.compileNode(rtn))
+ vm.setNode(source, vm.compileNode(rtn))
end
end
end
@@ -910,7 +920,7 @@ local compilerSwitch = util.switch()
: call(function (source)
if source.returns then
for _, rtn in ipairs(source.returns) do
- nodeMgr.setNode(source, vm.compileNode(rtn[1]))
+ vm.setNode(source, vm.compileNode(rtn[1]))
end
end
end)
@@ -922,22 +932,22 @@ local compilerSwitch = util.switch()
if not node then
return
end
- for n in nodeMgr.eachObject(node) do
+ for n in node:eachObject() do
if n.type == 'global'
and n.cate == 'type'
and n.name == '...' then
return
end
end
- nodeMgr.setNode(source, node)
+ vm.setNode(source, node)
end
if vararg.type == 'varargs' then
- nodeMgr.setNode(source, vm.compileNode(vararg))
+ vm.setNode(source, vm.compileNode(vararg))
end
end)
: case 'varargs'
: call(function (source)
- nodeMgr.setNode(source, vm.compileNode(source.node))
+ vm.setNode(source, vm.compileNode(source.node))
end)
: case 'call'
: call(function (source)
@@ -945,14 +955,14 @@ local compilerSwitch = util.switch()
if not node then
return
end
- for n in nodeMgr.eachObject(node) do
+ for n in node:eachObject() do
if n.type == 'global'
and n.cate == 'type'
and n.name == '...' then
return
end
end
- nodeMgr.setNode(source, node)
+ vm.setNode(source, node)
end)
: case 'in'
: call(function (source)
@@ -972,31 +982,33 @@ local compilerSwitch = util.switch()
if source.keys then
for i, loc in ipairs(source.keys) do
local node = getReturn(source._iterator, i, source._iterArgs)
- nodeMgr.setNode(loc, node)
+ if node then
+ vm.setNode(loc, node)
+ end
end
end
end)
: case 'doc.type'
: call(function (source)
for _, typeUnit in ipairs(source.types) do
- nodeMgr.setNode(source, vm.compileNode(typeUnit))
+ vm.setNode(source, vm.compileNode(typeUnit))
end
end)
: case 'doc.type.integer'
: case 'doc.type.string'
: case 'doc.type.boolean'
: call(function (source)
- nodeMgr.setNode(source, source)
+ vm.setNode(source, source)
end)
: case 'doc.generic.name'
: call(function (source)
- nodeMgr.setNode(source, source)
+ vm.setNode(source, source)
end)
: case 'doc.type.name'
: call(function (source)
if source.signs then
local uri = guide.getUri(source)
- nodeMgr.setNode(source, source)
+ vm.setNode(source, source)
local global = globalMgr.getGlobal('type', source[1])
for _, set in ipairs(global:getSets(uri)) do
if set.type == 'doc.class' then
@@ -1005,7 +1017,7 @@ local compilerSwitch = util.switch()
if ext.type == 'doc.type.table' then
if ext._generic then
local resolved = ext._generic:resolve(uri, source.signs)
- nodeMgr.setNode(source, resolved)
+ vm.setNode(source, resolved)
end
end
end
@@ -1014,7 +1026,7 @@ local compilerSwitch = util.switch()
if set.type == 'doc.alias' then
if set.extends._generic then
local resolved = set.extends._generic:resolve(uri, source.signs)
- nodeMgr.setNode(source, resolved)
+ vm.setNode(source, resolved)
end
end
end
@@ -1022,23 +1034,23 @@ local compilerSwitch = util.switch()
end)
: case 'doc.class.name'
: call(function (source)
- nodeMgr.setNode(source, vm.compileNode(source.parent))
+ vm.setNode(source, vm.compileNode(source.parent))
end)
: case 'doc.field'
: call(function (source)
- nodeMgr.setNode(source, vm.compileNode(source.extends))
+ vm.setNode(source, vm.compileNode(source.extends))
end)
: case 'doc.type.field'
: call(function (source)
- nodeMgr.setNode(source, vm.compileNode(source.extends))
+ vm.setNode(source, vm.compileNode(source.extends))
end)
: case 'doc.param'
: call(function (source)
- nodeMgr.setNode(source, vm.compileNode(source.extends))
+ vm.setNode(source, vm.compileNode(source.extends))
end)
: case 'doc.vararg'
: call(function (source)
- nodeMgr.setNode(source, vm.compileNode(source.vararg))
+ vm.setNode(source, vm.compileNode(source.vararg))
end)
: case '...'
: call(function (source)
@@ -1051,45 +1063,45 @@ local compilerSwitch = util.switch()
end
for _, doc in ipairs(func.bindDocs) do
if doc.type == 'doc.vararg' then
- nodeMgr.setNode(source, vm.compileNode(doc))
+ vm.setNode(source, vm.compileNode(doc))
end
if doc.type == 'doc.param' and doc.param[1] == '...' then
- nodeMgr.setNode(source, vm.compileNode(doc))
+ vm.setNode(source, vm.compileNode(doc))
end
end
end)
: case 'doc.overload'
: call(function (source)
- nodeMgr.setNode(source, vm.compileNode(source.overload))
+ vm.setNode(source, vm.compileNode(source.overload))
end)
: case 'doc.see.name'
: call(function (source)
local type = globalMgr.getGlobal('type', source[1])
if type then
- nodeMgr.setNode(source, vm.compileNode(type))
+ vm.setNode(source, vm.compileNode(type))
end
end)
: case 'doc.type.arg'
: call(function (source)
if source.extends then
- nodeMgr.setNode(source, vm.compileNode(source.extends))
+ vm.setNode(source, vm.compileNode(source.extends))
else
- nodeMgr.setNode(source, globalMgr.getGlobal('type', 'any'))
+ vm.setNode(source, globalMgr.getGlobal('type', 'any'))
end
end)
: case 'generic'
: call(function (source)
- nodeMgr.setNode(source, source)
+ vm.setNode(source, source)
end)
: case 'unary'
: call(function (source)
if source.op.type == 'not' then
local result = vm.test(source[1])
if result == nil then
- nodeMgr.setNode(source, globalMgr.getGlobal('type', 'boolean'))
+ vm.setNode(source, globalMgr.getGlobal('type', 'boolean'))
return
else
- nodeMgr.setNode(source, {
+ vm.setNode(source, {
type = 'boolean',
start = source.start,
finish = source.finish,
@@ -1100,16 +1112,16 @@ local compilerSwitch = util.switch()
end
end
if source.op.type == '#' then
- nodeMgr.setNode(source, globalMgr.getGlobal('type', 'integer'))
+ vm.setNode(source, globalMgr.getGlobal('type', 'integer'))
return
end
if source.op.type == '-' then
local v = vm.getNumber(source[1])
if v == nil then
- nodeMgr.setNode(source, globalMgr.getGlobal('type', 'number'))
+ vm.setNode(source, globalMgr.getGlobal('type', 'number'))
return
else
- nodeMgr.setNode(source, {
+ vm.setNode(source, {
type = 'number',
start = source.start,
finish = source.finish,
@@ -1122,10 +1134,10 @@ local compilerSwitch = util.switch()
if source.op.type == '~' then
local v = vm.getInteger(source[1])
if v == nil then
- nodeMgr.setNode(source, globalMgr.getGlobal('type', 'integer'))
+ vm.setNode(source, globalMgr.getGlobal('type', 'integer'))
return
else
- nodeMgr.setNode(source, {
+ vm.setNode(source, {
type = 'integer',
start = source.start,
finish = source.finish,
@@ -1141,11 +1153,11 @@ local compilerSwitch = util.switch()
if source.op.type == 'and' then
local r1 = vm.test(source[1])
if r1 == true then
- nodeMgr.setNode(source, vm.compileNode(source[2]))
+ vm.setNode(source, vm.compileNode(source[2]))
return
end
if r1 == false then
- nodeMgr.setNode(source, vm.compileNode(source[1]))
+ vm.setNode(source, vm.compileNode(source[1]))
return
end
return
@@ -1153,11 +1165,11 @@ local compilerSwitch = util.switch()
if source.op.type == 'or' then
local r1 = vm.test(source[1])
if r1 == true then
- nodeMgr.setNode(source, vm.compileNode(source[1]))
+ vm.setNode(source, vm.compileNode(source[1]))
return
end
if r1 == false then
- nodeMgr.setNode(source, vm.compileNode(source[2]))
+ vm.setNode(source, vm.compileNode(source[2]))
return
end
return
@@ -1165,10 +1177,10 @@ local compilerSwitch = util.switch()
if source.op.type == '==' then
local result = vm.equal(source[1], source[2])
if result == nil then
- nodeMgr.setNode(source, globalMgr.getGlobal('type', 'boolean'))
+ vm.setNode(source, globalMgr.getGlobal('type', 'boolean'))
return
else
- nodeMgr.setNode(source, {
+ vm.setNode(source, {
type = 'boolean',
start = source.start,
finish = source.finish,
@@ -1181,10 +1193,10 @@ local compilerSwitch = util.switch()
if source.op.type == '~=' then
local result = vm.equal(source[1], source[2])
if result == nil then
- nodeMgr.setNode(source, globalMgr.getGlobal('type', 'boolean'))
+ vm.setNode(source, globalMgr.getGlobal('type', 'boolean'))
return
else
- nodeMgr.setNode(source, {
+ vm.setNode(source, {
type = 'boolean',
start = source.start,
finish = source.finish,
@@ -1198,7 +1210,7 @@ local compilerSwitch = util.switch()
local a = vm.getInteger(source[1])
local b = vm.getInteger(source[2])
if a and b then
- nodeMgr.setNode(source, {
+ vm.setNode(source, {
type = 'integer',
start = source.start,
finish = source.finish,
@@ -1207,7 +1219,7 @@ local compilerSwitch = util.switch()
})
return
else
- nodeMgr.setNode(source, globalMgr.getGlobal('type', 'integer'))
+ vm.setNode(source, globalMgr.getGlobal('type', 'integer'))
return
end
end
@@ -1215,7 +1227,7 @@ local compilerSwitch = util.switch()
local a = vm.getInteger(source[1])
local b = vm.getInteger(source[2])
if a and b then
- nodeMgr.setNode(source, {
+ vm.setNode(source, {
type = 'integer',
start = source.start,
finish = source.finish,
@@ -1224,7 +1236,7 @@ local compilerSwitch = util.switch()
})
return
else
- nodeMgr.setNode(source, globalMgr.getGlobal('type', 'integer'))
+ vm.setNode(source, globalMgr.getGlobal('type', 'integer'))
return
end
end
@@ -1232,7 +1244,7 @@ local compilerSwitch = util.switch()
local a = vm.getInteger(source[1])
local b = vm.getInteger(source[2])
if a and b then
- nodeMgr.setNode(source, {
+ vm.setNode(source, {
type = 'integer',
start = source.start,
finish = source.finish,
@@ -1241,7 +1253,7 @@ local compilerSwitch = util.switch()
})
return
else
- nodeMgr.setNode(source, globalMgr.getGlobal('type', 'integer'))
+ vm.setNode(source, globalMgr.getGlobal('type', 'integer'))
return
end
end
@@ -1249,7 +1261,7 @@ local compilerSwitch = util.switch()
local a = vm.getInteger(source[1])
local b = vm.getInteger(source[2])
if a and b then
- nodeMgr.setNode(source, {
+ vm.setNode(source, {
type = 'integer',
start = source.start,
finish = source.finish,
@@ -1258,7 +1270,7 @@ local compilerSwitch = util.switch()
})
return
else
- nodeMgr.setNode(source, globalMgr.getGlobal('type', 'integer'))
+ vm.setNode(source, globalMgr.getGlobal('type', 'integer'))
return
end
end
@@ -1266,7 +1278,7 @@ local compilerSwitch = util.switch()
local a = vm.getInteger(source[1])
local b = vm.getInteger(source[2])
if a and b then
- nodeMgr.setNode(source, {
+ vm.setNode(source, {
type = 'integer',
start = source.start,
finish = source.finish,
@@ -1275,7 +1287,7 @@ local compilerSwitch = util.switch()
})
return
else
- nodeMgr.setNode(source, globalMgr.getGlobal('type', 'integer'))
+ vm.setNode(source, globalMgr.getGlobal('type', 'integer'))
return
end
end
@@ -1284,7 +1296,7 @@ local compilerSwitch = util.switch()
local b = vm.getNumber(source[2])
if a and b then
local result = a + b
- nodeMgr.setNode(source, {
+ vm.setNode(source, {
type = math.type(result) == 'integer' and 'integer' or 'number',
start = source.start,
finish = source.finish,
@@ -1293,7 +1305,7 @@ local compilerSwitch = util.switch()
})
return
else
- nodeMgr.setNode(source, globalMgr.getGlobal('type', 'number'))
+ vm.setNode(source, globalMgr.getGlobal('type', 'number'))
return
end
end
@@ -1302,7 +1314,7 @@ local compilerSwitch = util.switch()
local b = vm.getNumber(source[2])
if a and b then
local result = a - b
- nodeMgr.setNode(source, {
+ vm.setNode(source, {
type = math.type(result) == 'integer' and 'integer' or 'number',
start = source.start,
finish = source.finish,
@@ -1311,7 +1323,7 @@ local compilerSwitch = util.switch()
})
return
else
- nodeMgr.setNode(source, globalMgr.getGlobal('type', 'number'))
+ vm.setNode(source, globalMgr.getGlobal('type', 'number'))
return
end
end
@@ -1320,7 +1332,7 @@ local compilerSwitch = util.switch()
local b = vm.getNumber(source[2])
if a and b then
local result = a * b
- nodeMgr.setNode(source, {
+ vm.setNode(source, {
type = math.type(result) == 'integer' and 'integer' or 'number',
start = source.start,
finish = source.finish,
@@ -1329,7 +1341,7 @@ local compilerSwitch = util.switch()
})
return
else
- nodeMgr.setNode(source, globalMgr.getGlobal('type', 'number'))
+ vm.setNode(source, globalMgr.getGlobal('type', 'number'))
return
end
end
@@ -1337,7 +1349,7 @@ local compilerSwitch = util.switch()
local a = vm.getNumber(source[1])
local b = vm.getNumber(source[2])
if a and b then
- nodeMgr.setNode(source, {
+ vm.setNode(source, {
type = 'number',
start = source.start,
finish = source.finish,
@@ -1346,7 +1358,7 @@ local compilerSwitch = util.switch()
})
return
else
- nodeMgr.setNode(source, globalMgr.getGlobal('type', 'number'))
+ vm.setNode(source, globalMgr.getGlobal('type', 'number'))
return
end
end
@@ -1355,7 +1367,7 @@ local compilerSwitch = util.switch()
local b = vm.getNumber(source[2])
if a and b then
local result = a % b
- nodeMgr.setNode(source, {
+ vm.setNode(source, {
type = math.type(result) == 'integer' and 'integer' or 'number',
start = source.start,
finish = source.finish,
@@ -1364,7 +1376,7 @@ local compilerSwitch = util.switch()
})
return
else
- nodeMgr.setNode(source, globalMgr.getGlobal('type', 'number'))
+ vm.setNode(source, globalMgr.getGlobal('type', 'number'))
return
end
end
@@ -1372,7 +1384,7 @@ local compilerSwitch = util.switch()
local a = vm.getNumber(source[1])
local b = vm.getNumber(source[2])
if a and b then
- nodeMgr.setNode(source, {
+ vm.setNode(source, {
type = 'number',
start = source.start,
finish = source.finish,
@@ -1381,7 +1393,7 @@ local compilerSwitch = util.switch()
})
return
else
- nodeMgr.setNode(source, globalMgr.getGlobal('type', 'number'))
+ vm.setNode(source, globalMgr.getGlobal('type', 'number'))
return
end
end
@@ -1390,7 +1402,7 @@ local compilerSwitch = util.switch()
local b = vm.getNumber(source[2])
if a and b and b ~= 0 then
local result = a // b
- nodeMgr.setNode(source, {
+ vm.setNode(source, {
type = math.type(result) == 'integer' and 'integer' or 'number',
start = source.start,
finish = source.finish,
@@ -1399,7 +1411,7 @@ local compilerSwitch = util.switch()
})
return
else
- nodeMgr.setNode(source, globalMgr.getGlobal('type', 'number'))
+ vm.setNode(source, globalMgr.getGlobal('type', 'number'))
return
end
end
@@ -1427,7 +1439,7 @@ local compilerSwitch = util.switch()
end
end
end
- nodeMgr.setNode(source, {
+ vm.setNode(source, {
type = 'string',
start = source.start,
finish = source.finish,
@@ -1436,7 +1448,7 @@ local compilerSwitch = util.switch()
})
return
else
- nodeMgr.setNode(source, globalMgr.getGlobal('type', 'string'))
+ vm.setNode(source, globalMgr.getGlobal('type', 'string'))
return
end
end
@@ -1451,13 +1463,13 @@ end
local function compileByGlobal(uri, source)
uri = uri or guide.getUri(source)
if source.type == 'global' then
- nodeMgr.setNode(source, source)
+ vm.setNode(source, source)
if source.cate == 'variable' then
local hasMarkDoc
for _, set in ipairs(source:getSets(uri)) do
if set.bindDocs then
if bindDocs(set) then
- nodeMgr.setNode(source, vm.compileNode(set))
+ vm.setNode(source, vm.compileNode(set))
hasMarkDoc = true
end
end
@@ -1465,7 +1477,7 @@ local function compileByGlobal(uri, source)
for _, set in ipairs(source:getSets(uri)) do
if set.value then
if not hasMarkDoc or guide.isLiteral(set.value) then
- nodeMgr.setNode(source, vm.compileNode(set.value))
+ vm.setNode(source, vm.compileNode(set.value))
end
end
end
@@ -1477,7 +1489,7 @@ local function compileByGlobal(uri, source)
for _, ext in ipairs(set.extends) do
if ext.type == 'doc.type.table' then
if not ext._generic then
- nodeMgr.setNode(source, vm.compileNode(ext))
+ vm.setNode(source, vm.compileNode(ext))
end
end
end
@@ -1485,7 +1497,7 @@ local function compileByGlobal(uri, source)
end
if set.type == 'doc.alias' then
if not set.extends._generic then
- nodeMgr.setNode(source, vm.compileNode(set.extends))
+ vm.setNode(source, vm.compileNode(set.extends))
end
end
end
@@ -1493,7 +1505,7 @@ local function compileByGlobal(uri, source)
return
end
if source._globalNode then
- nodeMgr.setNode(source, vm.compileNode(source._globalNode, uri))
+ vm.setNode(source, vm.compileNode(source._globalNode, uri))
return
end
end
@@ -1509,7 +1521,9 @@ function vm.resumeCache()
pauseCacheCount = pauseCacheCount - 1
if pauseCacheCount == 0 then
for source in pairs(originCacheKeys) do
- nodeMgr.nodeCache[source] = originCacheValues[source]
+ if originCacheValues[source] then
+ vm.setNode(source, originCacheValues[source], true)
+ end
originCacheKeys[source] = nil
originCacheValues[source] = nil
end
@@ -1521,23 +1535,22 @@ end
---@return vm.node
function vm.compileNode(source, uri)
if not source then
- return false
+ error('Can not compile nil node')
end
- if nodeMgr.nodeCache[source] ~= nil then
- return nodeMgr.nodeCache[source]
+ local cache = vm.getNode(source)
+ if cache ~= nil then
+ return cache
end
local pauseCache = pauseCacheCount > 0
if pauseCache and not originCacheKeys[source] then
originCacheKeys[source] = true
- originCacheValues[source] = nodeMgr.nodeCache[source]
+ originCacheValues[source] = cache
end
- nodeMgr.nodeCache[source] = false
+ vm.setNode(source, vm.createNode(), true)
compileByGlobal(uri, source)
compileByNode(source)
- --localMgr.subscribeLocal(source, source._node)
-
- return nodeMgr.nodeCache[source]
+ return vm.getNode(source)
end