mirror of
https://github.com/AleoHQ/leo.git
synced 2024-11-29 11:43:28 +03:00
remove mut variable keyword
This commit is contained in:
parent
82e13edbbe
commit
7977b20ad2
@ -25,8 +25,8 @@ use std::fmt;
|
|||||||
|
|
||||||
#[derive(Clone, PartialEq, Eq, Serialize, Deserialize)]
|
#[derive(Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
pub enum CircuitMember {
|
pub enum CircuitMember {
|
||||||
// (is_mutable, variable_name, variable_type)
|
// (variable_name, variable_type)
|
||||||
CircuitVariable(bool, Identifier, Type),
|
CircuitVariable(Identifier, Type),
|
||||||
// (function)
|
// (function)
|
||||||
CircuitFunction(Function),
|
CircuitFunction(Function),
|
||||||
}
|
}
|
||||||
@ -34,7 +34,6 @@ pub enum CircuitMember {
|
|||||||
impl<'ast> From<GrammarCircuitVariableDefinition<'ast>> for CircuitMember {
|
impl<'ast> From<GrammarCircuitVariableDefinition<'ast>> for CircuitMember {
|
||||||
fn from(circuit_value: GrammarCircuitVariableDefinition<'ast>) -> Self {
|
fn from(circuit_value: GrammarCircuitVariableDefinition<'ast>) -> Self {
|
||||||
CircuitMember::CircuitVariable(
|
CircuitMember::CircuitVariable(
|
||||||
circuit_value.mutable.is_some(),
|
|
||||||
Identifier::from(circuit_value.identifier),
|
Identifier::from(circuit_value.identifier),
|
||||||
Type::from(circuit_value.type_),
|
Type::from(circuit_value.type_),
|
||||||
)
|
)
|
||||||
@ -59,10 +58,7 @@ impl<'ast> From<GrammarCircuitMember<'ast>> for CircuitMember {
|
|||||||
impl fmt::Display for CircuitMember {
|
impl fmt::Display for CircuitMember {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
CircuitMember::CircuitVariable(ref mutable, ref identifier, ref type_) => {
|
CircuitMember::CircuitVariable(ref identifier, ref type_) => {
|
||||||
if *mutable {
|
|
||||||
write!(f, "mut ")?;
|
|
||||||
}
|
|
||||||
write!(f, "{}: {}", identifier, type_)
|
write!(f, "{}: {}", identifier, type_)
|
||||||
}
|
}
|
||||||
CircuitMember::CircuitFunction(ref function) => {
|
CircuitMember::CircuitFunction(ref function) => {
|
||||||
|
@ -58,7 +58,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
|||||||
|
|
||||||
for member in circuit.members.into_iter() {
|
for member in circuit.members.into_iter() {
|
||||||
match member {
|
match member {
|
||||||
CircuitMember::CircuitVariable(is_mutable, identifier, type_) => {
|
CircuitMember::CircuitVariable(identifier, type_) => {
|
||||||
let matched_variable = members
|
let matched_variable = members
|
||||||
.clone()
|
.clone()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@ -74,11 +74,6 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
|||||||
variable.expression,
|
variable.expression,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Add mutability to circuit variable
|
|
||||||
if is_mutable {
|
|
||||||
variable_value = ConstrainedValue::Mutable(Box::new(variable_value))
|
|
||||||
}
|
|
||||||
|
|
||||||
resolved_members.push(ConstrainedCircuitMember(identifier, variable_value))
|
resolved_members.push(ConstrainedCircuitMember(identifier, variable_value))
|
||||||
}
|
}
|
||||||
None => return Err(ExpressionError::expected_circuit_member(identifier.to_string(), span)),
|
None => return Err(ExpressionError::expected_circuit_member(identifier.to_string(), span)),
|
||||||
@ -89,10 +84,6 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
|||||||
let constrained_function_value =
|
let constrained_function_value =
|
||||||
ConstrainedValue::Function(Some(circuit_identifier.clone()), function);
|
ConstrainedValue::Function(Some(circuit_identifier.clone()), function);
|
||||||
|
|
||||||
// if _static {
|
|
||||||
// constrained_function_value = ConstrainedValue::Static(Box::new(constrained_function_value));
|
|
||||||
// }
|
|
||||||
|
|
||||||
resolved_members.push(ConstrainedCircuitMember(identifier, constrained_function_value));
|
resolved_members.push(ConstrainedCircuitMember(identifier, constrained_function_value));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -28,7 +28,6 @@ use serde::Serialize;
|
|||||||
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
|
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
|
||||||
#[pest_ast(rule(Rule::circuit_variable_definition))]
|
#[pest_ast(rule(Rule::circuit_variable_definition))]
|
||||||
pub struct CircuitVariableDefinition<'ast> {
|
pub struct CircuitVariableDefinition<'ast> {
|
||||||
pub mutable: Option<Mutable>,
|
|
||||||
pub identifier: Identifier<'ast>,
|
pub identifier: Identifier<'ast>,
|
||||||
pub type_: Type<'ast>,
|
pub type_: Type<'ast>,
|
||||||
#[pest_ast(outer())]
|
#[pest_ast(outer())]
|
||||||
|
@ -322,7 +322,7 @@ circuit = { "circuit " ~ identifier ~ "{" ~ NEWLINE* ~ circuit_member* ~ NEWLINE
|
|||||||
circuit_variable = { identifier ~ ":" ~ expression }
|
circuit_variable = { identifier ~ ":" ~ expression }
|
||||||
|
|
||||||
// Declared in circuits/circuit_variable_definition.rs
|
// Declared in circuits/circuit_variable_definition.rs
|
||||||
circuit_variable_definition = { mutable? ~ identifier ~ ":" ~ type_ ~ ","?}
|
circuit_variable_definition = { identifier ~ ":" ~ type_ ~ ","?}
|
||||||
|
|
||||||
// Declared in circuits/circuit_member.rs
|
// Declared in circuits/circuit_member.rs
|
||||||
circuit_member = { function | circuit_variable_definition ~ NEWLINE*}
|
circuit_member = { function | circuit_variable_definition ~ NEWLINE*}
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{types::circuits::CircuitVariableType, Attribute, FunctionType, SymbolTable, Type, TypeError};
|
use crate::{types::circuits::CircuitVariableType, FunctionType, SymbolTable, Type, TypeError};
|
||||||
use leo_ast::{Circuit, CircuitMember, Identifier, InputValue, Parameter, Span};
|
use leo_ast::{Circuit, CircuitMember, Identifier, InputValue, Parameter, Span};
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
@ -54,7 +54,7 @@ impl CircuitType {
|
|||||||
// Resolve the type of every circuit member.
|
// Resolve the type of every circuit member.
|
||||||
for member in unresolved.members {
|
for member in unresolved.members {
|
||||||
match member {
|
match member {
|
||||||
CircuitMember::CircuitVariable(is_mutable, variable_identifier, type_) => {
|
CircuitMember::CircuitVariable(variable_identifier, type_) => {
|
||||||
// Resolve the type of the circuit member variable.
|
// Resolve the type of the circuit member variable.
|
||||||
let type_ = Type::new_from_circuit(
|
let type_ = Type::new_from_circuit(
|
||||||
table,
|
table,
|
||||||
@ -63,14 +63,11 @@ impl CircuitType {
|
|||||||
circuit_identifier.span.clone(),
|
circuit_identifier.span.clone(),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Check if the circuit member variable is mutable.
|
|
||||||
let attribute = if is_mutable { Some(Attribute::Mutable) } else { None };
|
|
||||||
|
|
||||||
// Create a new circuit variable type.
|
// Create a new circuit variable type.
|
||||||
let variable = CircuitVariableType {
|
let variable = CircuitVariableType {
|
||||||
identifier: variable_identifier,
|
identifier: variable_identifier,
|
||||||
type_,
|
type_,
|
||||||
attribute,
|
attribute: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Store the circuit variable type.
|
// Store the circuit variable type.
|
||||||
|
Loading…
Reference in New Issue
Block a user