refactor(tvix/eval): add VM::call helper to set up call frames

Change-Id: Ia7ff572af90ae379b23bbd0f5215cd13a4dc0ab5
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6248
Reviewed-by: grfn <grfn@gws.fyi>
Reviewed-by: sterni <sternenseemann@systemli.org>
Tested-by: BuildkiteCI
This commit is contained in:
Vincent Ambo 2022-08-24 02:09:46 +03:00 committed by tazjin
parent 269788086e
commit fc892b7a9d

View file

@ -112,6 +112,16 @@ impl VM {
&self.stack[self.stack.len() - 1 - offset]
}
fn call(&mut self, lambda: Lambda) {
let frame = CallFrame {
lambda,
ip: 0,
stack_offset: self.stack.len(),
};
self.frames.push(frame);
}
fn run(&mut self) -> EvalResult<Value> {
#[cfg(feature = "disassembler")]
let mut tracer = Tracer::new();
@ -384,17 +394,12 @@ impl VM {
}
pub fn run_lambda(lambda: Lambda) -> EvalResult<Value> {
let frame = CallFrame {
lambda,
ip: 0,
stack_offset: 0,
};
let mut vm = VM {
frames: vec![frame],
frames: vec![],
stack: vec![],
with_stack: vec![],
};
vm.call(lambda);
vm.run()
}