mirror of
https://github.com/AleoHQ/leo.git
synced 2024-12-25 18:42:26 +03:00
split up input loading and parsing in compiler
This commit is contained in:
parent
59766d0740
commit
824a6059fb
@ -92,8 +92,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> Compiler<F, G> {
|
|||||||
|
|
||||||
fn load_program(&mut self) -> Result<String, CompilerError> {
|
fn load_program(&mut self) -> Result<String, CompilerError> {
|
||||||
// Load the program syntax tree from the file path
|
// Load the program syntax tree from the file path
|
||||||
let file_path = &self.main_file_path;
|
Ok(LeoParser::load_file(&self.main_file_path)?)
|
||||||
Ok(LeoParser::load_file(file_path)?)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_program(&mut self, program_string: &str) -> Result<(), CompilerError> {
|
pub fn parse_program(&mut self, program_string: &str) -> Result<(), CompilerError> {
|
||||||
@ -111,16 +110,10 @@ impl<F: Field + PrimeField, G: GroupType<F>> Compiler<F, G> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_inputs(&mut self, file_path: &PathBuf) -> Result<(), CompilerError> {
|
pub fn parse_inputs(&mut self, input_file_path: &PathBuf, input_file_string: &str) -> Result<(), CompilerError> {
|
||||||
let mut path = file_path.clone();
|
let syntax_tree = LeoInputsParser::parse_file(input_file_path, input_file_string)?;
|
||||||
path.push("inputs");
|
|
||||||
path.push("inputs.leo");
|
|
||||||
|
|
||||||
let input_file = &LeoInputsParser::load_file(&path)?;
|
// Check number/order of private parameters here
|
||||||
let syntax_tree = LeoInputsParser::parse_file(&path, input_file)?;
|
|
||||||
// println!("{:?}", syntax_tree);
|
|
||||||
|
|
||||||
// Check number of private parameters here
|
|
||||||
self.program_inputs = Inputs::from_inputs_file(syntax_tree)?;
|
self.program_inputs = Inputs::from_inputs_file(syntax_tree)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -19,6 +19,7 @@ use leo_compiler::{
|
|||||||
|
|
||||||
use snarkos_curves::edwards_bls12::Fq;
|
use snarkos_curves::edwards_bls12::Fq;
|
||||||
use snarkos_models::gadgets::r1cs::TestConstraintSystem;
|
use snarkos_models::gadgets::r1cs::TestConstraintSystem;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
pub type EdwardsTestCompiler = Compiler<Fq, EdwardsGroupType>;
|
pub type EdwardsTestCompiler = Compiler<Fq, EdwardsGroupType>;
|
||||||
pub type EdwardsConstrainedValue = ConstrainedValue<Fq, EdwardsGroupType>;
|
pub type EdwardsConstrainedValue = ConstrainedValue<Fq, EdwardsGroupType>;
|
||||||
@ -51,3 +52,13 @@ pub(crate) fn parse_program(bytes: &[u8]) -> Result<EdwardsTestCompiler, Compile
|
|||||||
|
|
||||||
Ok(compiler)
|
Ok(compiler)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn parse_inputs(bytes: &[u8]) -> Result<EdwardsTestCompiler, CompilerError> {
|
||||||
|
let program_string = String::from_utf8_lossy(bytes);
|
||||||
|
|
||||||
|
let mut compiler = EdwardsTestCompiler::new();
|
||||||
|
|
||||||
|
compiler.parse_inputs(&PathBuf::new(), &program_string)?;
|
||||||
|
|
||||||
|
Ok(compiler)
|
||||||
|
}
|
||||||
|
2
compiler/tests/syntax/inputs_semicolon.leo
Normal file
2
compiler/tests/syntax/inputs_semicolon.leo
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
[main]
|
||||||
|
a: private u32 = 5
|
@ -1,6 +1,7 @@
|
|||||||
use crate::parse_program;
|
use crate::{parse_inputs, parse_program};
|
||||||
use leo_ast::ParserError;
|
use leo_ast::ParserError;
|
||||||
use leo_compiler::errors::CompilerError;
|
use leo_compiler::errors::CompilerError;
|
||||||
|
use leo_inputs::InputParserError;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_semicolon() {
|
fn test_semicolon() {
|
||||||
@ -12,3 +13,14 @@ fn test_semicolon() {
|
|||||||
_ => panic!("test_semicolon failed the wrong expected error, should be a ParserError"),
|
_ => panic!("test_semicolon failed the wrong expected error, should be a ParserError"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn inputs_syntax_error() {
|
||||||
|
let bytes = include_bytes!("inputs_semicolon.leo");
|
||||||
|
let error = parse_inputs(bytes).err().unwrap();
|
||||||
|
|
||||||
|
match error {
|
||||||
|
CompilerError::InputParserError(InputParserError::SyntaxError(_)) => {}
|
||||||
|
_ => panic!("inputs syntax error should be a ParserError"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -9,8 +9,10 @@ use crate::{
|
|||||||
use snarkos_algorithms::snark::{create_random_proof, PreparedVerifyingKey, Proof};
|
use snarkos_algorithms::snark::{create_random_proof, PreparedVerifyingKey, Proof};
|
||||||
use snarkos_curves::bls12_377::Bls12_377;
|
use snarkos_curves::bls12_377::Bls12_377;
|
||||||
|
|
||||||
|
use crate::{directories::INPUTS_DIRECTORY_NAME, files::INPUTS_FILE_NAME};
|
||||||
use clap::ArgMatches;
|
use clap::ArgMatches;
|
||||||
use leo_compiler::{compiler::Compiler, edwards_bls12::EdwardsGroupType};
|
use leo_compiler::{compiler::Compiler, edwards_bls12::EdwardsGroupType};
|
||||||
|
use leo_inputs::LeoInputsParser;
|
||||||
use rand::thread_rng;
|
use rand::thread_rng;
|
||||||
use snarkos_curves::edwards_bls12::Fq;
|
use snarkos_curves::edwards_bls12::Fq;
|
||||||
use std::{convert::TryFrom, env::current_dir, time::Instant};
|
use std::{convert::TryFrom, env::current_dir, time::Instant};
|
||||||
@ -46,8 +48,14 @@ impl CLI for ProveCommand {
|
|||||||
let path = current_dir()?;
|
let path = current_dir()?;
|
||||||
let package_name = Manifest::try_from(&path)?.get_package_name();
|
let package_name = Manifest::try_from(&path)?.get_package_name();
|
||||||
|
|
||||||
|
// Construct the path to the inputs file in the inputs directory
|
||||||
|
let mut inputs_file_path = path.clone();
|
||||||
|
inputs_file_path.push(INPUTS_DIRECTORY_NAME);
|
||||||
|
inputs_file_path.push(INPUTS_FILE_NAME);
|
||||||
|
|
||||||
// Fetch private inputs here
|
// Fetch private inputs here
|
||||||
program.parse_inputs(&path)?;
|
let inputs_file_string = LeoInputsParser::load_file(&inputs_file_path)?;
|
||||||
|
program.parse_inputs(&inputs_file_path, &inputs_file_string)?;
|
||||||
|
|
||||||
// Start the timer
|
// Start the timer
|
||||||
let start = Instant::now();
|
let start = Instant::now();
|
||||||
|
@ -57,6 +57,12 @@ impl From<leo_compiler::errors::CompilerError> for CLIError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<leo_inputs::errors::InputParserError> for CLIError {
|
||||||
|
fn from(error: leo_inputs::errors::InputParserError) -> Self {
|
||||||
|
CLIError::Crate("leo_inputs", format!("{}", error))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl From<snarkos_errors::gadgets::SynthesisError> for CLIError {
|
impl From<snarkos_errors::gadgets::SynthesisError> for CLIError {
|
||||||
fn from(error: snarkos_errors::gadgets::SynthesisError) -> Self {
|
fn from(error: snarkos_errors::gadgets::SynthesisError) -> Self {
|
||||||
CLIError::Crate("snarkos_errors", format!("{}", error))
|
CLIError::Crate("snarkos_errors", format!("{}", error))
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
use crate::InputValue;
|
use crate::InputValue;
|
||||||
use leo_inputs::{types::IntegerType, InputParserError};
|
use leo_inputs::{types::IntegerType, InputParserError};
|
||||||
|
|
||||||
use snarkos_models::curves::{Field, PairingEngine};
|
use snarkos_models::curves::{Field, PairingEngine};
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ use leo_inputs::{
|
|||||||
types::{ArrayType, DataType, IntegerType, Type},
|
types::{ArrayType, DataType, IntegerType, Type},
|
||||||
values::{BooleanValue, FieldValue, GroupValue, NumberImplicitValue, NumberValue, Value},
|
values::{BooleanValue, FieldValue, GroupValue, NumberImplicitValue, NumberValue, Value},
|
||||||
};
|
};
|
||||||
|
|
||||||
use snarkos_models::curves::PairingEngine;
|
use snarkos_models::curves::PairingEngine;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
use crate::InputValue;
|
use crate::InputValue;
|
||||||
use leo_inputs::{common::visibility::Visibility, files::File, InputParserError};
|
use leo_inputs::{common::visibility::Visibility, files::File, InputParserError};
|
||||||
|
|
||||||
use snarkos_models::curves::PairingEngine;
|
use snarkos_models::curves::PairingEngine;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
Loading…
Reference in New Issue
Block a user