refactor: move helper option builder to lang

This commit is contained in:
rvcas 2022-12-15 13:19:20 -05:00 committed by Lucas
parent 42f8a694f4
commit 0188003323
2 changed files with 43 additions and 43 deletions

View File

@ -112,6 +112,46 @@ pub struct TypeAlias<T> {
} }
pub type TypedDataType = DataType<Arc<Type>>; pub type TypedDataType = DataType<Arc<Type>>;
impl TypedDataType {
pub fn option(tipo: Arc<Type>) -> Self {
DataType {
constructors: vec![
RecordConstructor {
location: Span::empty(),
name: "Some".to_string(),
arguments: vec![RecordConstructorArg {
label: None,
annotation: Annotation::Var {
location: Span::empty(),
name: "a".to_string(),
},
location: Span::empty(),
tipo: tipo.clone(),
doc: None,
}],
documentation: None,
sugar: false,
},
RecordConstructor {
location: Span::empty(),
name: "None".to_string(),
arguments: vec![],
documentation: None,
sugar: false,
},
],
doc: None,
location: Span::empty(),
name: "Option".to_string(),
opaque: false,
parameters: vec!["a".to_string()],
public: true,
typed_parameters: vec![tipo],
}
}
}
pub type UntypedDataType = DataType<()>; pub type UntypedDataType = DataType<()>;
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq)]

View File

@ -8,10 +8,7 @@ pub mod script;
pub mod telemetry; pub mod telemetry;
use aiken_lang::{ use aiken_lang::{
ast::{ ast::{Definition, Function, ModuleKind, TypedDataType, TypedDefinition, TypedFunction},
Annotation, DataType, Definition, Function, ModuleKind, RecordConstructor,
RecordConstructorArg, Span, TypedDataType, TypedDefinition, TypedFunction,
},
builder::{DataTypeKey, FunctionAccessKey}, builder::{DataTypeKey, FunctionAccessKey},
builtins::{self, generic_var}, builtins::{self, generic_var},
tipo::TypeInfo, tipo::TypeInfo,
@ -418,7 +415,7 @@ where
let mut imports = HashMap::new(); let mut imports = HashMap::new();
let mut constants = HashMap::new(); let mut constants = HashMap::new();
let option_data_type = make_option(); let option_data_type = TypedDataType::option(generic_var(self.id_gen.next()));
data_types.insert( data_types.insert(
DataTypeKey { DataTypeKey {
@ -510,7 +507,7 @@ where
let mut imports = HashMap::new(); let mut imports = HashMap::new();
let mut constants = HashMap::new(); let mut constants = HashMap::new();
let option_data_type = make_option(); let option_data_type = TypedDataType::option(generic_var(self.id_gen.next()));
data_types.insert( data_types.insert(
DataTypeKey { DataTypeKey {
@ -826,40 +823,3 @@ fn is_aiken_path(path: &Path, dir: impl AsRef<Path>) -> bool {
.expect("is_aiken_path(): to_str"), .expect("is_aiken_path(): to_str"),
) )
} }
fn make_option() -> TypedDataType {
DataType {
constructors: vec![
RecordConstructor {
location: Span::empty(),
name: "Some".to_string(),
arguments: vec![RecordConstructorArg {
label: None,
annotation: Annotation::Var {
location: Span::empty(),
name: "a".to_string(),
},
location: Span::empty(),
tipo: generic_var(0),
doc: None,
}],
documentation: None,
sugar: false,
},
RecordConstructor {
location: Span::empty(),
name: "None".to_string(),
arguments: vec![],
documentation: None,
sugar: false,
},
],
doc: None,
location: Span::empty(),
name: "Option".to_string(),
opaque: false,
parameters: vec!["a".to_string()],
public: true,
typed_parameters: vec![generic_var(0)],
}
}