about summary refs log tree commit diff
path: root/tvix/eval/src/vm.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tvix/eval/src/vm.rs')
-rw-r--r--tvix/eval/src/vm.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/tvix/eval/src/vm.rs b/tvix/eval/src/vm.rs
index 9d28c7be1b93..b89b61f7626a 100644
--- a/tvix/eval/src/vm.rs
+++ b/tvix/eval/src/vm.rs
@@ -229,6 +229,31 @@ impl<'o> VM<'o> {
         }
     }
 
+    /// Call the given `callable` value with the given list of `args`
+    ///
+    /// # Panics
+    ///
+    /// Panics if the passed list of `args` is empty
+    #[track_caller]
+    pub fn call_with<I>(&mut self, callable: &Value, args: I) -> EvalResult<Value>
+    where
+        I: IntoIterator<Item = Value>,
+    {
+        let mut num_args = 0_usize;
+        for arg in args {
+            num_args += 1;
+            self.push(arg);
+        }
+        if num_args == 0 {
+            panic!("call_with called with an empty list of args");
+        }
+        let mut res = self.call_value(callable)?;
+        for _ in 0..(num_args - 1) {
+            res = self.call_value(&res)?;
+        }
+        Ok(res)
+    }
+
     fn tail_call_value(&mut self, callable: Value) -> EvalResult<()> {
         match callable {
             Value::Builtin(builtin) => self.call_builtin(builtin),