From 8f2004d360dde108f90d2b49b0609bd43b7b6d7d Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Wed, 21 Sep 2022 00:32:49 +0300 Subject: refactor(tvix/eval): add VM::call_value helper method This makes it possible to call a callable value (builtin or closure/lambda) directly, without unwrapping it first. This is needed for pretty much all higher-order functions to work correctly. This is mostly equivalent to the previous code in coerce_to_string for calling `__toString`, except it expects the argument(s) to already be placed on the stack. Note that the span for the `NotCallable` error is not currently guaranteed to make any sense, will experiment with this. Change-Id: I821224368d438a28900858b343defc1817e46a0a Reviewed-on: https://cl.tvl.fyi/c/depot/+/6717 Tested-by: BuildkiteCI Reviewed-by: sterni --- tvix/eval/src/builtins/mod.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'tvix/eval/src/builtins') diff --git a/tvix/eval/src/builtins/mod.rs b/tvix/eval/src/builtins/mod.rs index 598c8aa08ece..1ea23d49e632 100644 --- a/tvix/eval/src/builtins/mod.rs +++ b/tvix/eval/src/builtins/mod.rs @@ -12,8 +12,7 @@ use std::{ use crate::{ errors::ErrorKind, - upvalues::UpvalueCarrier, - value::{Builtin, Closure, CoercionKind, NixAttrs, NixList, NixString, Value}, + value::{Builtin, CoercionKind, NixAttrs, NixList, NixString, Value}, vm::VM, }; @@ -147,14 +146,13 @@ fn pure_builtins() -> Vec { }), Builtin::new("map", &[true, true], |args, vm| { let list: NixList = args[1].to_list()?; - let func: Closure = args[0].to_closure()?; list.into_iter() .map(|val| { // Leave the argument on the stack before calling the // function. vm.push(val); - vm.call(func.lambda(), func.upvalues().clone(), 1) + vm.call_value(&args[0]) }) .collect::, _>>() .map(|list| Value::List(NixList::from(list))) -- cgit 1.4.1