mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-12-25 03:04:13 +03:00
cargo fmt
This commit is contained in:
parent
5c8fa2bd02
commit
f3b87b5ccb
@ -16,7 +16,10 @@
|
|||||||
|
|
||||||
use crate::CodeGenerator;
|
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.
|
/// 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
|
// 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) {
|
fn visit_member_access(&mut self, input: &'a MemberAccess) -> (String, String) {
|
||||||
let (inner_circuit, _inner_instructions) = self.visit_expression(&input.inner);
|
let (inner_circuit, _inner_instructions) = self.visit_expression(&input.inner);
|
||||||
let member_access_instruction = format!(
|
let member_access_instruction = format!("{}.{}", inner_circuit, input.name);
|
||||||
"{}.{}",
|
|
||||||
inner_circuit,
|
|
||||||
input.name
|
|
||||||
);
|
|
||||||
|
|
||||||
(member_access_instruction, String::new())
|
(member_access_instruction, String::new())
|
||||||
}
|
}
|
||||||
@ -197,7 +196,7 @@ impl<'a> CodeGenerator<'a> {
|
|||||||
match input {
|
match input {
|
||||||
AccessExpression::Member(access) => self.visit_member_access(access),
|
AccessExpression::Member(access) => self.visit_member_access(access),
|
||||||
AccessExpression::AssociatedConstant(_) => todo!(),
|
AccessExpression::AssociatedConstant(_) => todo!(),
|
||||||
AccessExpression::AssociatedFunction(_) => todo!()
|
AccessExpression::AssociatedFunction(_) => todo!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,20 +26,24 @@ impl<'a> CodeGenerator<'a> {
|
|||||||
let mut program_string = String::new();
|
let mut program_string = String::new();
|
||||||
|
|
||||||
// Visit each `Circuit` or `Record` in the Leo AST and produce a bytecode circuit.
|
// Visit each `Circuit` or `Record` in the Leo AST and produce a bytecode circuit.
|
||||||
program_string.push_str(&input
|
program_string.push_str(
|
||||||
|
&input
|
||||||
.circuits
|
.circuits
|
||||||
.values()
|
.values()
|
||||||
.map(|circuit| self.visit_circuit_or_record(circuit))
|
.map(|circuit| self.visit_circuit_or_record(circuit))
|
||||||
.join("\n"));
|
.join("\n"),
|
||||||
|
);
|
||||||
|
|
||||||
program_string.push_str("\n");
|
program_string.push_str("\n");
|
||||||
|
|
||||||
// Visit each `Function` in the Leo AST and produce a bytecode function.
|
// Visit each `Function` in the Leo AST and produce a bytecode function.
|
||||||
program_string.push_str(&input
|
program_string.push_str(
|
||||||
|
&input
|
||||||
.functions
|
.functions
|
||||||
.values()
|
.values()
|
||||||
.map(|function| self.visit_function(function))
|
.map(|function| self.visit_function(function))
|
||||||
.join("\n"));
|
.join("\n"),
|
||||||
|
);
|
||||||
|
|
||||||
program_string
|
program_string
|
||||||
}
|
}
|
||||||
@ -54,44 +58,39 @@ impl<'a> CodeGenerator<'a> {
|
|||||||
|
|
||||||
fn visit_circuit(&mut self, circuit: &'a Circuit) -> String {
|
fn visit_circuit(&mut self, circuit: &'a Circuit) -> String {
|
||||||
// Add private symbol to composite types.
|
// 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 =
|
let mut output_string = format!("interface {}:\n", circuit.identifier.to_string().to_lowercase()); // todo: check if this is safe from name conflicts.
|
||||||
format!("interface {}:\n", circuit.identifier.to_string().to_lowercase()); // todo: check if this is safe from name conflicts.
|
|
||||||
|
|
||||||
// Construct and append the record variables.
|
// Construct and append the record variables.
|
||||||
for var in circuit.members.iter() {
|
for var in circuit.members.iter() {
|
||||||
let (name, type_) = match var {
|
let (name, type_) = match var {
|
||||||
CircuitMember::CircuitVariable(name, type_) => (name, type_)
|
CircuitMember::CircuitVariable(name, type_) => (name, type_),
|
||||||
};
|
};
|
||||||
|
|
||||||
output_string.push_str(&format!(
|
output_string.push_str(&format!(" {} as {};\n", name, type_,))
|
||||||
" {} as {};\n",
|
|
||||||
name,
|
|
||||||
type_,
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
output_string
|
output_string
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_record(&mut self, record: &'a Circuit) -> String {
|
fn visit_record(&mut self, record: &'a Circuit) -> String {
|
||||||
// Add record symbol to composite types.
|
// Add record symbol to composite types.
|
||||||
let mut output_string = String::from("record");
|
let mut output_string = String::from("record");
|
||||||
self.composite_mapping.insert(&record.identifier.name, output_string.clone());
|
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.
|
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.
|
// Construct and append the record variables.
|
||||||
for var in record.members.iter() {
|
for var in record.members.iter() {
|
||||||
let (name, type_) = match var {
|
let (name, type_) = match var {
|
||||||
CircuitMember::CircuitVariable(name, type_) => (name, type_)
|
CircuitMember::CircuitVariable(name, type_) => (name, type_),
|
||||||
};
|
};
|
||||||
|
|
||||||
output_string.push_str(&format!(
|
output_string.push_str(&format!(
|
||||||
" {} as {}.private;\n", // todo: CAUTION private record variables only.
|
" {} as {}.private;\n", // todo: CAUTION private record variables only.
|
||||||
name,
|
name, type_,
|
||||||
type_,
|
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,12 +114,9 @@ impl<'a> CodeGenerator<'a> {
|
|||||||
self.variable_mapping
|
self.variable_mapping
|
||||||
.insert(&input.get_variable().identifier.name, register_string.clone());
|
.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()));
|
let type_string =
|
||||||
function_string.push_str(&format!(
|
self.visit_type_with_visibility(&input.get_variable().type_, Some(input.get_variable().mode()));
|
||||||
" input {} as {};\n",
|
function_string.push_str(&format!(" input {} as {};\n", register_string, type_string,))
|
||||||
register_string,
|
|
||||||
type_string,
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Construct and append the function body.
|
// 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 {
|
pub(crate) fn visit_type_with_visibility(&mut self, input: &'a Type, visibility: Option<ParamMode>) -> String {
|
||||||
let mut return_type = self.visit_type(input);
|
let mut return_type = self.visit_type(input);
|
||||||
|
|
||||||
|
@ -16,7 +16,9 @@
|
|||||||
|
|
||||||
use crate::{commands::Command, context::Context};
|
use crate::{commands::Command, context::Context};
|
||||||
use leo_errors::Result;
|
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 clap::StructOpt;
|
||||||
use tracing::span::Span;
|
use tracing::span::Span;
|
||||||
|
@ -84,7 +84,6 @@ enum CommandOpts {
|
|||||||
#[structopt(flatten)]
|
#[structopt(flatten)]
|
||||||
command: Clean,
|
command: Clean,
|
||||||
},
|
},
|
||||||
|
|
||||||
//
|
//
|
||||||
// #[structopt(about = "Run a program setup")]
|
// #[structopt(about = "Run a program setup")]
|
||||||
// Setup {
|
// Setup {
|
||||||
|
@ -48,7 +48,7 @@ impl AleoFile {
|
|||||||
path.exists()
|
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> {
|
pub fn read_from(&self, path: &Path) -> Result<String> {
|
||||||
let path = self.setup_file_path(path);
|
let path = self.setup_file_path(path);
|
||||||
|
|
||||||
@ -57,7 +57,7 @@ impl AleoFile {
|
|||||||
Ok(string)
|
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<()> {
|
pub fn write_to(&self, path: &Path, aleo: String) -> Result<()> {
|
||||||
let path = self.setup_file_path(path);
|
let path = self.setup_file_path(path);
|
||||||
let mut file = File::create(&path).map_err(PackageError::io_error_aleo_file)?;
|
let mut file = File::create(&path).map_err(PackageError::io_error_aleo_file)?;
|
||||||
|
Loading…
Reference in New Issue
Block a user