feat: implement bls primitives in code gen
This commit is contained in:
@@ -3,7 +3,7 @@ use std::rc::Rc;
|
||||
use uplc::builtins::DefaultFunction;
|
||||
|
||||
use crate::{
|
||||
ast::{BinOp, UnOp},
|
||||
ast::{BinOp, Curve, UnOp},
|
||||
tipo::{Type, ValueConstructor},
|
||||
};
|
||||
|
||||
@@ -19,6 +19,9 @@ pub enum Air {
|
||||
ByteArray {
|
||||
bytes: Vec<u8>,
|
||||
},
|
||||
CurvePoint {
|
||||
point: Curve,
|
||||
},
|
||||
Bool {
|
||||
value: bool,
|
||||
},
|
||||
|
||||
@@ -506,6 +506,7 @@ pub fn constants_ir(literal: &Constant) -> AirTree {
|
||||
Constant::Int { value, .. } => AirTree::int(value),
|
||||
Constant::String { value, .. } => AirTree::string(value),
|
||||
Constant::ByteArray { bytes, .. } => AirTree::byte_array(bytes.clone()),
|
||||
Constant::CurvePoint { point, .. } => AirTree::curve(*point.as_ref()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1217,6 +1218,8 @@ pub fn convert_data_to_type(term: Term<Name>, field_type: &Rc<Type>) -> Term<Nam
|
||||
Term::bls12_381_g1_uncompress().apply(Term::un_b_data().apply(term))
|
||||
} else if field_type.is_bls381_12_g2() {
|
||||
Term::bls12_381_g2_uncompress().apply(Term::un_b_data().apply(term))
|
||||
} else if field_type.is_ml_result() {
|
||||
panic!("ML Result not supported")
|
||||
} else {
|
||||
term
|
||||
}
|
||||
@@ -1302,7 +1305,7 @@ pub fn convert_constants_to_data(constants: Vec<Rc<UplcConstant>>) -> Vec<UplcCo
|
||||
UplcConstant::Bls12_381G2Element(b) => UplcConstant::Data(PlutusData::BoundedBytes(
|
||||
b.deref().clone().compress().into(),
|
||||
)),
|
||||
UplcConstant::Bls12_381MlResult(_) => unreachable!(),
|
||||
UplcConstant::Bls12_381MlResult(_) => unreachable!("Bls12_381MlResult not supported"),
|
||||
};
|
||||
new_constants.push(constant);
|
||||
}
|
||||
@@ -1365,6 +1368,8 @@ pub fn convert_type_to_data(term: Term<Name>, field_type: &Rc<Type>) -> Term<Nam
|
||||
Term::bls12_381_g1_compress().apply(Term::b_data().apply(term))
|
||||
} else if field_type.is_bls381_12_g2() {
|
||||
Term::bls12_381_g2_compress().apply(Term::b_data().apply(term))
|
||||
} else if field_type.is_ml_result() {
|
||||
panic!("ML Result not supported")
|
||||
} else {
|
||||
term
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ use std::{borrow::BorrowMut, rc::Rc, slice::Iter};
|
||||
use uplc::{builder::EXPECT_ON_LIST, builtins::DefaultFunction};
|
||||
|
||||
use crate::{
|
||||
ast::{BinOp, Span, UnOp},
|
||||
ast::{BinOp, Curve, Span, UnOp},
|
||||
builtins::{bool, byte_array, data, int, list, string, void},
|
||||
tipo::{Type, ValueConstructor, ValueConstructorVariant},
|
||||
};
|
||||
@@ -197,6 +197,9 @@ pub enum AirExpression {
|
||||
ByteArray {
|
||||
bytes: Vec<u8>,
|
||||
},
|
||||
CurvePoint {
|
||||
point: Curve,
|
||||
},
|
||||
Bool {
|
||||
value: bool,
|
||||
},
|
||||
@@ -341,6 +344,9 @@ impl AirTree {
|
||||
pub fn byte_array(bytes: Vec<u8>) -> AirTree {
|
||||
AirTree::Expression(AirExpression::ByteArray { bytes })
|
||||
}
|
||||
pub fn curve(point: Curve) -> AirTree {
|
||||
AirTree::Expression(AirExpression::CurvePoint { point })
|
||||
}
|
||||
pub fn bool(value: bool) -> AirTree {
|
||||
AirTree::Expression(AirExpression::Bool { value })
|
||||
}
|
||||
@@ -1058,6 +1064,9 @@ impl AirTree {
|
||||
AirExpression::ByteArray { bytes } => air_vec.push(Air::ByteArray {
|
||||
bytes: bytes.clone(),
|
||||
}),
|
||||
AirExpression::CurvePoint { point } => {
|
||||
air_vec.push(Air::CurvePoint { point: *point })
|
||||
}
|
||||
AirExpression::Bool { value } => air_vec.push(Air::Bool { value: *value }),
|
||||
AirExpression::List { tipo, tail, items } => {
|
||||
air_vec.push(Air::List {
|
||||
@@ -1286,6 +1295,7 @@ impl AirTree {
|
||||
AirExpression::String { .. } => string(),
|
||||
AirExpression::ByteArray { .. } => byte_array(),
|
||||
AirExpression::Bool { .. } => bool(),
|
||||
AirExpression::CurvePoint { point } => point.tipo(),
|
||||
AirExpression::List { tipo, .. }
|
||||
| AirExpression::Tuple { tipo, .. }
|
||||
| AirExpression::Call { tipo, .. }
|
||||
|
||||
Reference in New Issue
Block a user