Skip to content

Commit

Permalink
pull testnet3, regen tests
Browse files Browse the repository at this point in the history
  • Loading branch information
collinc97 committed Nov 23, 2022
2 parents a8a8086 + 40e56f8 commit 801df56
Show file tree
Hide file tree
Showing 274 changed files with 2,299 additions and 699 deletions.
38 changes: 23 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions compiler/ast/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ version = "1.6.0"
version = "1.9"
features = [ "serde-1" ]

[dependencies.itertools]
version = "0.10.5"

[dependencies.serde]
version = "1.0"
features = [ "derive", "rc" ]
Expand Down
12 changes: 10 additions & 2 deletions compiler/ast/src/expressions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,15 @@ pub use err::*;
mod ternary;
pub use ternary::*;

mod tuple_init;
pub use tuple_init::*;
mod tuple;
pub use tuple::*;

mod unary;
pub use unary::*;

mod unit;
pub use unit::*;

mod literal;
pub use literal::*;

Expand Down Expand Up @@ -71,6 +74,8 @@ pub enum Expression {
Tuple(TupleExpression),
/// An unary expression.
Unary(UnaryExpression),
/// A unit expression e.g. `()`
Unit(UnitExpression),
}

impl Node for Expression {
Expand All @@ -87,6 +92,7 @@ impl Node for Expression {
Ternary(n) => n.span(),
Tuple(n) => n.span(),
Unary(n) => n.span(),
Unit(n) => n.span(),
}
}

Expand All @@ -103,6 +109,7 @@ impl Node for Expression {
Ternary(n) => n.set_span(span),
Tuple(n) => n.set_span(span),
Unary(n) => n.set_span(span),
Unit(n) => n.set_span(span),
}
}
}
Expand All @@ -121,6 +128,7 @@ impl fmt::Display for Expression {
Ternary(n) => n.fmt(f),
Tuple(n) => n.fmt(f),
Unary(n) => n.fmt(f),
Unit(n) => n.fmt(f),
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

use super::*;

/// A tuple construction expression, e.g., `(foo, false, 42)`.
// TODO: Consider a restricted interface for constructing a tuple expression.

/// A tuple expression, e.g., `(foo, false, 42)`.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct TupleExpression {
/// The elements of the tuple.
Expand Down
32 changes: 32 additions & 0 deletions compiler/ast/src/expressions/unit.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (C) 2019-2022 Aleo Systems Inc.
// This file is part of the Leo library.

// The Leo library is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// The Leo library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// 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/>.

use super::*;

/// Represents a unit expression.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct UnitExpression {
/// The span of the unit expression.
pub span: Span,
}

impl fmt::Display for UnitExpression {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str("()")
}
}

crate::simple_node_impl!(UnitExpression);
6 changes: 6 additions & 0 deletions compiler/ast/src/passes/consumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub trait ExpressionConsumer {
Expression::Ternary(ternary) => self.consume_ternary(ternary),
Expression::Tuple(tuple) => self.consume_tuple(tuple),
Expression::Unary(unary) => self.consume_unary(unary),
Expression::Unit(unit) => self.consume_unit(unit),
}
}

Expand All @@ -59,6 +60,8 @@ pub trait ExpressionConsumer {
fn consume_tuple(&mut self, _input: TupleExpression) -> Self::Output;

fn consume_unary(&mut self, _input: UnaryExpression) -> Self::Output;

fn consume_unit(&mut self, _input: UnitExpression) -> Self::Output;
}

/// A Consumer trait for statements in the AST.
Expand All @@ -73,6 +76,7 @@ pub trait StatementConsumer {
Statement::Console(stmt) => self.consume_console(stmt),
Statement::Decrement(stmt) => self.consume_decrement(stmt),
Statement::Definition(stmt) => self.consume_definition(stmt),
Statement::Expression(stmt) => self.consume_expression_statement(stmt),
Statement::Finalize(stmt) => self.consume_finalize(stmt),
Statement::Increment(stmt) => self.consume_increment(stmt),
Statement::Iteration(stmt) => self.consume_iteration(*stmt),
Expand All @@ -92,6 +96,8 @@ pub trait StatementConsumer {

fn consume_definition(&mut self, input: DefinitionStatement) -> Self::Output;

fn consume_expression_statement(&mut self, input: ExpressionStatement) -> Self::Output;

fn consume_finalize(&mut self, input: FinalizeStatement) -> Self::Output;

fn consume_increment(&mut self, input: IncrementStatement) -> Self::Output;
Expand Down
18 changes: 17 additions & 1 deletion compiler/ast/src/passes/reconstructor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub trait ExpressionReconstructor {
Expression::Ternary(ternary) => self.reconstruct_ternary(ternary),
Expression::Tuple(tuple) => self.reconstruct_tuple(tuple),
Expression::Unary(unary) => self.reconstruct_unary(unary),
Expression::Unit(unit) => self.reconstruct_unit(unit),
}
}

Expand Down Expand Up @@ -150,6 +151,10 @@ pub trait ExpressionReconstructor {
Default::default(),
)
}

