Skip to content

Commit

Permalink
add new enum for hoistablefunctions
Browse files Browse the repository at this point in the history
  • Loading branch information
MicroProofs committed Sep 7, 2023
1 parent b93a3ee commit 01b51ed
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
35 changes: 34 additions & 1 deletion crates/aiken-lang/src/gen_uplc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2619,7 +2619,7 @@ impl<'a> CodeGenerator<'a> {
};
}
HoistableFunction::Link(_) => todo!("Deal with Link later"),
HoistableFunction::CyclicLink(_) => unreachable!(),
_ => unreachable!(),
}
}
validator_hoistable.dedup();
Expand Down Expand Up @@ -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![];

Expand Down Expand Up @@ -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));
Expand Down
4 changes: 4 additions & 0 deletions crates/aiken-lang/src/gen_uplc/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ pub enum HoistableFunction {
deps: Vec<(FunctionAccessKey, String)>,
params: Vec<String>,
},
CyclicFunction {
functions: Vec<(Vec<String>, AirTree)>,
deps: Vec<(FunctionAccessKey, String)>,
},
Link((FunctionAccessKey, String)),
CyclicLink((FunctionAccessKey, String)),
}
Expand Down

0 comments on commit 01b51ed

Please sign in to comment.