Extract calculate_stack_size to a standalone function

The `calculate_stack_size` method was duplicated in `bound_nodes.rs` and
`tco.rs`. This commit extracts it into a single standalone function in
`tco.rs` to avoid duplication. The stack size is now calculated and
stored in the `ExecNode`'s `ty` field during the TCO optimization phase.
This commit is contained in:
Michael Schimmel
2026-03-11 10:35:18 +01:00
parent 3657f19047
commit db26719cad
4 changed files with 106 additions and 119 deletions
+3 -4
View File
@@ -141,8 +141,8 @@ impl VM {
}
}
pub fn run(&mut self, root: &ExecNode, stack_size: u32) -> Result<Value, String> {
self.run_with_observer(&mut NoOpObserver, root, stack_size)
pub fn run(&mut self, root: &ExecNode) -> Result<Value, String> {
self.run_with_observer(&mut NoOpObserver, root)
}
pub fn resolve_tail_calls<O: VMObserver>(
@@ -263,12 +263,11 @@ impl VM {
&mut self,
observer: &mut O,
root: &ExecNode,
stack_size: u32,
) -> Result<Value, String> {
self.stack.clear();
self.frames.clear();
self.stack.resize(stack_size as usize, Value::Void);
self.stack.resize(root.ty.stack_size as usize, Value::Void);
self.frames.push(CallFrame {
stack_base: 0,