Refactor get_uplc_type to account for constr types that don't exactly resolve to a uplc type
Check arg_stack in uplc generator has only 1 argument at the end of the generation
warning fixes
This commit is contained in:
microproofs 2024-04-25 16:55:01 +02:00 committed by Kasey
parent 1091eba3c3
commit fc0e88018e
37 changed files with 268 additions and 251 deletions

View File

@ -1470,6 +1470,7 @@ impl<'a> CodeGenerator<'a> {
match uplc_type {
// primitives
Some(
UplcType::Integer
| UplcType::String
| UplcType::Bool
@ -1477,12 +1478,13 @@ impl<'a> CodeGenerator<'a> {
| UplcType::Unit
| UplcType::Bls12_381G1Element
| UplcType::Bls12_381G2Element
| UplcType::Bls12_381MlResult => value,
| UplcType::Bls12_381MlResult,
) => value,
// Untyped Data
UplcType::Data if tipo.is_data() => value,
Some(UplcType::Data) => value,
// Map type
UplcType::List(_) if tipo.is_map() => {
Some(UplcType::List(_)) if tipo.is_map() => {
assert!(!tipo.get_inner_types().is_empty());
let inner_list_type = &tipo.get_inner_types()[0];
@ -1565,7 +1567,7 @@ impl<'a> CodeGenerator<'a> {
AirTree::let_assignment(&map_name, value, func_call)
}
// Tuple type
UplcType::List(_) if tipo.is_tuple() => {
Some(UplcType::List(_)) if tipo.is_tuple() => {
let tuple_inner_types = tipo.get_inner_types();
assert!(!tuple_inner_types.is_empty());
@ -1610,7 +1612,7 @@ impl<'a> CodeGenerator<'a> {
AirTree::let_assignment(&tuple_name, value, tuple_access)
}
// Regular List type
UplcType::List(_) => {
Some(UplcType::List(_)) => {
assert!(!tipo.get_inner_types().is_empty());
let inner_list_type = &tipo.get_inner_types()[0];
@ -1686,7 +1688,7 @@ impl<'a> CodeGenerator<'a> {
}
}
// Pair type
UplcType::Pair(_, _) => {
Some(UplcType::Pair(_, _)) => {
let tuple_inner_types = tipo.get_inner_types();
assert!(tuple_inner_types.len() == 2);
@ -1726,7 +1728,7 @@ impl<'a> CodeGenerator<'a> {
}
// Constr type
UplcType::Data => {
None => {
let data_type =
lookup_data_type_by_tipo(&self.data_types, tipo).unwrap_or_else(|| {
unreachable!("We need a data type definition for type {:#?}", tipo)
@ -4012,6 +4014,7 @@ impl<'a> CodeGenerator<'a> {
arg_stack.push(arg);
}
}
assert!(arg_stack.len() == 1, "Expected one term on the stack");
arg_stack.pop().unwrap()
}
@ -4544,22 +4547,22 @@ impl<'a> CodeGenerator<'a> {
BinOp::Or => left.delayed_if_then_else(Term::bool(true), right),
BinOp::Eq | BinOp::NotEq => {
let builtin = match &uplc_type {
UplcType::Integer => Term::equals_integer(),
UplcType::String => Term::equals_string(),
UplcType::ByteString => Term::equals_bytestring(),
UplcType::Bls12_381G1Element => Term::bls12_381_g1_equal(),
UplcType::Bls12_381G2Element => Term::bls12_381_g2_equal(),
UplcType::Bool | UplcType::Unit => Term::unit(),
UplcType::List(_) | UplcType::Pair(_, _) | UplcType::Data => {
Term::equals_data()
}
UplcType::Bls12_381MlResult => {
Some(UplcType::Integer) => Term::equals_integer(),
Some(UplcType::String) => Term::equals_string(),
Some(UplcType::ByteString) => Term::equals_bytestring(),
Some(UplcType::Bls12_381G1Element) => Term::bls12_381_g1_equal(),
Some(UplcType::Bls12_381G2Element) => Term::bls12_381_g2_equal(),
Some(UplcType::Bool | UplcType::Unit) => Term::unit(),
Some(UplcType::List(_) | UplcType::Pair(_, _) | UplcType::Data)
| None => Term::equals_data(),
Some(UplcType::Bls12_381MlResult) => {
panic!("ML Result equality is not supported")
}
};
let binop_eq = match uplc_type {
UplcType::Bool => {
let binop_eq =
match uplc_type {
Some(UplcType::Bool) => {
if matches!(name, BinOp::Eq) {
left.delayed_if_then_else(
right.clone(),
@ -4574,29 +4577,32 @@ impl<'a> CodeGenerator<'a> {
)
}
}
UplcType::List(_) if tipo.is_map() => builtin
Some(UplcType::List(_)) if tipo.is_map() => builtin
.apply(Term::map_data().apply(left))
.apply(Term::map_data().apply(right)),
UplcType::List(_) => builtin
Some(UplcType::List(_)) => builtin
.apply(Term::list_data().apply(left))
.apply(Term::list_data().apply(right)),
UplcType::Pair(_, _) => {
builtin
Some(UplcType::Pair(_, _)) => builtin
.apply(Term::map_data().apply(
Term::mk_cons().apply(left).apply(Term::empty_map()),
))
.apply(Term::map_data().apply(
Term::mk_cons().apply(right).apply(Term::empty_map()),
))
}
)),
Some(
UplcType::Data
| UplcType::Bls12_381G1Element
| UplcType::Bls12_381G2Element
| UplcType::Bls12_381MlResult
| UplcType::Integer
| UplcType::String
| UplcType::ByteString => builtin.apply(left).apply(right),
UplcType::Unit => left.choose_unit(right.choose_unit(Term::bool(true))),
| UplcType::ByteString,
)
| None => builtin.apply(left).apply(right),
Some(UplcType::Unit) => {
left.choose_unit(right.choose_unit(Term::bool(true)))
}
};
if !tipo.is_bool() && matches!(name, BinOp::NotEq) {
@ -4857,6 +4863,7 @@ impl<'a> CodeGenerator<'a> {
let uplc_type = tipo.get_uplc_type();
let subject = match uplc_type {
Some(
UplcType::Bool
| UplcType::Integer
| UplcType::String
@ -4866,9 +4873,12 @@ impl<'a> CodeGenerator<'a> {
| UplcType::Pair(_, _)
| UplcType::Bls12_381G1Element
| UplcType::Bls12_381G2Element
| UplcType::Bls12_381MlResult => subject,
UplcType::Data if tipo.is_data() => subject,
UplcType::Data => Term::var(
| UplcType::Bls12_381MlResult,
) => subject,
Some(UplcType::Data) => subject,
None => Term::var(
self.special_functions
.use_function_uplc(CONSTR_INDEX_EXPOSER.to_string()),
)
@ -4916,28 +4926,30 @@ impl<'a> CodeGenerator<'a> {
let uplc_type = tipo.get_uplc_type();
let condition = match uplc_type {
Some(
UplcType::Bool
| UplcType::Unit
| UplcType::List(_)
| UplcType::Pair(_, _)
| UplcType::Bls12_381MlResult => unreachable!("{:#?}", tipo),
UplcType::Integer => Term::equals_integer()
| UplcType::Bls12_381MlResult,
) => unreachable!("{:#?}", tipo),
Some(UplcType::Data) => unimplemented!(),
Some(UplcType::Integer) => Term::equals_integer()
.apply(clause)
.apply(Term::var(subject_name)),
UplcType::String => Term::equals_string()
Some(UplcType::String) => Term::equals_string()
.apply(clause)
.apply(Term::var(subject_name)),
UplcType::ByteString => Term::equals_bytestring()
Some(UplcType::ByteString) => Term::equals_bytestring()
.apply(clause)
.apply(Term::var(subject_name)),
UplcType::Data if tipo.is_data() => unimplemented!(),
UplcType::Data => Term::equals_integer()
Some(UplcType::Bls12_381G1Element) => Term::bls12_381_g1_equal()
.apply(clause)
.apply(Term::var(subject_name)),
UplcType::Bls12_381G1Element => Term::bls12_381_g1_equal()
Some(UplcType::Bls12_381G2Element) => Term::bls12_381_g2_equal()
.apply(clause)
.apply(Term::var(subject_name)),
UplcType::Bls12_381G2Element => Term::bls12_381_g2_equal()
None => Term::equals_integer()
.apply(clause)
.apply(Term::var(subject_name)),
};
@ -5084,35 +5096,36 @@ impl<'a> CodeGenerator<'a> {
let uplc_type = tipo.get_uplc_type();
let condition = match uplc_type {
Some(
UplcType::Bool
| UplcType::Unit
| UplcType::List(_)
| UplcType::Pair(_, _)
| UplcType::Bls12_381MlResult => unreachable!("{:#?}", tipo),
UplcType::Integer => Term::equals_integer()
| UplcType::Bls12_381MlResult,
) => unreachable!("{:#?}", tipo),
Some(UplcType::Data) => unimplemented!(),
Some(UplcType::Integer) => Term::equals_integer()
.apply(checker)
.apply(Term::var(subject_name)),
UplcType::String => Term::equals_string()
Some(UplcType::String) => Term::equals_string()
.apply(checker)
.apply(Term::var(subject_name)),
UplcType::ByteString => Term::equals_bytestring()
Some(UplcType::ByteString) => Term::equals_bytestring()
.apply(checker)
.apply(Term::var(subject_name)),
UplcType::Data if tipo.is_data() => unimplemented!(),
UplcType::Data => Term::equals_integer().apply(checker).apply(
Some(UplcType::Bls12_381G1Element) => Term::bls12_381_g1_equal()
.apply(checker)
.apply(Term::var(subject_name)),
Some(UplcType::Bls12_381G2Element) => Term::bls12_381_g2_equal()
.apply(checker)
.apply(Term::var(subject_name)),
None => Term::equals_integer().apply(checker).apply(
Term::var(
self.special_functions
.use_function_uplc(CONSTR_INDEX_EXPOSER.to_string()),
)
.apply(Term::var(subject_name)),
),
UplcType::Bls12_381G1Element => Term::bls12_381_g1_equal()
.apply(checker)
.apply(Term::var(subject_name)),
UplcType::Bls12_381G2Element => Term::bls12_381_g2_equal()
.apply(checker)
.apply(Term::var(subject_name)),
};
Some(condition.if_then_else(then.delay(), term).force())

View File

@ -362,22 +362,22 @@ pub fn get_generic_variant_name(t: &Rc<Type>) -> String {
let uplc_type = t.get_uplc_type();
match uplc_type {
UplcType::Bool => "_bool".to_string(),
UplcType::Integer => "_int".to_string(),
UplcType::String => "_string".to_string(),
UplcType::ByteString => "_bytearray".to_string(),
UplcType::Unit => "_void".to_string(),
UplcType::List(_) if t.is_map() => "_map".to_string(),
UplcType::List(_) => "_list".to_string(),
UplcType::Pair(_, _) => "_pair".to_string(),
UplcType::Bls12_381G1Element => "_bls381_12_g1".to_string(),
UplcType::Bls12_381G2Element => "_bls381_12_g2".to_string(),
UplcType::Bls12_381MlResult => "_ml_result".to_string(),
UplcType::Data if t.is_unbound() => "_unbound".to_string(),
UplcType::Data if t.is_generic() => {
Some(UplcType::Bool) => "_bool".to_string(),
Some(UplcType::Integer) => "_int".to_string(),
Some(UplcType::String) => "_string".to_string(),
Some(UplcType::ByteString) => "_bytearray".to_string(),
Some(UplcType::Unit) => "_void".to_string(),
Some(UplcType::List(_)) if t.is_map() => "_map".to_string(),
Some(UplcType::List(_)) => "_list".to_string(),
Some(UplcType::Pair(_, _)) => "_pair".to_string(),
Some(UplcType::Bls12_381G1Element) => "_bls381_12_g1".to_string(),
Some(UplcType::Bls12_381G2Element) => "_bls381_12_g2".to_string(),
Some(UplcType::Bls12_381MlResult) => "_ml_result".to_string(),
None if t.is_unbound() => "_unbound".to_string(),
None if t.is_generic() => {
unreachable!("FOUND A POLYMORPHIC TYPE. EXPECTED MONOMORPHIC TYPE")
}
UplcType::Data => "_data".to_string(),
None | Some(UplcType::Data) => "_data".to_string(),
}
}
@ -943,29 +943,29 @@ pub fn known_data_to_type(term: Term<Name>, field_type: &Type) -> Term<Name> {
let uplc_type = field_type.get_uplc_type();
match uplc_type {
UplcType::Integer => Term::un_i_data().apply(term),
UplcType::ByteString => Term::un_b_data().apply(term),
UplcType::Bool => Term::less_than_integer()
Some(UplcType::Integer) => Term::un_i_data().apply(term),
Some(UplcType::ByteString) => Term::un_b_data().apply(term),
Some(UplcType::Bool) => Term::less_than_integer()
.apply(Term::integer(0.into()))
.apply(Term::fst_pair().apply(Term::unconstr_data().apply(term))),
UplcType::String => Term::decode_utf8().apply(Term::un_b_data().apply(term)),
UplcType::Unit => Term::unit().lambda("_").apply(term),
UplcType::List(_) if field_type.is_map() => Term::unmap_data().apply(term),
UplcType::List(_) => Term::unlist_data().apply(term),
UplcType::Pair(_, _) => Term::mk_pair_data()
Some(UplcType::String) => Term::decode_utf8().apply(Term::un_b_data().apply(term)),
Some(UplcType::Unit) => Term::unit().lambda("_").apply(term),
Some(UplcType::List(_)) if field_type.is_map() => Term::unmap_data().apply(term),
Some(UplcType::List(_)) => Term::unlist_data().apply(term),
Some(UplcType::Pair(_, _)) => Term::mk_pair_data()
.apply(Term::head_list().apply(Term::var("__list_data")))
.apply(Term::head_list().apply(Term::tail_list().apply(Term::var("__list_data"))))
.lambda("__list_data")
.apply(Term::unlist_data().apply(term)),
UplcType::Data if field_type.is_data() => term,
UplcType::Data => term,
UplcType::Bls12_381G1Element => {
Some(UplcType::Bls12_381G1Element) => {
Term::bls12_381_g1_uncompress().apply(Term::un_b_data().apply(term))
}
UplcType::Bls12_381G2Element => {
Some(UplcType::Bls12_381G2Element) => {
Term::bls12_381_g2_uncompress().apply(Term::un_b_data().apply(term))
}
UplcType::Bls12_381MlResult => panic!("ML Result not supported"),
Some(UplcType::Bls12_381MlResult) => panic!("ML Result not supported"),
Some(UplcType::Data) | None => term,
}
}
@ -973,21 +973,21 @@ pub fn unknown_data_to_type(term: Term<Name>, field_type: &Type) -> Term<Name> {
let uplc_type = field_type.get_uplc_type();
match uplc_type {
UplcType::Integer => Term::un_i_data().apply(term),
UplcType::ByteString => Term::un_b_data().apply(term),
UplcType::String => Term::decode_utf8().apply(Term::un_b_data().apply(term)),
UplcType::List(_) if field_type.is_map() => Term::unmap_data().apply(term),
UplcType::List(_) => Term::unlist_data().apply(term),
UplcType::Data if field_type.is_data() => term,
UplcType::Data => term,
UplcType::Bls12_381G1Element => {
Some(UplcType::Integer) => Term::un_i_data().apply(term),
Some(UplcType::ByteString) => Term::un_b_data().apply(term),
Some(UplcType::String) => Term::decode_utf8().apply(Term::un_b_data().apply(term)),
Some(UplcType::List(_)) if field_type.is_map() => Term::unmap_data().apply(term),
Some(UplcType::List(_)) => Term::unlist_data().apply(term),
Some(UplcType::Bls12_381G1Element) => {
Term::bls12_381_g1_uncompress().apply(Term::un_b_data().apply(term))
}
UplcType::Bls12_381G2Element => {
Some(UplcType::Bls12_381G2Element) => {
Term::bls12_381_g2_uncompress().apply(Term::un_b_data().apply(term))
}
UplcType::Bls12_381MlResult => panic!("ML Result not supported"),
UplcType::Pair(_, _) => Term::tail_list()
Some(UplcType::Bls12_381MlResult) => panic!("ML Result not supported"),
Some(UplcType::Pair(_, _)) => Term::tail_list()
.apply(Term::tail_list().apply(Term::var("__list_data")))
.delayed_choose_list(
Term::mk_pair_data()
@ -999,7 +999,7 @@ pub fn unknown_data_to_type(term: Term<Name>, field_type: &Type) -> Term<Name> {
)
.lambda("__list_data")
.apply(Term::unlist_data().apply(term)),
UplcType::Bool => Term::snd_pair()
Some(UplcType::Bool) => Term::snd_pair()
.apply(Term::var("__pair__"))
.delayed_choose_list(
Term::equals_integer()
@ -1016,7 +1016,7 @@ pub fn unknown_data_to_type(term: Term<Name>, field_type: &Type) -> Term<Name> {
)
.lambda("__pair__")
.apply(Term::unconstr_data().apply(term)),
UplcType::Unit => Term::equals_integer()
Some(UplcType::Unit) => Term::equals_integer()
.apply(Term::integer(0.into()))
.apply(Term::fst_pair().apply(Term::var("__pair__")))
.delayed_if_then_else(
@ -1027,6 +1027,8 @@ pub fn unknown_data_to_type(term: Term<Name>, field_type: &Type) -> Term<Name> {
)
.lambda("__pair__")
.apply(Term::unconstr_data().apply(term)),
Some(UplcType::Data) | None => term,
}
}
@ -1041,7 +1043,7 @@ pub fn unknown_data_to_type_debug(
let uplc_type = field_type.get_uplc_type();
match uplc_type {
UplcType::Integer => Term::var("__val")
Some(UplcType::Integer) => Term::var("__val")
.delayed_choose_data(
error_term.clone(),
error_term.clone(),
@ -1051,7 +1053,7 @@ pub fn unknown_data_to_type_debug(
)
.lambda("__val")
.apply(term),
UplcType::ByteString => Term::var("__val")
Some(UplcType::ByteString) => Term::var("__val")
.delayed_choose_data(
error_term.clone(),
error_term.clone(),
@ -1061,7 +1063,7 @@ pub fn unknown_data_to_type_debug(
)
.lambda("__val")
.apply(term),
UplcType::String => Term::var("__val")
Some(UplcType::String) => Term::var("__val")
.delayed_choose_data(
error_term.clone(),
error_term.clone(),
@ -1072,7 +1074,7 @@ pub fn unknown_data_to_type_debug(
.lambda("__val")
.apply(term),
UplcType::List(_) if field_type.is_map() => Term::var("__val")
Some(UplcType::List(_)) if field_type.is_map() => Term::var("__val")
.delayed_choose_data(
error_term.clone(),
Term::unmap_data().apply(Term::var("__val")),
@ -1082,7 +1084,7 @@ pub fn unknown_data_to_type_debug(
)
.lambda("__val")
.apply(term),
UplcType::List(_) => Term::var("__val")
Some(UplcType::List(_)) => Term::var("__val")
.delayed_choose_data(
error_term.clone(),
error_term.clone(),
@ -1092,19 +1094,8 @@ pub fn unknown_data_to_type_debug(
)
.lambda("__val")
.apply(term),
UplcType::Data if field_type.is_data() => term,
// constr type
UplcType::Data => Term::var("__val")
.delayed_choose_data(
Term::var("__val"),
error_term.clone(),
error_term.clone(),
error_term.clone(),
error_term.clone(),
)
.lambda("__val")
.apply(term),
UplcType::Bls12_381G1Element => Term::var("__val")
Some(UplcType::Bls12_381G1Element) => Term::var("__val")
.delayed_choose_data(
error_term.clone(),
error_term.clone(),
@ -1114,7 +1105,7 @@ pub fn unknown_data_to_type_debug(
)
.lambda("__val")
.apply(term),
UplcType::Bls12_381G2Element => Term::var("__val")
Some(UplcType::Bls12_381G2Element) => Term::var("__val")
.delayed_choose_data(
error_term.clone(),
error_term.clone(),
@ -1124,8 +1115,8 @@ pub fn unknown_data_to_type_debug(
)
.lambda("__val")
.apply(term),
UplcType::Bls12_381MlResult => panic!("ML Result not supported"),
UplcType::Pair(_, _) => Term::var("__val")
Some(UplcType::Bls12_381MlResult) => panic!("ML Result not supported"),
Some(UplcType::Pair(_, _)) => Term::var("__val")
.delayed_choose_data(
error_term.clone(),
error_term.clone(),
@ -1156,7 +1147,7 @@ pub fn unknown_data_to_type_debug(
)
.lambda("__val")
.apply(term),
UplcType::Bool => Term::var("__val")
Some(UplcType::Bool) => Term::var("__val")
.delayed_choose_data(
Term::snd_pair()
.apply(Term::var("__pair__"))
@ -1182,7 +1173,7 @@ pub fn unknown_data_to_type_debug(
)
.lambda("__val")
.apply(term),
UplcType::Unit => Term::var("__val")
Some(UplcType::Unit) => Term::var("__val")
.delayed_choose_data(
Term::equals_integer()
.apply(Term::integer(0.into()))
@ -1200,6 +1191,19 @@ pub fn unknown_data_to_type_debug(
)
.lambda("__val")
.apply(term),
Some(UplcType::Data) => term,
// constr type
None => Term::var("__val")
.delayed_choose_data(
Term::var("__val"),
error_term.clone(),
error_term.clone(),
error_term.clone(),
error_term.clone(),
)
.lambda("__val")
.apply(term),
}
}
@ -1294,21 +1298,20 @@ pub fn convert_type_to_data(term: Term<Name>, field_type: &Rc<Type>) -> Term<Nam
let uplc_type = field_type.get_uplc_type();
match uplc_type {
UplcType::Integer => Term::i_data().apply(term),
UplcType::String => Term::b_data().apply(Term::encode_utf8().apply(term)),
UplcType::ByteString => Term::b_data().apply(term),
UplcType::List(_) if field_type.is_map() => Term::map_data().apply(term),
UplcType::List(_) => Term::list_data().apply(term),
UplcType::Data if field_type.is_data() => term,
UplcType::Data => term,
UplcType::Bls12_381G1Element => {
Some(UplcType::Integer) => Term::i_data().apply(term),
Some(UplcType::String) => Term::b_data().apply(Term::encode_utf8().apply(term)),
Some(UplcType::ByteString) => Term::b_data().apply(term),
Some(UplcType::List(_)) if field_type.is_map() => Term::map_data().apply(term),
Some(UplcType::List(_)) => Term::list_data().apply(term),
Some(UplcType::Bls12_381G1Element) => {
Term::b_data().apply(Term::bls12_381_g1_compress().apply(term))
}
UplcType::Bls12_381G2Element => {
Some(UplcType::Bls12_381G2Element) => {
Term::b_data().apply(Term::bls12_381_g2_compress().apply(term))
}
UplcType::Bls12_381MlResult => panic!("ML Result not supported"),
UplcType::Pair(_, _) => Term::list_data()
Some(UplcType::Bls12_381MlResult) => panic!("ML Result not supported"),
Some(UplcType::Pair(_, _)) => Term::list_data()
.apply(
Term::mk_cons()
.apply(Term::fst_pair().apply(Term::var("__pair")))
@ -1320,7 +1323,7 @@ pub fn convert_type_to_data(term: Term<Name>, field_type: &Rc<Type>) -> Term<Nam
)
.lambda("__pair")
.apply(term),
UplcType::Unit => Term::Constant(
Some(UplcType::Unit) => Term::Constant(
UplcConstant::Data(PlutusData::Constr(Constr {
tag: convert_constr_to_tag(0).unwrap(),
any_constructor: None,
@ -1330,7 +1333,7 @@ pub fn convert_type_to_data(term: Term<Name>, field_type: &Rc<Type>) -> Term<Nam
)
.lambda("_")
.apply(term),
UplcType::Bool => term.if_then_else(
Some(UplcType::Bool) => term.if_then_else(
Term::Constant(
UplcConstant::Data(PlutusData::Constr(Constr {
tag: convert_constr_to_tag(1).unwrap(),
@ -1348,6 +1351,8 @@ pub fn convert_type_to_data(term: Term<Name>, field_type: &Rc<Type>) -> Term<Nam
.into(),
),
),
Some(UplcType::Data) | None => term,
}
}
@ -1758,7 +1763,7 @@ pub fn get_list_elements_len_and_tail(
pub fn cast_validator_args(term: Term<Name>, arguments: &[TypedArg]) -> Term<Name> {
let mut term = term;
for arg in arguments.iter().rev() {
if !matches!(arg.tipo.get_uplc_type(), UplcType::Data) {
if !matches!(arg.tipo.get_uplc_type(), Some(UplcType::Data) | None) {
term = term
.lambda(arg.arg_name.get_variable_name().unwrap_or("_"))
.apply(known_data_to_type(

View File

@ -8,10 +8,10 @@ use chumsky::prelude::*;
pub fn parser(
r: Recursive<'_, Token, UntypedExpr, ParseError>,
) -> impl Parser<Token, UntypedExpr, Error = ParseError> + '_ {
select! {Token::Name { name } if &name == PRELUDE => name}
select! {Token::Name { name } if name == PRELUDE => name}
.then_ignore(just(Token::Dot))
.or_not()
.then_ignore(select! {Token::UpName { name } if &name == PAIR => name})
.then_ignore(select! {Token::UpName { name } if name == PAIR => name})
.ignore_then(
r.clone()
.separated_by(just(Token::Comma))

View File

@ -269,6 +269,7 @@ impl Type {
pub fn is_primitive(&self) -> bool {
let uplc_type = self.get_uplc_type();
match uplc_type {
Some(
UplcType::Bool
| UplcType::Integer
| UplcType::String
@ -276,11 +277,12 @@ impl Type {
| UplcType::Unit
| UplcType::Bls12_381G1Element
| UplcType::Bls12_381G2Element
| UplcType::Bls12_381MlResult => true,
| UplcType::Bls12_381MlResult
| UplcType::Data,
) => true,
UplcType::Data if self.is_data() => true,
UplcType::Data => false,
UplcType::List(_) | UplcType::Pair(_, _) => false,
None => false,
Some(UplcType::List(_) | UplcType::Pair(_, _)) => false,
}
}
@ -472,7 +474,7 @@ impl Type {
Self::Var { tipo, .. } => tipo.borrow().get_inner_types(),
_ => vec![],
}
} else if matches!(self.get_uplc_type(), UplcType::Data) {
} else if self.get_uplc_type().is_none() {
match self {
Type::App { args, .. } => args.clone(),
Type::Fn { args, ret, .. } => {
@ -488,31 +490,35 @@ impl Type {
}
}
pub fn get_uplc_type(&self) -> UplcType {
pub fn get_uplc_type(&self) -> Option<UplcType> {
if self.is_int() {
UplcType::Integer
Some(UplcType::Integer)
} else if self.is_bytearray() {
UplcType::ByteString
Some(UplcType::ByteString)
} else if self.is_string() {
UplcType::String
Some(UplcType::String)
} else if self.is_bool() {
UplcType::Bool
Some(UplcType::Bool)
} else if self.is_void() {
UplcType::Unit
Some(UplcType::Unit)
} else if self.is_map() {
UplcType::List(UplcType::Pair(UplcType::Data.into(), UplcType::Data.into()).into())
Some(UplcType::List(
UplcType::Pair(UplcType::Data.into(), UplcType::Data.into()).into(),
))
} else if self.is_list() || self.is_tuple() {
UplcType::List(UplcType::Data.into())
Some(UplcType::List(UplcType::Data.into()))
} else if self.is_pair() {
UplcType::Pair(UplcType::Data.into(), UplcType::Data.into())
Some(UplcType::Pair(UplcType::Data.into(), UplcType::Data.into()))
} else if self.is_bls381_12_g1() {
UplcType::Bls12_381G1Element
Some(UplcType::Bls12_381G1Element)
} else if self.is_bls381_12_g2() {
UplcType::Bls12_381G2Element
Some(UplcType::Bls12_381G2Element)
} else if self.is_ml_result() {
UplcType::Bls12_381MlResult
Some(UplcType::Bls12_381MlResult)
} else if self.is_data() {
Some(UplcType::Data)
} else {
UplcType::Data
None
}
}
@ -1066,13 +1072,6 @@ impl TypeVar {
}
}
}
pub fn get_uplc_type(&self) -> Option<UplcType> {
match self {
Self::Link { tipo } => Some(tipo.get_uplc_type()),
_ => None,
}
}
}
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]

View File

@ -13,4 +13,4 @@ requirements = []
source = "github"
[etags]
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1713463885, nanos_since_epoch = 953327000 }, "2a710731e0127ec3e21c6c3962a0254c98602e7428b33fc4fcaa67ab368ce1b1"]
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1714055767, nanos_since_epoch = 971886000 }, "2a710731e0127ec3e21c6c3962a0254c98602e7428b33fc4fcaa67ab368ce1b1"]

View File

@ -5,7 +5,7 @@
"plutusVersion": "v2",
"compiler": {
"name": "Aiken",
"version": "v1.0.26-alpha+4d36884"
"version": "v1.0.26-alpha+821d869"
}
},
"validators": [

View File

@ -5,7 +5,7 @@
"plutusVersion": "v2",
"compiler": {
"name": "Aiken",
"version": "v1.0.26-alpha+4d36884"
"version": "v1.0.26-alpha+821d869"
}
},
"validators": [

View File

@ -13,4 +13,4 @@ requirements = []
source = "github"
[etags]
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1713463884, nanos_since_epoch = 765100000 }, "2a710731e0127ec3e21c6c3962a0254c98602e7428b33fc4fcaa67ab368ce1b1"]
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1714055769, nanos_since_epoch = 606310000 }, "2a710731e0127ec3e21c6c3962a0254c98602e7428b33fc4fcaa67ab368ce1b1"]

View File

@ -13,4 +13,4 @@ requirements = []
source = "github"
[etags]
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1713463888, nanos_since_epoch = 383357000 }, "2a710731e0127ec3e21c6c3962a0254c98602e7428b33fc4fcaa67ab368ce1b1"]
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1714055769, nanos_since_epoch = 886756000 }, "2a710731e0127ec3e21c6c3962a0254c98602e7428b33fc4fcaa67ab368ce1b1"]

View File

@ -13,4 +13,4 @@ requirements = []
source = "github"
[etags]
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1713463890, nanos_since_epoch = 965623000 }, "2a710731e0127ec3e21c6c3962a0254c98602e7428b33fc4fcaa67ab368ce1b1"]
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1714055768, nanos_since_epoch = 494960000 }, "2a710731e0127ec3e21c6c3962a0254c98602e7428b33fc4fcaa67ab368ce1b1"]

View File

@ -13,4 +13,4 @@ requirements = []
source = "github"
[etags]
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1713463887, nanos_since_epoch = 961778000 }, "2a710731e0127ec3e21c6c3962a0254c98602e7428b33fc4fcaa67ab368ce1b1"]
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1714055765, nanos_since_epoch = 138956000 }, "2a710731e0127ec3e21c6c3962a0254c98602e7428b33fc4fcaa67ab368ce1b1"]

View File

@ -13,4 +13,4 @@ requirements = []
source = "github"
[etags]
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1713463902, nanos_since_epoch = 215633000 }, "2a710731e0127ec3e21c6c3962a0254c98602e7428b33fc4fcaa67ab368ce1b1"]
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1714055779, nanos_since_epoch = 84463000 }, "2a710731e0127ec3e21c6c3962a0254c98602e7428b33fc4fcaa67ab368ce1b1"]

View File

@ -13,4 +13,4 @@ requirements = []
source = "github"
[etags]
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1713463897, nanos_since_epoch = 385755000 }, "2a710731e0127ec3e21c6c3962a0254c98602e7428b33fc4fcaa67ab368ce1b1"]
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1714055769, nanos_since_epoch = 870599000 }, "2a710731e0127ec3e21c6c3962a0254c98602e7428b33fc4fcaa67ab368ce1b1"]

View File

@ -13,4 +13,4 @@ requirements = []
source = "github"
[etags]
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1713463893, nanos_since_epoch = 847358000 }, "2a710731e0127ec3e21c6c3962a0254c98602e7428b33fc4fcaa67ab368ce1b1"]
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1714055768, nanos_since_epoch = 584957000 }, "2a710731e0127ec3e21c6c3962a0254c98602e7428b33fc4fcaa67ab368ce1b1"]

View File

@ -13,4 +13,4 @@ requirements = []
source = "github"
[etags]
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1713463886, nanos_since_epoch = 284148000 }, "2a710731e0127ec3e21c6c3962a0254c98602e7428b33fc4fcaa67ab368ce1b1"]
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1714055766, nanos_since_epoch = 525538000 }, "2a710731e0127ec3e21c6c3962a0254c98602e7428b33fc4fcaa67ab368ce1b1"]

View File

@ -13,4 +13,4 @@ requirements = []
source = "github"
[etags]
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1713463884, nanos_since_epoch = 163138000 }, "2a710731e0127ec3e21c6c3962a0254c98602e7428b33fc4fcaa67ab368ce1b1"]
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1714055773, nanos_since_epoch = 519699000 }, "2a710731e0127ec3e21c6c3962a0254c98602e7428b33fc4fcaa67ab368ce1b1"]

View File

@ -5,7 +5,7 @@
"plutusVersion": "v2",
"compiler": {
"name": "Aiken",
"version": "v1.0.26-alpha+4d36884"
"version": "v1.0.26-alpha+821d869"
}
},
"validators": [

View File

@ -13,4 +13,4 @@ requirements = []
source = "github"
[etags]
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1713463896, nanos_since_epoch = 514093000 }, "2a710731e0127ec3e21c6c3962a0254c98602e7428b33fc4fcaa67ab368ce1b1"]
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1714055769, nanos_since_epoch = 196556000 }, "2a710731e0127ec3e21c6c3962a0254c98602e7428b33fc4fcaa67ab368ce1b1"]

View File

@ -13,4 +13,4 @@ requirements = []
source = "github"
[etags]
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1713463896, nanos_since_epoch = 410684000 }, "2a710731e0127ec3e21c6c3962a0254c98602e7428b33fc4fcaa67ab368ce1b1"]
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1714055775, nanos_since_epoch = 337191000 }, "2a710731e0127ec3e21c6c3962a0254c98602e7428b33fc4fcaa67ab368ce1b1"]

View File

@ -13,4 +13,4 @@ requirements = []
source = "github"
[etags]
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1713463899, nanos_since_epoch = 4921000 }, "2a710731e0127ec3e21c6c3962a0254c98602e7428b33fc4fcaa67ab368ce1b1"]
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1714055766, nanos_since_epoch = 404145000 }, "2a710731e0127ec3e21c6c3962a0254c98602e7428b33fc4fcaa67ab368ce1b1"]

View File

@ -13,4 +13,4 @@ requirements = []
source = "github"
[etags]
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1713463884, nanos_since_epoch = 166567000 }, "2a710731e0127ec3e21c6c3962a0254c98602e7428b33fc4fcaa67ab368ce1b1"]
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1714055769, nanos_since_epoch = 438366000 }, "2a710731e0127ec3e21c6c3962a0254c98602e7428b33fc4fcaa67ab368ce1b1"]

View File

@ -5,7 +5,7 @@
"plutusVersion": "v2",
"compiler": {
"name": "Aiken",
"version": "v1.0.26-alpha+4d36884"
"version": "v1.0.26-alpha+821d869"
}
},
"validators": [

View File

@ -5,7 +5,7 @@
"plutusVersion": "v2",
"compiler": {
"name": "Aiken",
"version": "v1.0.26-alpha+4d36884"
"version": "v1.0.26-alpha+821d869"
}
},
"validators": [

View File

@ -13,4 +13,4 @@ requirements = []
source = "github"
[etags]
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1713463891, nanos_since_epoch = 684027000 }, "2a710731e0127ec3e21c6c3962a0254c98602e7428b33fc4fcaa67ab368ce1b1"]
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1714055779, nanos_since_epoch = 824042000 }, "2a710731e0127ec3e21c6c3962a0254c98602e7428b33fc4fcaa67ab368ce1b1"]

