use typed assignee access

This commit is contained in:
collin 2020-10-15 18:11:39 -07:00
parent 3bd6d2e6b6
commit 323992696c
2 changed files with 35 additions and 45 deletions

View File

@ -24,7 +24,7 @@ use crate::{
value::ConstrainedValue, value::ConstrainedValue,
GroupType, GroupType,
}; };
use leo_typed::{Assignee, Expression, Span}; use leo_typed::{Assignee, AssigneeAccess, Expression, Span};
use snarkos_models::{ use snarkos_models::{
curves::{Field, PrimeField}, curves::{Field, PrimeField},
@ -54,8 +54,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
self.enforce_expression(cs, file_scope.clone(), function_scope.clone(), None, expression)?; self.enforce_expression(cs, file_scope.clone(), function_scope.clone(), None, expression)?;
// Mutate the old value into the new value // Mutate the old value into the new value
match assignee { if assignee.accesses.is_empty() {
Assignee::Identifier(_identifier) => {
let condition = indicator.unwrap_or(Boolean::Constant(true)); let condition = indicator.unwrap_or(Boolean::Constant(true));
let old_value = self.get_mutable_assignee(variable_name.clone(), span.clone())?; let old_value = self.get_mutable_assignee(variable_name.clone(), span.clone())?;
@ -68,9 +67,10 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
*old_value = selected_value; *old_value = selected_value;
Ok(()) return Ok(());
} } else {
Assignee::Array(_assignee, range_or_expression) => self.assign_array( match assignee.accesses[0].clone() {
AssigneeAccess::Array(range_or_expression) => self.assign_array(
cs, cs,
file_scope, file_scope,
function_scope, function_scope,
@ -80,36 +80,31 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
new_value, new_value,
span, span,
), ),
Assignee::Tuple(_tuple, index) => self.assign_tuple(cs, indicator, variable_name, index, new_value, span), AssigneeAccess::Tuple(index) => self.assign_tuple(cs, indicator, variable_name, index, new_value, span),
Assignee::CircuitField(assignee, circuit_variable) => { AssigneeAccess::Member(identifier) => {
// Mutate a circuit variable using the self keyword. // Mutate a circuit variable using the self keyword.
if let Assignee::Identifier(circuit_name) = *assignee { if assignee.identifier.is_self() {
if circuit_name.is_self() { let self_circuit_variable_name =
let self_circuit_variable_name = new_scope(circuit_name.name, circuit_variable.name.clone()); new_scope(assignee.identifier.name.clone(), identifier.name.clone());
let self_variable_name = new_scope(file_scope, self_circuit_variable_name); let self_variable_name = new_scope(file_scope, self_circuit_variable_name);
let value = self.mutate_circuit_variable( let value = self.mutate_circuit_variable(
cs, cs,
indicator, indicator,
declared_circuit_reference, declared_circuit_reference,
circuit_variable, identifier,
new_value, new_value,
span, span,
)?; )?;
self.store(self_variable_name, value); self.store(self_variable_name, value);
} else { } else {
let _value = self.mutate_circuit_variable( let _value =
cs, self.mutate_circuit_variable(cs, indicator, variable_name, identifier, new_value, span)?;
indicator,
variable_name,
circuit_variable,
new_value,
span,
)?;
}
} }
Ok(()) Ok(())
} }
} }
} }
} }
}

View File

@ -22,12 +22,7 @@ use leo_typed::{Assignee, Span};
use snarkos_models::curves::{Field, PrimeField}; use snarkos_models::curves::{Field, PrimeField};
pub fn resolve_assignee(scope: String, assignee: Assignee) -> String { pub fn resolve_assignee(scope: String, assignee: Assignee) -> String {
match assignee { new_scope(scope, assignee.identifier().to_string())
Assignee::Identifier(name) => new_scope(scope, name.to_string()),
Assignee::Array(array, _index) => resolve_assignee(scope, *array),
Assignee::Tuple(tuple, _index) => resolve_assignee(scope, *tuple),
Assignee::CircuitField(circuit_name, _member) => resolve_assignee(scope, *circuit_name),
}
} }
impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> { impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {