mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-12-24 18:52:58 +03:00
use typed assignee access
This commit is contained in:
parent
3bd6d2e6b6
commit
323992696c
@ -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,61 +54,56 @@ 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())?;
|
|
||||||
|
|
||||||
new_value.resolve_type(Some(old_value.to_type(span.clone())?), span.clone())?;
|
new_value.resolve_type(Some(old_value.to_type(span.clone())?), span.clone())?;
|
||||||
|
|
||||||
let name_unique = format!("select {} {}:{}", new_value, span.line, span.start);
|
let name_unique = format!("select {} {}:{}", new_value, span.line, span.start);
|
||||||
let selected_value =
|
let selected_value =
|
||||||
ConstrainedValue::conditionally_select(cs.ns(|| name_unique), &condition, &new_value, old_value)
|
ConstrainedValue::conditionally_select(cs.ns(|| name_unique), &condition, &new_value, old_value)
|
||||||
.map_err(|_| StatementError::select_fail(new_value.to_string(), old_value.to_string(), span))?;
|
.map_err(|_| StatementError::select_fail(new_value.to_string(), old_value.to_string(), span))?;
|
||||||
|
|
||||||
*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() {
|
||||||
cs,
|
AssigneeAccess::Array(range_or_expression) => self.assign_array(
|
||||||
file_scope,
|
cs,
|
||||||
function_scope,
|
file_scope,
|
||||||
indicator,
|
function_scope,
|
||||||
variable_name,
|
indicator,
|
||||||
range_or_expression,
|
variable_name,
|
||||||
new_value,
|
range_or_expression,
|
||||||
span,
|
new_value,
|
||||||
),
|
span,
|
||||||
Assignee::Tuple(_tuple, index) => self.assign_tuple(cs, indicator, variable_name, index, new_value, span),
|
),
|
||||||
Assignee::CircuitField(assignee, circuit_variable) => {
|
AssigneeAccess::Tuple(index) => self.assign_tuple(cs, indicator, variable_name, index, new_value, span),
|
||||||
// Mutate a circuit variable using the self keyword.
|
AssigneeAccess::Member(identifier) => {
|
||||||
if let Assignee::Identifier(circuit_name) = *assignee {
|
// Mutate a circuit variable using the self keyword.
|
||||||
if circuit_name.is_self() {
|
if assignee.identifier.is_self() {
|
||||||
let self_circuit_variable_name = new_scope(circuit_name.name, circuit_variable.name.clone());
|
let self_circuit_variable_name =
|
||||||
|
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(())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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> {
|
||||||
|
Loading…
Reference in New Issue
Block a user