From 40b4205e731849ecf68d2c9e80573fd7a0c4030a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Mon, 10 Dec 2018 21:21:02 +0800 Subject: =?UTF-8?q?=E6=9B=B4=E6=96=B0vm?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/matcher/vm.lua | 53 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 15 deletions(-) (limited to 'server/src/matcher/vm.lua') diff --git a/server/src/matcher/vm.lua b/server/src/matcher/vm.lua index 9ae9e011..005586df 100644 --- a/server/src/matcher/vm.lua +++ b/server/src/matcher/vm.lua @@ -107,7 +107,6 @@ end function mt:createFunction(exp) local func = { type = 'function', - args = {}, returns = { type = 'list', }, @@ -119,6 +118,9 @@ function mt:createFunction(exp) if stop then return end + if not func.args then + func.args = {} + end if arg.type == 'name' then func.args[#func.args+1] = self:createLocal(arg[1], arg) elseif arg.type == '...' then @@ -157,20 +159,22 @@ function mt:call(func, values) self.func:cut 'labels' self.func:cut 'dots' - for i = 1, #func.args do - local var = func.arg[i] - if var then - if var.type == 'dots' then - local list = { - type = 'list', - } - for n = i, #values do - list[n-i+1] = values[n] + if func.args then + for i = 1, #func.args do + local var = func.arg[i] + if var then + if var.type == 'dots' then + local list = { + type = 'list', + } + for n = i, #values do + list[n-i+1] = values[n] + end + self:setValue(var, list) + break + else + self:setValue(var, values[i]) end - self:setValue(var, list) - break - else - self:setValue(var, values[i]) end end end @@ -282,7 +286,7 @@ end function mt:unpackList(list) local res = {} - if list.type == 'list' then + if list.type == 'list' or list.type == 'call' then for i, exp in ipairs(list) do local value = self:getExp(exp) if value.type == 'list' then @@ -490,6 +494,21 @@ function mt:doSet(action) end) end +function mt:doLocal(action) + local values + if action[2] then + values = self:unpackList(action[2]) + end + self:forList(action[1], function (key) + local var = self:createLocal(key[1], key) + if values then + local value = table.remove(values, 1) + self:setValue(var, value) + self:addInfo(var, 'set', key) + end + end) +end + function mt:doAction(action) local tp = action.type if tp == 'do' then @@ -505,6 +524,10 @@ function mt:doAction(action) self:addInfo(label, 'goto', action) elseif tp == 'set' then self:doSet(action) + elseif tp == 'local' then + self:doLocal(action) + elseif tp == 'simple' then + self:getSimple(action, 'value') end end -- cgit v1.2.3