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:
+3
-4
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user