From 88e50a55afff7b809d4b9d6cfaf93275bfe06f56 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Wed, 2 Feb 2022 16:32:30 +0100 Subject: Pass arguments to call and construct directly by value --- src/eval/func.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'src/eval/func.rs') diff --git a/src/eval/func.rs b/src/eval/func.rs index ccd0932f..6d405ca4 100644 --- a/src/eval/func.rs +++ b/src/eval/func.rs @@ -45,15 +45,17 @@ impl Func { } /// Call the function in the context with the arguments. - pub fn call(&self, ctx: &mut EvalContext, args: &mut Args) -> TypResult { - match self.0.as_ref() { - Repr::Native(native) => (native.func)(ctx, args), - Repr::Closure(closure) => closure.call(ctx, args), + pub fn call(&self, ctx: &mut EvalContext, mut args: Args) -> TypResult { + let value = match self.0.as_ref() { + Repr::Native(native) => (native.func)(ctx, &mut args)?, + Repr::Closure(closure) => closure.call(ctx, &mut args)?, Repr::With(wrapped, applied) => { args.items.splice(.. 0, applied.items.iter().cloned()); - wrapped.call(ctx, args) + return wrapped.call(ctx, args); } - } + }; + args.finish()?; + Ok(value) } /// Apply the given arguments to the function. -- cgit v1.2.3