Add 'again' keyword for recursive calls

The `again` keyword is introduced to facilitate explicit recursive
function calls.
It is restricted to tail-call positions to prevent dead code and ensure
TCO
optimization. Type checking is enhanced to validate argument types
against
function parameters.
This commit is contained in:
Michael Schimmel
2026-02-23 20:33:50 +01:00
parent be7ce31408
commit 4905b08548
13 changed files with 147 additions and 0 deletions
+6
View File
@@ -96,6 +96,10 @@ pub enum BoundKind<T = ()> {
args: Box<BoundNode<T>>,
},
Again {
args: Box<BoundNode<T>>,
},
Block {
exprs: Vec<BoundNode<T>>,
},
@@ -207,6 +211,7 @@ where
args: ab,
},
) => ca == cb && aa == ab,
(BoundKind::Again { args: aa }, BoundKind::Again { args: ab }) => aa == ab,
(BoundKind::Block { exprs: ea }, BoundKind::Block { exprs: eb }) => ea == eb,
(BoundKind::Tuple { elements: ea }, BoundKind::Tuple { elements: eb }) => ea == eb,
(BoundKind::Record { fields: fa }, BoundKind::Record { fields: fb }) => fa == fb,
@@ -254,6 +259,7 @@ impl<T> BoundKind<T> {
format!("LAMBDA({}, Captures:{})", p_str, upvalues.len())
}
BoundKind::Call { .. } => "CALL".to_string(),
BoundKind::Again { .. } => "AGAIN".to_string(),
BoundKind::Block { .. } => "BLOCK".to_string(),
BoundKind::Tuple { elements } => format!("TUPLE({})", elements.len()),
BoundKind::Record { fields } => format!("RECORD({})", fields.len()),