diff --git a/crates/aiken-lang/src/ast.rs b/crates/aiken-lang/src/ast.rs index 1e1fc5c6..d955b47c 100644 --- a/crates/aiken-lang/src/ast.rs +++ b/crates/aiken-lang/src/ast.rs @@ -342,6 +342,19 @@ impl TypedDataType { } } + pub fn pair(fst_tipo: Rc, snd_tipo: Rc) -> Self { + DataType { + constructors: vec![], + doc: None, + location: Span::empty(), + name: "Pair".to_string(), + opaque: false, + parameters: vec!["a".to_string(), "b".to_string()], + public: true, + typed_parameters: vec![fst_tipo, snd_tipo], + } + } + pub fn bool() -> Self { DataType { constructors: vec![ diff --git a/crates/aiken-lang/src/builtins.rs b/crates/aiken-lang/src/builtins.rs index 37a4f05b..461c152f 100644 --- a/crates/aiken-lang/src/builtins.rs +++ b/crates/aiken-lang/src/builtins.rs @@ -1328,6 +1328,17 @@ pub fn prelude_data_types(id_gen: &IdGenerator) -> IndexMap CodeGenerator<'a> { } => { if check_replaceable_opaque_type(&record.tipo(), &self.data_types) { self.build(record, module_build_name, &[]) + } else if record.tipo().is_pair() { + AirTree::pair_index( + usize::try_from(*index).unwrap(), + tipo.clone(), + self.build(record, module_build_name, &[]), + ) } else { let function_name = format!("__access_index_{}", *index); diff --git a/crates/aiken-lang/src/tipo.rs b/crates/aiken-lang/src/tipo.rs index 156045ef..ec323842 100644 --- a/crates/aiken-lang/src/tipo.rs +++ b/crates/aiken-lang/src/tipo.rs @@ -653,6 +653,15 @@ pub fn lookup_data_type_by_tipo( None } } + Type::Pair { .. } => { + let data_type_key = DataTypeKey { + module_name: "".to_string(), + defined_type: "Pair".to_string(), + }; + + data_types.get(&data_type_key).cloned().cloned() + } + _ => None, } }