Refactor: Use generic Define bound kind
This commit consolidates `DefLocal` and `DefGlobal` into a single `Define` bound kind. This simplifies the AST and makes it more consistent. It also introduces `DeclarationKind` to differentiate between variable and parameter definitions.
This commit is contained in:
@@ -31,8 +31,8 @@ impl<'a> Analyzer<'a> {
|
||||
|
||||
fn collect_globals(&mut self, node: &TypedNode) {
|
||||
match &node.kind {
|
||||
BoundKind::DefGlobal {
|
||||
global_index,
|
||||
BoundKind::Define {
|
||||
addr: Address::Global(global_index),
|
||||
value,
|
||||
..
|
||||
} => {
|
||||
@@ -61,13 +61,6 @@ impl<'a> Analyzer<'a> {
|
||||
let (new_kind, purity) = match &node.kind {
|
||||
BoundKind::Constant(v) => (BoundKind::Constant(v.clone()), Purity::Pure),
|
||||
BoundKind::Nop => (BoundKind::Nop, Purity::Pure),
|
||||
BoundKind::Parameter { name, slot } => (
|
||||
BoundKind::Parameter {
|
||||
name: name.clone(),
|
||||
slot: *slot,
|
||||
},
|
||||
Purity::Pure,
|
||||
),
|
||||
|
||||
BoundKind::Get { addr, name } => {
|
||||
let p = match addr {
|
||||
@@ -96,18 +89,20 @@ impl<'a> Analyzer<'a> {
|
||||
)
|
||||
}
|
||||
|
||||
BoundKind::DefLocal {
|
||||
BoundKind::Define {
|
||||
name,
|
||||
slot,
|
||||
addr,
|
||||
kind,
|
||||
value,
|
||||
captured_by,
|
||||
} => {
|
||||
let val_m = self.visit(Rc::new((**value).clone()));
|
||||
let p = val_m.ty.purity;
|
||||
(
|
||||
BoundKind::DefLocal {
|
||||
BoundKind::Define {
|
||||
name: name.clone(),
|
||||
slot: *slot,
|
||||
addr: *addr,
|
||||
kind: *kind,
|
||||
value: Box::new(val_m),
|
||||
captured_by: captured_by.clone(),
|
||||
},
|
||||
@@ -115,23 +110,6 @@ impl<'a> Analyzer<'a> {
|
||||
)
|
||||
}
|
||||
|
||||
BoundKind::DefGlobal {
|
||||
name,
|
||||
global_index,
|
||||
value,
|
||||
} => {
|
||||
let val_m = self.visit(Rc::new((**value).clone()));
|
||||
let p = val_m.ty.purity;
|
||||
(
|
||||
BoundKind::DefGlobal {
|
||||
name: name.clone(),
|
||||
global_index: *global_index,
|
||||
value: Box::new(val_m),
|
||||
},
|
||||
p,
|
||||
)
|
||||
}
|
||||
|
||||
BoundKind::If {
|
||||
cond,
|
||||
then_br,
|
||||
@@ -327,9 +305,7 @@ impl NodeExt for BoundKind<crate::ast::types::StaticType> {
|
||||
f(e);
|
||||
}
|
||||
}
|
||||
BoundKind::DefLocal { value, .. }
|
||||
| BoundKind::DefGlobal { value, .. }
|
||||
| BoundKind::Set { value, .. } => {
|
||||
BoundKind::Define { value, .. } | BoundKind::Set { value, .. } => {
|
||||
f(value);
|
||||
}
|
||||
BoundKind::Lambda { params, body, .. } => {
|
||||
|
||||
Reference in New Issue
Block a user