diff options
author | Vincent Ambo <mail@tazj.in> | 2022-08-26T23·13+0300 |
---|---|---|
committer | tazjin <tazjin@tvl.su> | 2022-09-03T21·55+0000 |
commit | 3d8888a13e20954f608dc0622ca04fe9abd10149 (patch) | |
tree | 90c7849dd9abb1a77db18f7a1bf73e3bef72a916 | |
parent | 5ecf573dffc581e7842263f674ef43a66a2ba900 (diff) |
refactor(tvix/eval): store Closure inside of the VM's call frames r/4627
In preparation for implementing calling of closures, store a closure directly in the VMs call frame. Change-Id: Iad24cd8c49fee4ebd4d0c84ffaa4c2505ee3dfd6 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6293 Tested-by: BuildkiteCI Reviewed-by: grfn <grfn@gws.fyi>
-rw-r--r-- | tvix/eval/src/vm.rs | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/tvix/eval/src/vm.rs b/tvix/eval/src/vm.rs index 5ebc95e7f15e..1429169efc13 100644 --- a/tvix/eval/src/vm.rs +++ b/tvix/eval/src/vm.rs @@ -14,7 +14,7 @@ use crate::{ use crate::disassembler::Tracer; struct CallFrame { - lambda: Lambda, + closure: Closure, ip: usize, stack_offset: usize, } @@ -86,7 +86,7 @@ impl VM { } fn chunk(&self) -> &Chunk { - &self.frame().lambda.chunk + &self.frame().closure.lambda.chunk } fn frame_mut(&mut self) -> &mut CallFrame { @@ -112,9 +112,9 @@ impl VM { &self.stack[self.stack.len() - 1 - offset] } - fn call(&mut self, lambda: Lambda, arg_count: usize) { + fn call(&mut self, closure: Closure, arg_count: usize) { let frame = CallFrame { - lambda, + closure, ip: 0, stack_offset: self.stack.len() - arg_count, }; @@ -357,7 +357,7 @@ impl VM { OpCode::OpCall => { let callable = self.pop(); match callable { - Value::Closure(Closure { lambda, .. }) => self.call(lambda, 1), + Value::Closure(closure) => self.call(closure, 1), Value::Builtin(builtin) => { let arg = self.pop(); let result = builtin.apply(arg)?; @@ -436,6 +436,6 @@ pub fn run_lambda(lambda: Lambda) -> EvalResult<Value> { with_stack: vec![], }; - vm.call(lambda, 0); + vm.call(Closure::new(lambda), 0); vm.run() } |