diff options
Diffstat (limited to 'vendor/github.com/d5/tengo/v2/vm.go')
-rw-r--r-- | vendor/github.com/d5/tengo/v2/vm.go | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/vendor/github.com/d5/tengo/v2/vm.go b/vendor/github.com/d5/tengo/v2/vm.go index af8783f0..811ecef9 100644 --- a/vendor/github.com/d5/tengo/v2/vm.go +++ b/vendor/github.com/d5/tengo/v2/vm.go @@ -537,12 +537,36 @@ func (v *VM) run() { } case parser.OpCall: numArgs := int(v.curInsts[v.ip+1]) - v.ip++ + spread := int(v.curInsts[v.ip+2]) + v.ip += 2 + value := v.stack[v.sp-1-numArgs] if !value.CanCall() { v.err = fmt.Errorf("not callable: %s", value.TypeName()) return } + + if spread == 1 { + v.sp-- + switch arr := v.stack[v.sp].(type) { + case *Array: + for _, item := range arr.Value { + v.stack[v.sp] = item + v.sp++ + } + numArgs += len(arr.Value) - 1 + case *ImmutableArray: + for _, item := range arr.Value { + v.stack[v.sp] = item + v.sp++ + } + numArgs += len(arr.Value) - 1 + default: + v.err = fmt.Errorf("not an array: %s", arr.TypeName()) + return + } + } + if callee, ok := value.(*CompiledFunction); ok { if callee.VarArgs { // if the closure is variadic, |