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-26T23·15+0300
committertazjin <tazjin@tvl.su>2022-09-03T21·55+0000
commit0f06d0ca333d879f914fb6f8e0803a9d5acd3d03 (patch)
treea173232ffa93b0dbf4eeb90b586590943f7ac889 /tvix/eval/src/vm.rs
parent3d8888a13e20954f608dc0622ca04fe9abd10149 (diff)
feat(tvix/eval): implement OpGetUpvalue in the VM r/4628
This resolves an upvalue at runtime by pushing it on the stack from
the closure's upvalue vector.

Change-Id: Ic3e7a7ecd9f7032f679114a1995e5bbf83062fcf
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6294
Tested-by: BuildkiteCI
Reviewed-by: grfn <grfn@gws.fyi>
Diffstat (limited to 'tvix/eval/src/vm.rs')
-rw-r--r--tvix/eval/src/vm.rs10
1 files changed, 6 insertions, 4 deletions
diff --git a/tvix/eval/src/vm.rs b/tvix/eval/src/vm.rs
index 1429169efc..58345ca7cc 100644
--- a/tvix/eval/src/vm.rs
+++ b/tvix/eval/src/vm.rs
@@ -6,7 +6,7 @@ use std::rc::Rc;
 use crate::{
     chunk::Chunk,
     errors::{ErrorKind, EvalResult},
-    opcode::{Count, JumpOffset, OpCode, StackIdx},
+    opcode::{Count, JumpOffset, OpCode, StackIdx, UpvalueIdx},
     value::{Closure, Lambda, NixAttrs, NixList, Value},
 };
 
@@ -320,8 +320,7 @@ impl VM {
 
                 OpCode::OpGetLocal(StackIdx(local_idx)) => {
                     let idx = self.frame().stack_offset + local_idx;
-                    let value = self.stack[idx].clone();
-                    self.push(value)
+                    self.push(self.stack[idx].clone());
                 }
 
                 OpCode::OpPushWith(StackIdx(idx)) => self.with_stack.push(idx),
@@ -367,8 +366,11 @@ impl VM {
                     };
                 }
 
-                OpCode::OpGetUpvalue(_) => todo!("getting upvalues"),
                 OpCode::OpClosure(_) => todo!("creating closure objects"),
+                OpCode::OpGetUpvalue(UpvalueIdx(upv_idx)) => {
+                    let value = self.frame().closure.upvalues[upv_idx].clone();
+                    self.push(value);
+                }
 
                 // Data-carrying operands should never be executed,
                 // that is a critical error in the VM.