diff --git a/crates/aiken-lang/src/gen_uplc2.rs b/crates/aiken-lang/src/gen_uplc2.rs index b059f302..914e2d0e 100644 --- a/crates/aiken-lang/src/gen_uplc2.rs +++ b/crates/aiken-lang/src/gen_uplc2.rs @@ -1142,12 +1142,10 @@ impl<'a> CodeGenerator<'a> { builder::handle_clause_guard(guard), ); - clause_then = clause_guard_assign.hoist_over(AirTree::clause_guard( - clause_guard_name, - AirTree::bool(true), - bool(), - clause_then, - )); + clause_then = clause_guard_assign.hoist_over( + AirTree::clause_guard(clause_guard_name, AirTree::bool(true), bool()) + .hoist_over(clause_then), + ); } match &mut props.specific_clause { @@ -1423,12 +1421,8 @@ impl<'a> CodeGenerator<'a> { elem_name.clone(), ); - let statement = self.nested_clause_condition( - elem, - AirTree::local_var(&elem_name, list_elem_type.clone()), - list_elem_type, - &mut elem_props, - ); + let statement = + self.nested_clause_condition(elem, list_elem_type, &mut elem_props); *complex_clause = *complex_clause || elem_props.complex_clause; @@ -1472,12 +1466,8 @@ impl<'a> CodeGenerator<'a> { specific_clause: props.specific_clause.clone(), }; - let statement = self.nested_clause_condition( - elem, - AirTree::local_var(&elem_name, subject_tipo.clone()), - subject_tipo, - &mut elem_props, - ); + let statement = + self.nested_clause_condition(elem, subject_tipo, &mut elem_props); *complex_clause = *complex_clause || elem_props.complex_clause; air_elems.push(statement); @@ -1578,7 +1568,6 @@ impl<'a> CodeGenerator<'a> { let statement = self.nested_clause_condition( &arg.value, - AirTree::local_var(&field_name, arg_type.clone()), arg_type, &mut field_props, ); @@ -1622,20 +1611,24 @@ impl<'a> CodeGenerator<'a> { fn nested_clause_condition( &mut self, pattern: &Pattern>, - value: AirTree, subject_tipo: &Arc, props: &mut ClauseProperties, ) -> AirTree { match pattern { Pattern::Int { value, .. } => { - todo!(); + AirTree::clause_guard(&props.original_subject_name, AirTree::int(value), int()) } - Pattern::Var { location, name } => todo!(), + Pattern::Var { name, .. } => AirTree::let_assignment( + name, + AirTree::local_var(&props.clause_var_name, subject_tipo.clone()), + ), Pattern::Assign { name, location, pattern, - } => todo!(), + } => { + todo!(); + } Pattern::Discard { name, location } => todo!(), Pattern::List { location, diff --git a/crates/aiken-lang/src/gen_uplc2/tree.rs b/crates/aiken-lang/src/gen_uplc2/tree.rs index da50f8ce..512debf1 100644 --- a/crates/aiken-lang/src/gen_uplc2/tree.rs +++ b/crates/aiken-lang/src/gen_uplc2/tree.rs @@ -50,14 +50,12 @@ pub enum AirStatement { subject_name: String, tipo: Arc, pattern: Box, - then: Box, }, ListClauseGuard { tipo: Arc, tail_name: String, next_tail_name: Option, inverse: bool, - then: Box, }, // Field Access FieldsExpose { @@ -475,18 +473,12 @@ impl AirTree { otherwise: otherwise.into(), }) } - pub fn clause_guard( - subject_name: impl ToString, - pattern: AirTree, - tipo: Arc, - then: AirTree, - ) -> AirTree { + pub fn clause_guard(subject_name: impl ToString, pattern: AirTree, tipo: Arc) -> AirTree { AirTree::Statement { statement: AirStatement::ClauseGuard { subject_name: subject_name.to_string(), tipo, pattern: pattern.into(), - then: then.into(), }, hoisted_over: None, } @@ -495,7 +487,6 @@ impl AirTree { tail_name: impl ToString, tipo: Arc, inverse: bool, - then: AirTree, next_tail_name: Option, ) -> AirTree { AirTree::Statement { @@ -504,7 +495,6 @@ impl AirTree { tail_name: tail_name.to_string(), next_tail_name, inverse, - then: then.into(), }, hoisted_over: None, } @@ -780,7 +770,6 @@ impl AirTree { subject_name, tipo, pattern, - then, } => { air_vec.push(Air::ClauseGuard { subject_name: subject_name.clone(), @@ -788,14 +777,12 @@ impl AirTree { }); pattern.create_air_vec(air_vec); - then.create_air_vec(air_vec); } AirStatement::ListClauseGuard { tipo, tail_name, next_tail_name, inverse, - then, } => { air_vec.push(Air::ListClauseGuard { tipo: tipo.clone(), @@ -803,8 +790,6 @@ impl AirTree { next_tail_name: next_tail_name.clone(), inverse: *inverse, }); - - then.create_air_vec(air_vec); } AirStatement::FieldsExpose { indices,