From 8a3a46523765900b4d43c028022a442b3af2dc51 Mon Sep 17 00:00:00 2001 From: rvcas Date: Sun, 5 Nov 2023 17:51:13 -0500 Subject: [PATCH] feat(bls): add new types to aiken prelude --- crates/aiken-lang/src/builtins.rs | 76 +++++++++++++++++++++++++++---- 1 file changed, 66 insertions(+), 10 deletions(-) diff --git a/crates/aiken-lang/src/builtins.rs b/crates/aiken-lang/src/builtins.rs index bafd854a..6391d411 100644 --- a/crates/aiken-lang/src/builtins.rs +++ b/crates/aiken-lang/src/builtins.rs @@ -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"; @@ -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(), @@ -1057,6 +1095,33 @@ pub fn byte_array() -> Rc { }) } +pub fn g1_element() -> Rc { + Rc::new(Type::App { + public: true, + module: "".to_string(), + name: G1_ELEMENT.to_string(), + args: vec![], + }) +} + +pub fn g2_element() -> Rc { + Rc::new(Type::App { + public: true, + module: "".to_string(), + name: G2_ELEMENT.to_string(), + args: vec![], + }) +} + +pub fn miller_loop_result() -> Rc { + Rc::new(Type::App { + public: true, + module: "".to_string(), + name: MILLER_LOOP_RESULT.to_string(), + args: vec![], + }) +} + pub fn tuple(elems: Vec>) -> Rc { Rc::new(Type::Tuple { elems }) } @@ -1097,15 +1162,6 @@ pub fn void() -> Rc { }) } -pub fn result(a: Rc, e: Rc) -> Rc { - Rc::new(Type::App { - public: true, - name: RESULT.to_string(), - module: "".to_string(), - args: vec![a, e], - }) -} - pub fn option(a: Rc) -> Rc { Rc::new(Type::App { public: true,