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
+9
View File
@@ -123,6 +123,15 @@ impl<'a> Analyzer<'a> {
(BoundKind::Call { callee: Box::new(callee_m), args: Box::new(args_m) }, p)
}
BoundKind::Again { args } => {
let args_m = self.visit(Rc::new((**args).clone()));
if let Some(lambda_id) = self.lambda_stack.last() {
self.recursive_identities.insert(lambda_id.clone());
is_recursive = true;
}
(BoundKind::Again { args: Box::new(args_m) }, Purity::Impure)
}
BoundKind::Block { exprs } => {
let mut new_exprs = Vec::with_capacity(exprs.len());
let mut p = Purity::Pure;