Refactor Binder to use simpler types

The Binder has been refactored to simplify its internal types and reduce
redundancy.
Key changes include:
- Removed StaticType from LocalInfo, as it's not strictly needed for the
  binder.
- Simplified `define` in CompilerScope to not take a StaticType.
- Removed StaticType from upvalues in FunctionCompiler.
- Adjusted global mappings to store only the index, not the type.
- Updated BoundKind to use a generic type parameter `T` for metadata,
  defaulting to `()` for untyped bound nodes.
- Introduced `BoundNode` and `TypedNode` type aliases for clarity.
- Minor adjustments to dumper and VM to accommodate the new generic
  BoundKind.
This commit is contained in:
Michael Schimmel
2026-02-19 12:07:28 +01:00
parent c49561255e
commit 4673ea78b9
7 changed files with 130 additions and 176 deletions
+9 -5
View File
@@ -1,6 +1,6 @@
use crate::ast::nodes::Node;
use crate::ast::compiler::bound_nodes::BoundKind;
use crate::ast::types::StaticType;
use std::fmt::Debug;
/// Human-readable AST dumper for the bound AST.
pub struct Dumper {
@@ -10,7 +10,7 @@ pub struct Dumper {
impl Dumper {
/// Produces a formatted string representation of the given bound AST node and its children.
pub fn dump(node: &Node<BoundKind, StaticType>) -> String {
pub fn dump<T: Debug>(node: &Node<BoundKind<T>, T>) -> String {
let mut dumper = Self {
output: String::new(),
indent: 0,
@@ -25,13 +25,13 @@ impl Dumper {
}
}
fn log(&mut self, label: &str, node: &Node<BoundKind, StaticType>) {
fn log<T: Debug>(&mut self, label: &str, node: &Node<BoundKind<T>, T>) {
self.write_indent();
self.output.push_str(label);
self.output.push_str(&format!(" <Type: {:?}>\n", node.ty));
self.output.push_str(&format!(" <Metadata: {:?}>\n", node.ty));
}
fn visit(&mut self, node: &Node<BoundKind, StaticType>) {
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),
@@ -156,6 +156,10 @@ impl Dumper {
self.visit(bound_expanded);
self.indent -= 1;
}
BoundKind::Extension(ext) => {
self.log(&ext.display_name(), node);
}
}
}
}