// EvalBinary evaluates a binary operator. func (c *Context) EvalBinary(left value.Value, op string, right value.Value) value.Value { left = left.Eval(c) right = right.Eval(c) fn := c.BinaryFn[op] if fn == nil { return value.Binary(c, left, op, right) } if fn.Body == nil { value.Errorf("binary %q undefined", op) } c.push() defer c.pop() c.assignLocal(fn.Left, left) c.assignLocal(fn.Right, right) var v value.Value for _, e := range fn.Body { v = e.Eval(c) } if v == nil { value.Errorf("no value returned by %q", op) } return v }
func (b *binary) Eval(context value.Context) value.Value { return value.Binary(b.left.Eval(context), b.op, b.right.Eval(context)) }