fix: mutually recursive zero arg functions needed to have their function bodies delayed

This commit is contained in:
microproofs 2024-03-09 10:04:30 -05:00
parent 7f0df40b4e
commit bffa678178
1 changed files with 7 additions and 3 deletions

View File

@ -4201,7 +4201,7 @@ impl<'a> CodeGenerator<'a> {
} }
} else if let Term::Apply { .. } = &term { } else if let Term::Apply { .. } = &term {
// Case for mutually recursive zero arg functions // Case for mutually recursive zero arg functions
Some(term) Some(term.force())
} else { } else {
unreachable!( unreachable!(
"Shouldn't call anything other than var or apply {:#?}", "Shouldn't call anything other than var or apply {:#?}",
@ -4493,9 +4493,13 @@ impl<'a> CodeGenerator<'a> {
for (params, func_body) in cyclic_functions.into_iter() { for (params, func_body) in cyclic_functions.into_iter() {
let mut function = func_body; let mut function = func_body;
if params.is_empty() {
function = function.delay();
} else {
for param in params.iter().rev() { for param in params.iter().rev() {
function = function.lambda(param); function = function.lambda(param);
} }
}
// We basically Scott encode our function bodies and use the chooser function // We basically Scott encode our function bodies and use the chooser function
// to determine which function body and params is run // to determine which function body and params is run