View File

@ -13,4 +13,4 @@ requirements = []
source = "github"
[etags]
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1713463887, nanos_since_epoch = 129564000 }, "2a710731e0127ec3e21c6c3962a0254c98602e7428b33fc4fcaa67ab368ce1b1"]
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1714055774, nanos_since_epoch = 480306000 }, "2a710731e0127ec3e21c6c3962a0254c98602e7428b33fc4fcaa67ab368ce1b1"]

View File

@ -13,4 +13,4 @@ requirements = []
source = "github"
[etags]
"aiken-lang/stdlib@specialize-dict-key" = [{ secs_since_epoch = 1713463739, nanos_since_epoch = 865019000 }, "4a03ebbbc134cedfe1bf03b59d5ed476f4dd97a769dc259552a9086e786bb108"]
"aiken-lang/stdlib@specialize-dict-key" = [{ secs_since_epoch = 1714055775, nanos_since_epoch = 582445000 }, "4a03ebbbc134cedfe1bf03b59d5ed476f4dd97a769dc259552a9086e786bb108"]

View File

@ -13,4 +13,4 @@ requirements = []
source = "github"
[etags]
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1713463893, nanos_since_epoch = 54580000 }, "2a710731e0127ec3e21c6c3962a0254c98602e7428b33fc4fcaa67ab368ce1b1"]
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1714055768, nanos_since_epoch = 799533000 }, "2a710731e0127ec3e21c6c3962a0254c98602e7428b33fc4fcaa67ab368ce1b1"]

