diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-03-13 18:03:24 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-03-13 18:03:24 +0800 |
commit | 2614c2f6e6a53e4142fe57a184fd7bead11a5f4f (patch) | |
tree | 17bd6669b19ac260bed90a9dfea241e4117074ff /server | |
parent | 628a272b7babbeab995cf582ff4337b897ac09e6 (diff) | |
download | lua-language-server-2614c2f6e6a53e4142fe57a184fd7bead11a5f4f.zip |
解除所有的source循环引用
Diffstat (limited to 'server')
-rw-r--r-- | server/src/core/definition.lua | 10 | ||||
-rw-r--r-- | server/src/core/diagnostics.lua | 6 | ||||
-rw-r--r-- | server/src/core/document_symbol.lua | 4 | ||||
-rw-r--r-- | server/src/core/hover/function.lua | 2 | ||||
-rw-r--r-- | server/src/core/hover/name.lua | 4 | ||||
-rw-r--r-- | server/src/core/references.lua | 8 | ||||
-rw-r--r-- | server/src/core/rename.lua | 12 | ||||
-rw-r--r-- | server/src/vm/function.lua | 45 | ||||
-rw-r--r-- | server/src/vm/global.lua | 3 | ||||
-rw-r--r-- | server/src/vm/label.lua | 78 | ||||
-rw-r--r-- | server/src/vm/library.lua | 18 | ||||
-rw-r--r-- | server/src/vm/local.lua | 80 | ||||
-rw-r--r-- | server/src/vm/multi.lua | 7 | ||||
-rw-r--r-- | server/src/vm/source.lua | 13 | ||||
-rw-r--r-- | server/src/vm/value.lua | 22 | ||||
-rw-r--r-- | server/src/vm/vm.lua | 72 |
16 files changed, 261 insertions, 123 deletions
diff --git a/server/src/core/definition.lua b/server/src/core/definition.lua index b7aadb44..27c6f8eb 100644 --- a/server/src/core/definition.lua +++ b/server/src/core/definition.lua @@ -100,8 +100,8 @@ local function parseLocal(vm, source, lsp) end local positions = {} positions[#positions+1] = { - loc.source.start, - loc.source.finish, + loc:getSource().start, + loc:getSource().finish, } if #positions == 0 then return nil @@ -131,11 +131,11 @@ end local function parseLabel(vm, label, lsp) local positions = {} - label:eachInfo(function (info) + label:eachInfo(function (info, src) if info.type == 'set' then positions[#positions+1] = { - info.source.start, - info.source.finish, + src.start, + src.finish, } end end) diff --git a/server/src/core/diagnostics.lua b/server/src/core/diagnostics.lua index 848a9fb7..24f7132d 100644 --- a/server/src/core/diagnostics.lua +++ b/server/src/core/diagnostics.lua @@ -166,13 +166,13 @@ function mt:searchRedefinition(callback) local related = {} for i = 1, #shadow do related[i] = { - start = shadow[i].source.start, - finish = shadow[i].source.finish, + start = shadow[i]:getSource().start, + finish = shadow[i]:getSource().finish, uri = uri, } end for i = 2, #shadow do - callback(shadow[i].source.start, shadow[i].source.finish, name, related) + callback(shadow[i]:getSource().start, shadow[i]:getSource().finish, name, related) end end) end diff --git a/server/src/core/document_symbol.lua b/server/src/core/document_symbol.lua index 8225fdb9..7411b079 100644 --- a/server/src/core/document_symbol.lua +++ b/server/src/core/document_symbol.lua @@ -64,7 +64,7 @@ local function buildLocal(vm, source, callback) else kind = SymbolKind.Variable end - local valueSource = value.source + local valueSource = value:getSource() if valueSource.start == 0 or value.uri ~= vm.uri then valueSource = source end @@ -118,7 +118,7 @@ local function buildSet(vm, source, callback) else kind = SymbolKind.Property end - local valueSource = value.source + local valueSource = value:getSource() if valueSource.start == 0 or value.uri ~= vm.uri then valueSource = source end diff --git a/server/src/core/hover/function.lua b/server/src/core/hover/function.lua index 9bb532ae..aa6816b5 100644 --- a/server/src/core/hover/function.lua +++ b/server/src/core/hover/function.lua @@ -20,7 +20,7 @@ local function buildValueArgs(func, object, select) start = 2 end local max - if func.source then + if func:getSource() then max = #names else max = math.max(#names, #values) diff --git a/server/src/core/hover/name.lua b/server/src/core/hover/name.lua index b363f653..52bcfef4 100644 --- a/server/src/core/hover/name.lua +++ b/server/src/core/hover/name.lua @@ -5,8 +5,8 @@ return function (source) end local func = value:getFunction() local declarat - if func and func.source then - declarat = func.source.name + if func and func:getSource() then + declarat = func:getSource().name else declarat = source end diff --git a/server/src/core/references.lua b/server/src/core/references.lua index 0f9c73ab..755612b5 100644 --- a/server/src/core/references.lua +++ b/server/src/core/references.lua @@ -2,18 +2,18 @@ local findSource = require 'core.find_source' local function parseResult(vm, source, declarat, callback) if source:bindLabel() then - source:bindLabel():eachInfo(function (info) + source:bindLabel():eachInfo(function (info, src) if declarat or info.type == 'get' then - callback(info.source) + callback(src) end end) return end if source:bindLocal() then local loc = source:bindLocal() - loc:eachInfo(function (info) + loc:eachInfo(function (info, src) if declarat or info.type == 'get' then - callback(info.source) + callback(src) end end) loc:getValue():eachInfo(function (info, src) diff --git a/server/src/core/rename.lua b/server/src/core/rename.lua index 4e8e574b..b9f692d6 100644 --- a/server/src/core/rename.lua +++ b/server/src/core/rename.lua @@ -7,8 +7,8 @@ local function parseResult(source, newName) if not parser.grammar(newName, 'Name') then return nil end - source:bindLabel():eachInfo(function (info) - positions[#positions+1] = {info.source.start, info.source.finish} + source:bindLabel():eachInfo(function (info, src) + positions[#positions+1] = { src.start, src.finish } end) return positions end @@ -27,10 +27,10 @@ local function parseResult(source, newName) end end local mark = {} - loc:eachInfo(function (info) - if not mark[info.source] then - mark[info.source] = info - positions[#positions+1] = {info.source.start, info.source.finish} + loc:eachInfo(function (info, src) + if not mark[src] then + mark[src] = info + positions[#positions+1] = { src.start, src.finish } end end) return positions diff --git a/server/src/vm/function.lua b/server/src/vm/function.lua index e246509d..72cbd410 100644 --- a/server/src/vm/function.lua +++ b/server/src/vm/function.lua @@ -1,6 +1,7 @@ local createMulti = require 'vm.multi' local createValue = require 'vm.value' local createLocal = require 'vm.local' +local sourceMgr = require 'vm.source' local mt = {} mt.__index = mt @@ -8,21 +9,26 @@ mt.type = 'function' mt._runed = 0 mt._top = 0 +function mt:getSource() + return sourceMgr.list[self.source] +end + function mt:getUri() - return self.source.uri + local source = self:getSource() + return source and source.uri or '' end function mt:push(source) self._top = self._top + 1 self.locals[self._top] = {} - self.blocks[self._top] = source + self.finishs[self._top] = source and source.finish or math.maxinteger end function mt:pop() - local closedBlock = self.blocks[self._top] + local closed = self.finishs[self._top] local closedLocals = self.locals[self._top] for _, loc in pairs(closedLocals) do - loc:close(closedBlock.finish) + loc:close(closed) end self._top = self._top - 1 end @@ -93,19 +99,19 @@ function mt:setReturn(index, value) if value then self.returns[index] = value else - self.returns[index] = createValue('any', self.source) + self.returns[index] = createValue('any', self:getSource() or sourceMgr.dummy()) end end function mt:getReturn(index) if self.maxReturns and index and self.maxReturns < index then - return createValue('nil') + return createValue('nil', sourceMgr.dummy()) end if not self.returns then self.returns = createMulti() end if index then - return self.returns:get(index) or createValue('nil') + return self.returns:get(index) or createValue('nil', sourceMgr.dummy()) else return self.returns end @@ -144,7 +150,7 @@ end function mt:run(vm) self._runed = self._runed + 1 - if not self.source then + if not self:getSource() then return end @@ -168,7 +174,7 @@ function mt:run(vm) -- 向局部变量中填充参数 for i, loc in ipairs(self.args) do - loc:setValue(self.argValues[i] or createValue('nil', arg)) + loc:setValue(self.argValues[i] or createValue('nil', sourceMgr.dummy())) end if self._dots then self._dots = createMulti() @@ -204,7 +210,7 @@ function mt:createLibArg(arg) self._dots = createMulti() else local name = arg.name or '_' - local loc = createLocal(name, nil, createValue('any')) + local loc = createLocal(name, sourceMgr.dummy(), createValue('any', sourceMgr.dummy())) self:saveLocal(name, loc) self.args[#self.args+1] = loc end @@ -215,10 +221,10 @@ function mt:hasDots() end function mt:createArgs(vm) - if not self.source then + if not self:getSource() then return end - local args = self.source.arg + local args = self:getSource().arg if not args then return end @@ -245,11 +251,22 @@ function mt:get(name) return self._flag[name] end +function mt:getSource() + return sourceMgr.list[self.source] +end + return function (source) + local id + if source then + id = source.id + if not id then + error('Not instanted source') + end + end local self = setmetatable({ - source = source, + source = id, locals = {}, - blocks = {}, + finishs = {}, args = {}, argValues = {}, }, mt) diff --git a/server/src/vm/global.lua b/server/src/vm/global.lua index ba5da73a..bb506ce9 100644 --- a/server/src/vm/global.lua +++ b/server/src/vm/global.lua @@ -1,11 +1,12 @@ local createValue = require 'vm.value' local library = require 'core.library' local libraryBuilder = require 'vm.library' +local sourceMgr = require 'vm.source' return function (lsp) local global = lsp and lsp.globalValue if not global then - global = createValue('table') + global = createValue('table', sourceMgr.dummy()) for name, lib in pairs(library.global) do if not global:rawGet(name) then local value = libraryBuilder.value(lib) diff --git a/server/src/vm/label.lua b/server/src/vm/label.lua index b82e98e8..cf24ce5d 100644 --- a/server/src/vm/label.lua +++ b/server/src/vm/label.lua @@ -1,32 +1,70 @@ -local function getDefaultSource() - return { - start = 0, - finish = 0, - uri = '', - } -end +local sourceMgr = require 'vm.source' + +local Sort = 0 local mt = {} mt.__index = mt mt.type = 'label' +mt._infoCount = 0 +mt._infoLimit = 10 function mt:getName() return self.name end function mt:addInfo(tp, source) - if source and not source.start then - error('Miss start: ' .. table.dump(source)) + if not source then + error('No source') + end + local id = source.id + if not id then + error('Not instanted source') end - self[#self+1] = { + if self._info[id] then + return + end + Sort = Sort + 1 + local info = { type = tp, - source = source or getDefaultSource(), + source = id, + _sort = Sort, } + + self._info[id] = info + self._infoCount = self._infoCount + 1 + + if self._infoCount > self._infoLimit then + for srcId in pairs(self._info) do + local src = sourceMgr.list[srcId] + if not src then + self._info[srcId] = nil + self._infoCount = self._infoCount - 1 + end + end + self._infoLimit = self._infoCount * 2 + if self._infoLimit < 10 then + self._infoLimit = 10 + end + end end function mt:eachInfo(callback) - for _, info in ipairs(self) do - local res = callback(info) + local list = {} + for srcId, info in pairs(self._info) do + local src = sourceMgr.list[srcId] + if src then + list[#list+1] = info + else + self._info[srcId] = nil + self._infoCount = self._infoCount - 1 + end + end + table.sort(list, function (a, b) + return a._sort < b._sort + end) + for i = 1, #list do + local info = list[i] + local res = callback(info, sourceMgr.list[info.source]) if res ~= nil then return res end @@ -34,10 +72,22 @@ function mt:eachInfo(callback) return nil end +function mt:getSource() + return sourceMgr.list[self.source] +end + return function (name, source) + if not source then + error('No source') + end + local id = source.id + if not id then + error('Not instanted source') + end local self = setmetatable({ name = name, - source = source, + source = id, + _info = {}, }, mt) return self end diff --git a/server/src/vm/library.lua b/server/src/vm/library.lua index 65a70219..8f034229 100644 --- a/server/src/vm/library.lua +++ b/server/src/vm/library.lua @@ -1,3 +1,5 @@ +local sourceMgr = require 'vm.source' + local createValue local createFunction @@ -14,9 +16,9 @@ function buildLibValue(lib) local tp = lib.type local value if tp == 'table' then - value = createValue('table') + value = createValue('table', sourceMgr.dummy()) elseif tp == 'function' then - value = createValue('function') + value = createValue('function', sourceMgr.dummy()) local func = createFunction() value:setFunction(func) if lib.args then @@ -34,17 +36,17 @@ function buildLibValue(lib) end end elseif tp == 'string' then - value = createValue('string') + value = createValue('string', sourceMgr.dummy()) elseif tp == 'boolean' then - value = createValue('boolean') + value = createValue('boolean', sourceMgr.dummy()) elseif tp == 'number' then - value = createValue('number') + value = createValue('number', sourceMgr.dummy()) elseif tp == 'integer' then - value = createValue('integer') + value = createValue('integer', sourceMgr.dummy()) elseif tp == 'nil' then - value = createValue('nil') + value = createValue('nil', sourceMgr.dummy()) else - value = createValue(tp or 'any') + value = createValue(tp or 'any', sourceMgr.dummy()) end value:setLib(lib) diff --git a/server/src/vm/local.lua b/server/src/vm/local.lua index fef5a97b..a62e812f 100644 --- a/server/src/vm/local.lua +++ b/server/src/vm/local.lua @@ -1,15 +1,13 @@ -local function getDefaultSource() - return { - start = 0, - finish = 0, - uri = '', - } -end +local sourceMgr = require 'vm.source' + +local Sort = 0 local mt = {} mt.__index = mt mt.type = 'local' mt._close = math.maxinteger +mt._infoCount = 0 +mt._infoLimit = 10 function mt:setValue(value) if self.value then @@ -32,19 +30,63 @@ function mt:getInitValue() end function mt:addInfo(tp, source) - self[#self+1] = { + if not source then + error('No source') + end + local id = source.id + if not id then + error('Not instanted source') + end + if self._info[id] then + return + end + Sort = Sort + 1 + local info = { type = tp, - source = source, + source = id, + _sort = Sort, } + + self._info[id] = info + self._infoCount = self._infoCount + 1 + + if self._infoCount > self._infoLimit then + for srcId in pairs(self._info) do + local src = sourceMgr.list[srcId] + if not src then + self._info[srcId] = nil + self._infoCount = self._infoCount - 1 + end + end + self._infoLimit = self._infoCount * 2 + if self._infoLimit < 10 then + self._infoLimit = 10 + end + end end function mt:eachInfo(callback) - for _, info in ipairs(self) do - local res = callback(info) + local list = {} + for srcId, info in pairs(self._info) do + local src = sourceMgr.list[srcId] + if src then + list[#list+1] = info + else + self._info[srcId] = nil + self._infoCount = self._infoCount - 1 + end + end + table.sort(list, function (a, b) + return a._sort < b._sort + end) + for i = 1, #list do + local info = list[i] + local res = callback(info, sourceMgr.list[info.source]) if res ~= nil then return res end end + return nil end function mt:set(name, v) @@ -76,7 +118,7 @@ function mt:shadow(old) end group[#group+1] = self self._shadow = group - old:close(self.source.start - 1) + old:close(self:getSource().start - 1) end function mt:close(pos) @@ -87,15 +129,27 @@ function mt:close(pos) end end +function mt:getSource() + return sourceMgr.list[self.source] +end + return function (name, source, value) if not value then error('Local must has a value') end + if not source then + error('No source') + end + local id = source.id + if not id then + error('Not instanted source') + end local self = setmetatable({ name = name, - source = source or getDefaultSource(), + source = id, value = value, initValue = value, + _info = {}, }, mt) return self end diff --git a/server/src/vm/multi.lua b/server/src/vm/multi.lua index f4f21b86..aaff97ec 100644 --- a/server/src/vm/multi.lua +++ b/server/src/vm/multi.lua @@ -1,4 +1,5 @@ local createValue = require 'vm.value' +local sourceMgr = require 'vm.source' local mt = {} mt.__index = mt @@ -20,14 +21,14 @@ end function mt:get(index) for n = #self+1, index do - self[n] = createValue('any') + self[n] = createValue('any', sourceMgr.dummy()) end return self[index] end function mt:set(index, value) for n = #self+1, index-1 do - self[n] = createValue('any') + self[n] = createValue('any', sourceMgr.dummy()) end self[index] = value end @@ -35,7 +36,7 @@ end function mt:first() local value = self[1] if not value then - return createValue('nil') + return createValue('nil', sourceMgr.dummy()) end if value.type == 'multi' then return value:first() diff --git a/server/src/vm/source.lua b/server/src/vm/source.lua index 8f65da8b..f30f95d9 100644 --- a/server/src/vm/source.lua +++ b/server/src/vm/source.lua @@ -1,5 +1,6 @@ local mt = {} mt.__index = mt +mt.uri = '' local Id = 0 local List = {} @@ -96,7 +97,7 @@ function mt:isDead() return self._dead end -local function instant(vm, source) +local function instant(source) if source.id then return false end @@ -107,7 +108,17 @@ local function instant(vm, source) return true end +local function dummy() + local src = { + start = 0, + finish = 0, + } + instant(src) + return src +end + return { instant = instant, list = List, + dummy = dummy, } diff --git a/server/src/vm/value.lua b/server/src/vm/value.lua index f8d3c4b2..44e9d1e4 100644 --- a/server/src/vm/value.lua +++ b/server/src/vm/value.lua @@ -2,15 +2,6 @@ local libraryBuilder = require 'vm.library' local library = require 'core.library' local sourceMgr = require 'vm.source' -local function getDefaultSource() - return { - start = 0, - finish = 0, - uri = '', - } -end - -local weakMt = { __mode = 'k' } local Sort = 0 local mt = {} @@ -24,8 +15,15 @@ local function create (tp, source, literal) if tp == '...' then error('Value type cant be ...') end + if not source then + error('No source') + end + local id = source.id + if not id then + error('Not instanted source') + end local self = setmetatable({ - source = source or getDefaultSource(), + source = id, _type = {}, _literal = literal, _info = {}, @@ -351,4 +349,8 @@ function mt:get(name) return self._flag[name] end +function mt:getSource() + return sourceMgr.list[self.source] +end + return create diff --git a/server/src/vm/vm.lua b/server/src/vm/vm.lua index d89a9a56..3b6a2110 100644 --- a/server/src/vm/vm.lua +++ b/server/src/vm/vm.lua @@ -85,7 +85,7 @@ end function mt:runFunction(func) func:run(self) - if not func.source then + if not func:getSource() then return end @@ -95,16 +95,16 @@ function mt:runFunction(func) -- 暂时使用这种方式激活参数的source for _, arg in ipairs(func.args) do - if arg.source ~= func:getObject() then - self:bindLocal(arg.source, arg, 'local') + if arg:getSource() ~= func:getObject() then + self:bindLocal(arg:getSource(), arg, 'local') end end local originFunction = self:getCurrentFunction() self:setCurrentFunction(func) - func:push(func.source) + func:push(func:getSource()) - self:doActions(func.source) + self:doActions(func:getSource()) func:pop() self:setCurrentFunction(originFunction) @@ -146,13 +146,13 @@ end function mt:callSetMetaTable(func, values, source) if not values[1] then - values[1] = self:createValue('any') + values[1] = self:createValue('any', self:getDefaultSource()) end if not values[2] then - values[2] = self:createValue('any') + values[2] = self:createValue('any', self:getDefaultSource()) end func:setReturn(1, values[1]) - values[1]:setMetaTable(values[2], source) + values[1]:setMetaTable(values[2]) end function mt:getRequire(strValue, destVM) @@ -161,7 +161,7 @@ function mt:getRequire(strValue, destVM) -- 获取主函数返回值,注意不能修改对方的环境 local mainValue = main:getFunction():getReturn(1) if not mainValue then - mainValue = self:createValue('any', nil) + mainValue = self:createValue('any', self:getDefaultSource()) mainValue.uri = destVM.uri end @@ -184,7 +184,7 @@ function mt:tryRequireOne(strValue, mode) local str = strValue:getLiteral() if type(str) == 'string' then -- 支持 require 'xxx' 的转到定义 - local strSource = strValue.source + local strSource = strValue:getSource() self:instantSource(strSource) local uri if mode == 'require' then @@ -217,7 +217,7 @@ end function mt:callRequire(func, values) if not values[1] then - values[1] = self:createValue('any') + values[1] = self:createValue('any', self:getDefaultSource()) end local str = values[1]:getLiteral() if type(str) ~= 'string' then @@ -231,7 +231,7 @@ function mt:callRequire(func, values) else local requireValue = self:tryRequireOne(values[1], 'require') if not requireValue then - requireValue = self:createValue('boolean') + requireValue = self:createValue('boolean', self:getDefaultSource()) requireValue:set('cross file', true) end func:setReturn(1, requireValue) @@ -240,7 +240,7 @@ end function mt:callLoadFile(func, values) if not values[1] then - values[1] = self:createValue('any') + values[1] = self:createValue('any', self:getDefaultSource()) end local str = values[1]:getLiteral() if type(str) ~= 'string' then @@ -248,7 +248,7 @@ function mt:callLoadFile(func, values) end local requireValue = self:tryRequireOne(values[1], 'loadfile') if not requireValue then - requireValue = self:createValue('any') + requireValue = self:createValue('any', self:getDefaultSource()) requireValue:set('cross file', true) end func:setReturn(1, requireValue) @@ -256,7 +256,7 @@ end function mt:callDoFile(func, values) if not values[1] then - values[1] = self:createValue('any') + values[1] = self:createValue('any', self:getDefaultSource()) end local str = values[1]:getLiteral() if type(str) ~= 'string' then @@ -264,7 +264,7 @@ function mt:callDoFile(func, values) end local requireValue = self:tryRequireOne(values[1], 'dofile') if not requireValue then - requireValue = self:createValue('any') + requireValue = self:createValue('any', self:getDefaultSource()) requireValue.isRequire = true end func:setReturn(1, requireValue) @@ -312,7 +312,7 @@ function mt:call(value, values, source) if lib then self:callLibrary(func, values, source, lib) else - if func.source then + if func:getSource() then if not source:get 'called' then source:set('called', true) func:setArgs(values) @@ -465,7 +465,7 @@ function mt:getSimple(simple, max) local first = simple[1] self:instantSource(first) local value = self:getExp(first) - value = self:getFirstInMulti(value) or createValue('nil') + value = self:getFirstInMulti(value) or createValue('nil', self:getDefaultSource()) first:bindValue(value, 'get') if not max then max = #simple @@ -477,7 +477,7 @@ function mt:getSimple(simple, max) local source = simple[i] self:instantSource(source) source:set('simple', simple) - value = self:getFirstInMulti(value) or createValue('nil') + value = self:getFirstInMulti(value) or createValue('nil', self:getDefaultSource()) if source.type == 'call' then local values, args = self:unpackList(source) @@ -488,7 +488,7 @@ function mt:getSimple(simple, max) end object = nil source:bindCall(func, args) - value = self:call(func, values, source) or createValue('any') + value = self:call(func, values, source) or createValue('any', self:getDefaultSource()) elseif source.type == 'index' then local child = source[1] local index = self:getIndex(source) @@ -551,11 +551,11 @@ function mt:getBinary(exp) v2:setType('number', 0.5) v1:setType('string', 0.1) v2:setType('string', 0.1) - return self:createValue('boolean') + return self:createValue('boolean', self:getDefaultSource()) elseif op == '~=' or op == '==' then - return self:createValue('boolean') + return self:createValue('boolean', self:getDefaultSource()) elseif op == '|' or op == '~' or op == '&' @@ -581,16 +581,16 @@ function mt:getBinary(exp) return self:createValue('integer', exp, v1:getLiteral() >> v2:getLiteral()) end end - return self:createValue('integer') + return self:createValue('integer', self:getDefaultSource()) elseif op == '..' then v1:setType('string', 0.5) v2:setType('string', 0.5) v1:setType('number', 0.1) v2:setType('number', 0.1) if type(v1:getLiteral()) == 'string' and type(v2:getLiteral()) == 'string' then - return self:createValue('string', nil, v1:getLiteral() .. v2:getLiteral()) + return self:createValue('string', self:getDefaultSource(), v1:getLiteral() .. v2:getLiteral()) end - return self:createValue('string') + return self:createValue('string', self:getDefaultSource()) elseif op == '+' or op == '-' or op == '*' @@ -624,7 +624,7 @@ function mt:getBinary(exp) end end end - return self:createValue('number') + return self:createValue('number', self:getDefaultSource()) end return nil end @@ -635,26 +635,26 @@ function mt:getUnary(exp) local op = exp.op -- TODO 搜索元方法 if op == 'not' then - return self:createValue('boolean') + return self:createValue('boolean', self:getDefaultSource()) elseif op == '#' then v1:setType('table', 0.5) v1:setType('string', 0.5) if type(v1:getLiteral()) == 'string' then return self:createValue('integer', exp, #v1:getLiteral()) end - return self:createValue('integer') + return self:createValue('integer', self:getDefaultSource()) elseif op == '-' then v1:setType('number', 0.5) if type(v1:getLiteral()) == 'number' then return self:createValue('number', exp, -v1:getLiteral()) end - return self:createValue('number') + return self:createValue('number', self:getDefaultSource()) elseif op == '~' then v1:setType('integer', 0.5) if math.type(v1:getLiteral()) == 'integer' then return self:createValue('integer', exp, ~v1:getLiteral()) end - return self:createValue('integer') + return self:createValue('integer', self:getDefaultSource()) end return nil end @@ -715,7 +715,7 @@ function mt:doReturn(action) values:eachValue(function (n, value) value.uri = self:getUri() func:setReturn(n, value) - local source = action[n] or value.source + local source = action[n] or value:getSource() if source.start == 0 then source = self:getDefaultSource() end @@ -758,7 +758,7 @@ end function mt:setOne(var, value) if not value then - value = createValue('nil') + value = createValue('nil', self:getDefaultSource()) end self:instantSource(var) if var.type == 'name' then @@ -862,7 +862,7 @@ function mt:doIn(action) local args = self:unpackList(action.exp) self:scopePush(action) - local func = table.remove(args, 1) or createValue('any') + local func = table.remove(args, 1) or createValue('any', self:getDefaultSource()) local values = self:call(func, args, action) or createMulti() self:forList(action.arg, function (arg) local value = table.remove(values, 1) @@ -917,7 +917,7 @@ function mt:doFunction(action) -- function x:b() local loc = self:loadLocal(name[1][1]) if loc then - func:setObject(parent, loc.source) + func:setObject(parent, loc:getSource()) else func:setObject(parent, name[#name-2]) end @@ -1074,7 +1074,7 @@ function mt:getUri() end function mt:instantSource(source) - if sourceMgr.instant(self, source) then + if sourceMgr.instant(source) then source:setUri(self:getUri()) self.sources[#self.sources+1] = source CachedSource[source] = true @@ -1128,7 +1128,7 @@ function mt:createEnvironment(ast) -- 全局变量`_G` local global = buildGlobal(self.lsp) -- 隐藏的上值`_ENV` - local env = self:createLocal('_ENV', nil, global) + local env = self:createLocal('_ENV', sourceMgr.dummy(), global) env:set('hide', true) self.env = env end |