summaryrefslogtreecommitdiff
path: root/script/vm/compiler.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-03-03 21:00:26 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-03-03 21:00:26 +0800
commit33a60bea7e39d134b3086aafb80c7724bcb1d1b4 (patch)
tree69ba166043a863c06af710d785c57ff52600a16d /script/vm/compiler.lua
parentd4c620b0d24df00bf185daf750886ba996d94552 (diff)
downloadlua-language-server-33a60bea7e39d134b3086aafb80c7724bcb1d1b4.zip
update
Diffstat (limited to 'script/vm/compiler.lua')
-rw-r--r--script/vm/compiler.lua36
1 files changed, 29 insertions, 7 deletions
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua
index 3af72110..35fefd01 100644
--- a/script/vm/compiler.lua
+++ b/script/vm/compiler.lua
@@ -150,6 +150,34 @@ function m.compileByParentNode(source, key, pushResult)
end
end
+local function selectNode(source, list, index)
+ local exp
+ if list[index] then
+ exp = list[index]
+ else
+ for i = index, 1, -1 do
+ if list[i] then
+ exp = list[i]
+ if exp.type == 'call'
+ or exp.type == '...' then
+ index = index - i + 1
+ end
+ break
+ end
+ end
+ end
+ if not exp then
+ return nil
+ end
+ if exp.type == 'call' then
+ return getReturn(exp.node, index, source, exp.args)
+ end
+ if exp.type == '...' then
+ -- TODO
+ end
+ return m.compileNode(exp)
+end
+
local compilerMap = util.switch()
: case 'boolean'
: case 'table'
@@ -224,9 +252,7 @@ local compilerMap = util.switch()
local index = source.index
if func.returns then
for _, rtn in ipairs(func.returns) do
- if rtn[index] then
- m.setNode(source, m.compileNode(rtn[index]))
- end
+ m.setNode(source, selectNode(source, rtn, index))
end
end
end)
@@ -237,10 +263,6 @@ local compilerMap = util.switch()
m.setNode(source, getReturn(vararg.node, source.sindex, source, vararg.args))
end
end)
- : case 'call'
- : call(function (source)
- m.setNode(source, getReturn(source.node, 1, source, source.args))
- end)
: getMap()
---@param source parser.object