summaryrefslogtreecommitdiff
path: root/server/src
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2018-12-11 18:11:02 +0800
committer最萌小汐 <sumneko@hotmail.com>2018-12-11 18:11:02 +0800
commit51215e5847cb5d42d4fe650a0e0421782672342f (patch)
tree90e165f6dce37c68a609ba896b69ab8d030592e1 /server/src
parentd6c2efc40ba580dbe3d7b77887dc77482792489e (diff)
downloadlua-language-server-51215e5847cb5d42d4fe650a0e0421782672342f.zip
整理代码
Diffstat (limited to 'server/src')
-rw-r--r--server/src/matcher/vm.lua59
1 files changed, 22 insertions, 37 deletions
diff --git a/server/src/matcher/vm.lua b/server/src/matcher/vm.lua
index 5625fea1..c76bf420 100644
--- a/server/src/matcher/vm.lua
+++ b/server/src/matcher/vm.lua
@@ -6,7 +6,7 @@ local DefaultSource = { start = 0, finish = 0 }
local mt = {}
mt.__index = mt
-function mt:createLocal(key, source)
+function mt:createLocal(key, source, value)
local loc = {
type = 'local',
key = key,
@@ -15,9 +15,8 @@ function mt:createLocal(key, source)
self.scope.locals[key] = loc
self.results.locals[#self.results.locals+1] = loc
- local value = self:createValue('nil', source)
- self:setValue(loc, value)
- self:addInfo(loc, 'local', source)
+ local value = value or self:createValue('nil', source)
+ self:setValue(loc, value, source)
return loc
end
@@ -55,22 +54,18 @@ function mt:buildTable(source)
local index = self:getIndex(key)
local field = self:createField(tbl, index, key)
if value.type == 'list' then
- self:setValue(field, value[1])
- self:addInfo(field, 'set', key)
+ self:setValue(field, value[1], key)
else
- self:setValue(field, value)
- self:addInfo(field, 'set', key)
+ self:setValue(field, value, key)
end
else
if key.type == 'name' then
local index = key[1]
local field = self:createField(tbl, index, key)
if value.type == 'list' then
- self:setValue(field, value[1])
- self:addInfo(field, 'set', key)
+ self:setValue(field, value[1], key)
else
- self:setValue(field, value)
- self:addInfo(field, 'set', key)
+ self:setValue(field, value, key)
end
end
end
@@ -112,7 +107,7 @@ function mt:coverValue(target, source)
end
end
-function mt:setValue(var, value)
+function mt:setValue(var, value, source)
assert(not value or value.type ~= 'list')
value = value or self:createValue('nil', var)
if var.value then
@@ -126,6 +121,9 @@ function mt:setValue(var, value)
else
var.value = value
end
+ if source and source.start then
+ self:addInfo(var, 'set', source)
+ end
return value
end
@@ -178,8 +176,7 @@ function mt:buildFunction(exp, object)
self.chunk:cut 'labels'
if object then
- local var = self:createLocal('self', object.source)
- self:setValue(var, self:getValue(object))
+ local var = self:createLocal('self', object.source, self:getValue(object))
func.args[1] = var
end
@@ -568,15 +565,10 @@ function mt:doSet(action)
local value = table.remove(values, 1)
if key.type == 'name' then
local var = self:getName(key[1], key)
- self:setValue(var, value)
- self:addInfo(var, 'set', key)
+ self:setValue(var, value, key)
elseif key.type == 'simple' then
local field = self:getSimple(key, 'field')
- self:setValue(field, value)
- local source = key[#key]
- if source.start then
- self:addInfo(field, 'set', source)
- end
+ self:setValue(field, value, key[#key])
end
end)
end
@@ -587,11 +579,11 @@ function mt:doLocal(action)
values = self:unpackList(action[2])
end
self:forList(action[1], function (key)
- local var = self:createLocal(key[1], key)
+ local value
if values then
- self:setValue(var, table.remove(values, 1))
- self:addInfo(var, 'set', key)
+ value = table.remove(values, 1)
end
+ local var = self:createLocal(key[1], key, value)
end)
end
@@ -617,9 +609,7 @@ function mt:doLoop(action)
self:getExp(action.step)
end
- local arg = self:createLocal(action.arg[1], action.arg)
- self:setValue(arg, min)
- self:addInfo(arg, 'set', action.arg)
+ local arg = self:createLocal(action.arg[1], action.arg, min)
self:doActions(action)
@@ -644,9 +634,8 @@ function mt:doIn(action)
local args = self:unpackList(list)
local values = self:call(func, args)
self:forList(action.arg, function (arg)
- local var = self:createLocal(arg[1], arg)
- self:setValue(var, table.remove(values, 1))
- self:addInfo(var, 'set', arg)
+ local value = table.remove(values, 1)
+ local var = self:createLocal(arg[1], arg, value)
end)
self:doActions(action)
@@ -685,18 +674,14 @@ function mt:doFunction(action)
source = name
end
local func = self:buildFunction(action, object)
- self:setValue(var, func)
- if source.start then
- self:addInfo(var, 'set', source)
- end
+ self:setValue(var, func, source)
end
function mt:doLocalFunction(action)
local name = action.name
local var = self:createLocal(name[1], name)
local func = self:buildFunction(action)
- self:setValue(var, func)
- self:addInfo(var, 'set', name)
+ self:setValue(var, func, name)
end
function mt:doAction(action)