- 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,5 +1,7 @@
|
||||
use crate::ast::nodes::Node;
|
||||
use crate::ast::compiler::bound_nodes::BoundKind;
|
||||
use crate::ast::types::Value;
|
||||
use crate::ast::vm::Closure;
|
||||
use std::fmt::Debug;
|
||||
|
||||
/// Human-readable AST dumper for the bound AST.
|
||||
@@ -34,7 +36,31 @@ impl Dumper {
|
||||
fn visit<T: Debug>(&mut self, node: &Node<BoundKind<T>, T>) {
|
||||
match &node.kind {
|
||||
BoundKind::Nop => self.log("Nop", node),
|
||||
BoundKind::Constant(v) => self.log(&format!("Constant: {}", v), node),
|
||||
BoundKind::Constant(v) => {
|
||||
self.log(&format!("Constant: {}", v), node);
|
||||
// Introspect Closure AST if possible
|
||||
if let Value::Object(obj) = v {
|
||||
if let Some(closure) = obj.as_any().downcast_ref::<Closure>() {
|
||||
self.indent += 1;
|
||||
self.write_indent();
|
||||
self.output.push_str("--- Specialized Body ---\n");
|
||||
// We need to cast the inner TypedNode to the generic T required by visit.
|
||||
// Since Dumper is generic over T, but Closure stores TypedNode (where T = StaticType),
|
||||
// we can only fully dump if T is StaticType.
|
||||
// However, we can hack it by creating a new Dumper for the inner AST string.
|
||||
|
||||
// We can't call self.visit because types mismatch if T != StaticType.
|
||||
// So we just recursively dump to string and append.
|
||||
let inner_dump = Dumper::dump(&closure.function_node);
|
||||
for line in inner_dump.lines() {
|
||||
self.write_indent();
|
||||
self.output.push_str(line);
|
||||
self.output.push('\n');
|
||||
}
|
||||
self.indent -= 1;
|
||||
}
|
||||
}
|
||||
},
|
||||
BoundKind::Get { addr, name } => self.log(&format!("Get: {} ({:?})", name.name, addr), node),
|
||||
|
||||
BoundKind::Set { addr, value } => {
|
||||
|
||||
Reference in New Issue
Block a user