diff options
author | Wim <wim@42.be> | 2020-07-18 17:27:41 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-18 17:27:41 +0200 |
commit | 23d8742f0d95096b92f11729fb47f86ac3b68d43 (patch) | |
tree | 7b8acb02b051ae06e5454fda4a9d5118428fe016 /vendor/github.com/d5/tengo/v2 | |
parent | 3b6a8be07b9422714db30fb50977f342057febf3 (diff) | |
download | matterbridge-msglm-23d8742f0d95096b92f11729fb47f86ac3b68d43.tar.gz matterbridge-msglm-23d8742f0d95096b92f11729fb47f86ac3b68d43.tar.bz2 matterbridge-msglm-23d8742f0d95096b92f11729fb47f86ac3b68d43.zip |
Update dependencies for 1.18.0 release (#1175)
Diffstat (limited to 'vendor/github.com/d5/tengo/v2')
-rw-r--r-- | vendor/github.com/d5/tengo/v2/compiler.go | 10 | ||||
-rw-r--r-- | vendor/github.com/d5/tengo/v2/objects.go | 32 | ||||
-rw-r--r-- | vendor/github.com/d5/tengo/v2/parser/expr.go | 12 | ||||
-rw-r--r-- | vendor/github.com/d5/tengo/v2/parser/opcodes.go | 2 | ||||
-rw-r--r-- | vendor/github.com/d5/tengo/v2/parser/parser.go | 17 | ||||
-rw-r--r-- | vendor/github.com/d5/tengo/v2/vm.go | 26 |
6 files changed, 84 insertions, 15 deletions
diff --git a/vendor/github.com/d5/tengo/v2/compiler.go b/vendor/github.com/d5/tengo/v2/compiler.go index cb1c8f30..1937a1d6 100644 --- a/vendor/github.com/d5/tengo/v2/compiler.go +++ b/vendor/github.com/d5/tengo/v2/compiler.go @@ -506,7 +506,11 @@ func (c *Compiler) Compile(node parser.Node) error { return err } } - c.emit(node, parser.OpCall, len(node.Args)) + ellipsis := 0 + if node.Ellipsis.IsValid() { + ellipsis = 1 + } + c.emit(node, parser.OpCall, len(node.Args), ellipsis) case *parser.ImportExpr: if node.ModuleName == "" { return c.errorf(node, "empty module name") @@ -526,7 +530,7 @@ func (c *Compiler) Compile(node parser.Node) error { return err } c.emit(node, parser.OpConstant, c.addConstant(compiled)) - c.emit(node, parser.OpCall, 0) + c.emit(node, parser.OpCall, 0, 0) case Object: // builtin module c.emit(node, parser.OpConstant, c.addConstant(v)) default: @@ -556,7 +560,7 @@ func (c *Compiler) Compile(node parser.Node) error { return err } c.emit(node, parser.OpConstant, c.addConstant(compiled)) - c.emit(node, parser.OpCall, 0) + c.emit(node, parser.OpCall, 0, 0) } else { return c.errorf(node, "module '%s' not found", node.ModuleName) } diff --git a/vendor/github.com/d5/tengo/v2/objects.go b/vendor/github.com/d5/tengo/v2/objects.go index 27c1d493..30913db5 100644 --- a/vendor/github.com/d5/tengo/v2/objects.go +++ b/vendor/github.com/d5/tengo/v2/objects.go @@ -1342,6 +1342,38 @@ func (o *String) BinaryOp(op token.Token, rhs Object) (Object, error) { } return &String{Value: o.Value + rhsStr}, nil } + case token.Less: + switch rhs := rhs.(type) { + case *String: + if o.Value < rhs.Value { + return TrueValue, nil + } + return FalseValue, nil + } + case token.LessEq: + switch rhs := rhs.(type) { + case *String: + if o.Value <= rhs.Value { + return TrueValue, nil + } + return FalseValue, nil + } + case token.Greater: + switch rhs := rhs.(type) { + case *String: + if o.Value > rhs.Value { + return TrueValue, nil + } + return FalseValue, nil + } + case token.GreaterEq: + switch rhs := rhs.(type) { + case *String: + if o.Value >= rhs.Value { + return TrueValue, nil + } + return FalseValue, nil + } } return nil, ErrInvalidOperator } diff --git a/vendor/github.com/d5/tengo/v2/parser/expr.go b/vendor/github.com/d5/tengo/v2/parser/expr.go index 71e5155b..b6b6c62b 100644 --- a/vendor/github.com/d5/tengo/v2/parser/expr.go +++ b/vendor/github.com/d5/tengo/v2/parser/expr.go @@ -111,10 +111,11 @@ func (e *BoolLit) String() string { // CallExpr represents a function call expression. type CallExpr struct { - Func Expr - LParen Pos - Args []Expr - RParen Pos + Func Expr + LParen Pos + Args []Expr + Ellipsis Pos + RParen Pos } func (e *CallExpr) exprNode() {} @@ -134,6 +135,9 @@ func (e *CallExpr) String() string { for _, e := range e.Args { args = append(args, e.String()) } + if len(args) > 0 && e.Ellipsis.IsValid() { + args[len(args)-1] = args[len(args)-1] + "..." + } return e.Func.String() + "(" + strings.Join(args, ", ") + ")" } diff --git a/vendor/github.com/d5/tengo/v2/parser/opcodes.go b/vendor/github.com/d5/tengo/v2/parser/opcodes.go index a4fbfbaf..d97f4896 100644 --- a/vendor/github.com/d5/tengo/v2/parser/opcodes.go +++ b/vendor/github.com/d5/tengo/v2/parser/opcodes.go @@ -120,7 +120,7 @@ var OpcodeOperands = [...][]int{ OpImmutable: {}, OpIndex: {}, OpSliceIndex: {}, - OpCall: {1}, + OpCall: {1, 1}, OpReturn: {1}, OpGetLocal: {1}, OpSetLocal: {1}, diff --git a/vendor/github.com/d5/tengo/v2/parser/parser.go b/vendor/github.com/d5/tengo/v2/parser/parser.go index 501a9106..fd20423b 100644 --- a/vendor/github.com/d5/tengo/v2/parser/parser.go +++ b/vendor/github.com/d5/tengo/v2/parser/parser.go @@ -270,9 +270,13 @@ func (p *Parser) parseCall(x Expr) *CallExpr { p.exprLevel++ var list []Expr - for p.token != token.RParen && p.token != token.EOF { + var ellipsis Pos + for p.token != token.RParen && p.token != token.EOF && !ellipsis.IsValid() { list = append(list, p.parseExpr()) - + if p.token == token.Ellipsis { + ellipsis = p.pos + p.next() + } if !p.expectComma(token.RParen, "call argument") { break } @@ -281,10 +285,11 @@ func (p *Parser) parseCall(x Expr) *CallExpr { p.exprLevel-- rparen := p.expect(token.RParen) return &CallExpr{ - Func: x, - LParen: lparen, - RParen: rparen, - Args: list, + Func: x, + LParen: lparen, + RParen: rparen, + Ellipsis: ellipsis, + Args: list, } } 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, |