diff --git a/crates/aiken-lang/src/gen_uplc.rs b/crates/aiken-lang/src/gen_uplc.rs index 3b28c6e4..37da2f0b 100644 --- a/crates/aiken-lang/src/gen_uplc.rs +++ b/crates/aiken-lang/src/gen_uplc.rs @@ -2823,6 +2823,7 @@ impl<'a> CodeGenerator<'a> { *dep_path = func_tree_path.common_ancestor(dep_path); } + sorted_function_vec.push((generic_func, variant)); } HoistableFunction::Link(_) => todo!("Deal with Link later"), HoistableFunction::CyclicLink(cyclic_name) => { @@ -2876,10 +2877,10 @@ impl<'a> CodeGenerator<'a> { *dep_path = func_tree_path.common_ancestor(dep_path); } + sorted_function_vec.push((generic_func, variant)); } } - sorted_function_vec.push((generic_func, variant)); sorting_attempts += 1; } sorted_function_vec.dedup(); @@ -3083,6 +3084,7 @@ impl<'a> CodeGenerator<'a> { } } } + sorted_dep_vec.push((dep.0.clone(), dep.1.clone())); } HoistableFunction::CyclicFunction { deps, .. } => { for (dep_generic_func, dep_variant) in deps.iter() { @@ -3094,6 +3096,7 @@ impl<'a> CodeGenerator<'a> { deps_vec.insert(0, (dep_generic_func.clone(), dep_variant.clone())); } } + sorted_dep_vec.push((dep.0.clone(), dep.1.clone())); } HoistableFunction::Link(_) => todo!("Deal with Link later"), HoistableFunction::CyclicLink(cyclic_func) => { @@ -3117,8 +3120,6 @@ impl<'a> CodeGenerator<'a> { } } } - - sorted_dep_vec.push((dep.0.clone(), dep.1.clone())); } sorted_dep_vec.dedup(); diff --git a/crates/aiken-lang/src/gen_uplc/builder.rs b/crates/aiken-lang/src/gen_uplc/builder.rs index d7a05291..ef2b6804 100644 --- a/crates/aiken-lang/src/gen_uplc/builder.rs +++ b/crates/aiken-lang/src/gen_uplc/builder.rs @@ -779,13 +779,35 @@ pub fn modify_cyclic_calls( cyclic_links.get(&(var_key.clone(), variant_name.to_string())) { if *cyclic_name == *func_key { + let cyclic_var_name = if cyclic_name.module_name.is_empty() { + cyclic_name.function_name.to_string() + } else { + format!("{}_{}", cyclic_name.module_name, cyclic_name.function_name) + }; + let index_name = names[*index].clone(); + let var = AirTree::var( + ValueConstructor::public( + tipo.clone(), + ValueConstructorVariant::ModuleFn { + name: cyclic_var_name.clone(), + field_map: None, + module: "".to_string(), + arity: 2, + location: Span::empty(), + builtin: None, + }, + ), + cyclic_var_name, + "".to_string(), + ); + *air_tree = AirTree::call( - air_tree.clone(), + var.clone(), tipo.clone(), vec![ - air_tree.clone(), + var, AirTree::anon_func( names.clone(), AirTree::local_var(index_name, tipo),