View File

@ -5,7 +5,7 @@
"plutusVersion": "v2",
"compiler": {
"name": "Aiken",
"version": "v1.0.26-alpha+4d36884"
"version": "v1.0.26-alpha+821d869"
}
},
"validators": [

View File

@ -13,4 +13,4 @@ requirements = []
source = "github"
[etags]
"aiken-lang/stdlib@specialize-dict-key" = [{ secs_since_epoch = 1713463624, nanos_since_epoch = 244261000 }, "4a03ebbbc134cedfe1bf03b59d5ed476f4dd97a769dc259552a9086e786bb108"]
"aiken-lang/stdlib@specialize-dict-key" = [{ secs_since_epoch = 1714055770, nanos_since_epoch = 469989000 }, "4a03ebbbc134cedfe1bf03b59d5ed476f4dd97a769dc259552a9086e786bb108"]

View File

@ -13,4 +13,4 @@ requirements = []
source = "github"
[etags]
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1713463884, nanos_since_epoch = 866338000 }, "2a710731e0127ec3e21c6c3962a0254c98602e7428b33fc4fcaa67ab368ce1b1"]
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1714055766, nanos_since_epoch = 449700000 }, "2a710731e0127ec3e21c6c3962a0254c98602e7428b33fc4fcaa67ab368ce1b1"]

