From 0f06d0ca333d879f914fb6f8e0803a9d5acd3d03 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Sat, 27 Aug 2022 02:15:22 +0300 Subject: feat(tvix/eval): implement OpGetUpvalue in the VM 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 --- tvix/eval/src/vm.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'tvix') diff --git a/tvix/eval/src/vm.rs b/tvix/eval/src/vm.rs index 1429169efc13..58345ca7cc27 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. -- cgit 1.4.1