From 876c4772563e8129e069f1d107b2a21378609ace Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Tue, 20 Sep 2022 23:47:30 +0300 Subject: feat(tvix/eval): implement builtins.map As we already have a VM passed to the builtins, we can simply execute the provided closure/lambda in it for each value. The primary annoyance with this is that we have to clone the upvalues for each element, but we can try making this cheaper in the future (it's also a general problem in the VM itself). Change-Id: I5bcf56d58c509c0eb081e7cf52f6093216451ce4 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6714 Tested-by: BuildkiteCI Reviewed-by: sterni --- .../eval/src/tests/tvix_tests/eval-okay-builtins-map.exp | 1 + .../eval/src/tests/tvix_tests/eval-okay-builtins-map.nix | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 tvix/eval/src/tests/tvix_tests/eval-okay-builtins-map.exp create mode 100644 tvix/eval/src/tests/tvix_tests/eval-okay-builtins-map.nix (limited to 'tvix/eval/src/tests/tvix_tests') diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-map.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-map.exp new file mode 100644 index 000000000000..e1ff70800245 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-map.exp @@ -0,0 +1 @@ +[ [ 1 2 3 4 5 ] [ 2 4 6 8 10 ] [ 2 4 6 8 10 ] [ 1 2 3 4 5 ] ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-map.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-map.nix new file mode 100644 index 000000000000..6ff42d0891dc --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-map.nix @@ -0,0 +1,16 @@ +[ + # identity function + (builtins.map (x: x) [ 1 2 3 4 5 ]) + + # double stuff + (builtins.map (x: x * 2) [ 1 2 3 4 5 ]) + + # same but with a closure this time + ( + let n = 2; + in builtins.map (x: x * n) [ 1 2 3 4 5 ] + ) + + # from global scope + (map (x: x) [ 1 2 3 4 5 ]) +] -- cgit 1.4.1