about summary refs log tree commit diff
path: root/tvix/eval/src/upvalues.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tvix/eval/src/upvalues.rs')
-rw-r--r--tvix/eval/src/upvalues.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/tvix/eval/src/upvalues.rs b/tvix/eval/src/upvalues.rs
index b51ef500e031..ddde8db95a21 100644
--- a/tvix/eval/src/upvalues.rs
+++ b/tvix/eval/src/upvalues.rs
@@ -16,12 +16,14 @@ use crate::{opcode::UpvalueIdx, Value};
 #[derive(Clone, Debug)]
 pub struct Upvalues {
     upvalues: Vec<Value>,
+    with_stack: Option<Vec<Value>>,
 }
 
 impl Upvalues {
     pub fn with_capacity(count: usize) -> Self {
         Upvalues {
             upvalues: Vec::with_capacity(count),
+            with_stack: None,
         }
     }
 
@@ -29,6 +31,22 @@ impl Upvalues {
     pub fn push(&mut self, value: Value) {
         self.upvalues.push(value);
     }
+
+    /// Set the captured with stack.
+    pub fn set_with_stack(&mut self, with_stack: Vec<Value>) {
+        self.with_stack = Some(with_stack);
+    }
+
+    pub fn with_stack(&self) -> Option<&Vec<Value>> {
+        self.with_stack.as_ref()
+    }
+
+    pub fn with_stack_len(&self) -> usize {
+        match &self.with_stack {
+            None => 0,
+            Some(stack) => stack.len(),
+        }
+    }
 }
 
 impl Index<UpvalueIdx> for Upvalues {