mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-09-11 05:45:30 +03:00
Standardize generic F and G order convention
This commit is contained in:
parent
97272fa9d7
commit
7e36d2b5fa
@ -18,16 +18,16 @@ use sha2::{Digest, Sha256};
|
||||
use std::{fs, marker::PhantomData, path::PathBuf};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Compiler<G: Group, F: Field + PrimeField> {
|
||||
pub struct Compiler<F: Field + PrimeField, G: Group> {
|
||||
package_name: String,
|
||||
main_file_path: PathBuf,
|
||||
program: Program<G, F>,
|
||||
program_inputs: Vec<Option<InputValue<G, F>>>,
|
||||
output: Option<ConstrainedValue<G, F>>,
|
||||
program: Program<F, G>,
|
||||
program_inputs: Vec<Option<InputValue<F, G>>>,
|
||||
output: Option<ConstrainedValue<F, G>>,
|
||||
_engine: PhantomData<F>,
|
||||
}
|
||||
|
||||
impl<G: Group, F: Field + PrimeField> Compiler<G, F> {
|
||||
impl<F: Field + PrimeField, G: Group> Compiler<F, G> {
|
||||
pub fn init(package_name: String, main_file_path: PathBuf) -> Self {
|
||||
Self {
|
||||
package_name,
|
||||
@ -82,7 +82,7 @@ impl<G: Group, F: Field + PrimeField> Compiler<G, F> {
|
||||
// Build program from abstract syntax tree
|
||||
let package_name = self.package_name.clone();
|
||||
|
||||
self.program = Program::<G, F>::from(syntax_tree, package_name);
|
||||
self.program = Program::<F, G>::from(syntax_tree, package_name);
|
||||
self.program_inputs = vec![None; self.program.num_parameters];
|
||||
|
||||
log::debug!("Compilation complete\n{:#?}", self.program);
|
||||
@ -91,7 +91,7 @@ impl<G: Group, F: Field + PrimeField> Compiler<G, F> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<G: Group, F: Field + PrimeField> ConstraintSynthesizer<F> for Compiler<G, F> {
|
||||
impl<F: Field + PrimeField, G: Group> ConstraintSynthesizer<F> for Compiler<F, G> {
|
||||
fn generate_constraints<CS: ConstraintSystem<F>>(
|
||||
self,
|
||||
cs: &mut CS,
|
||||
|
@ -15,13 +15,13 @@ use snarkos_models::{
|
||||
},
|
||||
};
|
||||
|
||||
impl<G: Group, F: Field + PrimeField, CS: ConstraintSystem<G>> ConstrainedProgram<G, F, CS> {
|
||||
impl<F: Field + PrimeField, G: Group, CS: ConstraintSystem<F>> ConstrainedProgram<F, G, CS> {
|
||||
pub(crate) fn bool_from_input(
|
||||
&mut self,
|
||||
cs: &mut CS,
|
||||
input_model: InputModel<G, F>,
|
||||
input_value: Option<InputValue<G, F>>,
|
||||
) -> Result<ConstrainedValue<G, F>, BooleanError> {
|
||||
input_model: InputModel<F, G>,
|
||||
input_value: Option<InputValue<F, G>>,
|
||||
) -> Result<ConstrainedValue<F, G>, BooleanError> {
|
||||
// Check that the input value is the correct type
|
||||
let bool_value = match input_value {
|
||||
Some(input) => {
|
||||
@ -49,13 +49,13 @@ impl<G: Group, F: Field + PrimeField, CS: ConstraintSystem<G>> ConstrainedProgra
|
||||
Ok(ConstrainedValue::Boolean(number))
|
||||
}
|
||||
|
||||
pub(crate) fn get_boolean_constant(bool: Boolean) -> ConstrainedValue<G, F> {
|
||||
pub(crate) fn get_boolean_constant(bool: Boolean) -> ConstrainedValue<F, G> {
|
||||
ConstrainedValue::Boolean(bool)
|
||||
}
|
||||
|
||||
pub(crate) fn evaluate_not(
|
||||
value: ConstrainedValue<G, F>,
|
||||
) -> Result<ConstrainedValue<G, F>, BooleanError> {
|
||||
value: ConstrainedValue<F, G>,
|
||||
) -> Result<ConstrainedValue<F, G>, BooleanError> {
|
||||
match value {
|
||||
ConstrainedValue::Boolean(boolean) => Ok(ConstrainedValue::Boolean(boolean.not())),
|
||||
value => Err(BooleanError::CannotEvaluate(format!("!{}", value))),
|
||||
@ -65,9 +65,9 @@ impl<G: Group, F: Field + PrimeField, CS: ConstraintSystem<G>> ConstrainedProgra
|
||||
pub(crate) fn enforce_or(
|
||||
&mut self,
|
||||
cs: &mut CS,
|
||||
left: ConstrainedValue<G, F>,
|
||||
right: ConstrainedValue<G, F>,
|
||||
) -> Result<ConstrainedValue<G, F>, BooleanError> {
|
||||
left: ConstrainedValue<F, G>,
|
||||
right: ConstrainedValue<F, G>,
|
||||
) -> Result<ConstrainedValue<F, G>, BooleanError> {
|
||||
match (left, right) {
|
||||
(ConstrainedValue::Boolean(left_bool), ConstrainedValue::Boolean(right_bool)) => Ok(
|
||||
ConstrainedValue::Boolean(Boolean::or(cs, &left_bool, &right_bool)?),
|
||||
@ -82,9 +82,9 @@ impl<G: Group, F: Field + PrimeField, CS: ConstraintSystem<G>> ConstrainedProgra
|
||||
pub(crate) fn enforce_and(
|
||||
&mut self,
|
||||
cs: &mut CS,
|
||||
left: ConstrainedValue<G, F>,
|
||||
right: ConstrainedValue<G, F>,
|
||||
) -> Result<ConstrainedValue<G, F>, BooleanError> {
|
||||
left: ConstrainedValue<F, G>,
|
||||
right: ConstrainedValue<F, G>,
|
||||
) -> Result<ConstrainedValue<F, G>, BooleanError> {
|
||||
match (left, right) {
|
||||
(ConstrainedValue::Boolean(left_bool), ConstrainedValue::Boolean(right_bool)) => Ok(
|
||||
ConstrainedValue::Boolean(Boolean::and(cs, &left_bool, &right_bool)?),
|
||||
@ -96,7 +96,7 @@ impl<G: Group, F: Field + PrimeField, CS: ConstraintSystem<G>> ConstrainedProgra
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn boolean_eq(left: Boolean, right: Boolean) -> ConstrainedValue<G, F> {
|
||||
pub(crate) fn boolean_eq(left: Boolean, right: Boolean) -> ConstrainedValue<F, G> {
|
||||
ConstrainedValue::Boolean(Boolean::Constant(left.eq(&right)))
|
||||
}
|
||||
|
||||
|
@ -14,13 +14,13 @@ use snarkos_models::{
|
||||
gadgets::{r1cs::ConstraintSystem, utilities::boolean::Boolean},
|
||||
};
|
||||
|
||||
impl<G: Group, F: Field + PrimeField, CS: ConstraintSystem<G>> ConstrainedProgram<G, F, CS> {
|
||||
impl<F: Field + PrimeField, G: Group, CS: ConstraintSystem<F>> ConstrainedProgram<F, G, CS> {
|
||||
/// Enforce a variable expression by getting the resolved value
|
||||
pub(crate) fn enforce_variable(
|
||||
&mut self,
|
||||
scope: String,
|
||||
unresolved_variable: Variable<G, F>,
|
||||
) -> Result<ConstrainedValue<G, F>, ExpressionError> {
|
||||
unresolved_variable: Variable<F, G>,
|
||||
) -> Result<ConstrainedValue<F, G>, ExpressionError> {
|
||||
// Evaluate the variable name in the current function scope
|
||||
let variable_name = new_scope_from_variable(scope, &unresolved_variable);
|
||||
|
||||
@ -41,9 +41,9 @@ impl<G: Group, F: Field + PrimeField, CS: ConstraintSystem<G>> ConstrainedProgra
|
||||
fn enforce_add_expression(
|
||||
&mut self,
|
||||
cs: &mut CS,
|
||||
left: ConstrainedValue<G, F>,
|
||||
right: ConstrainedValue<G, F>,
|
||||
) -> Result<ConstrainedValue<G, F>, ExpressionError> {
|
||||
left: ConstrainedValue<F, G>,
|
||||
right: ConstrainedValue<F, G>,
|
||||
) -> Result<ConstrainedValue<F, G>, ExpressionError> {
|
||||
Ok(match (left, right) {
|
||||
(ConstrainedValue::Integer(num_1), ConstrainedValue::Integer(num_2)) => {
|
||||
Self::enforce_integer_add(cs, num_1, num_2)?
|
||||
@ -63,9 +63,9 @@ impl<G: Group, F: Field + PrimeField, CS: ConstraintSystem<G>> ConstrainedProgra
|
||||
fn enforce_sub_expression(
|
||||
&mut self,
|
||||
cs: &mut CS,
|
||||
left: ConstrainedValue<G, F>,
|
||||
right: ConstrainedValue<G, F>,
|
||||
) -> Result<ConstrainedValue<G, F>, ExpressionError> {
|
||||
left: ConstrainedValue<F, G>,
|
||||
right: ConstrainedValue<F, G>,
|
||||
) -> Result<ConstrainedValue<F, G>, ExpressionError> {
|
||||
Ok(match (left, right) {
|
||||
(ConstrainedValue::Integer(num_1), ConstrainedValue::Integer(num_2)) => {
|
||||
Self::enforce_integer_sub(cs, num_1, num_2)?
|
||||
@ -85,9 +85,9 @@ impl<G: Group, F: Field + PrimeField, CS: ConstraintSystem<G>> ConstrainedProgra
|
||||
fn enforce_mul_expression(
|
||||
&mut self,
|
||||
cs: &mut CS,
|
||||
left: ConstrainedValue<G, F>,
|
||||
right: ConstrainedValue<G, F>,
|
||||
) -> Result<ConstrainedValue<G, F>, ExpressionError> {
|
||||
left: ConstrainedValue<F, G>,
|
||||
right: ConstrainedValue<F, G>,
|
||||
) -> Result<ConstrainedValue<F, G>, ExpressionError> {
|
||||
Ok(match (left, right) {
|
||||
(ConstrainedValue::Integer(num_1), ConstrainedValue::Integer(num_2)) => {
|
||||
Self::enforce_integer_mul(cs, num_1, num_2)?
|
||||
@ -107,9 +107,9 @@ impl<G: Group, F: Field + PrimeField, CS: ConstraintSystem<G>> ConstrainedProgra
|
||||
fn enforce_div_expression(
|
||||
&mut self,
|
||||
cs: &mut CS,
|
||||
left: ConstrainedValue<G, F>,
|
||||
right: ConstrainedValue<G, F>,
|
||||
) -> Result<ConstrainedValue<G, F>, ExpressionError> {
|
||||
left: ConstrainedValue<F, G>,
|
||||
right: ConstrainedValue<F, G>,
|
||||
) -> Result<ConstrainedValue<F, G>, ExpressionError> {
|
||||
Ok(match (left, right) {
|
||||
(ConstrainedValue::Integer(num_1), ConstrainedValue::Integer(num_2)) => {
|
||||
Self::enforce_integer_div(cs, num_1, num_2)?
|
||||
@ -128,9 +128,9 @@ impl<G: Group, F: Field + PrimeField, CS: ConstraintSystem<G>> ConstrainedProgra
|
||||
fn enforce_pow_expression(
|
||||
&mut self,
|
||||
cs: &mut CS,
|
||||
left: ConstrainedValue<G, F>,
|
||||
right: ConstrainedValue<G, F>,
|
||||
) -> Result<ConstrainedValue<G, F>, ExpressionError> {
|
||||
left: ConstrainedValue<F, G>,
|
||||
right: ConstrainedValue<F, G>,
|
||||
) -> Result<ConstrainedValue<F, G>, ExpressionError> {
|
||||
Ok(match (left, right) {
|
||||
(ConstrainedValue::Integer(num_1), ConstrainedValue::Integer(num_2)) => {
|
||||
Self::enforce_integer_pow(cs, num_1, num_2)?
|
||||
@ -153,9 +153,9 @@ impl<G: Group, F: Field + PrimeField, CS: ConstraintSystem<G>> ConstrainedProgra
|
||||
/// Evaluate Boolean operations
|
||||
fn evaluate_eq_expression(
|
||||
&mut self,
|
||||
left: ConstrainedValue<G, F>,
|
||||
right: ConstrainedValue<G, F>,
|
||||
) -> Result<ConstrainedValue<G, F>, ExpressionError> {
|
||||
left: ConstrainedValue<F, G>,
|
||||
right: ConstrainedValue<F, G>,
|
||||
) -> Result<ConstrainedValue<F, G>, ExpressionError> {
|
||||
Ok(match (left, right) {
|
||||
(ConstrainedValue::Boolean(bool_1), ConstrainedValue::Boolean(bool_2)) => {
|
||||
Self::boolean_eq(bool_1, bool_2)
|
||||
@ -177,9 +177,9 @@ impl<G: Group, F: Field + PrimeField, CS: ConstraintSystem<G>> ConstrainedProgra
|
||||
|
||||
fn evaluate_geq_expression(
|
||||
&mut self,
|
||||
left: ConstrainedValue<G, F>,
|
||||
right: ConstrainedValue<G, F>,
|
||||
) -> Result<ConstrainedValue<G, F>, ExpressionError> {
|
||||
left: ConstrainedValue<F, G>,
|
||||
right: ConstrainedValue<F, G>,
|
||||
) -> Result<ConstrainedValue<F, G>, ExpressionError> {
|
||||
match (left, right) {
|
||||
// (ResolvedValue::FieldElement(fe_1), ResolvedValue::FieldElement(fe_2)) => {
|
||||
// Self::field_geq(fe_1, fe_2)
|
||||
@ -193,9 +193,9 @@ impl<G: Group, F: Field + PrimeField, CS: ConstraintSystem<G>> ConstrainedProgra
|
||||
|
||||
fn evaluate_gt_expression(
|
||||
&mut self,
|
||||
left: ConstrainedValue<G, F>,
|
||||
right: ConstrainedValue<G, F>,
|
||||
) -> Result<ConstrainedValue<G, F>, ExpressionError> {
|
||||
left: ConstrainedValue<F, G>,
|
||||
right: ConstrainedValue<F, G>,
|
||||
) -> Result<ConstrainedValue<F, G>, ExpressionError> {
|
||||
match (left, right) {
|
||||
// (ResolvedValue::FieldElement(fe_1), ResolvedValue::FieldElement(fe_2)) => {
|
||||
// Self::field_gt(fe_1, fe_2)
|
||||
@ -209,9 +209,9 @@ impl<G: Group, F: Field + PrimeField, CS: ConstraintSystem<G>> ConstrainedProgra
|
||||
|
||||
fn evaluate_leq_expression(
|
||||
&mut self,
|
||||
left: ConstrainedValue<G, F>,
|
||||
right: ConstrainedValue<G, F>,
|
||||
) -> Result<ConstrainedValue<G, F>, ExpressionError> {
|
||||
left: ConstrainedValue<F, G>,
|
||||
right: ConstrainedValue<F, G>,
|
||||
) -> Result<ConstrainedValue<F, G>, ExpressionError> {
|
||||
match (left, right) {
|
||||
// (ResolvedValue::FieldElement(fe_1), ResolvedValue::FieldElement(fe_2)) => {
|
||||
// Self::field_leq(fe_1, fe_2)
|
||||
@ -225,9 +225,9 @@ impl<G: Group, F: Field + PrimeField, CS: ConstraintSystem<G>> ConstrainedProgra
|
||||
|
||||
fn evaluate_lt_expression(
|
||||
&mut self,
|
||||
left: ConstrainedValue<G, F>,
|
||||
right: ConstrainedValue<G, F>,
|
||||
) -> Result<ConstrainedValue<G, F>, ExpressionError> {
|
||||
left: ConstrainedValue<F, G>,
|
||||
right: ConstrainedValue<F, G>,
|
||||
) -> Result<ConstrainedValue<F, G>, ExpressionError> {
|
||||
match (left, right) {
|
||||
// (ResolvedValue::FieldElement(fe_1), ResolvedValue::FieldElement(fe_2)) => {
|
||||
// Self::field_lt(fe_1, fe_2)
|
||||
@ -245,8 +245,8 @@ impl<G: Group, F: Field + PrimeField, CS: ConstraintSystem<G>> ConstrainedProgra
|
||||
cs: &mut CS,
|
||||
file_scope: String,
|
||||
function_scope: String,
|
||||
array: Vec<Box<SpreadOrExpression<G, F>>>,
|
||||
) -> Result<ConstrainedValue<G, F>, ExpressionError> {
|
||||
array: Vec<Box<SpreadOrExpression<F, G>>>,
|
||||
) -> Result<ConstrainedValue<F, G>, ExpressionError> {
|
||||
let mut result = vec![];
|
||||
for element in array.into_iter() {
|
||||
match *element {
|
||||
@ -283,7 +283,7 @@ impl<G: Group, F: Field + PrimeField, CS: ConstraintSystem<G>> ConstrainedProgra
|
||||
cs: &mut CS,
|
||||
file_scope: String,
|
||||
function_scope: String,
|
||||
index: Expression<G, F>,
|
||||
index: Expression<F, G>,
|
||||
) -> Result<usize, ExpressionError> {
|
||||
match self.enforce_expression(cs, file_scope, function_scope, index)? {
|
||||
ConstrainedValue::Integer(number) => Ok(number.to_usize()),
|
||||
@ -296,9 +296,9 @@ impl<G: Group, F: Field + PrimeField, CS: ConstraintSystem<G>> ConstrainedProgra
|
||||
cs: &mut CS,
|
||||
file_scope: String,
|
||||
function_scope: String,
|
||||
array: Box<Expression<G, F>>,
|
||||
index: RangeOrExpression<G, F>,
|
||||
) -> Result<ConstrainedValue<G, F>, ExpressionError> {
|
||||
array: Box<Expression<F, G>>,
|
||||
index: RangeOrExpression<F, G>,
|
||||
) -> Result<ConstrainedValue<F, G>, ExpressionError> {
|
||||
match self.enforce_expression(cs, file_scope.clone(), function_scope.clone(), *array)? {
|
||||
ConstrainedValue::Array(array) => {
|
||||
match index {
|
||||
@ -331,9 +331,9 @@ impl<G: Group, F: Field + PrimeField, CS: ConstraintSystem<G>> ConstrainedProgra
|
||||
cs: &mut CS,
|
||||
file_scope: String,
|
||||
function_scope: String,
|
||||
variable: Variable<G, F>,
|
||||
members: Vec<StructMember<G, F>>,
|
||||
) -> Result<ConstrainedValue<G, F>, ExpressionError> {
|
||||
variable: Variable<F, G>,
|
||||
members: Vec<StructMember<F, G>>,
|
||||
) -> Result<ConstrainedValue<F, G>, ExpressionError> {
|
||||
let struct_name = new_variable_from_variable(file_scope.clone(), &variable);
|
||||
|
||||
if let Some(ConstrainedValue::StructDefinition(struct_definition)) =
|
||||
@ -380,9 +380,9 @@ impl<G: Group, F: Field + PrimeField, CS: ConstraintSystem<G>> ConstrainedProgra
|
||||
cs: &mut CS,
|
||||
file_scope: String,
|
||||
function_scope: String,
|
||||
struct_variable: Box<Expression<G, F>>,
|
||||
struct_member: Variable<G, F>,
|
||||
) -> Result<ConstrainedValue<G, F>, ExpressionError> {
|
||||
struct_variable: Box<Expression<F, G>>,
|
||||
struct_member: Variable<F, G>,
|
||||
) -> Result<ConstrainedValue<F, G>, ExpressionError> {
|
||||
match self.enforce_expression(cs, file_scope, function_scope, *struct_variable)? {
|
||||
ConstrainedValue::StructExpression(_name, members) => {
|
||||
let matched_member = members.into_iter().find(|member| member.0 == struct_member);
|
||||
@ -402,9 +402,9 @@ impl<G: Group, F: Field + PrimeField, CS: ConstraintSystem<G>> ConstrainedProgra
|
||||
cs: &mut CS,
|
||||
file_scope: String,
|
||||
function_scope: String,
|
||||
function: Variable<G, F>,
|
||||
arguments: Vec<Expression<G, F>>,
|
||||
) -> Result<ConstrainedValue<G, F>, ExpressionError> {
|
||||
function: Variable<F, G>,
|
||||
arguments: Vec<Expression<F, G>>,
|
||||
) -> Result<ConstrainedValue<F, G>, ExpressionError> {
|
||||
let function_name = new_variable_from_variable(file_scope.clone(), &function);
|
||||
let function_call = match self.get(&function_name.to_string()) {
|
||||
Some(ConstrainedValue::Function(function)) => function.clone(),
|
||||
@ -429,8 +429,8 @@ impl<G: Group, F: Field + PrimeField, CS: ConstraintSystem<G>> ConstrainedProgra
|
||||
cs: &mut CS,
|
||||
file_scope: String,
|
||||
function_scope: String,
|
||||
expression: Expression<G, F>,
|
||||
) -> Result<ConstrainedValue<G, F>, ExpressionError> {
|
||||
expression: Expression<F, G>,
|
||||
) -> Result<ConstrainedValue<F, G>, ExpressionError> {
|
||||
match expression {
|
||||
// Variables
|
||||
Expression::Variable(unresolved_variable) => {
|
||||
|
@ -12,13 +12,13 @@ use snarkos_models::{
|
||||
gadgets::r1cs::{ConstraintSystem, LinearCombination, Variable as R1CSVariable},
|
||||
};
|
||||
|
||||
impl<G: Group, F: Field + PrimeField, CS: ConstraintSystem<F>> ConstrainedProgram<G, F, CS> {
|
||||
impl<F: Field + PrimeField, G: Group, CS: ConstraintSystem<F>> ConstrainedProgram<F, G, CS> {
|
||||
pub(crate) fn field_element_from_input(
|
||||
&mut self,
|
||||
cs: &mut CS,
|
||||
input_model: InputModel<G, F>,
|
||||
input_value: Option<InputValue<G, F>>,
|
||||
) -> Result<ConstrainedValue<G, F>, FieldElementError> {
|
||||
input_model: InputModel<F, G>,
|
||||
input_value: Option<InputValue<F, G>>,
|
||||
) -> Result<ConstrainedValue<F, G>, FieldElementError> {
|
||||
// Check that the parameter value is the correct type
|
||||
let field_option = match input_value {
|
||||
Some(input) => {
|
||||
@ -51,7 +51,7 @@ impl<G: Group, F: Field + PrimeField, CS: ConstraintSystem<F>> ConstrainedProgra
|
||||
)))
|
||||
}
|
||||
|
||||
pub(crate) fn get_field_element_constant(fe: FieldElement<F>) -> ConstrainedValue<G, F> {
|
||||
pub(crate) fn get_field_element_constant(fe: FieldElement<F>) -> ConstrainedValue<F, G> {
|
||||
ConstrainedValue::FieldElement(fe)
|
||||
}
|
||||
|
||||
@ -124,7 +124,7 @@ impl<G: Group, F: Field + PrimeField, CS: ConstraintSystem<F>> ConstrainedProgra
|
||||
cs: &mut CS,
|
||||
fe_1: FieldElement<F>,
|
||||
fe_2: FieldElement<F>,
|
||||
) -> Result<ConstrainedValue<G, F>, FieldElementError> {
|
||||
) -> Result<ConstrainedValue<F, G>, FieldElementError> {
|
||||
Ok(match (fe_1, fe_2) {
|
||||
// if both constants, then return a constant result
|
||||
(FieldElement::Constant(fe_1_constant), FieldElement::Constant(fe_2_constant)) => {
|
||||
@ -201,7 +201,7 @@ impl<G: Group, F: Field + PrimeField, CS: ConstraintSystem<F>> ConstrainedProgra
|
||||
cs: &mut CS,
|
||||
fe_1: FieldElement<F>,
|
||||
fe_2: FieldElement<F>,
|
||||
) -> Result<ConstrainedValue<G, F>, FieldElementError> {
|
||||
) -> Result<ConstrainedValue<F, G>, FieldElementError> {
|
||||
Ok(match (fe_1, fe_2) {
|
||||
// if both constants, then return a constant result
|
||||
(FieldElement::Constant(fe_1_constant), FieldElement::Constant(fe_2_constant)) => {
|
||||
@ -278,7 +278,7 @@ impl<G: Group, F: Field + PrimeField, CS: ConstraintSystem<F>> ConstrainedProgra
|
||||
cs: &mut CS,
|
||||
fe_1: FieldElement<F>,
|
||||
fe_2: FieldElement<F>,
|
||||
) -> Result<ConstrainedValue<G, F>, FieldElementError> {
|
||||
) -> Result<ConstrainedValue<F, G>, FieldElementError> {
|
||||
Ok(match (fe_1, fe_2) {
|
||||
// if both constants, then return a constant result
|
||||
(FieldElement::Constant(fe_1_constant), FieldElement::Constant(fe_2_constant)) => {
|
||||
@ -355,7 +355,7 @@ impl<G: Group, F: Field + PrimeField, CS: ConstraintSystem<F>> ConstrainedProgra
|
||||
cs: &mut CS,
|
||||
fe_1: FieldElement<F>,
|
||||
fe_2: FieldElement<F>,
|
||||
) -> Result<ConstrainedValue<G, F>, FieldElementError> {
|
||||
) -> Result<ConstrainedValue<F, G>, FieldElementError> {
|
||||
Ok(match (fe_1, fe_2) {
|
||||
// if both constants, then return a constant result
|
||||
(FieldElement::Constant(fe_1_constant), FieldElement::Constant(fe_2_constant)) => {
|
||||
@ -443,7 +443,7 @@ impl<G: Group, F: Field + PrimeField, CS: ConstraintSystem<F>> ConstrainedProgra
|
||||
cs: &mut CS,
|
||||
fe_1: FieldElement<F>,
|
||||
num: Integer,
|
||||
) -> Result<ConstrainedValue<G, F>, FieldElementError> {
|
||||
) -> Result<ConstrainedValue<F, G>, FieldElementError> {
|
||||
Ok(match fe_1 {
|
||||
// if both constants, then return a constant result
|
||||
FieldElement::Constant(fe_1_constant) => ConstrainedValue::FieldElement(
|
||||
|
@ -17,7 +17,7 @@ use snarkos_models::{
|
||||
gadgets::r1cs::ConstraintSystem,
|
||||
};
|
||||
|
||||
impl<G: Group, F: Field + PrimeField, CS: ConstraintSystem<G>> ConstrainedProgram<G, F, CS> {
|
||||
impl<F: Field + PrimeField, G: Group, CS: ConstraintSystem<F>> ConstrainedProgram<F, G, CS> {
|
||||
fn check_inputs_length(expected: usize, actual: usize) -> Result<(), FunctionError> {
|
||||
// Make sure we are given the correct number of arguments
|
||||
if expected != actual {
|
||||
@ -33,8 +33,8 @@ impl<G: Group, F: Field + PrimeField, CS: ConstraintSystem<G>> ConstrainedProgra
|
||||
scope: String,
|
||||
caller_scope: String,
|
||||
function_name: String,
|
||||
input: Expression<G, F>,
|
||||
) -> Result<ConstrainedValue<G, F>, FunctionError> {
|
||||
input: Expression<F, G>,
|
||||
) -> Result<ConstrainedValue<F, G>, FunctionError> {
|
||||
match input {
|
||||
Expression::Variable(variable) => Ok(self.enforce_variable(caller_scope, variable)?),
|
||||
expression => Ok(self.enforce_expression(cs, scope, function_name, expression)?),
|
||||
@ -46,9 +46,9 @@ impl<G: Group, F: Field + PrimeField, CS: ConstraintSystem<G>> ConstrainedProgra
|
||||
cs: &mut CS,
|
||||
scope: String,
|
||||
caller_scope: String,
|
||||
function: Function<G, F>,
|
||||
inputs: Vec<Expression<G, F>>,
|
||||
) -> Result<ConstrainedValue<G, F>, FunctionError> {
|
||||
function: Function<F, G>,
|
||||
inputs: Vec<Expression<F, G>>,
|
||||
) -> Result<ConstrainedValue<F, G>, FunctionError> {
|
||||
let function_name = new_scope(scope.clone(), function.get_name());
|
||||
|
||||
// Make sure we are given the correct number of inputs
|
||||
@ -99,12 +99,12 @@ impl<G: Group, F: Field + PrimeField, CS: ConstraintSystem<G>> ConstrainedProgra
|
||||
fn allocate_array(
|
||||
&mut self,
|
||||
cs: &mut CS,
|
||||
array_name: Variable<G, F>,
|
||||
array_name: Variable<F, G>,
|
||||
array_private: bool,
|
||||
array_type: Type<G, F>,
|
||||
array_type: Type<F, G>,
|
||||
array_dimensions: Vec<usize>,
|
||||
input_value: Option<InputValue<G, F>>,
|
||||
) -> Result<ConstrainedValue<G, F>, FunctionError> {
|
||||
input_value: Option<InputValue<F, G>>,
|
||||
) -> Result<ConstrainedValue<F, G>, FunctionError> {
|
||||
let expected_length = array_dimensions[0];
|
||||
let mut array_value = vec![];
|
||||
|
||||
@ -163,9 +163,9 @@ impl<G: Group, F: Field + PrimeField, CS: ConstraintSystem<G>> ConstrainedProgra
|
||||
fn allocate_main_function_input(
|
||||
&mut self,
|
||||
cs: &mut CS,
|
||||
input_model: InputModel<G, F>,
|
||||
input_value: Option<InputValue<G, F>>,
|
||||
) -> Result<ConstrainedValue<G, F>, FunctionError> {
|
||||
input_model: InputModel<F, G>,
|
||||
input_value: Option<InputValue<F, G>>,
|
||||
) -> Result<ConstrainedValue<F, G>, FunctionError> {
|
||||
match input_model._type {
|
||||
Type::IntegerType(ref _integer_type) => {
|
||||
Ok(self.integer_from_parameter(cs, input_model, input_value)?)
|
||||
@ -190,9 +190,9 @@ impl<G: Group, F: Field + PrimeField, CS: ConstraintSystem<G>> ConstrainedProgra
|
||||
&mut self,
|
||||
cs: &mut CS,
|
||||
scope: String,
|
||||
function: Function<G, F>,
|
||||
inputs: Vec<Option<InputValue<G, F>>>,
|
||||
) -> Result<ConstrainedValue<G, F>, FunctionError> {
|
||||
function: Function<F, G>,
|
||||
inputs: Vec<Option<InputValue<F, G>>>,
|
||||
) -> Result<ConstrainedValue<F, G>, FunctionError> {
|
||||
let function_name = new_scope(scope.clone(), function.get_name());
|
||||
|
||||
// Make sure we are given the correct number of inputs
|
||||
@ -218,7 +218,7 @@ impl<G: Group, F: Field + PrimeField, CS: ConstraintSystem<G>> ConstrainedProgra
|
||||
pub(crate) fn resolve_definitions(
|
||||
&mut self,
|
||||
cs: &mut CS,
|
||||
program: Program<G, F>,
|
||||
program: Program<F, G>,
|
||||
) -> Result<(), ImportError> {
|
||||
let program_name = program.name.clone();
|
||||
|
||||
|
@ -14,7 +14,7 @@ use snarkos_models::{
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
|
||||
impl<G: Group, F: Field + PrimeField, CS: ConstraintSystem<F>> ConstrainedProgram<G, F, CS> {
|
||||
impl<F: Field + PrimeField, G: Group, CS: ConstraintSystem<F>> ConstrainedProgram<F, G, CS> {
|
||||
pub fn enforce_import(
|
||||
&mut self,
|
||||
cs: &mut CS,
|
||||
|
@ -12,15 +12,15 @@ use snarkos_models::{
|
||||
gadgets::{r1cs::ConstraintSystem, utilities::boolean::Boolean},
|
||||
};
|
||||
|
||||
impl<G: Group, F: Field + PrimeField, CS: ConstraintSystem<G>> ConstrainedProgram<G, F, CS> {
|
||||
pub(crate) fn get_integer_constant(integer: Integer) -> ConstrainedValue<G, F> {
|
||||
impl<F: Field + PrimeField, G: Group, CS: ConstraintSystem<F>> ConstrainedProgram<F, G, CS> {
|
||||
pub(crate) fn get_integer_constant(integer: Integer) -> ConstrainedValue<F, G> {
|
||||
ConstrainedValue::Integer(integer)
|
||||
}
|
||||
|
||||
pub(crate) fn evaluate_integer_eq(
|
||||
left: Integer,
|
||||
right: Integer,
|
||||
) -> Result<ConstrainedValue<G, F>, IntegerError> {
|
||||
) -> Result<ConstrainedValue<F, G>, IntegerError> {
|
||||
Ok(ConstrainedValue::Boolean(Boolean::Constant(
|
||||
match (left, right) {
|
||||
(Integer::U8(left_u8), Integer::U8(right_u8)) => left_u8.eq(&right_u8),
|
||||
@ -41,9 +41,9 @@ impl<G: Group, F: Field + PrimeField, CS: ConstraintSystem<G>> ConstrainedProgra
|
||||
pub(crate) fn integer_from_parameter(
|
||||
&mut self,
|
||||
cs: &mut CS,
|
||||
integer_model: InputModel<G, F>,
|
||||
integer_value: Option<InputValue<G, F>>,
|
||||
) -> Result<ConstrainedValue<G, F>, IntegerError> {
|
||||
integer_model: InputModel<F, G>,
|
||||
integer_value: Option<InputValue<F, G>>,
|
||||
) -> Result<ConstrainedValue<F, G>, IntegerError> {
|
||||
let integer_type = match &integer_model._type {
|
||||
Type::IntegerType(integer_type) => integer_type,
|
||||
_type => return Err(IntegerError::InvalidType(_type.to_string())),
|
||||
@ -107,7 +107,7 @@ impl<G: Group, F: Field + PrimeField, CS: ConstraintSystem<G>> ConstrainedProgra
|
||||
cs: &mut CS,
|
||||
left: Integer,
|
||||
right: Integer,
|
||||
) -> Result<ConstrainedValue<G, F>, IntegerError> {
|
||||
) -> Result<ConstrainedValue<F, G>, IntegerError> {
|
||||
Ok(ConstrainedValue::Integer(match (left, right) {
|
||||
(Integer::U8(left_u8), Integer::U8(right_u8)) => {
|
||||
Integer::U8(Self::enforce_u8_add(cs, left_u8, right_u8)?)
|
||||
@ -133,7 +133,7 @@ impl<G: Group, F: Field + PrimeField, CS: ConstraintSystem<G>> ConstrainedProgra
|
||||
cs: &mut CS,
|
||||
left: Integer,
|
||||
right: Integer,
|
||||
) -> Result<ConstrainedValue<G, F>, IntegerError> {
|
||||
) -> Result<ConstrainedValue<F, G>, IntegerError> {
|
||||
Ok(ConstrainedValue::Integer(match (left, right) {
|
||||
(Integer::U8(left_u8), Integer::U8(right_u8)) => {
|
||||
Integer::U8(Self::enforce_u8_sub(cs, left_u8, right_u8)?)
|
||||
@ -159,7 +159,7 @@ impl<G: Group, F: Field + PrimeField, CS: ConstraintSystem<G>> ConstrainedProgra
|
||||
cs: &mut CS,
|
||||
left: Integer,
|
||||
right: Integer,
|
||||
) -> Result<ConstrainedValue<G, F>, IntegerError> {
|
||||
) -> Result<ConstrainedValue<F, G>, IntegerError> {
|
||||
Ok(ConstrainedValue::Integer(match (left, right) {
|
||||
(Integer::U8(left_u8), Integer::U8(right_u8)) => {
|
||||
Integer::U8(Self::enforce_u8_mul(cs, left_u8, right_u8)?)
|
||||
@ -185,7 +185,7 @@ impl<G: Group, F: Field + PrimeField, CS: ConstraintSystem<G>> ConstrainedProgra
|
||||
cs: &mut CS,
|
||||
left: Integer,
|
||||
right: Integer,
|
||||
) -> Result<ConstrainedValue<G, F>, IntegerError> {
|
||||
) -> Result<ConstrainedValue<F, G>, IntegerError> {
|
||||
Ok(ConstrainedValue::Integer(match (left, right) {
|
||||
(Integer::U8(left_u8), Integer::U8(right_u8)) => {
|
||||
Integer::U8(Self::enforce_u8_div(cs, left_u8, right_u8)?)
|
||||
@ -211,7 +211,7 @@ impl<G: Group, F: Field + PrimeField, CS: ConstraintSystem<G>> ConstrainedProgra
|
||||
cs: &mut CS,
|
||||
left: Integer,
|
||||
right: Integer,
|
||||
) -> Result<ConstrainedValue<G, F>, IntegerError> {
|
||||
) -> Result<ConstrainedValue<F, G>, IntegerError> {
|
||||
Ok(ConstrainedValue::Integer(match (left, right) {
|
||||
(Integer::U8(left_u8), Integer::U8(right_u8)) => {
|
||||
Integer::U8(Self::enforce_u8_pow(cs, left_u8, right_u8)?)
|
||||
|
@ -15,13 +15,13 @@ use snarkos_models::{
|
||||
},
|
||||
};
|
||||
|
||||
impl<G: Group, F: Field + PrimeField, CS: ConstraintSystem<F>> ConstrainedProgram<G, F, CS> {
|
||||
impl<F: Field + PrimeField, G: Group, CS: ConstraintSystem<F>> ConstrainedProgram<F, G, CS> {
|
||||
pub(crate) fn u128_from_integer(
|
||||
&mut self,
|
||||
cs: &mut CS,
|
||||
parameter_model: InputModel<G, F>,
|
||||
parameter_model: InputModel<F, G>,
|
||||
integer_option: Option<usize>,
|
||||
) -> Result<ConstrainedValue<G, F>, IntegerError> {
|
||||
) -> Result<ConstrainedValue<F, G>, IntegerError> {
|
||||
// Type cast to u128 in rust.
|
||||
// If this fails should we return our own error?
|
||||
let u128_option = integer_option.map(|integer| integer as u128);
|
||||
|
@ -15,13 +15,13 @@ use snarkos_models::{
|
||||
},
|
||||
};
|
||||
|
||||
impl<G: Group, F: Field + PrimeField, CS: ConstraintSystem<F>> ConstrainedProgram<G, F, CS> {
|
||||
impl<F: Field + PrimeField, G: Group, CS: ConstraintSystem<F>> ConstrainedProgram<F, G, CS> {
|
||||
pub(crate) fn u16_from_input(
|
||||
&mut self,
|
||||
cs: &mut CS,
|
||||
parameter_model: InputModel<G, F>,
|
||||
parameter_model: InputModel<F, G>,
|
||||
integer_option: Option<usize>,
|
||||
) -> Result<ConstrainedValue<G, F>, IntegerError> {
|
||||
) -> Result<ConstrainedValue<F, G>, IntegerError> {
|
||||
// Type cast to u16 in rust.
|
||||
// If this fails should we return our own error?
|
||||
let u16_option = integer_option.map(|integer| integer as u16);
|
||||
|
@ -15,13 +15,13 @@ use snarkos_models::{
|
||||
},
|
||||
};
|
||||
|
||||
impl<G: Group, F: Field + PrimeField, CS: ConstraintSystem<F>> ConstrainedProgram<G, F, CS> {
|
||||
impl<F: Field + PrimeField, G: Group, CS: ConstraintSystem<F>> ConstrainedProgram<F, G, CS> {
|
||||
pub(crate) fn u32_from_input(
|
||||
&mut self,
|
||||
cs: &mut CS,
|
||||
parameter_model: InputModel<G, F>,
|
||||
parameter_model: InputModel<F, G>,
|
||||
integer_option: Option<usize>,
|
||||
) -> Result<ConstrainedValue<G, F>, IntegerError> {
|
||||
) -> Result<ConstrainedValue<F, G>, IntegerError> {
|
||||
// Type cast to u32 in rust.
|
||||
// If this fails should we return our own error?
|
||||
let u32_option = integer_option.map(|integer| integer as u32);
|
||||
|
@ -15,13 +15,13 @@ use snarkos_models::{
|
||||
},
|
||||
};
|
||||
|
||||
impl<G: Group, F: Field + PrimeField, CS: ConstraintSystem<F>> ConstrainedProgram<G, F, CS> {
|
||||
impl<F: Field + PrimeField, G: Group, CS: ConstraintSystem<F>> ConstrainedProgram<F, G, CS> {
|
||||
pub(crate) fn u64_from_input(
|
||||
&mut self,
|
||||
cs: &mut CS,
|
||||
parameter_model: InputModel<G, F>,
|
||||
parameter_model: InputModel<F, G>,
|
||||
integer_option: Option<usize>,
|
||||
) -> Result<ConstrainedValue<G, F>, IntegerError> {
|
||||
) -> Result<ConstrainedValue<F, G>, IntegerError> {
|
||||
// Type cast to u64 in rust.
|
||||
// If this fails should we return our own error?
|
||||
let u64_option = integer_option.map(|integer| integer as u64);
|
||||
|
@ -15,13 +15,13 @@ use snarkos_models::{
|
||||
},
|
||||
};
|
||||
|
||||
impl<G: Group, F: Field + PrimeField, CS: ConstraintSystem<F>> ConstrainedProgram<G, F, CS> {
|
||||
impl<F: Field + PrimeField, G: Group, CS: ConstraintSystem<F>> ConstrainedProgram<F, G, CS> {
|
||||
pub(crate) fn u8_from_input(
|
||||
&mut self,
|
||||
cs: &mut CS,
|
||||
parameter_model: InputModel<G, F>,
|
||||
parameter_model: InputModel<F, G>,
|
||||
integer_option: Option<usize>,
|
||||
) -> Result<ConstrainedValue<G, F>, IntegerError> {
|
||||
) -> Result<ConstrainedValue<F, G>, IntegerError> {
|
||||
// Type cast to u8 in rust.
|
||||
// If this fails should we return our own error?
|
||||
let u8_option = integer_option.map(|integer| integer as u8);
|
||||
|
@ -37,11 +37,11 @@ use snarkos_models::{
|
||||
gadgets::r1cs::ConstraintSystem,
|
||||
};
|
||||
|
||||
pub fn generate_constraints<G: Group, F: Field + PrimeField, CS: ConstraintSystem<F>>(
|
||||
pub fn generate_constraints<F: Field + PrimeField, G: Group, CS: ConstraintSystem<F>>(
|
||||
cs: &mut CS,
|
||||
program: Program<G, F>,
|
||||
parameters: Vec<Option<InputValue<G, F>>>,
|
||||
) -> Result<ConstrainedValue<G, F>, CompilerError> {
|
||||
program: Program<F, G>,
|
||||
parameters: Vec<Option<InputValue<F, G>>>,
|
||||
) -> Result<ConstrainedValue<F, G>, CompilerError> {
|
||||
let mut resolved_program = ConstrainedProgram::new();
|
||||
let program_name = program.get_name();
|
||||
let main_function_name = new_scope(program_name.clone(), "main".into());
|
||||
|
@ -8,7 +8,7 @@ use snarkos_models::{
|
||||
};
|
||||
use std::{collections::HashMap, marker::PhantomData};
|
||||
|
||||
pub struct ConstrainedProgram<G: Group, F: Field + PrimeField, CS: ConstraintSystem<F>> {
|
||||
pub struct ConstrainedProgram<F: Field + PrimeField, G: Group, CS: ConstraintSystem<F>> {
|
||||
pub resolved_names: HashMap<String, ConstrainedValue<F, G>>,
|
||||
pub _cs: PhantomData<CS>,
|
||||
}
|
||||
@ -46,7 +46,7 @@ pub fn new_variable_from_variables<F: Field + PrimeField, G: Group>(
|
||||
}
|
||||
}
|
||||
|
||||
impl<G: Group, F: Field + PrimeField, CS: ConstraintSystem<F>> ConstrainedProgram<G, F, CS> {
|
||||
impl<F: Field + PrimeField, G: Group, CS: ConstraintSystem<F>> ConstrainedProgram<F, G, CS> {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
resolved_names: HashMap::new(),
|
||||
|
@ -14,7 +14,7 @@ use snarkos_models::{
|
||||
gadgets::{r1cs::ConstraintSystem, utilities::boolean::Boolean, utilities::uint32::UInt32},
|
||||
};
|
||||
|
||||
impl<G: Group, F: Field + PrimeField, CS: ConstraintSystem<F>> ConstrainedProgram<G, F, CS> {
|
||||
impl<F: Field + PrimeField, G: Group, CS: ConstraintSystem<F>> ConstrainedProgram<F, G, CS> {
|
||||
fn resolve_assignee(&mut self, scope: String, assignee: Assignee<F, G>) -> String {
|
||||
match assignee {
|
||||
Assignee::Variable(name) => new_scope_from_variable(scope, &name),
|
||||
|
@ -17,13 +17,13 @@ use std::marker::PhantomData;
|
||||
|
||||
/// A variable in a constraint system.
|
||||
#[derive(Clone, PartialEq, Eq, Hash)]
|
||||
pub struct Variable<G: Group, F: Field + PrimeField> {
|
||||
pub struct Variable<F: Field + PrimeField, G: Group> {
|
||||
pub name: String,
|
||||
pub(crate) _group: PhantomData<G>,
|
||||
pub(crate) _engine: PhantomData<F>,
|
||||
}
|
||||
|
||||
impl<G: Group, F: Field + PrimeField> Variable<G, F> {
|
||||
impl<F: Field + PrimeField, G: Group> Variable<F, G> {
|
||||
pub fn new(name: String) -> Self {
|
||||
Self {
|
||||
name,
|
||||
@ -93,23 +93,23 @@ pub enum FieldElement<F: Field + PrimeField> {
|
||||
|
||||
/// Range or expression enum
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum RangeOrExpression<G: Group, F: Field + PrimeField> {
|
||||
pub enum RangeOrExpression<F: Field + PrimeField, G: Group> {
|
||||
Range(Option<Integer>, Option<Integer>),
|
||||
Expression(Expression<G, F>),
|
||||
Expression(Expression<F, G>),
|
||||
}
|
||||
|
||||
/// Spread or expression
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum SpreadOrExpression<G: Group, F: Field + PrimeField> {
|
||||
Spread(Expression<G, F>),
|
||||
Expression(Expression<G, F>),
|
||||
pub enum SpreadOrExpression<F: Field + PrimeField, G: Group> {
|
||||
Spread(Expression<F, G>),
|
||||
Expression(Expression<F, G>),
|
||||
}
|
||||
|
||||
/// Expression that evaluates to a value
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum Expression<G: Group, F: Field + PrimeField> {
|
||||
pub enum Expression<F: Field + PrimeField, G: Group> {
|
||||
// Variable
|
||||
Variable(Variable<G, F>),
|
||||
Variable(Variable<F, G>),
|
||||
|
||||
// Values
|
||||
Integer(Integer),
|
||||
@ -118,43 +118,43 @@ pub enum Expression<G: Group, F: Field + PrimeField> {
|
||||
Boolean(Boolean),
|
||||
|
||||
// Number operations
|
||||
Add(Box<Expression<G, F>>, Box<Expression<G, F>>),
|
||||
Sub(Box<Expression<G, F>>, Box<Expression<G, F>>),
|
||||
Mul(Box<Expression<G, F>>, Box<Expression<G, F>>),
|
||||
Div(Box<Expression<G, F>>, Box<Expression<G, F>>),
|
||||
Pow(Box<Expression<G, F>>, Box<Expression<G, F>>),
|
||||
Add(Box<Expression<F, G>>, Box<Expression<F, G>>),
|
||||
Sub(Box<Expression<F, G>>, Box<Expression<F, G>>),
|
||||
Mul(Box<Expression<F, G>>, Box<Expression<F, G>>),
|
||||
Div(Box<Expression<F, G>>, Box<Expression<F, G>>),
|
||||
Pow(Box<Expression<F, G>>, Box<Expression<F, G>>),
|
||||
|
||||
// Boolean operations
|
||||
Not(Box<Expression<G, F>>),
|
||||
Or(Box<Expression<G, F>>, Box<Expression<G, F>>),
|
||||
And(Box<Expression<G, F>>, Box<Expression<G, F>>),
|
||||
Eq(Box<Expression<G, F>>, Box<Expression<G, F>>),
|
||||
Geq(Box<Expression<G, F>>, Box<Expression<G, F>>),
|
||||
Gt(Box<Expression<G, F>>, Box<Expression<G, F>>),
|
||||
Leq(Box<Expression<G, F>>, Box<Expression<G, F>>),
|
||||
Lt(Box<Expression<G, F>>, Box<Expression<G, F>>),
|
||||
Not(Box<Expression<F, G>>),
|
||||
Or(Box<Expression<F, G>>, Box<Expression<F, G>>),
|
||||
And(Box<Expression<F, G>>, Box<Expression<F, G>>),
|
||||
Eq(Box<Expression<F, G>>, Box<Expression<F, G>>),
|
||||
Geq(Box<Expression<F, G>>, Box<Expression<F, G>>),
|
||||
Gt(Box<Expression<F, G>>, Box<Expression<F, G>>),
|
||||
Leq(Box<Expression<F, G>>, Box<Expression<F, G>>),
|
||||
Lt(Box<Expression<F, G>>, Box<Expression<F, G>>),
|
||||
|
||||
// Conditionals
|
||||
IfElse(Box<Expression<G, F>>, Box<Expression<G, F>>, Box<Expression<G, F>>),
|
||||
IfElse(Box<Expression<F, G>>, Box<Expression<F, G>>, Box<Expression<F, G>>),
|
||||
|
||||
// Arrays
|
||||
Array(Vec<Box<SpreadOrExpression<G, F>>>),
|
||||
ArrayAccess(Box<Expression<G, F>>, Box<RangeOrExpression<G, F>>), // (array name, range)
|
||||
Array(Vec<Box<SpreadOrExpression<F, G>>>),
|
||||
ArrayAccess(Box<Expression<F, G>>, Box<RangeOrExpression<F, G>>), // (array name, range)
|
||||
|
||||
// Structs
|
||||
Struct(Variable<G, F>, Vec<StructMember<G, F>>),
|
||||
StructMemberAccess(Box<Expression<G, F>>, Variable<G, F>), // (struct name, struct member name)
|
||||
Struct(Variable<F, G>, Vec<StructMember<F, G>>),
|
||||
StructMemberAccess(Box<Expression<F, G>>, Variable<F, G>), // (struct name, struct member name)
|
||||
|
||||
// Functions
|
||||
FunctionCall(Variable<G, F>, Vec<Expression<G, F>>),
|
||||
FunctionCall(Variable<F, G>, Vec<Expression<F, G>>),
|
||||
}
|
||||
|
||||
/// Definition assignee: v, arr[0..2], Point p.x
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum Assignee<G: Group, F: Field + PrimeField> {
|
||||
Variable(Variable<G, F>),
|
||||
Array(Box<Assignee<G, F>>, RangeOrExpression<G, F>),
|
||||
StructMember(Box<Assignee<G, F>>, Variable<G, F>),
|
||||
pub enum Assignee<F: Field + PrimeField, G: Group> {
|
||||
Variable(Variable<F, G>),
|
||||
Array(Box<Assignee<F, G>>, RangeOrExpression<F, G>),
|
||||
StructMember(Box<Assignee<F, G>>, Variable<F, G>),
|
||||
}
|
||||
|
||||
/// Explicit integer type
|
||||
@ -169,16 +169,16 @@ pub enum IntegerType {
|
||||
|
||||
/// Explicit type used for defining a variable or expression type
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub enum Type<G: Group, F: Field + PrimeField> {
|
||||
pub enum Type<F: Field + PrimeField, G: Group> {
|
||||
IntegerType(IntegerType),
|
||||
FieldElement,
|
||||
GroupElement,
|
||||
Boolean,
|
||||
Array(Box<Type<G, F>>, Vec<usize>),
|
||||
Struct(Variable<G, F>),
|
||||
Array(Box<Type<F, G>>, Vec<usize>),
|
||||
Struct(Variable<F, G>),
|
||||
}
|
||||
|
||||
impl<G: Group, F: Field + PrimeField> Type<G, F> {
|
||||
impl<F: Field + PrimeField, G: Group> Type<F, G> {
|
||||
pub fn next_dimension(&self, dimensions: &Vec<usize>) -> Self {
|
||||
let _type = self.clone();
|
||||
|
||||
@ -194,61 +194,61 @@ impl<G: Group, F: Field + PrimeField> Type<G, F> {
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
pub enum ConditionalNestedOrEnd<G: Group, F: Field + PrimeField> {
|
||||
Nested(Box<ConditionalStatement<G, F>>),
|
||||
End(Vec<Statement<G, F>>),
|
||||
pub enum ConditionalNestedOrEnd<F: Field + PrimeField, G: Group> {
|
||||
Nested(Box<ConditionalStatement<F, G>>),
|
||||
End(Vec<Statement<F, G>>),
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
pub struct ConditionalStatement<G: Group, F: Field + PrimeField> {
|
||||
pub condition: Expression<G, F>,
|
||||
pub statements: Vec<Statement<G, F>>,
|
||||
pub next: Option<ConditionalNestedOrEnd<G, F>>,
|
||||
pub struct ConditionalStatement<F: Field + PrimeField, G: Group> {
|
||||
pub condition: Expression<F, G>,
|
||||
pub statements: Vec<Statement<F, G>>,
|
||||
pub next: Option<ConditionalNestedOrEnd<F, G>>,
|
||||
}
|
||||
|
||||
/// Program statement that defines some action (or expression) to be carried out.
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
pub enum Statement<G: Group, F: Field + PrimeField> {
|
||||
pub enum Statement<F: Field + PrimeField, G: Group> {
|
||||
// Declaration(Variable),
|
||||
Return(Vec<Expression<G, F>>),
|
||||
Definition(Assignee<G, F>, Option<Type<G, F>>, Expression<G, F>),
|
||||
Assign(Assignee<G, F>, Expression<G, F>),
|
||||
MultipleAssign(Vec<Assignee<G, F>>, Expression<G, F>),
|
||||
Conditional(ConditionalStatement<G, F>),
|
||||
For(Variable<G, F>, Integer, Integer, Vec<Statement<G, F>>),
|
||||
AssertEq(Expression<G, F>, Expression<G, F>),
|
||||
Expression(Expression<G, F>),
|
||||
Return(Vec<Expression<F, G>>),
|
||||
Definition(Assignee<F, G>, Option<Type<F, G>>, Expression<F, G>),
|
||||
Assign(Assignee<F, G>, Expression<F, G>),
|
||||
MultipleAssign(Vec<Assignee<F, G>>, Expression<F, G>),
|
||||
Conditional(ConditionalStatement<F, G>),
|
||||
For(Variable<F, G>, Integer, Integer, Vec<Statement<F, G>>),
|
||||
AssertEq(Expression<F, G>, Expression<F, G>),
|
||||
Expression(Expression<F, G>),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct StructMember<G: Group, F: Field + PrimeField> {
|
||||
pub variable: Variable<G, F>,
|
||||
pub expression: Expression<G, F>,
|
||||
pub struct StructMember<F: Field + PrimeField, G: Group> {
|
||||
pub variable: Variable<F, G>,
|
||||
pub expression: Expression<F, G>,
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
pub struct StructField<G: Group, F: Field + PrimeField> {
|
||||
pub variable: Variable<G, F>,
|
||||
pub _type: Type<G, F>,
|
||||
pub struct StructField<F: Field + PrimeField, G: Group> {
|
||||
pub variable: Variable<F, G>,
|
||||
pub _type: Type<F, G>,
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
pub struct Struct<G: Group, F: Field + PrimeField> {
|
||||
pub variable: Variable<G, F>,
|
||||
pub fields: Vec<StructField<G, F>>,
|
||||
pub struct Struct<F: Field + PrimeField, G: Group> {
|
||||
pub variable: Variable<F, G>,
|
||||
pub fields: Vec<StructField<F, G>>,
|
||||
}
|
||||
|
||||
/// Function parameters
|
||||
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
pub struct InputModel<G: Group, F: Field + PrimeField> {
|
||||
pub struct InputModel<F: Field + PrimeField, G: Group> {
|
||||
pub private: bool,
|
||||
pub _type: Type<G, F>,
|
||||
pub variable: Variable<G, F>,
|
||||
pub _type: Type<F, G>,
|
||||
pub variable: Variable<F, G>,
|
||||
}
|
||||
|
||||
impl<G: Group, F: Field + PrimeField> InputModel<G, F> {
|
||||
pub fn inner_type(&self) -> Result<Type<G, F>, ValueError> {
|
||||
impl<F: Field + PrimeField, G: Group> InputModel<F, G> {
|
||||
pub fn inner_type(&self) -> Result<Type<F, G>, ValueError> {
|
||||
match &self._type {
|
||||
Type::Array(ref _type, _length) => Ok(*_type.clone()),
|
||||
ref _type => Err(ValueError::ArrayModel(_type.to_string())),
|
||||
@ -257,11 +257,12 @@ impl<G: Group, F: Field + PrimeField> InputModel<G, F> {
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
pub enum InputValue<G: Group, F: Field + PrimeField> {
|
||||
pub enum InputValue<F: Field + PrimeField, G: Group> {
|
||||
Integer(usize),
|
||||
Field(F),
|
||||
Group(G),
|
||||
Boolean(bool),
|
||||
Array(Vec<InputValue<G, F>>),
|
||||
Array(Vec<InputValue<F, G>>),
|
||||
}
|
||||
|
||||
/// The given name for a defined function in the program.
|
||||
@ -269,14 +270,14 @@ pub enum InputValue<G: Group, F: Field + PrimeField> {
|
||||
pub struct FunctionName(pub String);
|
||||
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
pub struct Function<G: Group, F: Field + PrimeField> {
|
||||
pub struct Function<F: Field + PrimeField, G: Group> {
|
||||
pub function_name: FunctionName,
|
||||
pub inputs: Vec<InputModel<G, F>>,
|
||||
pub returns: Vec<Type<G, F>>,
|
||||
pub statements: Vec<Statement<G, F>>,
|
||||
pub inputs: Vec<InputModel<F, G>>,
|
||||
pub returns: Vec<Type<F, G>>,
|
||||
pub statements: Vec<Statement<F, G>>,
|
||||
}
|
||||
|
||||
impl<G: Group, F: Field + PrimeField> Function<G, F> {
|
||||
impl<F: Field + PrimeField, G: Group> Function<F, G> {
|
||||
pub fn get_name(&self) -> String {
|
||||
self.function_name.0.clone()
|
||||
}
|
||||
@ -284,15 +285,15 @@ impl<G: Group, F: Field + PrimeField> Function<G, F> {
|
||||
|
||||
/// A simple program with statement expressions, program arguments and program returns.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Program<G: Group, F: Field + PrimeField> {
|
||||
pub name: Variable<G, F>,
|
||||
pub struct Program<F: Field + PrimeField, G: Group> {
|
||||
pub name: Variable<F, G>,
|
||||
pub num_parameters: usize,
|
||||
pub imports: Vec<Import<G, F>>,
|
||||
pub structs: HashMap<Variable<G, F>, Struct<G, F>>,
|
||||
pub functions: HashMap<FunctionName, Function<G, F>>,
|
||||
pub imports: Vec<Import<F, G>>,
|
||||
pub structs: HashMap<Variable<F, G>, Struct<F, G>>,
|
||||
pub functions: HashMap<FunctionName, Function<F, G>>,
|
||||
}
|
||||
|
||||
impl<'ast, G: Group, F: Field + PrimeField> Program<G, F> {
|
||||
impl<'ast, F: Field + PrimeField, G: Group> Program<F, G> {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
name: Variable {
|
||||
|
@ -9,12 +9,12 @@ use crate::{
|
||||
use snarkos_models::curves::{Group, Field, PrimeField};
|
||||
use std::fmt;
|
||||
|
||||
impl<G: Group, F: Field + PrimeField> fmt::Display for Variable<G, F> {
|
||||
impl<F: Field + PrimeField, G: Group> fmt::Display for Variable<F, G> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{}", self.name)
|
||||
}
|
||||
}
|
||||
impl<G: Group, F: Field + PrimeField> fmt::Debug for Variable<G, F> {
|
||||
impl<F: Field + PrimeField, G: Group> fmt::Debug for Variable<F, G> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{}", self.name)
|
||||
}
|
||||
@ -53,7 +53,7 @@ impl<F: Field + PrimeField> fmt::Debug for FieldElement<F> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, G: Group, F: Field + PrimeField> fmt::Display for RangeOrExpression<G, F> {
|
||||
impl<'ast, F: Field + PrimeField, G: Group> fmt::Display for RangeOrExpression<F, G> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
RangeOrExpression::Range(ref from, ref to) => write!(
|
||||
@ -71,7 +71,7 @@ impl<'ast, G: Group, F: Field + PrimeField> fmt::Display for RangeOrExpression<G
|
||||
}
|
||||
}
|
||||
|
||||
impl<G: Group, F: Field + PrimeField> fmt::Display for SpreadOrExpression<G, F> {
|
||||
impl<F: Field + PrimeField, G: Group> fmt::Display for SpreadOrExpression<F, G> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
SpreadOrExpression::Spread(ref spread) => write!(f, "...{}", spread),
|
||||
@ -80,7 +80,7 @@ impl<G: Group, F: Field + PrimeField> fmt::Display for SpreadOrExpression<G, F>
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, G: Group, F: Field + PrimeField> fmt::Display for Expression<G, F> {
|
||||
impl<'ast, F: Field + PrimeField, G: Group> fmt::Display for Expression<F, G> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
// Variables
|
||||
@ -157,7 +157,7 @@ impl<'ast, G: Group, F: Field + PrimeField> fmt::Display for Expression<G, F> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<G: Group, F: Field + PrimeField> fmt::Display for Assignee<G, F> {
|
||||
impl<F: Field + PrimeField, G: Group> fmt::Display for Assignee<F, G> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
Assignee::Variable(ref variable) => write!(f, "{}", variable),
|
||||
@ -169,7 +169,7 @@ impl<G: Group, F: Field + PrimeField> fmt::Display for Assignee<G, F> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<G: Group, F: Field + PrimeField> fmt::Display for ConditionalNestedOrEnd<G, F> {
|
||||
impl<F: Field + PrimeField, G: Group> fmt::Display for ConditionalNestedOrEnd<F, G> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
ConditionalNestedOrEnd::Nested(ref nested) => write!(f, "else {}", nested),
|
||||
@ -184,7 +184,7 @@ impl<G: Group, F: Field + PrimeField> fmt::Display for ConditionalNestedOrEnd<G,
|
||||
}
|
||||
}
|
||||
|
||||
impl<G: Group, F: Field + PrimeField> fmt::Display for ConditionalStatement<G, F> {
|
||||
impl<F: Field + PrimeField, G: Group> fmt::Display for ConditionalStatement<F, G> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "if ({}) {{\n", self.condition)?;
|
||||
for statement in self.statements.iter() {
|
||||
@ -197,7 +197,7 @@ impl<G: Group, F: Field + PrimeField> fmt::Display for ConditionalStatement<G, F
|
||||
}
|
||||
}
|
||||
|
||||
impl<G: Group, F: Field + PrimeField> fmt::Display for Statement<G, F> {
|
||||
impl<F: Field + PrimeField, G: Group> fmt::Display for Statement<F, G> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
Statement::Return(ref statements) => {
|
||||
@ -255,7 +255,7 @@ impl fmt::Display for IntegerType {
|
||||
}
|
||||
}
|
||||
|
||||
impl<G: Group, F: Field + PrimeField> fmt::Display for Type<G, F> {
|
||||
impl<F: Field + PrimeField, G: Group> fmt::Display for Type<F, G> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
Type::IntegerType(ref integer_type) => write!(f, "{}", integer_type),
|
||||
@ -274,13 +274,13 @@ impl<G: Group, F: Field + PrimeField> fmt::Display for Type<G, F> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<G: Group, F: Field + PrimeField> fmt::Display for StructField<G, F> {
|
||||
impl<F: Field + PrimeField, G: Group> fmt::Display for StructField<F, G> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{}: {}", self.variable, self._type)
|
||||
}
|
||||
}
|
||||
|
||||
impl<G: Group, F: Field + PrimeField> Struct<G, F> {
|
||||
impl<F: Field + PrimeField, G: Group> Struct<F, G> {
|
||||
fn format(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "struct {} {{ \n", self.variable)?;
|
||||
for field in self.fields.iter() {
|
||||
@ -290,26 +290,26 @@ impl<G: Group, F: Field + PrimeField> Struct<G, F> {
|
||||
}
|
||||
}
|
||||
|
||||
// impl<G: Group, F: Field + PrimeField> fmt::Display for Struct<G, F> {// uncomment when we no longer print out Program
|
||||
// impl<F: Field + PrimeField, G: Group> fmt::Display for Struct<F, G> {// uncomment when we no longer print out Program
|
||||
// fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
// self.format(f)
|
||||
// }
|
||||
// }
|
||||
|
||||
impl<G: Group, F: Field + PrimeField> fmt::Debug for Struct<G, F> {
|
||||
impl<F: Field + PrimeField, G: Group> fmt::Debug for Struct<F, G> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
self.format(f)
|
||||
}
|
||||
}
|
||||
|
||||
impl<G: Group, F: Field + PrimeField> fmt::Display for InputModel<G, F> {
|
||||
impl<F: Field + PrimeField, G: Group> fmt::Display for InputModel<F, G> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
let visibility = if self.private { "private" } else { "public" };
|
||||
write!(f, "{}: {} {}", self.variable, visibility, self._type,)
|
||||
}
|
||||
}
|
||||
|
||||
impl<G: Group, F: Field + PrimeField> fmt::Display for InputValue<G, F> {
|
||||
impl<F: Field + PrimeField, G: Group> fmt::Display for InputValue<F, G> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
InputValue::Integer(ref integer) => write!(f, "{}", integer),
|
||||
@ -347,7 +347,7 @@ impl fmt::Debug for FunctionName {
|
||||
}
|
||||
}
|
||||
|
||||
impl<G: Group, F: Field + PrimeField> Function<G, F> {
|
||||
impl<F: Field + PrimeField, G: Group> Function<F, G> {
|
||||
fn format(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "function {}", self.function_name)?;
|
||||
let parameters = self
|
||||
@ -378,13 +378,13 @@ impl<G: Group, F: Field + PrimeField> Function<G, F> {
|
||||
}
|
||||
}
|
||||
|
||||
// impl<G: Group, F: Field + PrimeField> fmt::Display for Function<G, F> {// uncomment when we no longer print out Program
|
||||
// impl<F: Field + PrimeField, G: Group> fmt::Display for Function<F, G> {// uncomment when we no longer print out Program
|
||||
// fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
// self.format(f)
|
||||
// }
|
||||
// }
|
||||
|
||||
impl<G: Group, F: Field + PrimeField> fmt::Debug for Function<G, F> {
|
||||
impl<F: Field + PrimeField, G: Group> fmt::Debug for Function<F, G> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
self.format(f)
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ use std::{collections::HashMap, marker::PhantomData};
|
||||
|
||||
/// pest ast -> types::Variable
|
||||
|
||||
impl<'ast, G: Group, F: Field + PrimeField> From<ast::Variable<'ast>> for types::Variable<G, F> {
|
||||
impl<'ast, F: Field + PrimeField, G: Group> From<ast::Variable<'ast>> for types::Variable<F, G> {
|
||||
fn from(variable: ast::Variable<'ast>) -> Self {
|
||||
types::Variable {
|
||||
name: variable.value,
|
||||
@ -21,7 +21,7 @@ impl<'ast, G: Group, F: Field + PrimeField> From<ast::Variable<'ast>> for types:
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, G: Group, F: Field + PrimeField> From<ast::Variable<'ast>> for types::Expression<G, F> {
|
||||
impl<'ast, F: Field + PrimeField, G: Group> From<ast::Variable<'ast>> for types::Expression<F, G> {
|
||||
fn from(variable: ast::Variable<'ast>) -> Self {
|
||||
types::Expression::Variable(types::Variable::from(variable))
|
||||
}
|
||||
@ -50,7 +50,7 @@ impl<'ast> types::Integer {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, G: Group, F: Field + PrimeField> From<ast::Integer<'ast>> for types::Expression<G, F> {
|
||||
impl<'ast, F: Field + PrimeField, G: Group> From<ast::Integer<'ast>> for types::Expression<F, G> {
|
||||
fn from(field: ast::Integer<'ast>) -> Self {
|
||||
types::Expression::Integer(match field._type {
|
||||
Some(_type) => types::Integer::from(field.number, _type),
|
||||
@ -66,21 +66,21 @@ impl<'ast, G: Group, F: Field + PrimeField> From<ast::Integer<'ast>> for types::
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, G: Group, F: Field + PrimeField> From<ast::RangeOrExpression<'ast>>
|
||||
for types::RangeOrExpression<G, F>
|
||||
impl<'ast, F: Field + PrimeField, G: Group> From<ast::RangeOrExpression<'ast>>
|
||||
for types::RangeOrExpression<F, G>
|
||||
{
|
||||
fn from(range_or_expression: ast::RangeOrExpression<'ast>) -> Self {
|
||||
match range_or_expression {
|
||||
ast::RangeOrExpression::Range(range) => {
|
||||
let from = range
|
||||
.from
|
||||
.map(|from| match types::Expression::<G, F>::from(from.0) {
|
||||
.map(|from| match types::Expression::<F, G>::from(from.0) {
|
||||
types::Expression::Integer(number) => number,
|
||||
expression => {
|
||||
unimplemented!("Range bounds should be integers, found {}", expression)
|
||||
}
|
||||
});
|
||||
let to = range.to.map(|to| match types::Expression::<G, F>::from(to.0) {
|
||||
let to = range.to.map(|to| match types::Expression::<F, G>::from(to.0) {
|
||||
types::Expression::Integer(number) => number,
|
||||
expression => {
|
||||
unimplemented!("Range bounds should be integers, found {}", expression)
|
||||
@ -98,7 +98,7 @@ impl<'ast, G: Group, F: Field + PrimeField> From<ast::RangeOrExpression<'ast>>
|
||||
|
||||
/// pest ast -> types::Field
|
||||
|
||||
impl<'ast, G: Group, F: Field + PrimeField> From<ast::Field<'ast>> for types::Expression<G, F> {
|
||||
impl<'ast, F: Field + PrimeField, G: Group> From<ast::Field<'ast>> for types::Expression<F, G> {
|
||||
fn from(field: ast::Field<'ast>) -> Self {
|
||||
types::Expression::FieldElement(types::FieldElement::Constant(
|
||||
F::from_str(&field.number.value).unwrap_or_default(),
|
||||
@ -108,7 +108,7 @@ impl<'ast, G: Group, F: Field + PrimeField> From<ast::Field<'ast>> for types::Ex
|
||||
|
||||
/// pest ast -> types::Group
|
||||
|
||||
impl<'ast, G: Group, F: Field + PrimeField> From<ast::Group<'ast>> for types::Expression<G, F> {
|
||||
impl<'ast, F: Field + PrimeField, G: Group> From<ast::Group<'ast>> for types::Expression<F, G> {
|
||||
fn from(_group: ast::Group<'ast>) -> Self {
|
||||
types::Expression::GroupElement(G::zero())
|
||||
}
|
||||
@ -116,7 +116,7 @@ impl<'ast, G: Group, F: Field + PrimeField> From<ast::Group<'ast>> for types::Ex
|
||||
|
||||
/// pest ast -> types::Boolean
|
||||
|
||||
impl<'ast, G: Group, F: Field + PrimeField> From<ast::Boolean<'ast>> for types::Expression<G, F> {
|
||||
impl<'ast, F: Field + PrimeField, G: Group> From<ast::Boolean<'ast>> for types::Expression<F, G> {
|
||||
fn from(boolean: ast::Boolean<'ast>) -> Self {
|
||||
types::Expression::Boolean(Boolean::Constant(
|
||||
boolean
|
||||
@ -129,7 +129,7 @@ impl<'ast, G: Group, F: Field + PrimeField> From<ast::Boolean<'ast>> for types::
|
||||
|
||||
/// pest ast -> types::Expression
|
||||
|
||||
impl<'ast, G: Group, F: Field + PrimeField> From<ast::Value<'ast>> for types::Expression<G, F> {
|
||||
impl<'ast, F: Field + PrimeField, G: Group> From<ast::Value<'ast>> for types::Expression<F, G> {
|
||||
fn from(value: ast::Value<'ast>) -> Self {
|
||||
match value {
|
||||
ast::Value::Integer(num) => types::Expression::from(num),
|
||||
@ -140,14 +140,14 @@ impl<'ast, G: Group, F: Field + PrimeField> From<ast::Value<'ast>> for types::Ex
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, G: Group, F: Field + PrimeField> From<ast::NotExpression<'ast>> for types::Expression<G, F> {
|
||||
impl<'ast, F: Field + PrimeField, G: Group> From<ast::NotExpression<'ast>> for types::Expression<F, G> {
|
||||
fn from(expression: ast::NotExpression<'ast>) -> Self {
|
||||
types::Expression::Not(Box::new(types::Expression::from(*expression.expression)))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, G: Group, F: Field + PrimeField> From<ast::SpreadOrExpression<'ast>>
|
||||
for types::SpreadOrExpression<G, F>
|
||||
impl<'ast, F: Field + PrimeField, G: Group> From<ast::SpreadOrExpression<'ast>>
|
||||
for types::SpreadOrExpression<F, G>
|
||||
{
|
||||
fn from(s_or_e: ast::SpreadOrExpression<'ast>) -> Self {
|
||||
match s_or_e {
|
||||
@ -161,7 +161,7 @@ impl<'ast, G: Group, F: Field + PrimeField> From<ast::SpreadOrExpression<'ast>>
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, G: Group, F: Field + PrimeField> From<ast::BinaryExpression<'ast>> for types::Expression<G, F> {
|
||||
impl<'ast, F: Field + PrimeField, G: Group> From<ast::BinaryExpression<'ast>> for types::Expression<F, G> {
|
||||
fn from(expression: ast::BinaryExpression<'ast>) -> Self {
|
||||
match expression.operation {
|
||||
// Boolean operations
|
||||
@ -221,7 +221,7 @@ impl<'ast, G: Group, F: Field + PrimeField> From<ast::BinaryExpression<'ast>> fo
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, G: Group, F: Field + PrimeField> From<ast::TernaryExpression<'ast>> for types::Expression<G, F> {
|
||||
impl<'ast, F: Field + PrimeField, G: Group> From<ast::TernaryExpression<'ast>> for types::Expression<F, G> {
|
||||
fn from(expression: ast::TernaryExpression<'ast>) -> Self {
|
||||
types::Expression::IfElse(
|
||||
Box::new(types::Expression::from(*expression.first)),
|
||||
@ -231,7 +231,7 @@ impl<'ast, G: Group, F: Field + PrimeField> From<ast::TernaryExpression<'ast>> f
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, G: Group, F: Field + PrimeField> From<ast::ArrayInlineExpression<'ast>> for types::Expression<G, F> {
|
||||
impl<'ast, F: Field + PrimeField, G: Group> From<ast::ArrayInlineExpression<'ast>> for types::Expression<F, G> {
|
||||
fn from(array: ast::ArrayInlineExpression<'ast>) -> Self {
|
||||
types::Expression::Array(
|
||||
array
|
||||
@ -242,18 +242,18 @@ impl<'ast, G: Group, F: Field + PrimeField> From<ast::ArrayInlineExpression<'ast
|
||||
)
|
||||
}
|
||||
}
|
||||
impl<'ast, G: Group, F: Field + PrimeField> From<ast::ArrayInitializerExpression<'ast>>
|
||||
for types::Expression<G, F>
|
||||
impl<'ast, F: Field + PrimeField, G: Group> From<ast::ArrayInitializerExpression<'ast>>
|
||||
for types::Expression<F, G>
|
||||
{
|
||||
fn from(array: ast::ArrayInitializerExpression<'ast>) -> Self {
|
||||
let count = types::Expression::<G, F>::get_count(array.count);
|
||||
let count = types::Expression::<F, G>::get_count(array.count);
|
||||
let expression = Box::new(types::SpreadOrExpression::from(*array.expression));
|
||||
|
||||
types::Expression::Array(vec![expression; count])
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, G: Group, F: Field + PrimeField> From<ast::InlineStructMember<'ast>> for types::StructMember<G, F> {
|
||||
impl<'ast, F: Field + PrimeField, G: Group> From<ast::InlineStructMember<'ast>> for types::StructMember<F, G> {
|
||||
fn from(member: ast::InlineStructMember<'ast>) -> Self {
|
||||
types::StructMember {
|
||||
variable: types::Variable::from(member.variable),
|
||||
@ -262,20 +262,20 @@ impl<'ast, G: Group, F: Field + PrimeField> From<ast::InlineStructMember<'ast>>
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, G: Group, F: Field + PrimeField> From<ast::StructInlineExpression<'ast>> for types::Expression<G, F> {
|
||||
impl<'ast, F: Field + PrimeField, G: Group> From<ast::StructInlineExpression<'ast>> for types::Expression<F, G> {
|
||||
fn from(expression: ast::StructInlineExpression<'ast>) -> Self {
|
||||
let variable = types::Variable::from(expression.variable);
|
||||
let members = expression
|
||||
.members
|
||||
.into_iter()
|
||||
.map(|member| types::StructMember::from(member))
|
||||
.collect::<Vec<types::StructMember<G, F>>>();
|
||||
.collect::<Vec<types::StructMember<F, G>>>();
|
||||
|
||||
types::Expression::Struct(variable, members)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, G: Group, F: Field + PrimeField> From<ast::PostfixExpression<'ast>> for types::Expression<G, F> {
|
||||
impl<'ast, F: Field + PrimeField, G: Group> From<ast::PostfixExpression<'ast>> for types::Expression<F, G> {
|
||||
fn from(expression: ast::PostfixExpression<'ast>) -> Self {
|
||||
let variable = types::Expression::Variable(types::Variable::from(expression.variable));
|
||||
|
||||
@ -312,7 +312,7 @@ impl<'ast, G: Group, F: Field + PrimeField> From<ast::PostfixExpression<'ast>> f
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, G: Group, F: Field + PrimeField> From<ast::Expression<'ast>> for types::Expression<G, F> {
|
||||
impl<'ast, F: Field + PrimeField, G: Group> From<ast::Expression<'ast>> for types::Expression<F, G> {
|
||||
fn from(expression: ast::Expression<'ast>) -> Self {
|
||||
match expression {
|
||||
ast::Expression::Value(value) => types::Expression::from(value),
|
||||
@ -328,7 +328,7 @@ impl<'ast, G: Group, F: Field + PrimeField> From<ast::Expression<'ast>> for type
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, G: Group, F: Field + PrimeField> types::Expression<G, F> {
|
||||
impl<'ast, F: Field + PrimeField, G: Group> types::Expression<F, G> {
|
||||
fn get_count(count: ast::Value<'ast>) -> usize {
|
||||
match count {
|
||||
ast::Value::Integer(f) => f
|
||||
@ -342,7 +342,7 @@ impl<'ast, G: Group, F: Field + PrimeField> types::Expression<G, F> {
|
||||
}
|
||||
|
||||
// ast::Assignee -> types::Expression for operator assign statements
|
||||
impl<'ast, G: Group, F: Field + PrimeField> From<ast::Assignee<'ast>> for types::Expression<G, F> {
|
||||
impl<'ast, F: Field + PrimeField, G: Group> From<ast::Assignee<'ast>> for types::Expression<F, G> {
|
||||
fn from(assignee: ast::Assignee<'ast>) -> Self {
|
||||
let variable = types::Expression::Variable(types::Variable::from(assignee.variable));
|
||||
|
||||
@ -367,13 +367,13 @@ impl<'ast, G: Group, F: Field + PrimeField> From<ast::Assignee<'ast>> for types:
|
||||
|
||||
/// pest ast -> types::Assignee
|
||||
|
||||
impl<'ast, G: Group, F: Field + PrimeField> From<ast::Variable<'ast>> for types::Assignee<G, F> {
|
||||
impl<'ast, F: Field + PrimeField, G: Group> From<ast::Variable<'ast>> for types::Assignee<F, G> {
|
||||
fn from(variable: ast::Variable<'ast>) -> Self {
|
||||
types::Assignee::Variable(types::Variable::from(variable))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, G: Group, F: Field + PrimeField> From<ast::Assignee<'ast>> for types::Assignee<G, F> {
|
||||
impl<'ast, F: Field + PrimeField, G: Group> From<ast::Assignee<'ast>> for types::Assignee<F, G> {
|
||||
fn from(assignee: ast::Assignee<'ast>) -> Self {
|
||||
let variable = types::Assignee::from(assignee.variable);
|
||||
|
||||
@ -396,7 +396,7 @@ impl<'ast, G: Group, F: Field + PrimeField> From<ast::Assignee<'ast>> for types:
|
||||
|
||||
/// pest ast -> types::Statement
|
||||
|
||||
impl<'ast, G: Group, F: Field + PrimeField> From<ast::ReturnStatement<'ast>> for types::Statement<G, F> {
|
||||
impl<'ast, F: Field + PrimeField, G: Group> From<ast::ReturnStatement<'ast>> for types::Statement<F, G> {
|
||||
fn from(statement: ast::ReturnStatement<'ast>) -> Self {
|
||||
types::Statement::Return(
|
||||
statement
|
||||
@ -408,17 +408,17 @@ impl<'ast, G: Group, F: Field + PrimeField> From<ast::ReturnStatement<'ast>> for
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, G: Group, F: Field + PrimeField> From<ast::DefinitionStatement<'ast>> for types::Statement<G, F> {
|
||||
impl<'ast, F: Field + PrimeField, G: Group> From<ast::DefinitionStatement<'ast>> for types::Statement<F, G> {
|
||||
fn from(statement: ast::DefinitionStatement<'ast>) -> Self {
|
||||
types::Statement::Definition(
|
||||
types::Assignee::from(statement.variable),
|
||||
statement._type.map(|_type| types::Type::<G, F>::from(_type)),
|
||||
statement._type.map(|_type| types::Type::<F, G>::from(_type)),
|
||||
types::Expression::from(statement.expression),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, G: Group, F: Field + PrimeField> From<ast::AssignStatement<'ast>> for types::Statement<G, F> {
|
||||
impl<'ast, F: Field + PrimeField, G: Group> From<ast::AssignStatement<'ast>> for types::Statement<F, G> {
|
||||
fn from(statement: ast::AssignStatement<'ast>) -> Self {
|
||||
match statement.assign {
|
||||
ast::OperationAssign::Assign(ref _assign) => types::Statement::Assign(
|
||||
@ -474,8 +474,8 @@ impl<'ast, G: Group, F: Field + PrimeField> From<ast::AssignStatement<'ast>> for
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, G: Group, F: Field + PrimeField> From<ast::MultipleAssignmentStatement<'ast>>
|
||||
for types::Statement<G, F>
|
||||
impl<'ast, F: Field + PrimeField, G: Group> From<ast::MultipleAssignmentStatement<'ast>>
|
||||
for types::Statement<F, G>
|
||||
{
|
||||
fn from(statement: ast::MultipleAssignmentStatement<'ast>) -> Self {
|
||||
let assignees = statement
|
||||
@ -498,8 +498,8 @@ impl<'ast, G: Group, F: Field + PrimeField> From<ast::MultipleAssignmentStatemen
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, G: Group, F: Field + PrimeField> From<ast::ConditionalNestedOrEnd<'ast>>
|
||||
for types::ConditionalNestedOrEnd<G, F>
|
||||
impl<'ast, F: Field + PrimeField, G: Group> From<ast::ConditionalNestedOrEnd<'ast>>
|
||||
for types::ConditionalNestedOrEnd<F, G>
|
||||
{
|
||||
fn from(statement: ast::ConditionalNestedOrEnd<'ast>) -> Self {
|
||||
match statement {
|
||||
@ -516,8 +516,8 @@ impl<'ast, G: Group, F: Field + PrimeField> From<ast::ConditionalNestedOrEnd<'as
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, G: Group, F: Field + PrimeField> From<ast::ConditionalStatement<'ast>>
|
||||
for types::ConditionalStatement<G, F>
|
||||
impl<'ast, F: Field + PrimeField, G: Group> From<ast::ConditionalStatement<'ast>>
|
||||
for types::ConditionalStatement<F, G>
|
||||
{
|
||||
fn from(statement: ast::ConditionalStatement<'ast>) -> Self {
|
||||
types::ConditionalStatement {
|
||||
@ -535,13 +535,13 @@ impl<'ast, G: Group, F: Field + PrimeField> From<ast::ConditionalStatement<'ast>
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, G: Group, F: Field + PrimeField> From<ast::ForStatement<'ast>> for types::Statement<G, F> {
|
||||
impl<'ast, F: Field + PrimeField, G: Group> From<ast::ForStatement<'ast>> for types::Statement<F, G> {
|
||||
fn from(statement: ast::ForStatement<'ast>) -> Self {
|
||||
let from = match types::Expression::<G, F>::from(statement.start) {
|
||||
let from = match types::Expression::<F, G>::from(statement.start) {
|
||||
types::Expression::Integer(number) => number,
|
||||
expression => unimplemented!("Range bounds should be integers, found {}", expression),
|
||||
};
|
||||
let to = match types::Expression::<G, F>::from(statement.stop) {
|
||||
let to = match types::Expression::<F, G>::from(statement.stop) {
|
||||
types::Expression::Integer(number) => number,
|
||||
expression => unimplemented!("Range bounds should be integers, found {}", expression),
|
||||
};
|
||||
@ -559,7 +559,7 @@ impl<'ast, G: Group, F: Field + PrimeField> From<ast::ForStatement<'ast>> for ty
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, G: Group, F: Field + PrimeField> From<ast::AssertStatement<'ast>> for types::Statement<G, F> {
|
||||
impl<'ast, F: Field + PrimeField, G: Group> From<ast::AssertStatement<'ast>> for types::Statement<F, G> {
|
||||
fn from(statement: ast::AssertStatement<'ast>) -> Self {
|
||||
match statement {
|
||||
ast::AssertStatement::AssertEq(assert_eq) => types::Statement::AssertEq(
|
||||
@ -570,13 +570,13 @@ impl<'ast, G: Group, F: Field + PrimeField> From<ast::AssertStatement<'ast>> for
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, G: Group, F: Field + PrimeField> From<ast::ExpressionStatement<'ast>> for types::Statement<G, F> {
|
||||
impl<'ast, F: Field + PrimeField, G: Group> From<ast::ExpressionStatement<'ast>> for types::Statement<F, G> {
|
||||
fn from(statement: ast::ExpressionStatement<'ast>) -> Self {
|
||||
types::Statement::Expression(types::Expression::from(statement.expression))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, G: Group, F: Field + PrimeField> From<ast::Statement<'ast>> for types::Statement<G, F> {
|
||||
impl<'ast, F: Field + PrimeField, G: Group> From<ast::Statement<'ast>> for types::Statement<F, G> {
|
||||
fn from(statement: ast::Statement<'ast>) -> Self {
|
||||
match statement {
|
||||
ast::Statement::Return(statement) => types::Statement::from(statement),
|
||||
@ -607,7 +607,7 @@ impl From<ast::IntegerType> for types::IntegerType {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, G: Group, F: Field + PrimeField> From<ast::BasicType<'ast>> for types::Type<G, F> {
|
||||
impl<'ast, F: Field + PrimeField, G: Group> From<ast::BasicType<'ast>> for types::Type<F, G> {
|
||||
fn from(basic_type: ast::BasicType<'ast>) -> Self {
|
||||
match basic_type {
|
||||
ast::BasicType::Integer(_type) => types::Type::IntegerType(types::IntegerType::from(_type)),
|
||||
@ -618,26 +618,26 @@ impl<'ast, G: Group, F: Field + PrimeField> From<ast::BasicType<'ast>> for types
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, G: Group, F: Field + PrimeField> From<ast::ArrayType<'ast>> for types::Type<G, F> {
|
||||
impl<'ast, F: Field + PrimeField, G: Group> From<ast::ArrayType<'ast>> for types::Type<F, G> {
|
||||
fn from(array_type: ast::ArrayType<'ast>) -> Self {
|
||||
let element_type = Box::new(types::Type::from(array_type._type));
|
||||
let dimensions = array_type
|
||||
.dimensions
|
||||
.into_iter()
|
||||
.map(|row| types::Expression::<G, F>::get_count(row))
|
||||
.map(|row| types::Expression::<F, G>::get_count(row))
|
||||
.collect();
|
||||
|
||||
types::Type::Array(element_type, dimensions)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, G: Group, F: Field + PrimeField> From<ast::StructType<'ast>> for types::Type<G, F> {
|
||||
impl<'ast, F: Field + PrimeField, G: Group> From<ast::StructType<'ast>> for types::Type<F, G> {
|
||||
fn from(struct_type: ast::StructType<'ast>) -> Self {
|
||||
types::Type::Struct(types::Variable::from(struct_type.variable))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, G: Group, F: Field + PrimeField> From<ast::Type<'ast>> for types::Type<G, F> {
|
||||
impl<'ast, F: Field + PrimeField, G: Group> From<ast::Type<'ast>> for types::Type<F, G> {
|
||||
fn from(_type: ast::Type<'ast>) -> Self {
|
||||
match _type {
|
||||
ast::Type::Basic(_type) => types::Type::from(_type),
|
||||
@ -649,7 +649,7 @@ impl<'ast, G: Group, F: Field + PrimeField> From<ast::Type<'ast>> for types::Typ
|
||||
|
||||
/// pest ast -> types::Struct
|
||||
|
||||
impl<'ast, G: Group, F: Field + PrimeField> From<ast::StructField<'ast>> for types::StructField<G, F> {
|
||||
impl<'ast, F: Field + PrimeField, G: Group> From<ast::StructField<'ast>> for types::StructField<F, G> {
|
||||
fn from(struct_field: ast::StructField<'ast>) -> Self {
|
||||
types::StructField {
|
||||
variable: types::Variable::from(struct_field.variable),
|
||||
@ -658,7 +658,7 @@ impl<'ast, G: Group, F: Field + PrimeField> From<ast::StructField<'ast>> for typ
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, G: Group, F: Field + PrimeField> From<ast::Struct<'ast>> for types::Struct<G, F> {
|
||||
impl<'ast, F: Field + PrimeField, G: Group> From<ast::Struct<'ast>> for types::Struct<F, G> {
|
||||
fn from(struct_definition: ast::Struct<'ast>) -> Self {
|
||||
let variable = types::Variable::from(struct_definition.variable);
|
||||
let fields = struct_definition
|
||||
@ -673,7 +673,7 @@ impl<'ast, G: Group, F: Field + PrimeField> From<ast::Struct<'ast>> for types::S
|
||||
|
||||
/// pest ast -> function types::Parameters
|
||||
|
||||
impl<'ast, G: Group, F: Field + PrimeField> From<ast::Parameter<'ast>> for types::InputModel<G, F> {
|
||||
impl<'ast, F: Field + PrimeField, G: Group> From<ast::Parameter<'ast>> for types::InputModel<F, G> {
|
||||
fn from(parameter: ast::Parameter<'ast>) -> Self {
|
||||
let _type = types::Type::from(parameter._type);
|
||||
let variable = types::Variable::from(parameter.variable);
|
||||
@ -706,7 +706,7 @@ impl<'ast> From<ast::FunctionName<'ast>> for types::FunctionName {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, G: Group, F: Field + PrimeField> From<ast::Function<'ast>> for types::Function<G, F> {
|
||||
impl<'ast, F: Field + PrimeField, G: Group> From<ast::Function<'ast>> for types::Function<F, G> {
|
||||
fn from(function_definition: ast::Function<'ast>) -> Self {
|
||||
let function_name = types::FunctionName::from(function_definition.function_name);
|
||||
let parameters = function_definition
|
||||
@ -736,7 +736,7 @@ impl<'ast, G: Group, F: Field + PrimeField> From<ast::Function<'ast>> for types:
|
||||
|
||||
/// pest ast -> Import
|
||||
|
||||
impl<'ast, G: Group, F: Field + PrimeField> From<ast::ImportSymbol<'ast>> for ImportSymbol<G, F> {
|
||||
impl<'ast, F: Field + PrimeField, G: Group> From<ast::ImportSymbol<'ast>> for ImportSymbol<F, G> {
|
||||
fn from(symbol: ast::ImportSymbol<'ast>) -> Self {
|
||||
ImportSymbol {
|
||||
symbol: types::Variable::from(symbol.value),
|
||||
@ -745,7 +745,7 @@ impl<'ast, G: Group, F: Field + PrimeField> From<ast::ImportSymbol<'ast>> for Im
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, G: Group, F: Field + PrimeField> From<ast::Import<'ast>> for Import<G, F> {
|
||||
impl<'ast, F: Field + PrimeField, G: Group> From<ast::Import<'ast>> for Import<F, G> {
|
||||
fn from(import: ast::Import<'ast>) -> Self {
|
||||
Import {
|
||||
path_string: import.source.value,
|
||||
@ -760,14 +760,14 @@ impl<'ast, G: Group, F: Field + PrimeField> From<ast::Import<'ast>> for Import<G
|
||||
|
||||
/// pest ast -> types::Program
|
||||
|
||||
impl<'ast, G: Group, F: Field + PrimeField> types::Program<G, F> {
|
||||
impl<'ast, F: Field + PrimeField, G: Group> types::Program<F, G> {
|
||||
pub fn from(file: ast::File<'ast>, name: String) -> Self {
|
||||
// Compiled ast -> aleo program representation
|
||||
let imports = file
|
||||
.imports
|
||||
.into_iter()
|
||||
.map(|import| Import::from(import))
|
||||
.collect::<Vec<Import<G, F>>>();
|
||||
.collect::<Vec<Import<F, G>>>();
|
||||
|
||||
let mut structs = HashMap::new();
|
||||
let mut functions = HashMap::new();
|
||||
|
Loading…
Reference in New Issue
Block a user