Skip to content

Commit

Permalink
feat(bls): add new types to aiken prelude
Browse files Browse the repository at this point in the history
  • Loading branch information
rvcas committed Nov 5, 2023
1 parent dc62ca4 commit 37232da
Showing 1 changed file with 66 additions and 10 deletions.
76 changes: 66 additions & 10 deletions crates/aiken-lang/src/builtins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ pub const INT: &str = "Int";
pub const DATA: &str = "Data";
pub const LIST: &str = "List";
pub const VOID: &str = "Void";
pub const RESULT: &str = "Result";
pub const G1_ELEMENT: &str = "G1Element";
pub const G2_ELEMENT: &str = "G2Element";
pub const MILLER_LOOP_RESULT: &str = "MillerLoopResult";
pub const STRING: &str = "String";
pub const OPTION: &str = "Option";
pub const ORDERING: &str = "Ordering";
Expand Down Expand Up @@ -121,6 +123,42 @@ pub fn prelude(id_gen: &IdGenerator) -> TypeInfo {
},
);

// G1Element
prelude.types.insert(
G1_ELEMENT.to_string(),
TypeConstructor {
parameters: vec![],
tipo: int(),
location: Span::empty(),
module: "".to_string(),
public: true,
},
);

// G2Element
prelude.types.insert(
G2_ELEMENT.to_string(),
TypeConstructor {
parameters: vec![],
tipo: int(),
location: Span::empty(),
module: "".to_string(),
public: true,
},
);

// MillerLoopResult
prelude.types.insert(
MILLER_LOOP_RESULT.to_string(),
TypeConstructor {
parameters: vec![],
tipo: int(),
location: Span::empty(),
module: "".to_string(),
public: true,
},
);

// Ordering
prelude.types_constructors.insert(
ORDERING.to_string(),
Expand Down Expand Up @@ -1057,6 +1095,33 @@ pub fn byte_array() -> Rc<Type> {
})
}

pub fn g1_element() -> Rc<Type> {
Rc::new(Type::App {
public: true,
module: "".to_string(),
name: G1_ELEMENT.to_string(),
args: vec![],
})
}

pub fn g2_element() -> Rc<Type> {
Rc::new(Type::App {
public: true,
module: "".to_string(),
name: G2_ELEMENT.to_string(),
args: vec![],
})
}

pub fn miller_loop_result() -> Rc<Type> {
Rc::new(Type::App {
public: true,
module: "".to_string(),
name: MILLER_LOOP_RESULT.to_string(),
args: vec![],
})
}

pub fn tuple(elems: Vec<Rc<Type>>) -> Rc<Type> {
Rc::new(Type::Tuple { elems })
}
Expand Down Expand Up @@ -1097,15 +1162,6 @@ pub fn void() -> Rc<Type> {
})
}

pub fn result(a: Rc<Type>, e: Rc<Type>) -> Rc<Type> {
Rc::new(Type::App {
public: true,
name: RESULT.to_string(),
module: "".to_string(),
args: vec![a, e],
})
}

pub fn option(a: Rc<Type>) -> Rc<Type> {
Rc::new(Type::App {
public: true,
Expand Down

0 comments on commit 37232da

Please sign in to comment.