fix utils
This commit is contained in:
parent
955d6bae5d
commit
230e8f0e84
2 changed files with 22 additions and 3 deletions
|
@ -1,6 +1,7 @@
|
|||
use super::{
|
||||
ArrayExpression, ArrayExpressionInner, BooleanExpression, Conditional, ConditionalKind,
|
||||
FieldElementExpression, Identifier, Select, UBitwidth, UExpression, UExpressionInner,
|
||||
ArrayExpression, ArrayExpressionInner, ArrayValue, BooleanExpression, Conditional,
|
||||
ConditionalKind, Expr, FieldElementExpression, Identifier, Select, Typed, TypedExpression,
|
||||
TypedExpressionOrSpread, UBitwidth, UExpression, UExpressionInner,
|
||||
};
|
||||
|
||||
pub fn f<'ast, T, U: TryInto<T>>(v: U) -> FieldElementExpression<'ast, T> {
|
||||
|
@ -11,6 +12,24 @@ pub fn a_id<'ast, T, I: TryInto<Identifier<'ast>>>(v: I) -> ArrayExpressionInner
|
|||
ArrayExpressionInner::Identifier(v.try_into().map_err(|_| ()).unwrap())
|
||||
}
|
||||
|
||||
pub fn a<
|
||||
'ast,
|
||||
T,
|
||||
E: Typed<'ast, T> + Expr<'ast, T> + Into<TypedExpression<'ast, T>>,
|
||||
const N: usize,
|
||||
>(
|
||||
values: [E; N],
|
||||
) -> ArrayExpression<'ast, T> {
|
||||
let ty = values[0].get_type();
|
||||
ArrayExpressionInner::Value(ArrayValue(
|
||||
values
|
||||
.into_iter()
|
||||
.map(|e| TypedExpressionOrSpread::Expression(e.into()))
|
||||
.collect(),
|
||||
))
|
||||
.annotate(ty, N as u32)
|
||||
}
|
||||
|
||||
pub fn u_32<'ast, T, U: TryInto<u32>>(v: U) -> UExpression<'ast, T> {
|
||||
UExpressionInner::Value(v.try_into().map_err(|_| ()).unwrap() as u128).annotate(UBitwidth::B32)
|
||||
}
|
||||
|
|
|
@ -109,7 +109,7 @@ impl<'ast, T: Field> Folder<'ast, T> for BooleanArrayComparator {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use zokrates_ast::typed::{BooleanExpression, EqExpression, FieldElementExpression, Type};
|
||||
use zokrates_ast::typed::{BooleanExpression, EqExpression, Type};
|
||||
use zokrates_field::DummyCurveField;
|
||||
|
||||
use zokrates_ast::typed::utils::{a, a_id, conditional, f, select, u_32};
|
||||
|
|
Loading…
Reference in a new issue