about summary refs log tree commit diff
path: root/tvix
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2022-08-23T23·09+0300
committertazjin <tazjin@tvl.su>2022-09-02T12·31+0000
commitfc892b7a9dd635467f362767ad58fefc26ffc122 (patch)
tree9453a1750514bf1650e019d60c6c5530dced97ac /tvix
parent269788086ec7cfabe70734b9be840efa87bd3f28 (diff)
refactor(tvix/eval): add VM::call helper to set up call frames r/4582
Change-Id: Ia7ff572af90ae379b23bbd0f5215cd13a4dc0ab5
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6248
Reviewed-by: grfn <grfn@gws.fyi>
Reviewed-by: sterni <sternenseemann@systemli.org>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix')
-rw-r--r--tvix/eval/src/vm.rs19
1 files changed, 12 insertions, 7 deletions
diff --git a/tvix/eval/src/vm.rs b/tvix/eval/src/vm.rs
index 63e5e4ad7387..1b9419ce2232 100644
--- a/tvix/eval/src/vm.rs
+++ b/tvix/eval/src/vm.rs
@@ -112,6 +112,16 @@ impl VM {
         &self.stack[self.stack.len() - 1 - offset]
     }
 
+    fn call(&mut self, lambda: Lambda) {
+        let frame = CallFrame {
+            lambda,
+            ip: 0,
+            stack_offset: self.stack.len(),
+        };
+
+        self.frames.push(frame);
+    }
+
     fn run(&mut self) -> EvalResult<Value> {
         #[cfg(feature = "disassembler")]
         let mut tracer = Tracer::new();
@@ -384,17 +394,12 @@ impl VM {
 }
 
 pub fn run_lambda(lambda: Lambda) -> EvalResult<Value> {
-    let frame = CallFrame {
-        lambda,
-        ip: 0,
-        stack_offset: 0,
-    };
-
     let mut vm = VM {
-        frames: vec![frame],
+        frames: vec![],
         stack: vec![],
         with_stack: vec![],
     };
 
+    vm.call(lambda);
     vm.run()
 }