Refactor Call to include is_tail flag
The `TailCall` variant has been merged into `Call` by adding an `is_tail` boolean field. This simplifies the AST by reducing the number of node variants and makes it easier to handle tail call optimization. The `tco.rs` module is responsible for setting this flag when a call occurs in tail position.
This commit is contained in:
+8
-17
@@ -14,26 +14,17 @@ impl TCO {
|
||||
|
||||
fn transform<T: Clone>(node: Node<BoundKind<T>, T>, is_tail_position: bool) -> Node<BoundKind<T>, T> {
|
||||
match node.kind {
|
||||
BoundKind::Call { callee, args } => {
|
||||
BoundKind::Call { callee, args, .. } => {
|
||||
let new_callee = Box::new(Self::transform(*callee, false));
|
||||
let new_args = Box::new(Self::transform(*args, false));
|
||||
|
||||
if is_tail_position {
|
||||
Node {
|
||||
kind: BoundKind::TailCall {
|
||||
callee: new_callee,
|
||||
args: new_args,
|
||||
},
|
||||
..node
|
||||
}
|
||||
} else {
|
||||
Node {
|
||||
kind: BoundKind::Call {
|
||||
callee: new_callee,
|
||||
args: new_args,
|
||||
},
|
||||
..node
|
||||
}
|
||||
Node {
|
||||
kind: BoundKind::Call {
|
||||
callee: new_callee,
|
||||
args: new_args,
|
||||
is_tail: is_tail_position,
|
||||
},
|
||||
..node
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user