fn reconstruct_unit(&mut self, input: UnitExpression) -> (Expression, Self::AdditionalOutput) {
(Expression::Unit(input), Default::default())
}
}

/// A Reconstructor trait for statements in the AST.
Expand All @@ -165,6 +170,7 @@ pub trait StatementReconstructor: ExpressionReconstructor {
Statement::Console(stmt) => self.reconstruct_console(stmt),
Statement::Decrement(stmt) => self.reconstruct_decrement(stmt),
Statement::Definition(stmt) => self.reconstruct_definition(stmt),
Statement::Expression(stmt) => self.reconstruct_expression_statement(stmt),
Statement::Finalize(stmt) => self.reconstruct_finalize(stmt),
Statement::Increment(stmt) => self.reconstruct_increment(stmt),
Statement::Iteration(stmt) => self.reconstruct_iteration(*stmt),
Expand Down Expand Up @@ -245,7 +251,7 @@ pub trait StatementReconstructor: ExpressionReconstructor {
(
Statement::Definition(DefinitionStatement {
declaration_type: input.declaration_type,
variable_name: input.variable_name,
place: input.place,
type_: input.type_,
value: self.reconstruct_expression(input.value).0,
span: input.span,
Expand All @@ -254,6 +260,16 @@ pub trait StatementReconstructor: ExpressionReconstructor {
)
}

fn reconstruct_expression_statement(&mut self, input: ExpressionStatement) -> (Statement, Self::AdditionalOutput) {
(
Statement::Expression(ExpressionStatement {
expression: self.reconstruct_expression(input.expression).0,
span: input.span,
}),
Default::default(),
)
}

fn reconstruct_finalize(&mut self, input: FinalizeStatement) -> (Statement, Self::AdditionalOutput) {
(
Statement::Finalize(FinalizeStatement {
Expand Down
10 changes: 10 additions & 0 deletions compiler/ast/src/passes/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub trait ExpressionVisitor<'a> {
Expression::Ternary(ternary) => self.visit_ternary(ternary, additional),
Expression::Tuple(tuple) => self.visit_tuple(tuple, additional),
Expression::Unary(unary) => self.visit_unary(unary, additional),
Expression::Unit(unit) => self.visit_unit(unit, additional),
}
}

Expand Down Expand Up @@ -106,6 +107,10 @@ pub trait ExpressionVisitor<'a> {
self.visit_expression(&input.receiver, additional);
Default::default()
}

fn visit_unit(&mut self, _input: &'a UnitExpression, _additional: &Self::AdditionalInput) -> Self::Output {
Default::default()
}
}

/// A Visitor trait for statements in the AST.
Expand All @@ -118,6 +123,7 @@ pub trait StatementVisitor<'a>: ExpressionVisitor<'a> {
Statement::Console(stmt) => self.visit_console(stmt),
Statement::Decrement(stmt) => self.visit_decrement(stmt),
Statement::Definition(stmt) => self.visit_definition(stmt),
Statement::Expression(stmt) => self.visit_expression_statement(stmt),
Statement::Finalize(stmt) => self.visit_finalize(stmt),
Statement::Increment(stmt) => self.visit_increment(stmt),
Statement::Iteration(stmt) => self.visit_iteration(stmt),
Expand Down Expand Up @@ -167,6 +173,10 @@ pub trait StatementVisitor<'a>: ExpressionVisitor<'a> {
self.visit_expression(&input.value, &Default::default());
}

fn visit_expression_statement(&mut self, input: &'a ExpressionStatement) {
self.visit_expression(&input.expression, &Default::default());
}

fn visit_finalize(&mut self, input: &'a FinalizeStatement) {
input.arguments.iter().for_each(|expr| {
self.visit_expression(expr, &Default::default());
Expand Down
Loading

0 comments on commit 801df56

Please sign in to comment.