From 01b51edcc7a7d03677cf09bc4f88355dd6f7781a Mon Sep 17 00:00:00 2001 From: microproofs Date: Wed, 6 Sep 2023 22:13:36 -0400 Subject: [PATCH] add new enum for hoistablefunctions --- crates/aiken-lang/src/gen_uplc.rs | 35 ++++++++++++++++++++++- crates/aiken-lang/src/gen_uplc/builder.rs | 4 +++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/crates/aiken-lang/src/gen_uplc.rs b/crates/aiken-lang/src/gen_uplc.rs index eabba08f0..a375b6441 100644 --- a/crates/aiken-lang/src/gen_uplc.rs +++ b/crates/aiken-lang/src/gen_uplc.rs @@ -2619,7 +2619,7 @@ impl<'a> CodeGenerator<'a> { }; } HoistableFunction::Link(_) => todo!("Deal with Link later"), - HoistableFunction::CyclicLink(_) => unreachable!(), + _ => unreachable!(), } } validator_hoistable.dedup(); @@ -2685,8 +2685,40 @@ impl<'a> CodeGenerator<'a> { function_name: format!("__cyclic_function_{}", index), module_name: "".to_string(), }; + + let (functions, mut deps) = function_names + .into_iter() + .map(|(func_key, variant)| { + let (_, func) = functions_to_hoist + .get(func_key) + .expect("Missing Function Definition") + .get(variant) + .expect("Missing Function Variant Definition"); + + match func { + HoistableFunction::Function { body, deps, params } => { + (params.clone(), body.clone(), deps.clone()) + } + + _ => unreachable!(), + } + }) + .fold((vec![], vec![]), |mut acc, f| { + acc.0.push((f.0, f.1)); + + acc.1.push(f.2); + + acc + }); + + let cyclic_function = HoistableFunction::CyclicFunction { + functions, + deps: deps.into_iter().flatten().dedup().collect_vec(), + }; } + todo!(); + // Rest of code is for hoisting functions let mut sorted_function_vec = vec![]; @@ -2736,6 +2768,7 @@ impl<'a> CodeGenerator<'a> { } HoistableFunction::Link(_) => todo!("Deal with Link later"), HoistableFunction::CyclicLink(_) => {} + HoistableFunction::CyclicFunction { functions, deps } => todo!(), } sorted_function_vec.push((generic_func, variant)); diff --git a/crates/aiken-lang/src/gen_uplc/builder.rs b/crates/aiken-lang/src/gen_uplc/builder.rs index eab0c0c0e..3c07e30fb 100644 --- a/crates/aiken-lang/src/gen_uplc/builder.rs +++ b/crates/aiken-lang/src/gen_uplc/builder.rs @@ -45,6 +45,10 @@ pub enum HoistableFunction { deps: Vec<(FunctionAccessKey, String)>, params: Vec, }, + CyclicFunction { + functions: Vec<(Vec, AirTree)>, + deps: Vec<(FunctionAccessKey, String)>, + }, Link((FunctionAccessKey, String)), CyclicLink((FunctionAccessKey, String)), }