summaryrefslogtreecommitdiff
path: root/server/src/vm
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/vm')
-rw-r--r--server/src/vm/source.lua4
-rw-r--r--server/src/vm/value.lua1
-rw-r--r--server/src/vm/vm.lua32
3 files changed, 18 insertions, 19 deletions
diff --git a/server/src/vm/source.lua b/server/src/vm/source.lua
index 98102bf7..8c80262a 100644
--- a/server/src/vm/source.lua
+++ b/server/src/vm/source.lua
@@ -55,11 +55,11 @@ function mt:action()
end
function mt:setUri(uri)
- self._uri = uri
+ self.uri = uri
end
function mt:getUri()
- return self._uri
+ return self.uri
end
function mt:set(name, v)
diff --git a/server/src/vm/value.lua b/server/src/vm/value.lua
index b520054c..39a6f1aa 100644
--- a/server/src/vm/value.lua
+++ b/server/src/vm/value.lua
@@ -12,6 +12,7 @@ end
local mt = {}
mt.__index = mt
mt.type = 'value'
+mt.uri = ''
function mt:setType(tp, rate)
if type(tp) == 'table' then
diff --git a/server/src/vm/vm.lua b/server/src/vm/vm.lua
index 57b6c1cd..4ff5f372 100644
--- a/server/src/vm/vm.lua
+++ b/server/src/vm/vm.lua
@@ -155,13 +155,11 @@ end
function mt:getRequire(strValue, destVM)
-- 取出对方的主函数
- local main = destVM.results.main
+ local main = destVM.main
-- 获取主函数返回值,注意不能修改对方的环境
- local mainValue
- if main.returns then
- mainValue = self:getFirstInMulti(main.returns)
- else
- mainValue = self:createValue('boolean', nil, true)
+ local mainValue = main:getFunction():getReturn(1)
+ if not mainValue then
+ mainValue = self:createValue('any', nil)
mainValue.uri = destVM.uri
end
@@ -170,7 +168,7 @@ end
function mt:getLoadFile(strValue, destVM)
-- 取出对方的主函数
- local main = destVM.results.main
+ local main = destVM.main
-- loadfile 的返回值就是对方的主函数
local mainValue = main
@@ -185,26 +183,23 @@ function mt:tryRequireOne(strValue, mode)
if type(str) == 'string' then
-- 支持 require 'xxx' 的转到定义
local strSource = strValue.source
- strSource.bind = strValue
- self.results.sources[#self.results.sources+1] = strSource
- strValue.isRequire = true
-
+ self:instantSource(strSource)
local uri
if mode == 'require' then
- uri = self.lsp.workspace:searchPath(self.chunk.func.uri, str)
+ uri = self.lsp.workspace:searchPath(self:getUri(), str)
elseif mode == 'loadfile' then
- uri = self.lsp.workspace:loadPath(self.chunk.func.uri, str)
+ uri = self.lsp.workspace:loadPath(self:getUri(), str)
elseif mode == 'dofile' then
- uri = self.lsp.workspace:loadPath(self.chunk.func.uri, str)
+ uri = self.lsp.workspace:loadPath(self:getUri(), str)
end
if not uri then
return nil
end
- strValue.uri = uri
+ strSource:set('target uri', uri)
-- 如果取不到VM(不编译),则做个标记,之后再取一次
local destVM = self.lsp:getVM(uri)
- self.lsp:compileChain(self.chunk.func.uri, uri)
+ self.lsp:compileChain(self:getUri(), uri)
if destVM then
if mode == 'require' then
return self:getRequire(strValue, destVM)
@@ -331,6 +326,7 @@ end
function mt:createValue(tp, source, literal)
local value = createValue(tp, source, literal)
+ value.uri = self:getUri()
return value
end
@@ -699,7 +695,8 @@ function mt:doReturn(action)
local values = self:unpackList(action)
local func = self:getCurrentFunction()
values:eachValue(function (n, value)
- func:setReturn(n, value)
+ value.uri = self:getUri()
+ func:setReturn(n, value, action[n])
end)
end
@@ -1088,6 +1085,7 @@ function mt:createLocal(key, source, value)
loc = createLocal(key, source, value)
self:saveLocal(key, loc)
self:bindLocal(source, loc, 'local')
+ value:addInfo('local', source)
return loc
end