about summary refs log tree commit diff
path: root/tvix/eval/src/vm.rs
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2022-08-29T15·33+0300
committertazjin <tazjin@tvl.su>2022-09-07T15·25+0000
commit9a783e50a490a873f157ec298165b3f38973e4b5 (patch)
treec3e5362a04d51ce422c00255354916beb32f1faf /tvix/eval/src/vm.rs
parentdb9cb70d5d7807adff255e21a04d78c5700d1260 (diff)
feat(tvix/eval): implement OpForce in VM r/4688
This operation forces the evaluation of a thunk.

There is some potential here for making an implementation that avoids
some copies, but the thunk machinery is tricky to get right so the
first priority is to make sure it is correct by keeping the
implementation simple.

Change-Id: Ib381455b02f42ded717faff63f55afed4c8fb7e3
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6352
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
Diffstat (limited to 'tvix/eval/src/vm.rs')
-rw-r--r--tvix/eval/src/vm.rs12
1 files changed, 11 insertions, 1 deletions
diff --git a/tvix/eval/src/vm.rs b/tvix/eval/src/vm.rs
index e32c0d7f6b..c55bc81777 100644
--- a/tvix/eval/src/vm.rs
+++ b/tvix/eval/src/vm.rs
@@ -136,7 +136,7 @@ impl VM {
         self.frames.push(frame);
     }
 
-    fn run(&mut self) -> EvalResult<Value> {
+    pub fn run(&mut self) -> EvalResult<Value> {
         #[cfg(feature = "disassembler")]
         let mut tracer = Tracer::new();
 
@@ -441,6 +441,16 @@ impl VM {
                     self.populate_upvalues(upvalue_count, upvalues)?;
                 }
 
+                OpCode::OpForce => {
+                    let mut value = self.pop();
+
+                    while let Value::Thunk(thunk) = value {
+                        value = thunk.force(self)?.clone();
+                    }
+
+                    self.push(value);
+                }
+
                 OpCode::OpFinalise(StackIdx(idx)) => {
                     match &self.stack[self.frame().stack_offset + idx] {
                         Value::Closure(closure) => closure