- Adjust Environment to use BoundNode for the function registry and
correctly initialize the `TypeChecker` with argument types during macro expansion. - Refactor `Specializer::compile` to perform type checking with provided arguments before specialization and to correctly extract the return type. - Enhance the `Dumper` to introspect and display specialized closure bodies. - Update `LambdaCollector` to use `BoundNode` consistently. - Modify `TypeChecker` to accept and inject specialized argument types for lambdas.
This commit is contained in:
@@ -1,21 +1,20 @@
|
||||
use std::collections::HashMap;
|
||||
use crate::ast::compiler::TypedNode;
|
||||
use crate::ast::compiler::bound_nodes::{BoundKind, Address};
|
||||
use crate::ast::compiler::bound_nodes::{BoundKind, Address, BoundNode};
|
||||
|
||||
/// 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> {
|
||||
registry: &'a mut HashMap<u32, TypedNode>,
|
||||
registry: &'a mut HashMap<u32, BoundNode>,
|
||||
}
|
||||
|
||||
impl<'a> LambdaCollector<'a> {
|
||||
/// Performs a full traversal of the AST and populates the provided registry.
|
||||
pub fn collect(node: &TypedNode, registry: &'a mut HashMap<u32, TypedNode>) {
|
||||
pub fn collect(node: &BoundNode, registry: &'a mut HashMap<u32, BoundNode>) {
|
||||
let mut collector = Self { registry };
|
||||
collector.visit(node);
|
||||
}
|
||||
|
||||
fn visit(&mut self, node: &TypedNode) {
|
||||
fn visit(&mut self, node: &BoundNode) {
|
||||
match &node.kind {
|
||||
BoundKind::Block { exprs } => {
|
||||
for expr in exprs {
|
||||
@@ -50,8 +49,6 @@ impl<'a> LambdaCollector<'a> {
|
||||
}
|
||||
|
||||
BoundKind::Lambda { body, .. } => {
|
||||
// Nested functions are not yet supported for global specialization
|
||||
// but we traverse them to find potential global definitions inside (if allowed).
|
||||
self.visit(body);
|
||||
}
|
||||
|
||||
@@ -83,7 +80,7 @@ impl<'a> LambdaCollector<'a> {
|
||||
self.visit(bound_expanded);
|
||||
}
|
||||
|
||||
_ => {} // Leaf nodes (Constant, Get, Nop, etc.)
|
||||
_ => {} // Leaf nodes
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user