diff --git a/compiler/passes/src/code_generation/visit_expressions.rs b/compiler/passes/src/code_generation/visit_expressions.rs index c1d1a130fe..665803dcfa 100644 --- a/compiler/passes/src/code_generation/visit_expressions.rs +++ b/compiler/passes/src/code_generation/visit_expressions.rs @@ -16,7 +16,10 @@ use crate::CodeGenerator; -use leo_ast::{BinaryExpression, BinaryOperation, CallExpression, ErrExpression, Expression, Identifier, TernaryExpression, UnaryExpression, UnaryOperation, LiteralExpression, CircuitInitExpression, AccessExpression, MemberAccess}; +use leo_ast::{ + AccessExpression, BinaryExpression, BinaryOperation, CallExpression, CircuitInitExpression, ErrExpression, + Expression, Identifier, LiteralExpression, MemberAccess, TernaryExpression, UnaryExpression, UnaryOperation, +}; /// Implement the necessary methods to visit nodes in the AST. // Note: We opt for this option instead of using `Visitor` and `Director` because this pass requires @@ -184,11 +187,7 @@ impl<'a> CodeGenerator<'a> { fn visit_member_access(&mut self, input: &'a MemberAccess) -> (String, String) { let (inner_circuit, _inner_instructions) = self.visit_expression(&input.inner); - let member_access_instruction = format!( - "{}.{}", - inner_circuit, - input.name - ); + let member_access_instruction = format!("{}.{}", inner_circuit, input.name); (member_access_instruction, String::new()) } @@ -197,7 +196,7 @@ impl<'a> CodeGenerator<'a> { match input { AccessExpression::Member(access) => self.visit_member_access(access), AccessExpression::AssociatedConstant(_) => todo!(), - AccessExpression::AssociatedFunction(_) => todo!() + AccessExpression::AssociatedFunction(_) => todo!(), } } diff --git a/compiler/passes/src/code_generation/visit_program.rs b/compiler/passes/src/code_generation/visit_program.rs index 7a6674be9b..9d2a969538 100644 --- a/compiler/passes/src/code_generation/visit_program.rs +++ b/compiler/passes/src/code_generation/visit_program.rs @@ -26,20 +26,24 @@ impl<'a> CodeGenerator<'a> { let mut program_string = String::new(); // Visit each `Circuit` or `Record` in the Leo AST and produce a bytecode circuit. - program_string.push_str(&input - .circuits - .values() - .map(|circuit| self.visit_circuit_or_record(circuit)) - .join("\n")); + program_string.push_str( + &input + .circuits + .values() + .map(|circuit| self.visit_circuit_or_record(circuit)) + .join("\n"), + ); program_string.push_str("\n"); // Visit each `Function` in the Leo AST and produce a bytecode function. - program_string.push_str(&input - .functions - .values() - .map(|function| self.visit_function(function)) - .join("\n")); + program_string.push_str( + &input + .functions + .values() + .map(|function| self.visit_function(function)) + .join("\n"), + ); program_string } @@ -54,44 +58,39 @@ impl<'a> CodeGenerator<'a> { fn visit_circuit(&mut self, circuit: &'a Circuit) -> String { // Add private symbol to composite types. - self.composite_mapping.insert(&circuit.identifier.name, String::from("private")); // todo: private by default here. + self.composite_mapping + .insert(&circuit.identifier.name, String::from("private")); // todo: private by default here. - let mut output_string = - format!("interface {}:\n", circuit.identifier.to_string().to_lowercase()); // todo: check if this is safe from name conflicts. + let mut output_string = format!("interface {}:\n", circuit.identifier.to_string().to_lowercase()); // todo: check if this is safe from name conflicts. // Construct and append the record variables. for var in circuit.members.iter() { let (name, type_) = match var { - CircuitMember::CircuitVariable(name, type_) => (name, type_) + CircuitMember::CircuitVariable(name, type_) => (name, type_), }; - output_string.push_str(&format!( - " {} as {};\n", - name, - type_, - )) + output_string.push_str(&format!(" {} as {};\n", name, type_,)) } - output_string } fn visit_record(&mut self, record: &'a Circuit) -> String { // Add record symbol to composite types. let mut output_string = String::from("record"); - self.composite_mapping.insert(&record.identifier.name, output_string.clone()); - output_string.push_str( &format!(" {}:\n", record.identifier.to_string().to_lowercase())); // todo: check if this is safe from name conflicts. + self.composite_mapping + .insert(&record.identifier.name, output_string.clone()); + output_string.push_str(&format!(" {}:\n", record.identifier.to_string().to_lowercase())); // todo: check if this is safe from name conflicts. // Construct and append the record variables. for var in record.members.iter() { let (name, type_) = match var { - CircuitMember::CircuitVariable(name, type_) => (name, type_) + CircuitMember::CircuitVariable(name, type_) => (name, type_), }; output_string.push_str(&format!( " {} as {}.private;\n", // todo: CAUTION private record variables only. - name, - type_, + name, type_, )) } @@ -115,12 +114,9 @@ impl<'a> CodeGenerator<'a> { self.variable_mapping .insert(&input.get_variable().identifier.name, register_string.clone()); - let type_string = self.visit_type_with_visibility(&input.get_variable().type_, Some(input.get_variable().mode())); - function_string.push_str(&format!( - " input {} as {};\n", - register_string, - type_string, - )) + let type_string = + self.visit_type_with_visibility(&input.get_variable().type_, Some(input.get_variable().mode())); + function_string.push_str(&format!(" input {} as {};\n", register_string, type_string,)) } // Construct and append the function body. diff --git a/compiler/passes/src/code_generation/visit_type.rs b/compiler/passes/src/code_generation/visit_type.rs index 50ca2b9447..4a29d7e470 100644 --- a/compiler/passes/src/code_generation/visit_type.rs +++ b/compiler/passes/src/code_generation/visit_type.rs @@ -39,7 +39,6 @@ impl<'a> CodeGenerator<'a> { } } - pub(crate) fn visit_type_with_visibility(&mut self, input: &'a Type, visibility: Option) -> String { let mut return_type = self.visit_type(input); diff --git a/leo/commands/build.rs b/leo/commands/build.rs index 6105575632..9d7b150ba2 100644 --- a/leo/commands/build.rs +++ b/leo/commands/build.rs @@ -238,4 +238,4 @@ impl Command for Build { Ok((program.input_ast, program.ast, checksum_differs)) } -} \ No newline at end of file +} diff --git a/leo/commands/clean.rs b/leo/commands/clean.rs index 80cfe8e90c..79b24def79 100644 --- a/leo/commands/clean.rs +++ b/leo/commands/clean.rs @@ -16,7 +16,9 @@ use crate::{commands::Command, context::Context}; use leo_errors::Result; -use leo_package::outputs::{AleoFile, ChecksumFile, CircuitFile, ProofFile, ProvingKeyFile, Snapshot, SnapshotFile, VerificationKeyFile}; +use leo_package::outputs::{ + AleoFile, ChecksumFile, CircuitFile, ProofFile, ProvingKeyFile, Snapshot, SnapshotFile, VerificationKeyFile, +}; use clap::StructOpt; use tracing::span::Span; diff --git a/leo/main.rs b/leo/main.rs index 7705019fa8..9633df3c7b 100644 --- a/leo/main.rs +++ b/leo/main.rs @@ -84,7 +84,6 @@ enum CommandOpts { #[structopt(flatten)] command: Clean, }, - // // #[structopt(about = "Run a program setup")] // Setup { diff --git a/leo/package/src/outputs/aleo.rs b/leo/package/src/outputs/aleo.rs index 91b252a0ad..de7dd56ae7 100644 --- a/leo/package/src/outputs/aleo.rs +++ b/leo/package/src/outputs/aleo.rs @@ -48,7 +48,7 @@ impl AleoFile { path.exists() } - /// Reads the aleo from the given file path if it exists. + /// Reads the aleo file from the given file path if it exists. pub fn read_from(&self, path: &Path) -> Result { let path = self.setup_file_path(path); @@ -57,7 +57,7 @@ impl AleoFile { Ok(string) } - /// Writes the given aleo to a file. + /// Writes the given aleo string to a file. pub fn write_to(&self, path: &Path, aleo: String) -> Result<()> { let path = self.setup_file_path(path); let mut file = File::create(&path).map_err(PackageError::io_error_aleo_file)?;