View File

@ -13,4 +13,4 @@ requirements = []
source = "github"
[etags]
"aiken-lang/stdlib@specialize-dict-key" = [{ secs_since_epoch = 1713463713, nanos_since_epoch = 938757000 }, "4a03ebbbc134cedfe1bf03b59d5ed476f4dd97a769dc259552a9086e786bb108"]
"aiken-lang/stdlib@specialize-dict-key" = [{ secs_since_epoch = 1714055778, nanos_since_epoch = 453151000 }, "4a03ebbbc134cedfe1bf03b59d5ed476f4dd97a769dc259552a9086e786bb108"]

View File

@ -5,7 +5,7 @@
"plutusVersion": "v2",
"compiler": {
"name": "Aiken",
"version": "v1.0.26-alpha+4d36884"
"version": "v1.0.26-alpha+821d869"
}
},
"validators": [

View File

@ -5,7 +5,7 @@
"plutusVersion": "v2",
"compiler": {
"name": "Aiken",
"version": "v1.0.26-alpha+4d36884"
"version": "v1.0.26-alpha+821d869"
}
},
"validators": [

View File

@ -6,7 +6,7 @@
"plutusVersion": "v2",
"compiler": {
"name": "Aiken",
"version": "v1.0.26-alpha+4d36884"
"version": "v1.0.26-alpha+821d869"
},
"license": "Apache-2.0"
},

