Example #1
0
// EvalUnary evaluates a unary operator.
func (c *Context) EvalUnary(op string, right value.Value) value.Value {
	right = right.Eval(c)
	fn := c.UnaryFn[op]
	if fn == nil {
		return value.Unary(c, op, right)
	}
	if fn.Body == nil {
		value.Errorf("unary %q undefined", op)
	}
	c.push()
	defer c.pop()
	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
}
Example #2
0
func (u *unary) Eval(context value.Context) value.Value {
	return value.Unary(u.op, u.right.Eval(context))
}