Skip to content

Commit

Permalink
remove wild card match from tree functions
Browse files Browse the repository at this point in the history
Start working on supporting Pair clauses
  • Loading branch information
MicroProofs committed Apr 27, 2024
1 parent bc842c6 commit 4be5420
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 21 deletions.
27 changes: 23 additions & 4 deletions crates/aiken-lang/src/gen_uplc/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ pub enum SpecificClause {
TupleClause {
defined_tuple_indices: IndexSet<(usize, String)>,
},
PairClause,
}

impl ClauseProperties {
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -985,7 +1004,7 @@ pub fn unknown_data_to_type(term: Term<Name>, field_type: &Type) -> Term<Name> {
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(
Expand Down Expand Up @@ -1410,7 +1429,7 @@ pub fn list_access_to_uplc(
let head_item = |name, tipo: &Rc<Type>, 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
Expand Down
57 changes: 40 additions & 17 deletions crates/aiken-lang/src/gen_uplc/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, .. }
Expand All @@ -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()]
}
Expand All @@ -1679,19 +1689,32 @@ 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 {
types.push(tipo);
}
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![],
}
}

Expand Down

0 comments on commit 4be5420

Please sign in to comment.