mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-10-26 07:00:35 +03:00
remove trait parameters from program types
This commit is contained in:
parent
674f0dc83d
commit
4657f565f5
@ -21,7 +21,7 @@ use std::{fs, marker::PhantomData, path::PathBuf};
|
||||
pub struct Compiler<F: Field + PrimeField, G: GroupType<F>> {
|
||||
package_name: String,
|
||||
main_file_path: PathBuf,
|
||||
program: Program<F>,
|
||||
program: Program,
|
||||
program_inputs: Vec<Option<InputValue>>,
|
||||
output: Option<ConstrainedValue<F, G>>,
|
||||
_engine: PhantomData<F>,
|
||||
@ -98,7 +98,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> Compiler<F, G> {
|
||||
// Build program from abstract syntax tree
|
||||
let package_name = self.package_name.clone();
|
||||
|
||||
self.program = Program::<F>::from(syntax_tree, package_name);
|
||||
self.program = Program::from(syntax_tree, package_name);
|
||||
self.program_inputs = vec![None; self.program.num_parameters];
|
||||
|
||||
log::debug!("Program parsing complete\n{:#?}", self.program);
|
||||
|
@ -25,8 +25,8 @@ impl<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>> Constraine
|
||||
&mut self,
|
||||
file_scope: String,
|
||||
function_scope: String,
|
||||
expected_types: &Vec<Type<F>>,
|
||||
unresolved_identifier: Identifier<F>,
|
||||
expected_types: &Vec<Type>,
|
||||
unresolved_identifier: Identifier,
|
||||
) -> Result<ConstrainedValue<F, G>, ExpressionError> {
|
||||
// Evaluate the identifier name in the current function scope
|
||||
let variable_name = new_scope(function_scope, unresolved_identifier.to_string());
|
||||
@ -332,10 +332,10 @@ impl<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>> Constraine
|
||||
cs: &mut CS,
|
||||
file_scope: String,
|
||||
function_scope: String,
|
||||
expected_types: &Vec<Type<F>>,
|
||||
first: Expression<F>,
|
||||
second: Expression<F>,
|
||||
third: Expression<F>,
|
||||
expected_types: &Vec<Type>,
|
||||
first: Expression,
|
||||
second: Expression,
|
||||
third: Expression,
|
||||
) -> Result<ConstrainedValue<F, G>, ExpressionError> {
|
||||
let resolved_first = match self.enforce_expression(
|
||||
cs,
|
||||
@ -384,8 +384,8 @@ impl<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>> Constraine
|
||||
cs: &mut CS,
|
||||
file_scope: String,
|
||||
function_scope: String,
|
||||
expected_types: &Vec<Type<F>>,
|
||||
array: Vec<Box<SpreadOrExpression<F>>>,
|
||||
expected_types: &Vec<Type>,
|
||||
array: Vec<Box<SpreadOrExpression>>,
|
||||
) -> Result<ConstrainedValue<F, G>, ExpressionError> {
|
||||
// Check explicit array type dimension if given
|
||||
let mut expected_types = expected_types.clone();
|
||||
@ -448,7 +448,7 @@ impl<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>> Constraine
|
||||
cs: &mut CS,
|
||||
file_scope: String,
|
||||
function_scope: String,
|
||||
index: Expression<F>,
|
||||
index: Expression,
|
||||
) -> Result<usize, ExpressionError> {
|
||||
let expected_types = vec![Type::IntegerType(IntegerType::U32)];
|
||||
match self.enforce_branch(
|
||||
@ -468,9 +468,9 @@ impl<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>> Constraine
|
||||
cs: &mut CS,
|
||||
file_scope: String,
|
||||
function_scope: String,
|
||||
expected_types: &Vec<Type<F>>,
|
||||
array: Box<Expression<F>>,
|
||||
index: RangeOrExpression<F>,
|
||||
expected_types: &Vec<Type>,
|
||||
array: Box<Expression>,
|
||||
index: RangeOrExpression,
|
||||
) -> Result<ConstrainedValue<F, G>, ExpressionError> {
|
||||
let array = match self.enforce_branch(
|
||||
cs,
|
||||
@ -509,8 +509,8 @@ impl<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>> Constraine
|
||||
cs: &mut CS,
|
||||
file_scope: String,
|
||||
function_scope: String,
|
||||
identifier: Identifier<F>,
|
||||
members: Vec<CircuitFieldDefinition<F>>,
|
||||
identifier: Identifier,
|
||||
members: Vec<CircuitFieldDefinition>,
|
||||
) -> Result<ConstrainedValue<F, G>, ExpressionError> {
|
||||
let mut program_identifier = new_scope(file_scope.clone(), identifier.to_string());
|
||||
|
||||
@ -583,9 +583,9 @@ impl<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>> Constraine
|
||||
cs: &mut CS,
|
||||
file_scope: String,
|
||||
function_scope: String,
|
||||
expected_types: &Vec<Type<F>>,
|
||||
circuit_identifier: Box<Expression<F>>,
|
||||
circuit_member: Identifier<F>,
|
||||
expected_types: &Vec<Type>,
|
||||
circuit_identifier: Box<Expression>,
|
||||
circuit_member: Identifier,
|
||||
) -> Result<ConstrainedValue<F, G>, ExpressionError> {
|
||||
let (circuit_name, members) = match self.enforce_branch(
|
||||
cs,
|
||||
@ -644,9 +644,9 @@ impl<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>> Constraine
|
||||
cs: &mut CS,
|
||||
file_scope: String,
|
||||
function_scope: String,
|
||||
expected_types: &Vec<Type<F>>,
|
||||
circuit_identifier: Box<Expression<F>>,
|
||||
circuit_member: Identifier<F>,
|
||||
expected_types: &Vec<Type>,
|
||||
circuit_identifier: Box<Expression>,
|
||||
circuit_member: Identifier,
|
||||
) -> Result<ConstrainedValue<F, G>, ExpressionError> {
|
||||
// Get defined circuit
|
||||
let circuit = match self.enforce_expression(
|
||||
@ -698,9 +698,9 @@ impl<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>> Constraine
|
||||
cs: &mut CS,
|
||||
file_scope: String,
|
||||
function_scope: String,
|
||||
expected_types: &Vec<Type<F>>,
|
||||
function: Box<Expression<F>>,
|
||||
arguments: Vec<Expression<F>>,
|
||||
expected_types: &Vec<Type>,
|
||||
function: Box<Expression>,
|
||||
arguments: Vec<Expression>,
|
||||
) -> Result<ConstrainedValue<F, G>, ExpressionError> {
|
||||
let function_value = self.enforce_expression(
|
||||
cs,
|
||||
@ -737,7 +737,7 @@ impl<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>> Constraine
|
||||
}
|
||||
|
||||
pub(crate) fn enforce_number_implicit(
|
||||
expected_types: &Vec<Type<F>>,
|
||||
expected_types: &Vec<Type>,
|
||||
value: String,
|
||||
) -> Result<ConstrainedValue<F, G>, ExpressionError> {
|
||||
if expected_types.len() == 1 {
|
||||
@ -755,8 +755,8 @@ impl<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>> Constraine
|
||||
cs: &mut CS,
|
||||
file_scope: String,
|
||||
function_scope: String,
|
||||
expected_types: &Vec<Type<F>>,
|
||||
expression: Expression<F>,
|
||||
expected_types: &Vec<Type>,
|
||||
expression: Expression,
|
||||
) -> Result<ConstrainedValue<F, G>, ExpressionError> {
|
||||
let mut branch =
|
||||
self.enforce_expression(cs, file_scope, function_scope, expected_types, expression)?;
|
||||
@ -772,9 +772,9 @@ impl<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>> Constraine
|
||||
cs: &mut CS,
|
||||
file_scope: String,
|
||||
function_scope: String,
|
||||
expected_types: &Vec<Type<F>>,
|
||||
left: Expression<F>,
|
||||
right: Expression<F>,
|
||||
expected_types: &Vec<Type>,
|
||||
left: Expression,
|
||||
right: Expression,
|
||||
) -> Result<(ConstrainedValue<F, G>, ConstrainedValue<F, G>), ExpressionError> {
|
||||
let resolved_left = self.enforce_branch(
|
||||
cs,
|
||||
@ -799,8 +799,8 @@ impl<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>> Constraine
|
||||
cs: &mut CS,
|
||||
file_scope: String,
|
||||
function_scope: String,
|
||||
expected_types: &Vec<Type<F>>,
|
||||
expression: Expression<F>,
|
||||
expected_types: &Vec<Type>,
|
||||
expression: Expression,
|
||||
) -> Result<ConstrainedValue<F, G>, ExpressionError> {
|
||||
match expression {
|
||||
// Variables
|
||||
|
@ -30,8 +30,8 @@ impl<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>> Constraine
|
||||
scope: String,
|
||||
caller_scope: String,
|
||||
function_name: String,
|
||||
expected_types: Vec<Type<F>>,
|
||||
input: Expression<F>,
|
||||
expected_types: Vec<Type>,
|
||||
input: Expression,
|
||||
) -> Result<ConstrainedValue<F, G>, FunctionError> {
|
||||
// Evaluate the function input value as pass by value from the caller or
|
||||
// evaluate as an expression in the current function scope
|
||||
@ -57,8 +57,8 @@ impl<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>> Constraine
|
||||
cs: &mut CS,
|
||||
scope: String,
|
||||
caller_scope: String,
|
||||
function: Function<F>,
|
||||
inputs: Vec<Expression<F>>,
|
||||
function: Function,
|
||||
inputs: Vec<Expression>,
|
||||
) -> Result<ConstrainedValue<F, G>, FunctionError> {
|
||||
let function_name = new_scope(scope.clone(), function.get_name());
|
||||
|
||||
@ -118,7 +118,7 @@ impl<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>> Constraine
|
||||
cs: &mut CS,
|
||||
name: String,
|
||||
private: bool,
|
||||
array_type: Type<F>,
|
||||
array_type: Type,
|
||||
array_dimensions: Vec<usize>,
|
||||
input_value: Option<InputValue>,
|
||||
) -> Result<ConstrainedValue<F, G>, FunctionError> {
|
||||
@ -170,7 +170,7 @@ impl<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>> Constraine
|
||||
fn allocate_main_function_input(
|
||||
&mut self,
|
||||
cs: &mut CS,
|
||||
_type: Type<F>,
|
||||
_type: Type,
|
||||
name: String,
|
||||
private: bool,
|
||||
input_value: Option<InputValue>,
|
||||
@ -193,7 +193,7 @@ impl<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>> Constraine
|
||||
&mut self,
|
||||
cs: &mut CS,
|
||||
scope: String,
|
||||
function: Function<F>,
|
||||
function: Function,
|
||||
inputs: Vec<Option<InputValue>>,
|
||||
) -> Result<ConstrainedValue<F, G>, FunctionError> {
|
||||
let function_name = new_scope(scope.clone(), function.get_name());
|
||||
@ -229,7 +229,7 @@ impl<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>> Constraine
|
||||
pub(crate) fn resolve_definitions(
|
||||
&mut self,
|
||||
cs: &mut CS,
|
||||
program: Program<F>,
|
||||
program: Program,
|
||||
) -> Result<(), ImportError> {
|
||||
let program_name = program.name.clone();
|
||||
|
||||
|
@ -19,7 +19,7 @@ impl<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>> Constraine
|
||||
&mut self,
|
||||
cs: &mut CS,
|
||||
scope: String,
|
||||
import: Import<F>,
|
||||
import: Import,
|
||||
) -> Result<(), ImportError> {
|
||||
let path = current_dir().map_err(|error| ImportError::DirectoryError(error))?;
|
||||
|
||||
|
@ -43,7 +43,7 @@ use snarkos_models::{
|
||||
|
||||
pub fn generate_constraints<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
cs: &mut CS,
|
||||
program: Program<F>,
|
||||
program: Program,
|
||||
parameters: Vec<Option<InputValue>>,
|
||||
) -> Result<ConstrainedValue<F, G>, CompilerError> {
|
||||
let mut resolved_program = ConstrainedProgram::new();
|
||||
|
@ -20,7 +20,7 @@ use snarkos_models::{
|
||||
};
|
||||
|
||||
impl<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>> ConstrainedProgram<F, G, CS> {
|
||||
fn resolve_assignee(&mut self, scope: String, assignee: Assignee<F>) -> String {
|
||||
fn resolve_assignee(&mut self, scope: String, assignee: Assignee) -> String {
|
||||
match assignee {
|
||||
Assignee::Identifier(name) => new_scope(scope, name.to_string()),
|
||||
Assignee::Array(array, _index) => self.resolve_assignee(scope, *array),
|
||||
@ -50,7 +50,7 @@ impl<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>> Constraine
|
||||
file_scope: String,
|
||||
function_scope: String,
|
||||
name: String,
|
||||
range_or_expression: RangeOrExpression<F>,
|
||||
range_or_expression: RangeOrExpression,
|
||||
new_value: ConstrainedValue<F, G>,
|
||||
) -> Result<(), StatementError> {
|
||||
// Resolve index so we know if we are assigning to a single value or a range of values
|
||||
@ -94,7 +94,7 @@ impl<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>> Constraine
|
||||
fn mutute_circuit_field(
|
||||
&mut self,
|
||||
circuit_name: String,
|
||||
object_name: Identifier<F>,
|
||||
object_name: Identifier,
|
||||
new_value: ConstrainedValue<F, G>,
|
||||
) -> Result<(), StatementError> {
|
||||
match self.get_mutable_assignee(circuit_name)? {
|
||||
@ -132,8 +132,8 @@ impl<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>> Constraine
|
||||
cs: &mut CS,
|
||||
file_scope: String,
|
||||
function_scope: String,
|
||||
assignee: Assignee<F>,
|
||||
expression: Expression<F>,
|
||||
assignee: Assignee,
|
||||
expression: Expression,
|
||||
) -> Result<(), StatementError> {
|
||||
// Get the name of the variable we are assigning to
|
||||
let variable_name = self.resolve_assignee(function_scope.clone(), assignee.clone());
|
||||
@ -173,7 +173,7 @@ impl<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>> Constraine
|
||||
fn store_definition(
|
||||
&mut self,
|
||||
function_scope: String,
|
||||
variable: Variable<F>,
|
||||
variable: Variable,
|
||||
mut value: ConstrainedValue<F, G>,
|
||||
) -> Result<(), StatementError> {
|
||||
// Store with given mutability
|
||||
@ -193,8 +193,8 @@ impl<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>> Constraine
|
||||
cs: &mut CS,
|
||||
file_scope: String,
|
||||
function_scope: String,
|
||||
variable: Variable<F>,
|
||||
expression: Expression<F>,
|
||||
variable: Variable,
|
||||
expression: Expression,
|
||||
) -> Result<(), StatementError> {
|
||||
let mut expected_types = vec![];
|
||||
if let Some(ref _type) = variable._type {
|
||||
@ -216,8 +216,8 @@ impl<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>> Constraine
|
||||
cs: &mut CS,
|
||||
file_scope: String,
|
||||
function_scope: String,
|
||||
variables: Vec<Variable<F>>,
|
||||
function: Expression<F>,
|
||||
variables: Vec<Variable>,
|
||||
function: Expression,
|
||||
) -> Result<(), StatementError> {
|
||||
let mut expected_types = vec![];
|
||||
for variable in variables.iter() {
|
||||
@ -259,8 +259,8 @@ impl<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>> Constraine
|
||||
cs: &mut CS,
|
||||
file_scope: String,
|
||||
function_scope: String,
|
||||
expressions: Vec<Expression<F>>,
|
||||
return_types: Vec<Type<F>>,
|
||||
expressions: Vec<Expression>,
|
||||
return_types: Vec<Type>,
|
||||
) -> Result<ConstrainedValue<F, G>, StatementError> {
|
||||
// Make sure we return the correct number of values
|
||||
if return_types.len() != expressions.len() {
|
||||
@ -292,8 +292,8 @@ impl<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>> Constraine
|
||||
cs: &mut CS,
|
||||
file_scope: String,
|
||||
function_scope: String,
|
||||
statements: Vec<Statement<F>>,
|
||||
return_types: Vec<Type<F>>,
|
||||
statements: Vec<Statement>,
|
||||
return_types: Vec<Type>,
|
||||
) -> Result<Option<ConstrainedValue<F, G>>, StatementError> {
|
||||
let mut res = None;
|
||||
// Evaluate statements and possibly return early
|
||||
@ -318,8 +318,8 @@ impl<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>> Constraine
|
||||
cs: &mut CS,
|
||||
file_scope: String,
|
||||
function_scope: String,
|
||||
statement: ConditionalStatement<F>,
|
||||
return_types: Vec<Type<F>>,
|
||||
statement: ConditionalStatement,
|
||||
return_types: Vec<Type>,
|
||||
) -> Result<Option<ConstrainedValue<F, G>>, StatementError> {
|
||||
let expected_types = vec![Type::Boolean];
|
||||
let condition = match self.enforce_expression(
|
||||
@ -370,11 +370,11 @@ impl<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>> Constraine
|
||||
cs: &mut CS,
|
||||
file_scope: String,
|
||||
function_scope: String,
|
||||
index: Identifier<F>,
|
||||
index: Identifier,
|
||||
start: Integer,
|
||||
stop: Integer,
|
||||
statements: Vec<Statement<F>>,
|
||||
return_types: Vec<Type<F>>,
|
||||
statements: Vec<Statement>,
|
||||
return_types: Vec<Type>,
|
||||
) -> Result<Option<ConstrainedValue<F, G>>, StatementError> {
|
||||
let mut res = None;
|
||||
|
||||
@ -446,8 +446,8 @@ impl<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>> Constraine
|
||||
cs: &mut CS,
|
||||
file_scope: String,
|
||||
function_scope: String,
|
||||
statement: Statement<F>,
|
||||
return_types: Vec<Type<F>>,
|
||||
statement: Statement,
|
||||
return_types: Vec<Type>,
|
||||
) -> Result<Option<ConstrainedValue<F, G>>, StatementError> {
|
||||
let mut res = None;
|
||||
match statement {
|
||||
|
@ -17,7 +17,7 @@ use std::fmt;
|
||||
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
pub struct ConstrainedCircuitMember<F: Field + PrimeField, G: GroupType<F>>(
|
||||
pub Identifier<F>,
|
||||
pub Identifier,
|
||||
pub ConstrainedValue<F, G>,
|
||||
);
|
||||
|
||||
@ -30,10 +30,10 @@ pub enum ConstrainedValue<F: Field + PrimeField, G: GroupType<F>> {
|
||||
|
||||
Array(Vec<ConstrainedValue<F, G>>),
|
||||
|
||||
CircuitDefinition(Circuit<F>),
|
||||
CircuitExpression(Identifier<F>, Vec<ConstrainedCircuitMember<F, G>>),
|
||||
CircuitDefinition(Circuit),
|
||||
CircuitExpression(Identifier, Vec<ConstrainedCircuitMember<F, G>>),
|
||||
|
||||
Function(Option<Identifier<F>>, Function<F>), // (optional circuit identifier, function definition)
|
||||
Function(Option<Identifier>, Function), // (optional circuit identifier, function definition)
|
||||
Return(Vec<ConstrainedValue<F, G>>),
|
||||
|
||||
Mutable(Box<ConstrainedValue<F, G>>),
|
||||
@ -51,7 +51,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedValue<F, G> {
|
||||
ConstrainedValue::from_type(value, &other_type)
|
||||
}
|
||||
|
||||
pub(crate) fn from_type(value: String, _type: &Type<F>) -> Result<Self, ValueError> {
|
||||
pub(crate) fn from_type(value: String, _type: &Type) -> Result<Self, ValueError> {
|
||||
match _type {
|
||||
Type::IntegerType(integer_type) => Ok(ConstrainedValue::Integer(match integer_type {
|
||||
IntegerType::U8 => Integer::U8(UInt8::constant(value.parse::<u8>()?)),
|
||||
@ -70,7 +70,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedValue<F, G> {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn to_type(&self) -> Type<F> {
|
||||
pub(crate) fn to_type(&self) -> Type {
|
||||
match self {
|
||||
ConstrainedValue::Integer(integer) => Type::IntegerType(integer.get_type()),
|
||||
ConstrainedValue::Field(_field) => Type::Field,
|
||||
@ -80,7 +80,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedValue<F, G> {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn resolve_type(&mut self, types: &Vec<Type<F>>) -> Result<(), ValueError> {
|
||||
pub(crate) fn resolve_type(&mut self, types: &Vec<Type>) -> Result<(), ValueError> {
|
||||
if let ConstrainedValue::Unresolved(ref string) = self {
|
||||
if !types.is_empty() {
|
||||
*self = ConstrainedValue::from_type(string.clone(), &types[0])?
|
||||
|
@ -18,7 +18,7 @@ use snarkos_models::{
|
||||
},
|
||||
},
|
||||
};
|
||||
use std::{borrow::Borrow, str::FromStr};
|
||||
use std::borrow::Borrow;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum FieldType<F: Field + PrimeField> {
|
||||
|
@ -2,23 +2,22 @@
|
||||
|
||||
use crate::Identifier;
|
||||
|
||||
use snarkos_models::curves::{Field, PrimeField};
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ImportSymbol<F: Field + PrimeField> {
|
||||
pub symbol: Identifier<F>,
|
||||
pub alias: Option<Identifier<F>>,
|
||||
pub struct ImportSymbol {
|
||||
pub symbol: Identifier,
|
||||
pub alias: Option<Identifier>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Import<F: Field + PrimeField> {
|
||||
pub struct Import {
|
||||
pub path_string: String,
|
||||
pub symbols: Vec<ImportSymbol<F>>,
|
||||
pub symbols: Vec<ImportSymbol>,
|
||||
}
|
||||
|
||||
impl<F: Field + PrimeField> Import<F> {
|
||||
pub fn new(source: String, symbols: Vec<ImportSymbol<F>>) -> Import<F> {
|
||||
impl Import {
|
||||
pub fn new(source: String, symbols: Vec<ImportSymbol>) -> Import {
|
||||
Import {
|
||||
path_string: source,
|
||||
symbols,
|
||||
@ -51,7 +50,7 @@ impl<F: Field + PrimeField> Import<F> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: Field + PrimeField> fmt::Display for ImportSymbol<F> {
|
||||
impl fmt::Display for ImportSymbol {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
if self.alias.is_some() {
|
||||
write!(f, "\t{} as {}", self.symbol, self.alias.as_ref().unwrap())
|
||||
@ -61,13 +60,13 @@ impl<F: Field + PrimeField> fmt::Display for ImportSymbol<F> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, F: Field + PrimeField> fmt::Display for Import<F> {
|
||||
impl<'ast> fmt::Display for Import {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
self.format(f)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, F: Field + PrimeField> fmt::Debug for Import<F> {
|
||||
impl<'ast> fmt::Debug for Import {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
self.format(f)
|
||||
}
|
||||
|
@ -3,31 +3,21 @@
|
||||
|
||||
use crate::Import;
|
||||
|
||||
use snarkos_models::{
|
||||
curves::{Field, PrimeField},
|
||||
gadgets::{
|
||||
r1cs::Variable as R1CSVariable,
|
||||
utilities::{
|
||||
boolean::Boolean, uint128::UInt128, uint16::UInt16, uint32::UInt32, uint64::UInt64,
|
||||
uint8::UInt8,
|
||||
},
|
||||
},
|
||||
use snarkos_models::gadgets::utilities::{
|
||||
boolean::Boolean, uint128::UInt128, uint16::UInt16, uint32::UInt32, uint64::UInt64,
|
||||
uint8::UInt8,
|
||||
};
|
||||
use std::{collections::HashMap, marker::PhantomData};
|
||||
use std::collections::HashMap;
|
||||
|
||||
/// An identifier in the constrained program.
|
||||
#[derive(Clone, PartialEq, Eq, Hash)]
|
||||
pub struct Identifier<F: Field + PrimeField> {
|
||||
pub struct Identifier {
|
||||
pub name: String,
|
||||
pub(crate) _engine: PhantomData<F>,
|
||||
}
|
||||
|
||||
impl<F: Field + PrimeField> Identifier<F> {
|
||||
impl Identifier {
|
||||
pub fn new(name: String) -> Self {
|
||||
Self {
|
||||
name,
|
||||
_engine: PhantomData::<F>,
|
||||
}
|
||||
Self { name }
|
||||
}
|
||||
|
||||
pub fn is_self(&self) -> bool {
|
||||
@ -37,10 +27,10 @@ impl<F: Field + PrimeField> Identifier<F> {
|
||||
|
||||
/// A variable that is assigned to a value in the constrained program
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
pub struct Variable<F: Field + PrimeField> {
|
||||
pub identifier: Identifier<F>,
|
||||
pub struct Variable {
|
||||
pub identifier: Identifier,
|
||||
pub mutable: bool,
|
||||
pub _type: Option<Type<F>>,
|
||||
pub _type: Option<Type>,
|
||||
}
|
||||
|
||||
/// An integer type enum wrapping the integer value. Used only in expressions.
|
||||
@ -53,32 +43,25 @@ pub enum Integer {
|
||||
U128(UInt128),
|
||||
}
|
||||
|
||||
/// A constant or allocated element in the field
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
pub enum FieldElement<F: Field + PrimeField> {
|
||||
Constant(F),
|
||||
Allocated(Option<F>, R1CSVariable),
|
||||
}
|
||||
|
||||
/// Range or expression enum
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum RangeOrExpression<F: Field + PrimeField> {
|
||||
pub enum RangeOrExpression {
|
||||
Range(Option<Integer>, Option<Integer>),
|
||||
Expression(Expression<F>),
|
||||
Expression(Expression),
|
||||
}
|
||||
|
||||
/// Spread or expression
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum SpreadOrExpression<F: Field + PrimeField> {
|
||||
Spread(Expression<F>),
|
||||
Expression(Expression<F>),
|
||||
pub enum SpreadOrExpression {
|
||||
Spread(Expression),
|
||||
Expression(Expression),
|
||||
}
|
||||
|
||||
/// Expression that evaluates to a value
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum Expression<F: Field + PrimeField> {
|
||||
pub enum Expression {
|
||||
// Identifier
|
||||
Identifier(Identifier<F>),
|
||||
Identifier(Identifier),
|
||||
|
||||
// Values
|
||||
Integer(Integer),
|
||||
@ -88,44 +71,44 @@ pub enum Expression<F: Field + PrimeField> {
|
||||
Implicit(String),
|
||||
|
||||
// Number operations
|
||||
Add(Box<Expression<F>>, Box<Expression<F>>),
|
||||
Sub(Box<Expression<F>>, Box<Expression<F>>),
|
||||
Mul(Box<Expression<F>>, Box<Expression<F>>),
|
||||
Div(Box<Expression<F>>, Box<Expression<F>>),
|
||||
Pow(Box<Expression<F>>, Box<Expression<F>>),
|
||||
Add(Box<Expression>, Box<Expression>),
|
||||
Sub(Box<Expression>, Box<Expression>),
|
||||
Mul(Box<Expression>, Box<Expression>),
|
||||
Div(Box<Expression>, Box<Expression>),
|
||||
Pow(Box<Expression>, Box<Expression>),
|
||||
|
||||
// Boolean operations
|
||||
Not(Box<Expression<F>>),
|
||||
Or(Box<Expression<F>>, Box<Expression<F>>),
|
||||
And(Box<Expression<F>>, Box<Expression<F>>),
|
||||
Eq(Box<Expression<F>>, Box<Expression<F>>),
|
||||
Geq(Box<Expression<F>>, Box<Expression<F>>),
|
||||
Gt(Box<Expression<F>>, Box<Expression<F>>),
|
||||
Leq(Box<Expression<F>>, Box<Expression<F>>),
|
||||
Lt(Box<Expression<F>>, Box<Expression<F>>),
|
||||
Not(Box<Expression>),
|
||||
Or(Box<Expression>, Box<Expression>),
|
||||
And(Box<Expression>, Box<Expression>),
|
||||
Eq(Box<Expression>, Box<Expression>),
|
||||
Geq(Box<Expression>, Box<Expression>),
|
||||
Gt(Box<Expression>, Box<Expression>),
|
||||
Leq(Box<Expression>, Box<Expression>),
|
||||
Lt(Box<Expression>, Box<Expression>),
|
||||
|
||||
// Conditionals
|
||||
IfElse(Box<Expression<F>>, Box<Expression<F>>, Box<Expression<F>>),
|
||||
IfElse(Box<Expression>, Box<Expression>, Box<Expression>),
|
||||
|
||||
// Arrays
|
||||
Array(Vec<Box<SpreadOrExpression<F>>>),
|
||||
ArrayAccess(Box<Expression<F>>, Box<RangeOrExpression<F>>), // (array name, range)
|
||||
Array(Vec<Box<SpreadOrExpression>>),
|
||||
ArrayAccess(Box<Expression>, Box<RangeOrExpression>), // (array name, range)
|
||||
|
||||
// Circuits
|
||||
Circuit(Identifier<F>, Vec<CircuitFieldDefinition<F>>),
|
||||
CircuitMemberAccess(Box<Expression<F>>, Identifier<F>), // (declared circuit name, circuit member name)
|
||||
CircuitStaticFunctionAccess(Box<Expression<F>>, Identifier<F>), // (defined circuit name, circuit static member name)
|
||||
Circuit(Identifier, Vec<CircuitFieldDefinition>),
|
||||
CircuitMemberAccess(Box<Expression>, Identifier), // (declared circuit name, circuit member name)
|
||||
CircuitStaticFunctionAccess(Box<Expression>, Identifier), // (defined circuit name, circuit static member name)
|
||||
|
||||
// Functions
|
||||
FunctionCall(Box<Expression<F>>, Vec<Expression<F>>),
|
||||
FunctionCall(Box<Expression>, Vec<Expression>),
|
||||
}
|
||||
|
||||
/// Definition assignee: v, arr[0..2], Point p.x
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum Assignee<F: Field + PrimeField> {
|
||||
Identifier(Identifier<F>),
|
||||
Array(Box<Assignee<F>>, RangeOrExpression<F>),
|
||||
CircuitField(Box<Assignee<F>>, Identifier<F>), // (circuit name, circuit field name)
|
||||
pub enum Assignee {
|
||||
Identifier(Identifier),
|
||||
Array(Box<Assignee>, RangeOrExpression),
|
||||
CircuitField(Box<Assignee>, Identifier), // (circuit name, circuit field name)
|
||||
}
|
||||
|
||||
/// Explicit integer type
|
||||
@ -140,17 +123,17 @@ pub enum IntegerType {
|
||||
|
||||
/// Explicit type used for defining a variable or expression type
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub enum Type<F: Field + PrimeField> {
|
||||
pub enum Type {
|
||||
IntegerType(IntegerType),
|
||||
Field,
|
||||
Group,
|
||||
Boolean,
|
||||
Array(Box<Type<F>>, Vec<usize>),
|
||||
Circuit(Identifier<F>),
|
||||
Array(Box<Type>, Vec<usize>),
|
||||
Circuit(Identifier),
|
||||
SelfType,
|
||||
}
|
||||
|
||||
impl<F: Field + PrimeField> Type<F> {
|
||||
impl Type {
|
||||
pub fn outer_dimension(&self, dimensions: &Vec<usize>) -> Self {
|
||||
let _type = self.clone();
|
||||
|
||||
@ -179,59 +162,59 @@ impl<F: Field + PrimeField> Type<F> {
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
pub enum ConditionalNestedOrEnd<F: Field + PrimeField> {
|
||||
Nested(Box<ConditionalStatement<F>>),
|
||||
End(Vec<Statement<F>>),
|
||||
pub enum ConditionalNestedOrEnd {
|
||||
Nested(Box<ConditionalStatement>),
|
||||
End(Vec<Statement>),
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
pub struct ConditionalStatement<F: Field + PrimeField> {
|
||||
pub condition: Expression<F>,
|
||||
pub statements: Vec<Statement<F>>,
|
||||
pub next: Option<ConditionalNestedOrEnd<F>>,
|
||||
pub struct ConditionalStatement {
|
||||
pub condition: Expression,
|
||||
pub statements: Vec<Statement>,
|
||||
pub next: Option<ConditionalNestedOrEnd>,
|
||||
}
|
||||
|
||||
/// Program statement that defines some action (or expression) to be carried out.
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
pub enum Statement<F: Field + PrimeField> {
|
||||
Return(Vec<Expression<F>>),
|
||||
Definition(Variable<F>, Expression<F>),
|
||||
Assign(Assignee<F>, Expression<F>),
|
||||
MultipleAssign(Vec<Variable<F>>, Expression<F>),
|
||||
Conditional(ConditionalStatement<F>),
|
||||
For(Identifier<F>, Integer, Integer, Vec<Statement<F>>),
|
||||
AssertEq(Expression<F>, Expression<F>),
|
||||
Expression(Expression<F>),
|
||||
pub enum Statement {
|
||||
Return(Vec<Expression>),
|
||||
Definition(Variable, Expression),
|
||||
Assign(Assignee, Expression),
|
||||
MultipleAssign(Vec<Variable>, Expression),
|
||||
Conditional(ConditionalStatement),
|
||||
For(Identifier, Integer, Integer, Vec<Statement>),
|
||||
AssertEq(Expression, Expression),
|
||||
Expression(Expression),
|
||||
}
|
||||
|
||||
/// Circuits
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct CircuitFieldDefinition<F: Field + PrimeField> {
|
||||
pub identifier: Identifier<F>,
|
||||
pub expression: Expression<F>,
|
||||
pub struct CircuitFieldDefinition {
|
||||
pub identifier: Identifier,
|
||||
pub expression: Expression,
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
pub enum CircuitMember<F: Field + PrimeField> {
|
||||
CircuitField(Identifier<F>, Type<F>),
|
||||
CircuitFunction(bool, Function<F>),
|
||||
pub enum CircuitMember {
|
||||
CircuitField(Identifier, Type),
|
||||
CircuitFunction(bool, Function),
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
pub struct Circuit<F: Field + PrimeField> {
|
||||
pub identifier: Identifier<F>,
|
||||
pub members: Vec<CircuitMember<F>>,
|
||||
pub struct Circuit {
|
||||
pub identifier: Identifier,
|
||||
pub members: Vec<CircuitMember>,
|
||||
}
|
||||
|
||||
/// Function parameters
|
||||
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
pub struct InputModel<F: Field + PrimeField> {
|
||||
pub identifier: Identifier<F>,
|
||||
pub struct InputModel {
|
||||
pub identifier: Identifier,
|
||||
pub mutable: bool,
|
||||
pub private: bool,
|
||||
pub _type: Type<F>,
|
||||
pub _type: Type,
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
@ -244,14 +227,14 @@ pub enum InputValue {
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
pub struct Function<F: Field + PrimeField> {
|
||||
pub function_name: Identifier<F>,
|
||||
pub inputs: Vec<InputModel<F>>,
|
||||
pub returns: Vec<Type<F>>,
|
||||
pub statements: Vec<Statement<F>>,
|
||||
pub struct Function {
|
||||
pub function_name: Identifier,
|
||||
pub inputs: Vec<InputModel>,
|
||||
pub returns: Vec<Type>,
|
||||
pub statements: Vec<Statement>,
|
||||
}
|
||||
|
||||
impl<F: Field + PrimeField> Function<F> {
|
||||
impl Function {
|
||||
pub fn get_name(&self) -> String {
|
||||
self.function_name.name.clone()
|
||||
}
|
||||
@ -259,15 +242,15 @@ impl<F: Field + PrimeField> Function<F> {
|
||||
|
||||
/// A simple program with statement expressions, program arguments and program returns.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Program<F: Field + PrimeField> {
|
||||
pub name: Identifier<F>,
|
||||
pub struct Program {
|
||||
pub name: Identifier,
|
||||
pub num_parameters: usize,
|
||||
pub imports: Vec<Import<F>>,
|
||||
pub circuits: HashMap<Identifier<F>, Circuit<F>>,
|
||||
pub functions: HashMap<Identifier<F>, Function<F>>,
|
||||
pub imports: Vec<Import>,
|
||||
pub circuits: HashMap<Identifier, Circuit>,
|
||||
pub functions: HashMap<Identifier, Function>,
|
||||
}
|
||||
|
||||
impl<'ast, F: Field + PrimeField> Program<F> {
|
||||
impl<'ast> Program {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
name: Identifier::new("".into()),
|
||||
|
@ -6,21 +6,20 @@ use crate::{
|
||||
SpreadOrExpression, Statement, Type, Variable,
|
||||
};
|
||||
|
||||
use snarkos_models::curves::{Field, PrimeField};
|
||||
use std::fmt;
|
||||
|
||||
impl<F: Field + PrimeField> fmt::Display for Identifier<F> {
|
||||
impl fmt::Display for Identifier {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{}", self.name)
|
||||
}
|
||||
}
|
||||
impl<F: Field + PrimeField> fmt::Debug for Identifier<F> {
|
||||
impl fmt::Debug for Identifier {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{}", self.name)
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: Field + PrimeField> fmt::Display for Variable<F> {
|
||||
impl fmt::Display for Variable {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
if self.mutable {
|
||||
write!(f, "mut ")?;
|
||||
@ -42,7 +41,7 @@ impl fmt::Display for Integer {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, F: Field + PrimeField> fmt::Display for RangeOrExpression<F> {
|
||||
impl<'ast> fmt::Display for RangeOrExpression {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
RangeOrExpression::Range(ref from, ref to) => write!(
|
||||
@ -60,7 +59,7 @@ impl<'ast, F: Field + PrimeField> fmt::Display for RangeOrExpression<F> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: Field + PrimeField> fmt::Display for SpreadOrExpression<F> {
|
||||
impl fmt::Display for SpreadOrExpression {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
SpreadOrExpression::Spread(ref spread) => write!(f, "...{}", spread),
|
||||
@ -69,7 +68,7 @@ impl<F: Field + PrimeField> fmt::Display for SpreadOrExpression<F> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, F: Field + PrimeField> fmt::Display for Expression<F> {
|
||||
impl<'ast> fmt::Display for Expression {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
// Variables
|
||||
@ -150,7 +149,7 @@ impl<'ast, F: Field + PrimeField> fmt::Display for Expression<F> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: Field + PrimeField> fmt::Display for Assignee<F> {
|
||||
impl fmt::Display for Assignee {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
Assignee::Identifier(ref variable) => write!(f, "{}", variable),
|
||||
@ -162,7 +161,7 @@ impl<F: Field + PrimeField> fmt::Display for Assignee<F> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: Field + PrimeField> fmt::Display for ConditionalNestedOrEnd<F> {
|
||||
impl fmt::Display for ConditionalNestedOrEnd {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
ConditionalNestedOrEnd::Nested(ref nested) => write!(f, "else {}", nested),
|
||||
@ -177,7 +176,7 @@ impl<F: Field + PrimeField> fmt::Display for ConditionalNestedOrEnd<F> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: Field + PrimeField> fmt::Display for ConditionalStatement<F> {
|
||||
impl fmt::Display for ConditionalStatement {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "if ({}) {{\n", self.condition)?;
|
||||
for statement in self.statements.iter() {
|
||||
@ -190,7 +189,7 @@ impl<F: Field + PrimeField> fmt::Display for ConditionalStatement<F> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: Field + PrimeField> fmt::Display for Statement<F> {
|
||||
impl fmt::Display for Statement {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
Statement::Return(ref statements) => {
|
||||
@ -247,7 +246,7 @@ impl fmt::Display for IntegerType {
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: Field + PrimeField> fmt::Display for Type<F> {
|
||||
impl fmt::Display for Type {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
Type::IntegerType(ref integer_type) => write!(f, "{}", integer_type),
|
||||
@ -267,7 +266,7 @@ impl<F: Field + PrimeField> fmt::Display for Type<F> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: Field + PrimeField> fmt::Display for CircuitMember<F> {
|
||||
impl fmt::Display for CircuitMember {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
CircuitMember::CircuitField(ref identifier, ref _type) => {
|
||||
@ -283,7 +282,7 @@ impl<F: Field + PrimeField> fmt::Display for CircuitMember<F> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: Field + PrimeField> Circuit<F> {
|
||||
impl Circuit {
|
||||
fn format(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "circuit {} {{ \n", self.identifier)?;
|
||||
for field in self.members.iter() {
|
||||
@ -293,19 +292,19 @@ impl<F: Field + PrimeField> Circuit<F> {
|
||||
}
|
||||
}
|
||||
|
||||
// impl<F: Field + PrimeField> fmt::Display for Circuit<F> {// uncomment when we no longer print out Program
|
||||
// impl fmt::Display for Circuit {// uncomment when we no longer print out Program
|
||||
// fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
// self.format(f)
|
||||
// }
|
||||
// }
|
||||
|
||||
impl<F: Field + PrimeField> fmt::Debug for Circuit<F> {
|
||||
impl fmt::Debug for Circuit {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
self.format(f)
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: Field + PrimeField> fmt::Display for InputModel<F> {
|
||||
impl fmt::Display for InputModel {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
// mut var: private bool
|
||||
if self.mutable {
|
||||
@ -342,7 +341,7 @@ impl fmt::Display for InputValue {
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: Field + PrimeField> Function<F> {
|
||||
impl Function {
|
||||
fn format(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "function {}", self.function_name)?;
|
||||
let parameters = self
|
||||
@ -373,13 +372,13 @@ impl<F: Field + PrimeField> Function<F> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: Field + PrimeField> fmt::Display for Function<F> {
|
||||
impl fmt::Display for Function {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
self.format(f)
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: Field + PrimeField> fmt::Debug for Function<F> {
|
||||
impl fmt::Debug for Function {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
self.format(f)
|
||||
}
|
||||
|
@ -2,24 +2,21 @@
|
||||
|
||||
use crate::{ast, types, Import, ImportSymbol};
|
||||
|
||||
use snarkos_models::{
|
||||
curves::{Field, PrimeField},
|
||||
gadgets::utilities::{
|
||||
boolean::Boolean, uint128::UInt128, uint16::UInt16, uint32::UInt32, uint64::UInt64,
|
||||
uint8::UInt8,
|
||||
},
|
||||
use snarkos_models::gadgets::utilities::{
|
||||
boolean::Boolean, uint128::UInt128, uint16::UInt16, uint32::UInt32, uint64::UInt64,
|
||||
uint8::UInt8,
|
||||
};
|
||||
use std::collections::HashMap;
|
||||
|
||||
/// pest ast -> types::Identifier
|
||||
|
||||
impl<'ast, F: Field + PrimeField> From<ast::Identifier<'ast>> for types::Identifier<F> {
|
||||
impl<'ast> From<ast::Identifier<'ast>> for types::Identifier {
|
||||
fn from(identifier: ast::Identifier<'ast>) -> Self {
|
||||
types::Identifier::new(identifier.value)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, F: Field + PrimeField> From<ast::Identifier<'ast>> for types::Expression<F> {
|
||||
impl<'ast> From<ast::Identifier<'ast>> for types::Expression {
|
||||
fn from(identifier: ast::Identifier<'ast>) -> Self {
|
||||
types::Expression::Identifier(types::Identifier::from(identifier))
|
||||
}
|
||||
@ -27,7 +24,7 @@ impl<'ast, F: Field + PrimeField> From<ast::Identifier<'ast>> for types::Express
|
||||
|
||||
/// pest ast -> types::Variable
|
||||
|
||||
impl<'ast, F: Field + PrimeField> From<ast::Variable<'ast>> for types::Variable<F> {
|
||||
impl<'ast> From<ast::Variable<'ast>> for types::Variable {
|
||||
fn from(variable: ast::Variable<'ast>) -> Self {
|
||||
types::Variable {
|
||||
identifier: types::Identifier::from(variable.identifier),
|
||||
@ -70,21 +67,19 @@ impl<'ast> types::Integer {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, F: Field + PrimeField> From<ast::Integer<'ast>> for types::Expression<F> {
|
||||
impl<'ast> From<ast::Integer<'ast>> for types::Expression {
|
||||
fn from(field: ast::Integer<'ast>) -> Self {
|
||||
types::Expression::Integer(types::Integer::from(field.number, field._type))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, F: Field + PrimeField> From<ast::RangeOrExpression<'ast>>
|
||||
for types::RangeOrExpression<F>
|
||||
{
|
||||
impl<'ast> From<ast::RangeOrExpression<'ast>> for types::RangeOrExpression {
|
||||
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::<F>::from(from.0) {
|
||||
.map(|from| match types::Expression::from(from.0) {
|
||||
types::Expression::Integer(number) => number,
|
||||
types::Expression::Implicit(string) => {
|
||||
types::Integer::from_implicit(string)
|
||||
@ -93,7 +88,7 @@ impl<'ast, F: Field + PrimeField> From<ast::RangeOrExpression<'ast>>
|
||||
unimplemented!("Range bounds should be integers, found {}", expression)
|
||||
}
|
||||
});
|
||||
let to = range.to.map(|to| match types::Expression::<F>::from(to.0) {
|
||||
let to = range.to.map(|to| match types::Expression::from(to.0) {
|
||||
types::Expression::Integer(number) => number,
|
||||
types::Expression::Implicit(string) => types::Integer::from_implicit(string),
|
||||
expression => {
|
||||
@ -112,7 +107,7 @@ impl<'ast, F: Field + PrimeField> From<ast::RangeOrExpression<'ast>>
|
||||
|
||||
/// pest ast -> types::Field
|
||||
|
||||
impl<'ast, F: Field + PrimeField> From<ast::Field<'ast>> for types::Expression<F> {
|
||||
impl<'ast> From<ast::Field<'ast>> for types::Expression {
|
||||
fn from(field: ast::Field<'ast>) -> Self {
|
||||
types::Expression::Field(field.number.value)
|
||||
}
|
||||
@ -120,7 +115,7 @@ impl<'ast, F: Field + PrimeField> From<ast::Field<'ast>> for types::Expression<F
|
||||
|
||||
/// pest ast -> types::Group
|
||||
|
||||
impl<'ast, F: Field + PrimeField> From<ast::Group<'ast>> for types::Expression<F> {
|
||||
impl<'ast> From<ast::Group<'ast>> for types::Expression {
|
||||
fn from(group: ast::Group<'ast>) -> Self {
|
||||
types::Expression::Group(group.to_string())
|
||||
}
|
||||
@ -128,7 +123,7 @@ impl<'ast, F: Field + PrimeField> From<ast::Group<'ast>> for types::Expression<F
|
||||
|
||||
/// pest ast -> types::Boolean
|
||||
|
||||
impl<'ast, F: Field + PrimeField> From<ast::Boolean<'ast>> for types::Expression<F> {
|
||||
impl<'ast> From<ast::Boolean<'ast>> for types::Expression {
|
||||
fn from(boolean: ast::Boolean<'ast>) -> Self {
|
||||
types::Expression::Boolean(Boolean::Constant(
|
||||
boolean
|
||||
@ -141,7 +136,7 @@ impl<'ast, F: Field + PrimeField> From<ast::Boolean<'ast>> for types::Expression
|
||||
|
||||
/// pest ast -> types::NumberImplicit
|
||||
|
||||
impl<'ast, F: Field + PrimeField> From<ast::NumberImplicit<'ast>> for types::Expression<F> {
|
||||
impl<'ast> From<ast::NumberImplicit<'ast>> for types::Expression {
|
||||
fn from(number: ast::NumberImplicit<'ast>) -> Self {
|
||||
types::Expression::Implicit(number.number.value)
|
||||
}
|
||||
@ -149,7 +144,7 @@ impl<'ast, F: Field + PrimeField> From<ast::NumberImplicit<'ast>> for types::Exp
|
||||
|
||||
/// pest ast -> types::Expression
|
||||
|
||||
impl<'ast, F: Field + PrimeField> From<ast::Value<'ast>> for types::Expression<F> {
|
||||
impl<'ast> From<ast::Value<'ast>> for types::Expression {
|
||||
fn from(value: ast::Value<'ast>) -> Self {
|
||||
match value {
|
||||
ast::Value::Integer(num) => types::Expression::from(num),
|
||||
@ -161,15 +156,13 @@ impl<'ast, F: Field + PrimeField> From<ast::Value<'ast>> for types::Expression<F
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, F: Field + PrimeField> From<ast::NotExpression<'ast>> for types::Expression<F> {
|
||||
impl<'ast> From<ast::NotExpression<'ast>> for types::Expression {
|
||||
fn from(expression: ast::NotExpression<'ast>) -> Self {
|
||||
types::Expression::Not(Box::new(types::Expression::from(*expression.expression)))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, F: Field + PrimeField> From<ast::SpreadOrExpression<'ast>>
|
||||
for types::SpreadOrExpression<F>
|
||||
{
|
||||
impl<'ast> From<ast::SpreadOrExpression<'ast>> for types::SpreadOrExpression {
|
||||
fn from(s_or_e: ast::SpreadOrExpression<'ast>) -> Self {
|
||||
match s_or_e {
|
||||
ast::SpreadOrExpression::Spread(spread) => {
|
||||
@ -182,7 +175,7 @@ impl<'ast, F: Field + PrimeField> From<ast::SpreadOrExpression<'ast>>
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, F: Field + PrimeField> From<ast::BinaryExpression<'ast>> for types::Expression<F> {
|
||||
impl<'ast> From<ast::BinaryExpression<'ast>> for types::Expression {
|
||||
fn from(expression: ast::BinaryExpression<'ast>) -> Self {
|
||||
match expression.operation {
|
||||
// Boolean operations
|
||||
@ -242,7 +235,7 @@ impl<'ast, F: Field + PrimeField> From<ast::BinaryExpression<'ast>> for types::E
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, F: Field + PrimeField> From<ast::TernaryExpression<'ast>> for types::Expression<F> {
|
||||
impl<'ast> From<ast::TernaryExpression<'ast>> for types::Expression {
|
||||
fn from(expression: ast::TernaryExpression<'ast>) -> Self {
|
||||
types::Expression::IfElse(
|
||||
Box::new(types::Expression::from(*expression.first)),
|
||||
@ -252,7 +245,7 @@ impl<'ast, F: Field + PrimeField> From<ast::TernaryExpression<'ast>> for types::
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, F: Field + PrimeField> From<ast::ArrayInlineExpression<'ast>> for types::Expression<F> {
|
||||
impl<'ast> From<ast::ArrayInlineExpression<'ast>> for types::Expression {
|
||||
fn from(array: ast::ArrayInlineExpression<'ast>) -> Self {
|
||||
types::Expression::Array(
|
||||
array
|
||||
@ -263,20 +256,16 @@ impl<'ast, F: Field + PrimeField> From<ast::ArrayInlineExpression<'ast>> for typ
|
||||
)
|
||||
}
|
||||
}
|
||||
impl<'ast, F: Field + PrimeField> From<ast::ArrayInitializerExpression<'ast>>
|
||||
for types::Expression<F>
|
||||
{
|
||||
impl<'ast> From<ast::ArrayInitializerExpression<'ast>> for types::Expression {
|
||||
fn from(array: ast::ArrayInitializerExpression<'ast>) -> Self {
|
||||
let count = types::Expression::<F>::get_count(array.count);
|
||||
let count = types::Expression::get_count(array.count);
|
||||
let expression = Box::new(types::SpreadOrExpression::from(*array.expression));
|
||||
|
||||
types::Expression::Array(vec![expression; count])
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, F: Field + PrimeField> From<ast::CircuitField<'ast>>
|
||||
for types::CircuitFieldDefinition<F>
|
||||
{
|
||||
impl<'ast> From<ast::CircuitField<'ast>> for types::CircuitFieldDefinition {
|
||||
fn from(member: ast::CircuitField<'ast>) -> Self {
|
||||
types::CircuitFieldDefinition {
|
||||
identifier: types::Identifier::from(member.identifier),
|
||||
@ -285,22 +274,20 @@ impl<'ast, F: Field + PrimeField> From<ast::CircuitField<'ast>>
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, F: Field + PrimeField> From<ast::CircuitInlineExpression<'ast>>
|
||||
for types::Expression<F>
|
||||
{
|
||||
impl<'ast> From<ast::CircuitInlineExpression<'ast>> for types::Expression {
|
||||
fn from(expression: ast::CircuitInlineExpression<'ast>) -> Self {
|
||||
let variable = types::Identifier::from(expression.identifier);
|
||||
let members = expression
|
||||
.members
|
||||
.into_iter()
|
||||
.map(|member| types::CircuitFieldDefinition::from(member))
|
||||
.collect::<Vec<types::CircuitFieldDefinition<F>>>();
|
||||
.collect::<Vec<types::CircuitFieldDefinition>>();
|
||||
|
||||
types::Expression::Circuit(variable, members)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, F: Field + PrimeField> From<ast::PostfixExpression<'ast>> for types::Expression<F> {
|
||||
impl<'ast> From<ast::PostfixExpression<'ast>> for types::Expression {
|
||||
fn from(expression: ast::PostfixExpression<'ast>) -> Self {
|
||||
let variable =
|
||||
types::Expression::Identifier(types::Identifier::from(expression.identifier));
|
||||
@ -344,7 +331,7 @@ impl<'ast, F: Field + PrimeField> From<ast::PostfixExpression<'ast>> for types::
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, F: Field + PrimeField> From<ast::Expression<'ast>> for types::Expression<F> {
|
||||
impl<'ast> From<ast::Expression<'ast>> for types::Expression {
|
||||
fn from(expression: ast::Expression<'ast>) -> Self {
|
||||
match expression {
|
||||
ast::Expression::Value(value) => types::Expression::from(value),
|
||||
@ -360,7 +347,7 @@ impl<'ast, F: Field + PrimeField> From<ast::Expression<'ast>> for types::Express
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, F: Field + PrimeField> types::Expression<F> {
|
||||
impl<'ast> types::Expression {
|
||||
fn get_count(count: ast::Value<'ast>) -> usize {
|
||||
match count {
|
||||
ast::Value::Integer(integer) => integer
|
||||
@ -379,7 +366,7 @@ impl<'ast, F: Field + PrimeField> types::Expression<F> {
|
||||
}
|
||||
|
||||
// ast::Assignee -> types::Expression for operator assign statements
|
||||
impl<'ast, F: Field + PrimeField> From<ast::Assignee<'ast>> for types::Expression<F> {
|
||||
impl<'ast> From<ast::Assignee<'ast>> for types::Expression {
|
||||
fn from(assignee: ast::Assignee<'ast>) -> Self {
|
||||
let variable = types::Expression::Identifier(types::Identifier::from(assignee.identifier));
|
||||
|
||||
@ -404,13 +391,13 @@ impl<'ast, F: Field + PrimeField> From<ast::Assignee<'ast>> for types::Expressio
|
||||
|
||||
/// pest ast -> types::Assignee
|
||||
|
||||
impl<'ast, F: Field + PrimeField> From<ast::Identifier<'ast>> for types::Assignee<F> {
|
||||
impl<'ast> From<ast::Identifier<'ast>> for types::Assignee {
|
||||
fn from(variable: ast::Identifier<'ast>) -> Self {
|
||||
types::Assignee::Identifier(types::Identifier::from(variable))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, F: Field + PrimeField> From<ast::Assignee<'ast>> for types::Assignee<F> {
|
||||
impl<'ast> From<ast::Assignee<'ast>> for types::Assignee {
|
||||
fn from(assignee: ast::Assignee<'ast>) -> Self {
|
||||
let variable = types::Assignee::from(assignee.identifier);
|
||||
|
||||
@ -433,7 +420,7 @@ impl<'ast, F: Field + PrimeField> From<ast::Assignee<'ast>> for types::Assignee<
|
||||
|
||||
/// pest ast -> types::Statement
|
||||
|
||||
impl<'ast, F: Field + PrimeField> From<ast::ReturnStatement<'ast>> for types::Statement<F> {
|
||||
impl<'ast> From<ast::ReturnStatement<'ast>> for types::Statement {
|
||||
fn from(statement: ast::ReturnStatement<'ast>) -> Self {
|
||||
types::Statement::Return(
|
||||
statement
|
||||
@ -445,7 +432,7 @@ impl<'ast, F: Field + PrimeField> From<ast::ReturnStatement<'ast>> for types::St
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, F: Field + PrimeField> From<ast::DefinitionStatement<'ast>> for types::Statement<F> {
|
||||
impl<'ast> From<ast::DefinitionStatement<'ast>> for types::Statement {
|
||||
fn from(statement: ast::DefinitionStatement<'ast>) -> Self {
|
||||
types::Statement::Definition(
|
||||
types::Variable::from(statement.variable),
|
||||
@ -454,7 +441,7 @@ impl<'ast, F: Field + PrimeField> From<ast::DefinitionStatement<'ast>> for types
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, F: Field + PrimeField> From<ast::AssignStatement<'ast>> for types::Statement<F> {
|
||||
impl<'ast> From<ast::AssignStatement<'ast>> for types::Statement {
|
||||
fn from(statement: ast::AssignStatement<'ast>) -> Self {
|
||||
match statement.assign {
|
||||
ast::OperationAssign::Assign(ref _assign) => types::Statement::Assign(
|
||||
@ -510,9 +497,7 @@ impl<'ast, F: Field + PrimeField> From<ast::AssignStatement<'ast>> for types::St
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, F: Field + PrimeField> From<ast::MultipleAssignmentStatement<'ast>>
|
||||
for types::Statement<F>
|
||||
{
|
||||
impl<'ast> From<ast::MultipleAssignmentStatement<'ast>> for types::Statement {
|
||||
fn from(statement: ast::MultipleAssignmentStatement<'ast>) -> Self {
|
||||
let variables = statement
|
||||
.variables
|
||||
@ -534,9 +519,7 @@ impl<'ast, F: Field + PrimeField> From<ast::MultipleAssignmentStatement<'ast>>
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, F: Field + PrimeField> From<ast::ConditionalNestedOrEnd<'ast>>
|
||||
for types::ConditionalNestedOrEnd<F>
|
||||
{
|
||||
impl<'ast> From<ast::ConditionalNestedOrEnd<'ast>> for types::ConditionalNestedOrEnd {
|
||||
fn from(statement: ast::ConditionalNestedOrEnd<'ast>) -> Self {
|
||||
match statement {
|
||||
ast::ConditionalNestedOrEnd::Nested(nested) => types::ConditionalNestedOrEnd::Nested(
|
||||
@ -552,9 +535,7 @@ impl<'ast, F: Field + PrimeField> From<ast::ConditionalNestedOrEnd<'ast>>
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, F: Field + PrimeField> From<ast::ConditionalStatement<'ast>>
|
||||
for types::ConditionalStatement<F>
|
||||
{
|
||||
impl<'ast> From<ast::ConditionalStatement<'ast>> for types::ConditionalStatement {
|
||||
fn from(statement: ast::ConditionalStatement<'ast>) -> Self {
|
||||
types::ConditionalStatement {
|
||||
condition: types::Expression::from(statement.condition),
|
||||
@ -571,14 +552,14 @@ impl<'ast, F: Field + PrimeField> From<ast::ConditionalStatement<'ast>>
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, F: Field + PrimeField> From<ast::ForStatement<'ast>> for types::Statement<F> {
|
||||
impl<'ast> From<ast::ForStatement<'ast>> for types::Statement {
|
||||
fn from(statement: ast::ForStatement<'ast>) -> Self {
|
||||
let from = match types::Expression::<F>::from(statement.start) {
|
||||
let from = match types::Expression::from(statement.start) {
|
||||
types::Expression::Integer(number) => number,
|
||||
types::Expression::Implicit(string) => types::Integer::from_implicit(string),
|
||||
expression => unimplemented!("Range bounds should be integers, found {}", expression),
|
||||
};
|
||||
let to = match types::Expression::<F>::from(statement.stop) {
|
||||
let to = match types::Expression::from(statement.stop) {
|
||||
types::Expression::Integer(number) => number,
|
||||
types::Expression::Implicit(string) => types::Integer::from_implicit(string),
|
||||
expression => unimplemented!("Range bounds should be integers, found {}", expression),
|
||||
@ -597,7 +578,7 @@ impl<'ast, F: Field + PrimeField> From<ast::ForStatement<'ast>> for types::State
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, F: Field + PrimeField> From<ast::AssertStatement<'ast>> for types::Statement<F> {
|
||||
impl<'ast> From<ast::AssertStatement<'ast>> for types::Statement {
|
||||
fn from(statement: ast::AssertStatement<'ast>) -> Self {
|
||||
match statement {
|
||||
ast::AssertStatement::AssertEq(assert_eq) => types::Statement::AssertEq(
|
||||
@ -608,13 +589,13 @@ impl<'ast, F: Field + PrimeField> From<ast::AssertStatement<'ast>> for types::St
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, F: Field + PrimeField> From<ast::ExpressionStatement<'ast>> for types::Statement<F> {
|
||||
impl<'ast> From<ast::ExpressionStatement<'ast>> for types::Statement {
|
||||
fn from(statement: ast::ExpressionStatement<'ast>) -> Self {
|
||||
types::Statement::Expression(types::Expression::from(statement.expression))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, F: Field + PrimeField> From<ast::Statement<'ast>> for types::Statement<F> {
|
||||
impl<'ast> From<ast::Statement<'ast>> for types::Statement {
|
||||
fn from(statement: ast::Statement<'ast>) -> Self {
|
||||
match statement {
|
||||
ast::Statement::Return(statement) => types::Statement::from(statement),
|
||||
@ -645,7 +626,7 @@ impl From<ast::IntegerType> for types::IntegerType {
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: Field + PrimeField> From<ast::BasicType> for types::Type<F> {
|
||||
impl From<ast::BasicType> for types::Type {
|
||||
fn from(basic_type: ast::BasicType) -> Self {
|
||||
match basic_type {
|
||||
ast::BasicType::Integer(_type) => {
|
||||
@ -658,26 +639,26 @@ impl<F: Field + PrimeField> From<ast::BasicType> for types::Type<F> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, F: Field + PrimeField> From<ast::ArrayType<'ast>> for types::Type<F> {
|
||||
impl<'ast> From<ast::ArrayType<'ast>> for types::Type {
|
||||
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::<F>::get_count(row))
|
||||
.map(|row| types::Expression::get_count(row))
|
||||
.collect();
|
||||
|
||||
types::Type::Array(element_type, dimensions)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, F: Field + PrimeField> From<ast::CircuitType<'ast>> for types::Type<F> {
|
||||
impl<'ast> From<ast::CircuitType<'ast>> for types::Type {
|
||||
fn from(circuit_type: ast::CircuitType<'ast>) -> Self {
|
||||
types::Type::Circuit(types::Identifier::from(circuit_type.identifier))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, F: Field + PrimeField> From<ast::Type<'ast>> for types::Type<F> {
|
||||
impl<'ast> From<ast::Type<'ast>> for types::Type {
|
||||
fn from(_type: ast::Type<'ast>) -> Self {
|
||||
match _type {
|
||||
ast::Type::Basic(_type) => types::Type::from(_type),
|
||||
@ -690,9 +671,7 @@ impl<'ast, F: Field + PrimeField> From<ast::Type<'ast>> for types::Type<F> {
|
||||
|
||||
/// pest ast -> types::Circuit
|
||||
|
||||
impl<'ast, F: Field + PrimeField> From<ast::CircuitFieldDefinition<'ast>>
|
||||
for types::CircuitMember<F>
|
||||
{
|
||||
impl<'ast> From<ast::CircuitFieldDefinition<'ast>> for types::CircuitMember {
|
||||
fn from(circuit_value: ast::CircuitFieldDefinition<'ast>) -> Self {
|
||||
types::CircuitMember::CircuitField(
|
||||
types::Identifier::from(circuit_value.identifier),
|
||||
@ -701,7 +680,7 @@ impl<'ast, F: Field + PrimeField> From<ast::CircuitFieldDefinition<'ast>>
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, F: Field + PrimeField> From<ast::CircuitFunction<'ast>> for types::CircuitMember<F> {
|
||||
impl<'ast> From<ast::CircuitFunction<'ast>> for types::CircuitMember {
|
||||
fn from(circuit_function: ast::CircuitFunction<'ast>) -> Self {
|
||||
types::CircuitMember::CircuitFunction(
|
||||
circuit_function._static.is_some(),
|
||||
@ -710,7 +689,7 @@ impl<'ast, F: Field + PrimeField> From<ast::CircuitFunction<'ast>> for types::Ci
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, F: Field + PrimeField> From<ast::CircuitMember<'ast>> for types::CircuitMember<F> {
|
||||
impl<'ast> From<ast::CircuitMember<'ast>> for types::CircuitMember {
|
||||
fn from(object: ast::CircuitMember<'ast>) -> Self {
|
||||
match object {
|
||||
ast::CircuitMember::CircuitFieldDefinition(circuit_value) => {
|
||||
@ -723,7 +702,7 @@ impl<'ast, F: Field + PrimeField> From<ast::CircuitMember<'ast>> for types::Circ
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, F: Field + PrimeField> From<ast::Circuit<'ast>> for types::Circuit<F> {
|
||||
impl<'ast> From<ast::Circuit<'ast>> for types::Circuit {
|
||||
fn from(circuit: ast::Circuit<'ast>) -> Self {
|
||||
let variable = types::Identifier::from(circuit.identifier);
|
||||
let members = circuit
|
||||
@ -741,7 +720,7 @@ impl<'ast, F: Field + PrimeField> From<ast::Circuit<'ast>> for types::Circuit<F>
|
||||
|
||||
/// pest ast -> function types::Parameters
|
||||
|
||||
impl<'ast, F: Field + PrimeField> From<ast::InputModel<'ast>> for types::InputModel<F> {
|
||||
impl<'ast> From<ast::InputModel<'ast>> for types::InputModel {
|
||||
fn from(parameter: ast::InputModel<'ast>) -> Self {
|
||||
types::InputModel {
|
||||
identifier: types::Identifier::from(parameter.identifier),
|
||||
@ -757,7 +736,7 @@ impl<'ast, F: Field + PrimeField> From<ast::InputModel<'ast>> for types::InputMo
|
||||
|
||||
/// pest ast -> types::Function
|
||||
|
||||
impl<'ast, F: Field + PrimeField> From<ast::Function<'ast>> for types::Function<F> {
|
||||
impl<'ast> From<ast::Function<'ast>> for types::Function {
|
||||
fn from(function_definition: ast::Function<'ast>) -> Self {
|
||||
let function_name = types::Identifier::from(function_definition.function_name);
|
||||
let parameters = function_definition
|
||||
@ -787,7 +766,7 @@ impl<'ast, F: Field + PrimeField> From<ast::Function<'ast>> for types::Function<
|
||||
|
||||
/// pest ast -> Import
|
||||
|
||||
impl<'ast, F: Field + PrimeField> From<ast::ImportSymbol<'ast>> for ImportSymbol<F> {
|
||||
impl<'ast> From<ast::ImportSymbol<'ast>> for ImportSymbol {
|
||||
fn from(symbol: ast::ImportSymbol<'ast>) -> Self {
|
||||
ImportSymbol {
|
||||
symbol: types::Identifier::from(symbol.value),
|
||||
@ -796,7 +775,7 @@ impl<'ast, F: Field + PrimeField> From<ast::ImportSymbol<'ast>> for ImportSymbol
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast, F: Field + PrimeField> From<ast::Import<'ast>> for Import<F> {
|
||||
impl<'ast> From<ast::Import<'ast>> for Import {
|
||||
fn from(import: ast::Import<'ast>) -> Self {
|
||||
Import {
|
||||
path_string: import.source.value,
|
||||
@ -811,14 +790,14 @@ impl<'ast, F: Field + PrimeField> From<ast::Import<'ast>> for Import<F> {
|
||||
|
||||
/// pest ast -> types::Program
|
||||
|
||||
impl<'ast, F: Field + PrimeField> types::Program<F> {
|
||||
impl<'ast> types::Program {
|
||||
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<F>>>();
|
||||
.collect::<Vec<Import>>();
|
||||
|
||||
let mut circuits = HashMap::new();
|
||||
let mut functions = HashMap::new();
|
||||
|
@ -1,7 +1,7 @@
|
||||
use crate::{compile_program, get_error, get_output, EdwardsConstrainedValue, EdwardsTestCompiler};
|
||||
use leo_compiler::{
|
||||
errors::{CompilerError, FieldError, FunctionError},
|
||||
ConstrainedValue, FieldElement, InputValue,
|
||||
ConstrainedValue, FieldType, InputValue,
|
||||
};
|
||||
|
||||
use snarkos_curves::edwards_bls12::Fq;
|
||||
@ -12,7 +12,7 @@ const DIRECTORY_NAME: &str = "tests/field_element/";
|
||||
fn output_zero(program: EdwardsTestCompiler) {
|
||||
let output = get_output(program);
|
||||
assert_eq!(
|
||||
EdwardsConstrainedValue::Return(vec![ConstrainedValue::Field(FieldElement::Constant(
|
||||
EdwardsConstrainedValue::Return(vec![ConstrainedValue::Field(FieldType::Constant(
|
||||
Fq::zero()
|
||||
))])
|
||||
.to_string(),
|
||||
@ -23,7 +23,7 @@ fn output_zero(program: EdwardsTestCompiler) {
|
||||
fn output_one(program: EdwardsTestCompiler) {
|
||||
let output = get_output(program);
|
||||
assert_eq!(
|
||||
EdwardsConstrainedValue::Return(vec![ConstrainedValue::Field(FieldElement::Constant(
|
||||
EdwardsConstrainedValue::Return(vec![ConstrainedValue::Field(FieldType::Constant(
|
||||
Fq::one()
|
||||
))])
|
||||
.to_string(),
|
||||
|
Loading…
Reference in New Issue
Block a user