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
+154 -154
View File
@@ -1,154 +1,154 @@
use crate::ast::compiler::bound_nodes::{BoundKind, Node};
use crate::ast::types::Identity;
use std::collections::HashMap;
pub struct CapturePass;
impl CapturePass {
pub fn apply<T: Clone>(node: Node<T>, capture_map: &HashMap<Identity, Vec<Identity>>) -> Node<T> {
Self::transform(node, capture_map)
}
fn transform<T: Clone>(mut node: Node<T>, capture_map: &HashMap<Identity, Vec<Identity>>) -> Node<T> {
use std::rc::Rc;
match node.kind {
BoundKind::Define {
name,
addr,
kind,
value,
..
} => {
let captured_by = capture_map.get(&node.identity).cloned().unwrap_or_default();
node.kind = BoundKind::Define {
name,
addr,
kind,
value: Rc::new(Self::transform(value.as_ref().clone(), capture_map)),
captured_by,
};
}
BoundKind::If {
cond,
then_br,
else_br,
} => {
node.kind = BoundKind::If {
cond: Rc::new(Self::transform(cond.as_ref().clone(), capture_map)),
then_br: Rc::new(Self::transform(then_br.as_ref().clone(), capture_map)),
else_br: else_br.map(|e| Rc::new(Self::transform(e.as_ref().clone(), capture_map))),
};
}
BoundKind::Set { addr, value } => {
node.kind = BoundKind::Set {
addr,
value: Rc::new(Self::transform(value.as_ref().clone(), capture_map)),
};
}
BoundKind::FieldAccessor(_) => {}
BoundKind::GetField { rec, field } => {
node.kind = BoundKind::GetField {
rec: Rc::new(Self::transform(rec.as_ref().clone(), capture_map)),
field,
};
}
BoundKind::Destructure { pattern, value } => {
node.kind = BoundKind::Destructure {
pattern: Rc::new(Self::transform(pattern.as_ref().clone(), capture_map)),
value: Rc::new(Self::transform(value.as_ref().clone(), capture_map)),
};
}
BoundKind::Lambda {
params,
upvalues,
body,
positional_count,
} => {
node.kind = BoundKind::Lambda {
params: Rc::new(Self::transform(params.as_ref().clone(), capture_map)),
upvalues,
body: Rc::new(Self::transform(body.as_ref().clone(), capture_map)),
positional_count,
};
}
BoundKind::Call { callee, args } => {
node.kind = BoundKind::Call {
callee: Rc::new(Self::transform(callee.as_ref().clone(), capture_map)),
args: Rc::new(Self::transform(args.as_ref().clone(), capture_map)),
};
}
BoundKind::Again { args } => {
node.kind = BoundKind::Again {
args: Rc::new(Self::transform(args.as_ref().clone(), capture_map)),
};
}
BoundKind::Pipe {
inputs,
lambda,
out_type,
} => {
let mut t_inputs = Vec::with_capacity(inputs.len());
for input in inputs {
t_inputs.push(Rc::new(Self::transform(input.as_ref().clone(), capture_map)));
}
node.kind = BoundKind::Pipe {
inputs: t_inputs,
lambda: Rc::new(Self::transform(lambda.as_ref().clone(), capture_map)),
out_type: out_type.clone(),
};
}
BoundKind::Block { exprs } => {
node.kind = BoundKind::Block {
exprs: exprs
.into_iter()
.map(|e| Rc::new(Self::transform(e.as_ref().clone(), capture_map)))
.collect(),
};
}
BoundKind::Tuple { elements } => {
node.kind = BoundKind::Tuple {
elements: elements
.into_iter()
.map(|e| Rc::new(Self::transform(e.as_ref().clone(), capture_map)))
.collect(),
};
}
BoundKind::Record { layout, values } => {
node.kind = BoundKind::Record {
layout,
values: values
.into_iter()
.map(|v| Rc::new(Self::transform(v.as_ref().clone(), capture_map)))
.collect(),
};
}
BoundKind::Expansion {
original_call,
bound_expanded,
} => {
node.kind = BoundKind::Expansion {
original_call,
bound_expanded: Rc::new(Self::transform(bound_expanded.as_ref().clone(), capture_map)),
};
}
BoundKind::Nop
| BoundKind::Constant(_)
| BoundKind::Get { .. }
| BoundKind::Extension(_)
| BoundKind::Error => {}
}
node
}
}
use crate::ast::compiler::bound_nodes::{BoundKind, Node};
use crate::ast::types::Identity;
use std::collections::HashMap;
pub struct CapturePass;
impl CapturePass {
pub fn apply<T: Clone>(node: Node<T>, capture_map: &HashMap<Identity, Vec<Identity>>) -> Node<T> {
Self::transform(node, capture_map)
}
fn transform<T: Clone>(mut node: Node<T>, capture_map: &HashMap<Identity, Vec<Identity>>) -> Node<T> {
use std::rc::Rc;
match node.kind {
BoundKind::Define {
name,
addr,
kind,
value,
..
} => {
let captured_by = capture_map.get(&node.identity).cloned().unwrap_or_default();
node.kind = BoundKind::Define {
name,
addr,
kind,
value: Rc::new(Self::transform(value.as_ref().clone(), capture_map)),
captured_by,
};
}
BoundKind::If {
cond,
then_br,
else_br,
} => {
node.kind = BoundKind::If {
cond: Rc::new(Self::transform(cond.as_ref().clone(), capture_map)),
then_br: Rc::new(Self::transform(then_br.as_ref().clone(), capture_map)),
else_br: else_br.map(|e| Rc::new(Self::transform(e.as_ref().clone(), capture_map))),
};
}
BoundKind::Set { addr, value } => {
node.kind = BoundKind::Set {
addr,
value: Rc::new(Self::transform(value.as_ref().clone(), capture_map)),
};
}
BoundKind::FieldAccessor(_) => {}
BoundKind::GetField { rec, field } => {
node.kind = BoundKind::GetField {
rec: Rc::new(Self::transform(rec.as_ref().clone(), capture_map)),
field,
};
}
BoundKind::Destructure { pattern, value } => {
node.kind = BoundKind::Destructure {
pattern: Rc::new(Self::transform(pattern.as_ref().clone(), capture_map)),
value: Rc::new(Self::transform(value.as_ref().clone(), capture_map)),
};
}
BoundKind::Lambda {
params,
upvalues,
body,
positional_count,
} => {
node.kind = BoundKind::Lambda {
params: Rc::new(Self::transform(params.as_ref().clone(), capture_map)),
upvalues,
body: Rc::new(Self::transform(body.as_ref().clone(), capture_map)),
positional_count,
};
}
BoundKind::Call { callee, args } => {
node.kind = BoundKind::Call {
callee: Rc::new(Self::transform(callee.as_ref().clone(), capture_map)),
args: Rc::new(Self::transform(args.as_ref().clone(), capture_map)),
};
}
BoundKind::Again { args } => {
node.kind = BoundKind::Again {
args: Rc::new(Self::transform(args.as_ref().clone(), capture_map)),
};
}
BoundKind::Pipe {
inputs,
lambda,
out_type,
} => {
let mut t_inputs = Vec::with_capacity(inputs.len());
for input in inputs {
t_inputs.push(Rc::new(Self::transform(input.as_ref().clone(), capture_map)));
}
node.kind = BoundKind::Pipe {
inputs: t_inputs,
lambda: Rc::new(Self::transform(lambda.as_ref().clone(), capture_map)),
out_type: out_type.clone(),
};
}
BoundKind::Block { exprs } => {
node.kind = BoundKind::Block {
exprs: exprs
.into_iter()
.map(|e| Rc::new(Self::transform(e.as_ref().clone(), capture_map)))
.collect(),
};
}
BoundKind::Tuple { elements } => {
node.kind = BoundKind::Tuple {
elements: elements
.into_iter()
.map(|e| Rc::new(Self::transform(e.as_ref().clone(), capture_map)))
.collect(),
};
}
BoundKind::Record { layout, values } => {
node.kind = BoundKind::Record {
layout,
values: values
.into_iter()
.map(|v| Rc::new(Self::transform(v.as_ref().clone(), capture_map)))
.collect(),
};
}
BoundKind::Expansion {
original_call,
bound_expanded,
} => {
node.kind = BoundKind::Expansion {
original_call,
bound_expanded: Rc::new(Self::transform(bound_expanded.as_ref().clone(), capture_map)),
};
}
BoundKind::Nop
| BoundKind::Constant(_)
| BoundKind::Get { .. }
| BoundKind::Extension(_)
| BoundKind::Error => {}
}
node
}
}