summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--script/vm/compiler.lua19
-rw-r--r--script/vm/def.lua5
-rw-r--r--script/vm/field.lua3
-rw-r--r--script/vm/generic.lua3
-rw-r--r--script/vm/global.lua17
-rw-r--r--script/vm/init.lua3
-rw-r--r--script/vm/local-id.lua42
-rw-r--r--script/vm/ref.lua3
-rw-r--r--script/vm/sign.lua3
9 files changed, 46 insertions, 52 deletions
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua
index cb18557b..2b63e868 100644
--- a/script/vm/compiler.lua
+++ b/script/vm/compiler.lua
@@ -1,9 +1,6 @@
local guide = require 'parser.guide'
local util = require 'utility'
-local localID = require 'vm.local-id'
-local signMgr = require 'vm.sign'
local config = require 'config'
-local genericMgr = require 'vm.generic'
local rpath = require 'workspace.require-path'
local files = require 'files'
---@class vm
@@ -62,9 +59,9 @@ local searchFieldSwitch = util.switch()
: call(function (suri, node, key, ref, pushResult)
local fields
if key then
- fields = localID.getSources(node, key)
+ fields = vm.getLocalSources(node, key)
else
- fields = localID.getFields(node)
+ fields = vm.getLocalFields(node)
end
if fields then
for _, src in ipairs(fields) do
@@ -331,7 +328,7 @@ local function getObjectSign(source)
for _, doc in ipairs(source.bindDocs) do
if doc.type == 'doc.generic' then
if not source._sign then
- source._sign = signMgr()
+ source._sign = vm.createSign()
break
end
end
@@ -359,7 +356,7 @@ local function getObjectSign(source)
if not hasGeneric then
return false
end
- source._sign = signMgr()
+ source._sign = vm.createSign()
if source.type == 'doc.type.function' then
for _, arg in ipairs(source.args) do
if arg.extends then
@@ -403,7 +400,7 @@ function vm.getReturnOfFunction(func, index)
if not sign then
return rtn
end
- return genericMgr(rtn, sign)
+ return vm.createGeneric(rtn, sign)
end
end
@@ -583,7 +580,7 @@ local function bindDocs(source)
end
local function compileByLocalID(source)
- local sources = localID.getSources(source)
+ local sources = vm.getLocalSources(source)
if not sources then
return
end
@@ -746,7 +743,7 @@ local function compileCallArgNode(arg, call, callNode, fixIndex, myIndex)
if isValidCallArgNode(arg, fn) then
if fn.type == 'doc.type.function' then
if sign then
- local generic = genericMgr(fn, sign)
+ local generic = vm.createGeneric(fn, sign)
local args = {}
for i = fixIndex + 1, myIndex - 1 do
args[#args+1] = call.args[i]
@@ -1151,7 +1148,7 @@ local compilerSwitch = util.switch()
end)
end
if hasGeneric then
- vm.setNode(source, genericMgr(rtn, sign))
+ vm.setNode(source, vm.createGeneric(rtn, sign))
else
vm.setNode(source, vm.compileNode(rtn))
end
diff --git a/script/vm/def.lua b/script/vm/def.lua
index 60dcf03c..83e92686 100644
--- a/script/vm/def.lua
+++ b/script/vm/def.lua
@@ -2,7 +2,6 @@
local vm = require 'vm.vm'
local util = require 'utility'
local guide = require 'parser.guide'
-local localID = require 'vm.local-id'
local simpleSwitch
@@ -116,7 +115,7 @@ local searchFieldSwitch = util.switch()
end)
: case 'local'
: call(function (suri, obj, key, pushResult)
- local sources = localID.getSources(obj, key)
+ local sources = vm.getLocalSources(obj, key)
if sources then
for _, src in ipairs(sources) do
if guide.isSet(src) then
@@ -195,7 +194,7 @@ end
---@param source parser.object
---@param pushResult fun(src: parser.object)
local function searchByLocalID(source, pushResult)
- local idSources = localID.getSources(source)
+ local idSources = vm.getLocalSources(source)
if not idSources then
return
end
diff --git a/script/vm/field.lua b/script/vm/field.lua
index 614dc89b..5de838be 100644
--- a/script/vm/field.lua
+++ b/script/vm/field.lua
@@ -2,7 +2,6 @@
local vm = require 'vm.vm'
local util = require 'utility'
local guide = require 'parser.guide'
-local localID = require 'vm.local-id'
local searchByNodeSwitch = util.switch()
: case 'global'
@@ -17,7 +16,7 @@ local searchByNodeSwitch = util.switch()
end)
local function searchByLocalID(source, pushResult)
- local fields = localID.getFields(source)
+ local fields = vm.getLocalFields(source)
if fields then
for _, field in ipairs(fields) do
pushResult(field)
diff --git a/script/vm/generic.lua b/script/vm/generic.lua
index b58c7bce..6462028e 100644
--- a/script/vm/generic.lua
+++ b/script/vm/generic.lua
@@ -1,3 +1,4 @@
+---@class vm
local vm = require 'vm.vm'
---@class parser.object
@@ -129,7 +130,7 @@ end
---@param proto vm.object
---@param sign vm.sign
---@return vm.generic
-return function (proto, sign)
+function vm.createGeneric(proto, sign)
local generic = setmetatable({
sign = sign,
proto = proto,
diff --git a/script/vm/global.lua b/script/vm/global.lua
index eea398dc..a54ab552 100644
--- a/script/vm/global.lua
+++ b/script/vm/global.lua
@@ -2,9 +2,6 @@ local util = require 'utility'
local scope = require 'workspace.scope'
local guide = require 'parser.guide'
local files = require 'files'
-local signMgr = require 'vm.sign'
-local genericMgr = require 'vm.generic'
-local localID = require 'vm.local-id'
---@class vm
local vm = require 'vm.vm'
@@ -279,14 +276,14 @@ local compilerGlobalSwitch = util.switch()
source._globalNode = class
if source.signs then
- source._sign = signMgr()
+ source._sign = vm.createSign()
for _, sign in ipairs(source.signs) do
source._sign:addSign(vm.compileNode(sign))
end
if source.extends then
for _, ext in ipairs(source.extends) do
if ext.type == 'doc.type.table' then
- ext._generic = genericMgr(ext, source._sign)
+ ext._generic = vm.createGeneric(ext, source._sign)
end
end
end
@@ -301,11 +298,11 @@ local compilerGlobalSwitch = util.switch()
source._globalNode = alias
if source.signs then
- source._sign = signMgr()
+ source._sign = vm.createSign()
for _, sign in ipairs(source.signs) do
source._sign:addSign(vm.compileNode(sign))
end
- source.extends._generic = genericMgr(source.extends, source._sign)
+ source.extends._generic = vm.createGeneric(source.extends, source._sign)
end
end)
: case 'doc.type.name'
@@ -449,11 +446,11 @@ local function compileSelf(source)
if not node then
return
end
- local fields = localID.getFields(source)
+ local fields = vm.getLocalFields(source)
if not fields then
return
end
- local nodeLocalID = localID.getID(node)
+ local nodeLocalID = vm.getLocalID(node)
local globalNode = node._globalNode
if not nodeLocalID and not globalNode then
return
@@ -464,7 +461,7 @@ local function compileSelf(source)
if key then
if nodeLocalID then
local myID = nodeLocalID .. vm.ID_SPLITE .. key
- localID.insertLocalID(myID, field)
+ vm.insertLocalID(myID, field)
end
if globalNode then
local myID = globalNode:getName() .. vm.ID_SPLITE .. key
diff --git a/script/vm/init.lua b/script/vm/init.lua
index 23dd0d54..f5003c11 100644
--- a/script/vm/init.lua
+++ b/script/vm/init.lua
@@ -13,5 +13,8 @@ require 'vm.type'
require 'vm.library'
require 'vm.runner'
require 'vm.infer'
+require 'vm.generic'
+require 'vm.sign'
+require 'vm.local-id'
require 'vm.global'
return vm
diff --git a/script/vm/local-id.lua b/script/vm/local-id.lua
index 75251095..80c68769 100644
--- a/script/vm/local-id.lua
+++ b/script/vm/local-id.lua
@@ -1,13 +1,13 @@
local util = require 'utility'
local guide = require 'parser.guide'
+---@class vm
local vm = require 'vm.vm'
---@class parser.object
---@field _localID string
---@field _localIDs table<string, parser.object[]>
----@class vm.local-id
-local m = {}
+local compileLocalID, getLocal
local compileSwitch = util.switch()
: case 'local'
@@ -18,13 +18,13 @@ local compileSwitch = util.switch()
return
end
for _, ref in ipairs(source.ref) do
- m.compileLocalID(ref)
+ compileLocalID(ref)
end
end)
: case 'getlocal'
: call(function (source)
source._localID = ('%d'):format(source.node.start)
- m.compileLocalID(source.next)
+ compileLocalID(source.next)
end)
: case 'getfield'
: case 'setfield'
@@ -40,7 +40,7 @@ local compileSwitch = util.switch()
source._localID = parentID .. vm.ID_SPLITE .. key
source.field._localID = source._localID
if source.type == 'getfield' then
- m.compileLocalID(source.next)
+ compileLocalID(source.next)
end
end)
: case 'getmethod'
@@ -57,7 +57,7 @@ local compileSwitch = util.switch()
source._localID = parentID .. vm.ID_SPLITE .. key
source.method._localID = source._localID
if source.type == 'getmethod' then
- m.compileLocalID(source.next)
+ compileLocalID(source.next)
end
end)
: case 'getindex'
@@ -74,7 +74,7 @@ local compileSwitch = util.switch()
source._localID = parentID .. vm.ID_SPLITE .. key
source.index._localID = source._localID
if source.type == 'setindex' then
- m.compileLocalID(source.next)
+ compileLocalID(source.next)
end
end)
@@ -82,7 +82,7 @@ local leftSwitch = util.switch()
: case 'field'
: case 'method'
: call(function (source)
- return m.getLocal(source.parent)
+ return getLocal(source.parent)
end)
: case 'getfield'
: case 'setfield'
@@ -91,7 +91,7 @@ local leftSwitch = util.switch()
: case 'getindex'
: case 'setindex'
: call(function (source)
- return m.getLocal(source.node)
+ return getLocal(source.node)
end)
: case 'getlocal'
: call(function (source)
@@ -105,13 +105,13 @@ local leftSwitch = util.switch()
---@param source parser.object
---@return parser.object?
-function m.getLocal(source)
+function getLocal(source)
return leftSwitch(source.type, source)
end
---@param id string
---@param source parser.object
-function m.insertLocalID(id, source)
+function vm.insertLocalID(id, source)
local root = guide.getRoot(source)
if not root._localIDs then
root._localIDs = util.multiTable(2)
@@ -120,7 +120,7 @@ function m.insertLocalID(id, source)
sources[#sources+1] = source
end
-function m.compileLocalID(source)
+function compileLocalID(source)
if not source then
return
end
@@ -133,29 +133,29 @@ function m.compileLocalID(source)
if not id then
return
end
- m.insertLocalID(id, source)
+ vm.insertLocalID(id, source)
end
---@param source parser.object
---@return string?
-function m.getID(source)
+function vm.getLocalID(source)
if source._localID ~= nil then
return source._localID
end
source._localID = false
- local loc = m.getLocal(source)
+ local loc = getLocal(source)
if not loc then
return source._localID
end
- m.compileLocalID(loc)
+ compileLocalID(loc)
return source._localID
end
---@param source parser.object
---@param key? string
---@return parser.object[]?
-function m.getSources(source, key)
- local id = m.getID(source)
+function vm.getLocalSources(source, key)
+ local id = vm.getLocalID(source)
if not id then
return nil
end
@@ -174,8 +174,8 @@ end
---@param source parser.object
---@return parser.object[]
-function m.getFields(source)
- local id = m.getID(source)
+function vm.getLocalFields(source)
+ local id = vm.getLocalID(source)
if not id then
return nil
end
@@ -203,5 +203,3 @@ function m.getFields(source)
end
return fields
end
-
-return m
diff --git a/script/vm/ref.lua b/script/vm/ref.lua
index 714d3ccd..545c294a 100644
--- a/script/vm/ref.lua
+++ b/script/vm/ref.lua
@@ -2,7 +2,6 @@
local vm = require 'vm.vm'
local util = require 'utility'
local guide = require 'parser.guide'
-local localID = require 'vm.local-id'
local files = require 'files'
local await = require 'await'
local progress = require 'progress'
@@ -241,7 +240,7 @@ end
---@param source parser.object
---@param pushResult fun(src: parser.object)
local function searchByLocalID(source, pushResult)
- local idSources = localID.getSources(source)
+ local idSources = vm.getLocalSources(source)
if not idSources then
return
end
diff --git a/script/vm/sign.lua b/script/vm/sign.lua
index c19f72d4..fe112bc2 100644
--- a/script/vm/sign.lua
+++ b/script/vm/sign.lua
@@ -1,4 +1,5 @@
local guide = require 'parser.guide'
+---@class vm
local vm = require 'vm.vm'
---@class vm.sign
@@ -168,7 +169,7 @@ function mt:resolve(uri, args, removeGeneric)
end
---@return vm.sign
-return function ()
+function vm.createSign()
local genericMgr = setmetatable({
signList = {},
}, mt)