diff --git a/benchmark/simple.leo b/benchmark/simple.leo index 54945d6b66..3ad5b9cb03 100644 --- a/benchmark/simple.leo +++ b/benchmark/simple.leo @@ -1,5 +1,5 @@ function main() -> (u32) { a = 2; - a /= 3; + a **= 3; return a } \ No newline at end of file diff --git a/compiler/src/ast.rs b/compiler/src/ast.rs index 6406f27d66..777bdab1a9 100644 --- a/compiler/src/ast.rs +++ b/compiler/src/ast.rs @@ -89,6 +89,41 @@ pub enum BinaryOperator { Pow, } +#[derive(Clone, Debug, FromPest, PartialEq)] +#[pest_ast(rule(Rule::assign))] +pub struct Assign {} + +#[derive(Clone, Debug, FromPest, PartialEq)] +#[pest_ast(rule(Rule::operation_add_assign))] +pub struct AddAssign {} + +#[derive(Clone, Debug, FromPest, PartialEq)] +#[pest_ast(rule(Rule::operation_sub_assign))] +pub struct SubAssign {} + +#[derive(Clone, Debug, FromPest, PartialEq)] +#[pest_ast(rule(Rule::operation_mul_assign))] +pub struct MulAssign {} + +#[derive(Clone, Debug, FromPest, PartialEq)] +#[pest_ast(rule(Rule::operation_div_assign))] +pub struct DivAssign {} + +#[derive(Clone, Debug, FromPest, PartialEq)] +#[pest_ast(rule(Rule::operation_pow_assign))] +pub struct PowAssign {} + +#[derive(Clone, Debug, FromPest, PartialEq)] +#[pest_ast(rule(Rule::operation_assign))] +pub enum OperationAssign { + Assign(Assign), + AddAssign(AddAssign), + SubAssign(SubAssign), + MulAssign(MulAssign), + DivAssign(DivAssign), + PowAssign(PowAssign), +} + // Types #[derive(Clone, Debug, FromPest, PartialEq)] @@ -851,36 +886,6 @@ pub struct DefinitionStatement<'ast> { pub span: Span<'ast>, } -#[derive(Clone, Debug, FromPest, PartialEq)] -#[pest_ast(rule(Rule::assign))] -pub struct Assign {} - -#[derive(Clone, Debug, FromPest, PartialEq)] -#[pest_ast(rule(Rule::operation_add_assign))] -pub struct AddAssign {} - -#[derive(Clone, Debug, FromPest, PartialEq)] -#[pest_ast(rule(Rule::operation_sub_assign))] -pub struct SubAssign {} - -#[derive(Clone, Debug, FromPest, PartialEq)] -#[pest_ast(rule(Rule::operation_mul_assign))] -pub struct MulAssign {} - -#[derive(Clone, Debug, FromPest, PartialEq)] -#[pest_ast(rule(Rule::operation_div_assign))] -pub struct DivAssign {} - -#[derive(Clone, Debug, FromPest, PartialEq)] -#[pest_ast(rule(Rule::operation_assign))] -pub enum OperationAssign { - Assign(Assign), - AddAssign(AddAssign), - SubAssign(SubAssign), - MulAssign(MulAssign), - DivAssign(DivAssign), -} - #[derive(Clone, Debug, FromPest, PartialEq)] #[pest_ast(rule(Rule::statement_assign))] pub struct AssignStatement<'ast> { diff --git a/compiler/src/leo.pest b/compiler/src/leo.pest index 4409bca335..d7104f3619 100644 --- a/compiler/src/leo.pest +++ b/compiler/src/leo.pest @@ -44,11 +44,11 @@ operation_add_assign = { "+=" } operation_sub_assign = { "-=" } operation_mul_assign = { "*=" } operation_div_assign = { "/=" } +operation_pow_assign = { "**=" } operation_assign = { - assign - | operation_add_assign | operation_sub_assign - | operation_mul_assign | operation_div_assign + assign | operation_add_assign | operation_sub_assign | + operation_mul_assign | operation_div_assign | operation_pow_assign } /// Types diff --git a/compiler/src/types_from.rs b/compiler/src/types_from.rs index 2ed957757f..17ea33f3e9 100644 --- a/compiler/src/types_from.rs +++ b/compiler/src/types_from.rs @@ -420,6 +420,13 @@ impl<'ast, F: Field + PrimeField> From> for types::St Box::new(types::Expression::from(statement.expression)), ), ), + ast::OperationAssign::PowAssign(ref _assign) => types::Statement::Assign( + types::Assignee::from(statement.assignee), + types::Expression::Pow( + Box::new(converted), + Box::new(types::Expression::from(statement.expression)), + ), + ), ast::OperationAssign::Assign(ref _assign) => { unimplemented!("cannot assign twice to assign statement") }