Refactor: Replace UntypedNode with SyntaxNode

This commit replaces the `UntypedNode` enum with the more accurately
named `SyntaxNode`. This change is primarily for clarity and better
reflects the role of these nodes as representing the structure of the
source code prior to semantic analysis.

The corresponding enum `UntypedKind` has also been renamed to
`SyntaxKind` to maintain consistency.

No functional changes are introduced by this refactoring; it is purely a
renaming and organizational update.
This commit is contained in:
Michael Schimmel
2026-03-13 14:21:28 +01:00
parent 7d72a99fa1
commit 84226f6a16
31 changed files with 8611 additions and 8611 deletions
+99 -99
View File
@@ -1,99 +1,99 @@
use crate::ast::compiler::bound_nodes::{Address, BoundKind, 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>>>,
}
impl<'a, T: Clone> LambdaCollector<'a, T> {
/// 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>>>) {
let mut collector = Self { registry };
collector.visit(node);
}
fn visit(&mut self, node: &Node<T>) {
match &node.kind {
BoundKind::Block { exprs } => {
for expr in exprs {
self.visit(expr);
}
}
BoundKind::Define { addr, value, .. } => {
// Register global function definitions (lambdas)
if let Address::Global(global_index) = addr {
let mut current = value;
while let BoundKind::Expansion { bound_expanded, .. } = &current.kind {
current = bound_expanded;
}
if let BoundKind::Lambda { .. } = &current.kind {
self.registry
.insert(*global_index, (*current).clone());
}
}
self.visit(value);
}
BoundKind::Set { addr, value } => {
// Also track assignments to globals if they hold lambdas.
if let Address::Global(global_index) = addr {
let mut current = value;
while let BoundKind::Expansion { bound_expanded, .. } = &current.kind {
current = bound_expanded;
}
if let BoundKind::Lambda { .. } = &current.kind {
self.registry
.insert(*global_index, (*current).clone());
}
}
self.visit(value);
}
BoundKind::If {
cond,
then_br,
else_br,
} => {
self.visit(cond);
self.visit(then_br);
if let Some(e) = else_br {
self.visit(e);
}
}
BoundKind::Lambda { params, body, .. } => {
self.visit(params);
self.visit(body);
}
BoundKind::Call { callee, args } => {
self.visit(callee);
self.visit(args);
}
BoundKind::Tuple { elements } => {
for el in elements {
self.visit(el);
}
}
BoundKind::Record { values, .. } => {
for v in values {
self.visit(v);
}
}
BoundKind::Expansion { bound_expanded, .. } => {
self.visit(bound_expanded);
}
_ => {} // Leaf nodes
}
}
}
use crate::ast::compiler::bound_nodes::{Address, BoundKind, 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>>>,
}
impl<'a, T: Clone> LambdaCollector<'a, T> {
/// 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>>>) {
let mut collector = Self { registry };
collector.visit(node);
}
fn visit(&mut self, node: &Node<T>) {
match &node.kind {
BoundKind::Block { exprs } => {
for expr in exprs {
self.visit(expr);
}
}
BoundKind::Define { addr, value, .. } => {
// Register global function definitions (lambdas)
if let Address::Global(global_index) = addr {
let mut current = value;
while let BoundKind::Expansion { bound_expanded, .. } = &current.kind {
current = bound_expanded;
}
if let BoundKind::Lambda { .. } = &current.kind {
self.registry
.insert(*global_index, (*current).clone());
}
}
self.visit(value);
}
BoundKind::Set { addr, value } => {
// Also track assignments to globals if they hold lambdas.
if let Address::Global(global_index) = addr {
let mut current = value;
while let BoundKind::Expansion { bound_expanded, .. } = &current.kind {
current = bound_expanded;
}
if let BoundKind::Lambda { .. } = &current.kind {
self.registry
.insert(*global_index, (*current).clone());
}
}
self.visit(value);
}
BoundKind::If {
cond,
then_br,
else_br,
} => {
self.visit(cond);
self.visit(then_br);
if let Some(e) = else_br {
self.visit(e);
}
}
BoundKind::Lambda { params, body, .. } => {
self.visit(params);
self.visit(body);
}
BoundKind::Call { callee, args } => {
self.visit(callee);
self.visit(args);
}
BoundKind::Tuple { elements } => {
for el in elements {
self.visit(el);
}
}
BoundKind::Record { values, .. } => {
for v in values {
self.visit(v);
}
}
BoundKind::Expansion { bound_expanded, .. } => {
self.visit(bound_expanded);
}
_ => {} // Leaf nodes
}
}
}