Refactor bound node types for clarity

Introduce generic `CompilerPhase` trait to unify different stages of the
bound AST. Rename `LocalSlot` to `VirtualId` and introduce `StackOffset`
for clearer distinction between compile-time and run-time addressing.
Update type aliases and implementations to reflect these changes.
This commit is contained in:
Michael Schimmel
2026-03-13 19:20:44 +01:00
parent d035da9d91
commit e5d82ee2b6
15 changed files with 403 additions and 458 deletions
+6 -6
View File
@@ -1,21 +1,21 @@
use crate::ast::compiler::bound_nodes::{Address, BoundKind, GlobalIdx, Node};
use crate::ast::compiler::bound_nodes::{Address, BoundKind, CompilerPhase, GlobalIdx, Node};
use std::collections::HashMap;
use std::rc::Rc;
/// A pass that collects all global function definitions (lambdas) into a registry.
/// This allows the Specializer to retrieve the original AST of a function for monomorphization.
pub struct LambdaCollector<'a, T> {
registry: &'a mut HashMap<GlobalIdx, Rc<Node<T>>>,
pub struct LambdaCollector<'a, P: CompilerPhase> {
registry: &'a mut HashMap<GlobalIdx, Rc<Node<P>>>,
}
impl<'a, T: Clone> LambdaCollector<'a, T> {
impl<'a, P: CompilerPhase> LambdaCollector<'a, P> {
/// Performs a full traversal of the AST and populates the provided registry.
pub fn collect(node: &Node<T>, registry: &'a mut HashMap<GlobalIdx, Rc<Node<T>>>) {
pub fn collect(node: &Node<P>, registry: &'a mut HashMap<GlobalIdx, Rc<Node<P>>>) {
let mut collector = Self { registry };
collector.visit(node);
}
fn visit(&mut self, node: &Node<T>) {
fn visit(&mut self, node: &Node<P>) {
match &node.kind {
BoundKind::Block { exprs } => {
for expr in exprs {