fixing more pair issues

This commit is contained in:
microproofs 2024-04-11 10:15:12 -04:00 committed by Kasey
parent ebe415cfc9
commit 46c7cb797a
4 changed files with 39 additions and 0 deletions

View File

@ -342,6 +342,19 @@ impl TypedDataType {
}
}
pub fn pair(fst_tipo: Rc<Type>, snd_tipo: Rc<Type>) -> 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![

View File

@ -1328,6 +1328,17 @@ pub fn prelude_data_types(id_gen: &IdGenerator) -> IndexMap<DataTypeKey, TypedDa
bool_data_type,
);
let pair_data_type =
TypedDataType::pair(generic_var(id_gen.next()), generic_var(id_gen.next()));
data_types.insert(
DataTypeKey {
module_name: "".to_string(),
defined_type: "Pair".to_string(),
},
pair_data_type,
);
// Option
let option_data_type = TypedDataType::option(generic_var(id_gen.next()));
data_types.insert(

View File

@ -649,6 +649,12 @@ impl<'a> 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);

View File

@ -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,
}
}