Regen expectations

This commit is contained in:
Pranav Gaddamadugu 2023-10-13 16:13:20 -04:00 committed by Pranav Gaddamadugu
parent 6756320fd8
commit 59dfeb9d57
16 changed files with 23 additions and 96 deletions

View File

@ -20,7 +20,6 @@ use leo_ast::{Function, Program, ProgramId};
use leo_span::Symbol;
use indexmap::IndexMap;
use snarkvm_console::program::Access;
pub struct CodeGenerator<'a> {
/// The symbol table for the program.

View File

@ -170,7 +170,7 @@ impl<'a> CodeGenerator<'a> {
Some(Type::Array(array_type)) => Type::Array(array_type),
_ => unreachable!("All types should be known at this phase of compilation"),
};
let array_type: String = self.visit_type(&array_type);
let array_type: String = Self::visit_type(&array_type);
let array_instruction =
format!(" cast {expression_operands} into {destination_register} as {};\n", array_type);

View File

@ -130,7 +130,7 @@ impl<'a> CodeGenerator<'a> {
// Construct and append the record variables.
for var in struct_.members.iter() {
writeln!(output_string, " {} as {};", var.identifier, self.visit_type(&var.type_),)
writeln!(output_string, " {} as {};", var.identifier, Self::visit_type(&var.type_),)
.expect("failed to write to string");
}
@ -154,7 +154,7 @@ impl<'a> CodeGenerator<'a> {
output_string,
" {} as {}.{mode};", // todo: CAUTION private record variables only.
var.identifier,
self.visit_type(&var.type_)
Self::visit_type(&var.type_)
)
.expect("failed to write to string");
}

View File

