From 21b60896f0835642dd659d3689f9bb04bc763831 Mon Sep 17 00:00:00 2001 From: microproofs Date: Tue, 19 Mar 2024 20:31:30 -0400 Subject: [PATCH] remove wild card match from tree functions Start working on supporting Pair clauses --- crates/aiken-lang/src/gen_uplc/builder.rs | 27 +++++++++-- crates/aiken-lang/src/gen_uplc/tree.rs | 57 ++++++++++++++++------- 2 files changed, 63 insertions(+), 21 deletions(-) diff --git a/crates/aiken-lang/src/gen_uplc/builder.rs b/crates/aiken-lang/src/gen_uplc/builder.rs index 5711373b..642f7507 100644 --- a/crates/aiken-lang/src/gen_uplc/builder.rs +++ b/crates/aiken-lang/src/gen_uplc/builder.rs @@ -95,6 +95,7 @@ pub enum SpecificClause { TupleClause { defined_tuple_indices: IndexSet<(usize, String)>, }, + PairClause, } impl ClauseProperties { @@ -112,7 +113,7 @@ impl ClauseProperties { checked_index: -1, }, } - } else if t.is_tuple() || t.is_pair() { + } else if t.is_tuple() { ClauseProperties { clause_var_name: constr_var, complex_clause: false, @@ -123,6 +124,15 @@ impl ClauseProperties { defined_tuple_indices: IndexSet::new(), }, } + } else if t.is_pair() { + ClauseProperties { + clause_var_name: constr_var, + complex_clause: false, + original_subject_name: subject_name, + needs_constr_var: false, + final_clause: false, + specific_clause: SpecificClause::PairClause, + } } else { ClauseProperties { clause_var_name: constr_var, @@ -154,7 +164,7 @@ impl ClauseProperties { checked_index: -1, }, } - } else if t.is_tuple() || t.is_pair() { + } else if t.is_tuple() { ClauseProperties { clause_var_name: constr_var, complex_clause: false, @@ -165,6 +175,15 @@ impl ClauseProperties { defined_tuple_indices: IndexSet::new(), }, } + } else if t.is_pair() { + ClauseProperties { + clause_var_name: constr_var, + complex_clause: false, + original_subject_name: subject_name, + needs_constr_var: false, + final_clause, + specific_clause: SpecificClause::PairClause, + } } else { ClauseProperties { clause_var_name: constr_var, @@ -985,7 +1004,7 @@ pub fn unknown_data_to_type(term: Term, field_type: &Type) -> Term { Term::unmap_data().apply(term) } else if field_type.is_string() { Term::Builtin(DefaultFunction::DecodeUtf8).apply(Term::un_b_data().apply(term)) - } else if field_type.is_tuple() && matches!(field_type.get_uplc_type(), UplcType::Pair(_, _)) { + } else if field_type.is_pair() { Term::tail_list() .apply(Term::tail_list().apply(Term::var("__list_data"))) .delayed_choose_list( @@ -1410,7 +1429,7 @@ pub fn list_access_to_uplc( let head_item = |name, tipo: &Rc, tail_name: &str| { if name == "_" { Term::unit() - } else if matches!(tipo.get_uplc_type(), UplcType::Pair(_, _)) && is_list_accessor { + } else if tipo.is_pair() && is_list_accessor { Term::head_list().apply(Term::var(tail_name.to_string())) } else if matches!(expect_level, ExpectLevel::Full) { // Expect level is full so we have an unknown piece of data to cast diff --git a/crates/aiken-lang/src/gen_uplc/tree.rs b/crates/aiken-lang/src/gen_uplc/tree.rs index b3af15cb..8de60875 100644 --- a/crates/aiken-lang/src/gen_uplc/tree.rs +++ b/crates/aiken-lang/src/gen_uplc/tree.rs @@ -1645,18 +1645,18 @@ impl AirTree { match self { AirTree::ClauseGuard { subject_tipo, .. } | AirTree::ListClauseGuard { subject_tipo, .. } - | AirTree::TupleGuard { subject_tipo, .. } => vec![subject_tipo], + | AirTree::PairGuard { subject_tipo, .. } + | AirTree::TupleGuard { subject_tipo, .. } + | AirTree::Clause { subject_tipo, .. } + | AirTree::ListClause { subject_tipo, .. } + | AirTree::TupleClause { subject_tipo, .. } + | AirTree::PairClause { subject_tipo, .. } => vec![subject_tipo], + AirTree::ListAccessor { tipo, .. } | AirTree::ListExpose { tipo, .. } - | AirTree::TupleAccessor { tipo, .. } => vec![tipo], - AirTree::FieldsExpose { indices, .. } => { - let mut types = vec![]; - for (_, _, tipo) in indices { - types.push(tipo); - } - types - } - AirTree::List { tipo, .. } + | AirTree::TupleAccessor { tipo, .. } + | AirTree::PairAccessor { tipo, .. } + | AirTree::List { tipo, .. } | AirTree::Tuple { tipo, .. } | AirTree::Call { tipo, .. } | AirTree::Builtin { tipo, .. } @@ -1665,7 +1665,17 @@ impl AirTree { | AirTree::If { tipo, .. } | AirTree::Constr { tipo, .. } | AirTree::ErrorTerm { tipo, .. } - | AirTree::Trace { tipo, .. } => vec![tipo], + | AirTree::Trace { tipo, .. } + | AirTree::Pair { tipo, .. } => vec![tipo], + + AirTree::FieldsExpose { indices, .. } => { + let mut types = vec![]; + for (_, _, tipo) in indices { + types.push(tipo); + } + types + } + AirTree::Var { constructor, .. } => { vec![constructor.tipo.borrow_mut()] } @@ -1679,9 +1689,7 @@ impl AirTree { AirTree::When { tipo, subject_tipo, .. } => vec![tipo, subject_tipo], - AirTree::Clause { subject_tipo, .. } - | AirTree::ListClause { subject_tipo, .. } - | AirTree::TupleClause { subject_tipo, .. } => vec![subject_tipo], + AirTree::RecordUpdate { tipo, indices, .. } => { let mut types = vec![tipo]; for (_, tipo) in indices { @@ -1689,9 +1697,24 @@ impl AirTree { } types } - _ => { - vec![] - } + AirTree::Let { .. } + | AirTree::DefineFunc { .. } + | AirTree::DefineCyclicFuncs { .. } + | AirTree::AssertConstr { .. } + | AirTree::AssertBool { .. } + | AirTree::FieldsEmpty { .. } + | AirTree::ListEmpty { .. } + | AirTree::NoOp { .. } + | AirTree::Int { .. } + | AirTree::String { .. } + | AirTree::ByteArray { .. } + | AirTree::CurvePoint { .. } + | AirTree::Bool { .. } + | AirTree::Void + | AirTree::Fn { .. } + | AirTree::UnOp { .. } + | AirTree::WrapClause { .. } + | AirTree::Finally { .. } => vec![], } }