mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-11-23 23:23:50 +03:00
Merge branch 'master' of github.com:AleoHQ/leo into feature/unordered-definitions
This commit is contained in:
commit
424287eb7b
@ -66,7 +66,7 @@ impl<'ast> fmt::Display for Expression<'ast> {
|
||||
match *self {
|
||||
Expression::Value(ref expression) => write!(f, "{}", expression),
|
||||
Expression::Identifier(ref expression) => write!(f, "{}", expression),
|
||||
Expression::Unary(ref expression) => write!(f, "!{}", expression.expression),
|
||||
Expression::Unary(ref expression) => write!(f, "{}", expression),
|
||||
Expression::Binary(ref expression) => write!(f, "{} == {}", expression.left, expression.right),
|
||||
Expression::Ternary(ref expression) => write!(
|
||||
f,
|
||||
|
@ -3,6 +3,7 @@ use crate::{ast::Rule, expressions::Expression, operations::UnaryOperation, Span
|
||||
use pest::Span;
|
||||
use pest_ast::FromPest;
|
||||
use serde::Serialize;
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
|
||||
#[pest_ast(rule(Rule::expression_unary))]
|
||||
@ -13,3 +14,9 @@ pub struct UnaryExpression<'ast> {
|
||||
#[serde(with = "SpanDef")]
|
||||
pub span: Span<'ast>,
|
||||
}
|
||||
|
||||
impl<'ast> fmt::Display for UnaryExpression<'ast> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{}{}", self.operation, self.expression)
|
||||
}
|
||||
}
|
||||
|
@ -78,10 +78,10 @@ let_ = { "let " }
|
||||
// Declared in operations/unary_operation.rs
|
||||
operation_unary = {
|
||||
operation_not
|
||||
| operation_minus
|
||||
| operation_negate
|
||||
}
|
||||
operation_not = { "!" }
|
||||
operation_minus = { "-" }
|
||||
operation_negate = { "-" }
|
||||
|
||||
// Declared in operations/binary_operation.rs
|
||||
operation_and = { "&&" }
|
||||
@ -235,7 +235,7 @@ group_tuple = !{"(" ~ value_number ~ "," ~ value_number ~ ")"}
|
||||
group_single_or_tuple = {value_number | group_tuple}
|
||||
|
||||
// Declared in values/address.rs
|
||||
address = @{ "aleo" ~ ASCII_DIGIT ~ (LOWERCASE_LETTER | ASCII_DIGIT){58} }
|
||||
address = @{ "aleo1" ~ (LOWERCASE_LETTER | ASCII_DIGIT){58} }
|
||||
|
||||
// Declared in values/address_value.rs
|
||||
value_address = ${ type_address ~ "(" ~ address ~ ")" }
|
||||
|
@ -2,18 +2,28 @@ use crate::ast::Rule;
|
||||
|
||||
use pest_ast::FromPest;
|
||||
use serde::Serialize;
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
|
||||
#[pest_ast(rule(Rule::operation_unary))]
|
||||
pub enum UnaryOperation {
|
||||
Minus(Minus),
|
||||
Negate(Negate),
|
||||
Not(Not),
|
||||
}
|
||||
|
||||
impl fmt::Display for UnaryOperation {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
UnaryOperation::Negate(_) => write!(f, "-"),
|
||||
UnaryOperation::Not(_) => write!(f, "!"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
|
||||
#[pest_ast(rule(Rule::operation_not))]
|
||||
pub struct Not {}
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
|
||||
#[pest_ast(rule(Rule::operation_minus))]
|
||||
pub struct Minus {}
|
||||
#[pest_ast(rule(Rule::operation_negate))]
|
||||
pub struct Negate {}
|
||||
|
@ -6,8 +6,8 @@ pub use self::add::*;
|
||||
pub mod sub;
|
||||
pub use self::sub::*;
|
||||
|
||||
pub mod minus;
|
||||
pub use self::minus::*;
|
||||
pub mod negate;
|
||||
pub use self::negate::*;
|
||||
|
||||
pub mod mul;
|
||||
pub use self::mul::*;
|
||||
|
@ -1,4 +1,4 @@
|
||||
//! Enforces a unary minus `-` operator in a resolved Leo program.
|
||||
//! Enforces a unary negate `-` operator in a resolved Leo program.
|
||||
|
||||
use crate::{errors::ExpressionError, value::ConstrainedValue, GroupType};
|
||||
use leo_typed::Span;
|
||||
@ -8,7 +8,7 @@ use snarkos_models::{
|
||||
gadgets::r1cs::ConstraintSystem,
|
||||
};
|
||||
|
||||
pub fn enforce_minus<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
pub fn enforce_negate<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
cs: &mut CS,
|
||||
value: ConstrainedValue<F, G>,
|
||||
span: Span,
|
@ -45,11 +45,11 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
||||
}
|
||||
|
||||
// Binary operations
|
||||
Expression::Minus(expression, span) => {
|
||||
Expression::Negate(expression, span) => {
|
||||
let resolved_value =
|
||||
self.enforce_expression(cs, file_scope, function_scope, expected_types, *expression)?;
|
||||
|
||||
enforce_minus(cs, resolved_value, span)
|
||||
enforce_negate(cs, resolved_value, span)
|
||||
}
|
||||
Expression::Add(left, right, span) => {
|
||||
let (resolved_left, resolved_right) = self.enforce_binary_expression(
|
||||
|
@ -52,7 +52,7 @@ pub enum Expression {
|
||||
|
||||
// Boolean operations
|
||||
Not(Box<Expression>, Span),
|
||||
Minus(Box<Expression>, Span),
|
||||
Negate(Box<Expression>, Span),
|
||||
Or(Box<Expression>, Box<Expression>, Span),
|
||||
And(Box<Expression>, Box<Expression>, Span),
|
||||
Eq(Box<Expression>, Box<Expression>, Span),
|
||||
@ -143,7 +143,7 @@ impl<'ast> fmt::Display for Expression {
|
||||
Expression::Integer(ref type_, ref integer, ref _span) => write!(f, "{}{}", integer, type_),
|
||||
|
||||
// Number operations
|
||||
Expression::Minus(ref expression, ref _span) => write!(f, "-{}", expression),
|
||||
Expression::Negate(ref expression, ref _span) => write!(f, "-{}", expression),
|
||||
Expression::Add(ref left, ref right, ref _span) => write!(f, "{} + {}", left, right),
|
||||
Expression::Sub(ref left, ref right, ref _span) => write!(f, "{} - {}", left, right),
|
||||
Expression::Mul(ref left, ref right, ref _span) => write!(f, "{} * {}", left, right),
|
||||
@ -438,7 +438,7 @@ impl<'ast> From<UnaryExpression<'ast>> for Expression {
|
||||
Box::new(Expression::from(*expression.expression)),
|
||||
Span::from(expression.span),
|
||||
),
|
||||
UnaryOperation::Minus(_) => Expression::Minus(
|
||||
UnaryOperation::Negate(_) => Expression::Negate(
|
||||
Box::new(Expression::from(*expression.expression)),
|
||||
Span::from(expression.span),
|
||||
),
|
||||
|
Loading…
Reference in New Issue
Block a user