@ -19,7 +19,7 @@ use crate::CodeGenerator;
use leo_ast::{Mode, Type};
impl<'a> CodeGenerator<'a> {
pub(crate) fn visit_type(&mut self, input: &Type) -> String {
pub(crate) fn visit_type(input: &Type) -> String {
match input {
Type::Address
| Type::Boolean
@ -31,7 +31,7 @@ impl<'a> CodeGenerator<'a> {
| Type::Identifier(..)
| Type::Integer(..) => format!("{input}"),
Type::Array(array_type) => {
format!("[{}; {}u32]", self.visit_type(&array_type.element_type()), array_type.length())
format!("[{}; {}u32]", Self::visit_type(array_type.element_type()), array_type.length())
}
Type::Mapping(_) => {
unreachable!("Mapping types are not supported at this phase of compilation")
@ -52,8 +52,8 @@ impl<'a> CodeGenerator<'a> {
format!("{identifier}.record")
}
_ => match visibility {
Mode::None => self.visit_type(type_),
_ => format!("{}.{visibility}", self.visit_type(type_)),
Mode::None => Self::visit_type(type_),
_ => format!("{}.{visibility}", Self::visit_type(type_)),
},
}
}

View File

@ -17,10 +17,7 @@
use leo_ast::{NodeID, Type};
use indexmap::IndexMap;
use std::{
cell::{Ref, RefCell},
fmt::Display,
};
use std::cell::RefCell;
/// A mapping between node IDs and their types.
#[derive(Debug, Default, Clone)]

View File

@ -18,15 +18,12 @@ use crate::DeadCodeEliminator;
use leo_ast::{
AccessExpression,
ArrayAccess,
AssociatedFunction,
Expression,
ExpressionReconstructor,
Identifier,
MemberAccess,
StructExpression,
StructVariableInitializer,
TupleAccess,
Type,
};
use leo_span::sym;

View File

@ -15,24 +15,8 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::Destructurer;
use itertools::Itertools;
use leo_ast::{
AccessExpression,
ArrayAccess,
AssociatedFunction,
Expression,
ExpressionReconstructor,
Member,
MemberAccess,
Node,
Statement,
StructExpression,
StructVariableInitializer,
TernaryExpression,
TupleAccess,
Type,
};
use leo_ast::{Expression, ExpressionReconstructor, Statement, TupleAccess};
impl ExpressionReconstructor for Destructurer<'_> {
type AdditionalOutput = Vec<Statement>;

View File

@ -16,6 +16,6 @@
use crate::Destructurer;
use leo_ast::{Finalize, Function, ProgramReconstructor, StatementReconstructor, Type};
use leo_ast::ProgramReconstructor;
impl ProgramReconstructor for Destructurer<'_> {}

View File

@ -15,17 +15,9 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::Destructurer;
use itertools::Itertools;
use std::borrow::Borrow;
use leo_ast::{
AccessExpression,
AssertStatement,
AssertVariant,
AssignStatement,
AssociatedFunction,
BinaryExpression,
BinaryOperation,
Block,
ConditionalStatement,
ConsoleStatement,
@ -40,10 +32,9 @@ use leo_ast::{
StatementReconstructor,
TupleExpression,
Type,
UnaryExpression,
UnaryOperation,
};
use leo_span::sym;
use itertools::Itertools;
impl StatementReconstructor for Destructurer<'_> {
/// Flattens an assign statement, if necessary.

View File

@ -14,37 +14,9 @@
// 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 crate::{Assigner, SymbolTable, TypeTable};
use crate::{Assigner, TypeTable};
use leo_ast::{
AccessExpression,
ArrayAccess,
ArrayExpression,
ArrayType,
BinaryExpression,
BinaryOperation,
Block,
Expression,
ExpressionReconstructor,
Identifier,
IntegerType,
Literal,
Member,
MemberAccess,
Node,
NodeBuilder,
NonNegativeNumber,
ReturnStatement,
Statement,
Struct,
StructExpression,
StructVariableInitializer,
TernaryExpression,
TupleAccess,
TupleExpression,
TupleType,
Type,
};
use leo_ast::{Expression, Identifier, Node, NodeBuilder, Statement, TupleExpression};
use leo_span::Symbol;
use indexmap::IndexMap;

View File

@ -16,8 +16,6 @@
//! The destructuring pass traverses the AST and destructures tuples into individual variables.
//! This pass assumes that tuples have a depth of 1, which is ensured by the type checking pass.
//!
//! TODO(@d0cd)
mod destructure_expression;
@ -28,7 +26,7 @@ mod destructure_statement;
pub mod destructurer;
pub use destructurer::*;
use crate::{Assigner, Pass, SymbolTable, TypeTable};
use crate::{Assigner, Pass, TypeTable};
use leo_ast::{Ast, NodeBuilder, ProgramReconstructor};
use leo_errors::Result;

View File

@ -15,22 +15,15 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::Flattener;
use itertools::Itertools;
use leo_ast::{
AccessExpression,
ArrayAccess,
AssociatedFunction,
Expression,
ExpressionReconstructor,
Member,
MemberAccess,
Node,
Statement,
StructExpression,
StructVariableInitializer,
TernaryExpression,
TupleAccess,
Type,
};

View File

@ -16,7 +16,7 @@
use crate::Flattener;
use leo_ast::{Finalize, Function, ProgramReconstructor, StatementReconstructor, Type};
use leo_ast::{Finalize, Function, ProgramReconstructor, StatementReconstructor};
impl ProgramReconstructor for Flattener<'_> {
/// Flattens a function's body and finalize block, if it exists.

View File

@ -15,15 +15,11 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::Flattener;
use itertools::Itertools;
use std::borrow::Borrow;
use leo_ast::{
AccessExpression,
AssertStatement,
AssertVariant,
AssignStatement,
AssociatedFunction,
BinaryExpression,
BinaryOperation,
Block,
@ -32,18 +28,17 @@ use leo_ast::{
DefinitionStatement,
Expression,
ExpressionReconstructor,
Identifier,
IterationStatement,
Node,
ReturnStatement,
Statement,
StatementReconstructor,
TupleExpression,
Type,
UnaryExpression,
UnaryOperation,
};
use leo_span::sym;
use itertools::Itertools;
impl StatementReconstructor for Flattener<'_> {
/// Rewrites an assert statement into a flattened form.
@ -172,7 +167,7 @@ impl StatementReconstructor for Flattener<'_> {
/// Otherwise, the statement is returned as is.
fn reconstruct_assign(&mut self, assign: AssignStatement) -> (Statement, Self::AdditionalOutput) {
// Flatten the rhs of the assignment.
let (value, mut statements) = self.reconstruct_expression(assign.value);
let (value, statements) = self.reconstruct_expression(assign.value);
match (assign.place, &value) {
(Expression::Identifier(identifier), _) => (self.simple_assign_statement(identifier, value), statements),
(Expression::Tuple(tuple), expression) => {

View File

@ -16,7 +16,7 @@
use crate::{Assigner, RenameTable, SymbolTable, TypeTable};
use leo_ast::{AssignStatement, Expression, Identifier, Node, NodeBuilder, Statement};
use leo_ast::{Expression, Identifier, Node, NodeBuilder, Statement};
pub struct StaticSingleAssigner<'a> {
/// A counter used to generate unique node IDs.

View File

@ -16,12 +16,13 @@
use crate::{CallGraph, StructGraph, SymbolTable, TypeTable};
use leo_ast::{ArrayType, CoreConstant, CoreFunction, Identifier, IntegerType, MappingType, Node, Type, Variant};
use leo_ast::{CoreConstant, CoreFunction, Identifier, IntegerType, MappingType, Node, Type, Variant};
use leo_errors::{emitter::Handler, TypeCheckerError};
use leo_span::{Span, Symbol};
use itertools::Itertools;
use snarkvm_console::network::{Network, Testnet3};
use itertools::Itertools;
use std::cell::RefCell;
pub struct TypeChecker<'a> {