From cb0aab3cfab2122a87d1d221290f7178b4291758 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Mon, 16 Aug 2021 18:14:58 +0200 Subject: [PATCH] Change how functions are called --- src/eval/function.rs | 10 +++------- src/eval/mod.rs | 8 ++++---- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/eval/function.rs b/src/eval/function.rs index f18af05eb..85608ca1f 100644 --- a/src/eval/function.rs +++ b/src/eval/function.rs @@ -1,5 +1,4 @@ use std::fmt::{self, Debug, Display, Formatter, Write}; -use std::ops::Deref; use std::rc::Rc; use super::{Cast, EvalContext, Str, Value}; @@ -34,13 +33,10 @@ impl Function { pub fn name(&self) -> Option<&EcoString> { self.repr.name.as_ref() } -} -impl Deref for Function { - type Target = Func; - - fn deref(&self) -> &Self::Target { - &self.repr.func + /// Call the function in the context with the arguments. + pub fn call(&self, ctx: &mut EvalContext, args: &mut Arguments) -> TypResult { + (&self.repr.func)(ctx, args) } } diff --git a/src/eval/mod.rs b/src/eval/mod.rs index f2afbafb0..a03c83b62 100644 --- a/src/eval/mod.rs +++ b/src/eval/mod.rs @@ -377,7 +377,7 @@ impl Eval for CallExpr { Value::Func(func) => { let point = || Tracepoint::Call(func.name().map(Into::into)); - let value = func(ctx, &mut args).trace(point, self.span)?; + let value = func.call(ctx, &mut args).trace(point, self.span)?; args.finish()?; Ok(value) } @@ -520,13 +520,13 @@ impl Eval for WithExpr { type Output = Value; fn eval(&self, ctx: &mut EvalContext) -> TypResult { - let callee = self.callee.eval(ctx)?.cast::().at(self.callee.span())?; + let wrapped = self.callee.eval(ctx)?.cast::().at(self.callee.span())?; let applied = self.args.eval(ctx)?; - let name = callee.name().cloned(); + let name = wrapped.name().cloned(); let func = Function::new(name, move |ctx, args| { args.items.splice(.. 0, applied.items.iter().cloned()); - callee(ctx, args) + wrapped.call(ctx, args) }); Ok(Value::Func(func))