From 025a9a4a0a66c8593cd6b7e4b0f0fa7aea84c353 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Sun, 28 Aug 2022 17:28:20 +0300 Subject: feat(tvix/eval): implement OpFinalise instruction This instruction finalises the initialisation of deferred upvalues in closures (and soon, thunks). The compiler does not yet emit this instruction, some more accounting is needed for that. Change-Id: Ic4181b26e19779e206f51e17388559400da5f93a Reviewed-on: https://cl.tvl.fyi/c/depot/+/6337 Tested-by: BuildkiteCI Reviewed-by: sterni --- tvix/eval/src/value/function.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'tvix/eval/src/value') diff --git a/tvix/eval/src/value/function.rs b/tvix/eval/src/value/function.rs index e5db43d58ace..e8301d82da11 100644 --- a/tvix/eval/src/value/function.rs +++ b/tvix/eval/src/value/function.rs @@ -60,4 +60,15 @@ impl Closure { pub fn push_upvalue(&self, value: Value) { self.0.borrow_mut().upvalues.push(value) } + + /// Resolve the deferred upvalues in the closure from a slice of + /// the current stack, using the indices stored in the deferred + /// values. + pub fn resolve_deferred_upvalues(&self, stack: &[Value]) { + for upvalue in self.0.borrow_mut().upvalues.iter_mut() { + if let Value::DeferredUpvalue(idx) = upvalue { + *upvalue = stack[idx.0].clone(); + } + } + } } -- cgit 1.4.1