View File

@ -3,15 +3,15 @@
exit_codes=()
TESTS=()
# for scenario in $(find . -maxdepth 1 -mindepth 1 -type d ! -name script_context); do
# ./run $scenario &
# TESTS+=("$!")
# done
#
# for p in ${TESTS[@]}; do
# wait $p
# exit_codes+=("$?")
# done
for scenario in $(find . -maxdepth 1 -mindepth 1 -type d ! -name script_context); do
./run $scenario &
TESTS+=("$!")
done
for p in ${TESTS[@]}; do
wait $p
exit_codes+=("$?")
done
for interaction in $(find script_context/validators -type f); do

View File

@ -13,4 +13,4 @@ requirements = []
source = "github"
[etags]
"aiken-lang/stdlib@specialize-dict-key" = [{ secs_since_epoch = 1713463977, nanos_since_epoch = 479564000 }, "4a03ebbbc134cedfe1bf03b59d5ed476f4dd97a769dc259552a9086e786bb108"]
"aiken-lang/stdlib@specialize-dict-key" = [{ secs_since_epoch = 1714055683, nanos_since_epoch = 673729000 }, "4a03ebbbc134cedfe1bf03b59d5ed476f4dd97a769dc259552a9086e786bb108"]

View File

@ -5,7 +5,7 @@
"plutusVersion": "v2",
"compiler": {
"name": "Aiken",
"version": "v1.0.26-alpha+4d36884"
"version": "v1.0.26-alpha+821d869"
}
},
"validators": [