mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-12-24 18:52:58 +03:00
cargo fmt
This commit is contained in:
parent
5c8fa2bd02
commit
f3b87b5ccb
@ -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!(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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.
|
||||
|
@ -39,7 +39,6 @@ impl<'a> CodeGenerator<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub(crate) fn visit_type_with_visibility(&mut self, input: &'a Type, visibility: Option<ParamMode>) -> String {
|
||||
let mut return_type = self.visit_type(input);
|
||||
|
||||
|
@ -238,4 +238,4 @@ impl Command for Build {
|
||||
|
||||
Ok((program.input_ast, program.ast, checksum_differs))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -84,7 +84,6 @@ enum CommandOpts {
|
||||
#[structopt(flatten)]
|
||||
command: Clean,
|
||||
},
|
||||
|
||||
//
|
||||
// #[structopt(about = "Run a program setup")]
|
||||
// Setup {
|
||||
|
@ -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<String> {
|
||||
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)?;
|
||||
|
Loading…
Reference in New Issue
Block a user