Refactor environment loading and program execution

The `preload_dependencies` function has been refactored to directly run
parsed programs instead of collecting all forms into a single `Program`
node. This simplifies the compilation pipeline by allowing each
dependency to be processed individually.

Additionally, the `VM::run_with_observer` method has been updated to
manage its stack and frames more cleanly, avoiding the need for
`eval_in_frame`. The main loop now correctly extracts expressions from
the `Program` node for source code emission.
This commit is contained in:
2026-03-31 13:59:28 +02:00
parent 02ea2f0d80
commit 8fd2f2d113
4 changed files with 54 additions and 53 deletions
+10 -14
View File
@@ -266,27 +266,23 @@ impl VM {
self.resolve_tail_calls(observer, result)
}
pub fn eval_in_frame<O: VMObserver>(&mut self, observer: &mut O, root: &ExecNode, stack: Vec<Value>) -> Result<Value, String> {
self.stack = stack;
self.frames.clear();
self.frames.push(CallFrame {
stack_base: 0,
closure: None,
});
let result = self.eval_internal(observer, root);
self.frames.pop();
result
}
pub fn run_with_observer<O: VMObserver>(
&mut self,
observer: &mut O,
root: &ExecNode,
) -> Result<Value, String> {
let mut stack = Vec::new();
stack.resize(root.ty.stack_size as usize, Value::Void);
self.stack.clear();
self.frames.clear();
let result = self.eval_in_frame(observer, root, stack);
self.stack.resize(root.ty.stack_size as usize, Value::Void);
self.frames.push(CallFrame {
stack_base: 0,
closure: None,
});
let result = self.eval_internal(observer, root);
self.frames.pop();
self.resolve_tail_calls(observer, result)
}