diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-02-12 15:47:36 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-02-12 15:47:36 +0800 |
commit | 941233c749a67ba699f038edcfbb85459ff1be02 (patch) | |
tree | bacbb2f416a72d36ac1d23f8c9533f095118db3f /server | |
parent | 72cb32854c8c1d8d273fcb24b2235e0e7505b99f (diff) | |
download | lua-language-server-941233c749a67ba699f038edcfbb85459ff1be02.zip |
暂存
Diffstat (limited to 'server')
-rw-r--r-- | server/src/vm/function.lua | 12 | ||||
-rw-r--r-- | server/src/vm/source.lua | 8 | ||||
-rw-r--r-- | server/src/vm/vm.lua | 37 |
3 files changed, 38 insertions, 19 deletions
diff --git a/server/src/vm/function.lua b/server/src/vm/function.lua index 4136a5f6..f06c93ef 100644 --- a/server/src/vm/function.lua +++ b/server/src/vm/function.lua @@ -92,6 +92,18 @@ function mt:loadDots(expect) return self._dots:get(expect) end +function mt:saveUpvalue(name, loc) + self.upvalues[name] = loc +end + +function mt:setObject(object) + self._object = object +end + +function mt:setColon(colon) + self._colon = colon +end + function mt:hasRuned() return self._runed > 0 end diff --git a/server/src/vm/source.lua b/server/src/vm/source.lua index c5bad8bf..e2de6a27 100644 --- a/server/src/vm/source.lua +++ b/server/src/vm/source.lua @@ -18,6 +18,14 @@ function mt:bindLabel(label) end end +function mt:bindFunction(func) + if func then + self._bindFunction = func + else + return self._bindFunction + end +end + function mt:setUri(uri) self._uri = uri end diff --git a/server/src/vm/vm.lua b/server/src/vm/vm.lua index 7a95b722..a594bf14 100644 --- a/server/src/vm/vm.lua +++ b/server/src/vm/vm.lua @@ -194,38 +194,37 @@ function mt:runFunction(func) end local originFunction = self:getCurrentFunction() + self:setCurrentFunction(func) + func:push() self:doActions(func.source) + func:pop() self:setCurrentFunction(originFunction) end function mt:buildFunction(exp, object, colon) - if exp and exp.func then - return exp.func + if exp and exp:bindFunction() then + return exp:bindFunction() end - local func = self:createValue('function', exp) - func.args = {} - func.argValues = {} + local value = self:createFunction(exp) if not exp then - return func + return value end - func.built = exp - func.upvalues = {} - func.object = object - func.colon = colon - func.uri = exp.uri - exp.func = func - for name, loc in pairs(self.scope.locals) do - func.upvalues[name] = loc - end + exp:bindFunction(value) + local func = value:getFunction() - self.results.funcs[#self.results.funcs+1] = func + self:eachLocal(function (name, loc) + func:saveLocal(name, loc) + end) - return func + func:setObject(object) + func:setColon(colon) + + return value end function mt:forList(list, callback) @@ -476,8 +475,8 @@ function mt:getFunctionReturns(func, i) end end -function mt:createValue(tp, source, v) - local value = createValue(tp, source, v) +function mt:createValue(tp, source) + local value = createValue(tp, source) local lib = library.object[tp] if lib then self:getLibChild(value, lib, 'object') |