summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-05-11 11:32:35 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-05-11 11:32:35 +0800
commit344309db423700e1c7afd28c0383cc8042aae0ca (patch)
tree179cb2cca2658e92b4612cc9f5b8f4c03b3ce126 /script
parentacca4a929950cca9a92541733abc4662dc8a3e55 (diff)
downloadlua-language-server-344309db423700e1c7afd28c0383cc8042aae0ca.zip
stash
Diffstat (limited to 'script')
-rw-r--r--script/core/generic.lua52
-rw-r--r--script/core/linker.lua5
-rw-r--r--script/parser/guide.lua48
3 files changed, 59 insertions, 46 deletions
diff --git a/script/core/generic.lua b/script/core/generic.lua
new file mode 100644
index 00000000..4246f8bd
--- /dev/null
+++ b/script/core/generic.lua
@@ -0,0 +1,52 @@
+local util = require 'utility'
+
+local counter = util.counter()
+
+---@class generic.value
+---@field type string
+---@field closure generic.closure
+---@field types parser.guide.object[]|generic.value[]
+
+---递归实例化对象
+---@param obj parser.guide.object
+---@param callback fun(docName: parser.guide.object)
+local function instantValue(obj, callback)
+end
+
+---@class generic.closure
+---@field type string
+---@field proto parser.guide.object
+---@field upvalues table<string, generic.value[]>
+---@field params generic.value[]
+---@field returns generic.value[]
+
+local m = {}
+
+---给闭包设置调用信息
+---@param closure generic.closure
+---@param params parser.guide.object[]
+function m.setCallParams(closure, params)
+ -- 立刻解决所有的泛型
+ -- 对每个参数进行核对,存入泛型表
+ -- 为所有的 param 与 return 创建副本
+ -- 如果return中有function,也要递归创建闭包
+end
+
+---创建一个闭包
+---@param protoFunction parser.guide.object # 原型函数
+---@param parentClosure? generic.closure
+---@return generic.closure
+function m.createClosure(protoFunction, parentClosure)
+ ---@type generic.closure
+ local closure = {
+ type = 'generic.closure',
+ id = counter(),
+ proto = protoFunction,
+ upvalues = {},
+ params = {},
+ returns = {},
+ }
+ return closure
+end
+
+return m
diff --git a/script/core/linker.lua b/script/core/linker.lua
index 9644f36e..f351a4f0 100644
--- a/script/core/linker.lua
+++ b/script/core/linker.lua
@@ -1,5 +1,6 @@
-local util = require 'utility'
-local guide = require 'parser.guide'
+local util = require 'utility'
+local guide = require 'parser.guide'
+local generic = require 'core.generic'
local Linkers
local LastIDCache = {}
diff --git a/script/parser/guide.lua b/script/parser/guide.lua
index f07a966e..048a15bb 100644
--- a/script/parser/guide.lua
+++ b/script/parser/guide.lua
@@ -1,34 +1,8 @@
-local util = require 'utility'
local error = error
local type = type
-local next = next
-local tostring = tostring
-local print = print
-local ipairs = ipairs
-local tableInsert = table.insert
-local tableUnpack = table.unpack
-local tableRemove = table.remove
-local tableMove = table.move
-local tableSort = table.sort
-local tableConcat = table.concat
-local mathType = math.type
-local pairs = pairs
-local setmetatable = setmetatable
-local assert = assert
-local select = select
-local osClock = os.clock
-local tonumber = tonumber
-local tointeger = math.tointeger
-local DEVELOP = _G.DEVELOP
-local log = log
-local _G = _G
---@class parser.guide.object
-local function logWarn(...)
- log.warn(...)
-end
-
---@class guide
---@field debugMode boolean
local m = {}
@@ -123,20 +97,6 @@ m.actionMap = {
['funcargs'] = {'#'},
}
-local TypeSort = {
- ['boolean'] = 1,
- ['string'] = 2,
- ['integer'] = 3,
- ['number'] = 4,
- ['table'] = 5,
- ['function'] = 6,
- ['true'] = 101,
- ['false'] = 102,
- ['nil'] = 999,
-}
-
-local NIL = setmetatable({'<nil>'}, { __tostring = function () return 'nil' end })
-
--- 是否是字面量
---@param obj parser.guide.object
---@return boolean
@@ -510,8 +470,8 @@ function m.addChilds(list, obj, map)
for i = 1, #keys do
local key = keys[i]
if key == '#' then
- for i = 1, #obj do
- list[#list+1] = obj[i]
+ for j = 1, #obj do
+ list[#list+1] = obj[j]
end
elseif obj[key] then
list[#list+1] = obj[key]
@@ -519,8 +479,8 @@ function m.addChilds(list, obj, map)
and key:sub(1, 1) == '#' then
key = key:sub(2)
if obj[key] then
- for i = 1, #obj[key] do
- list[#list+1] = obj[key][i]
+ for j = 1, #obj[key] do
+ list[#list+1] = obj[key][j]
end
end
end