From 8702ad5ccd989140760d32ec111fb0a329a46c9c Mon Sep 17 00:00:00 2001 From: howardwu Date: Mon, 20 Apr 2020 21:51:57 -0700 Subject: [PATCH] Clean up --- src/leo.pest | 9 ++++++--- src/lib.rs | 7 ++----- src/main.rs | 24 +++++++++++------------- src/program/constraints/integer.rs | 2 +- src/program/mod.rs | 6 +++--- 5 files changed, 23 insertions(+), 25 deletions(-) diff --git a/src/leo.pest b/src/leo.pest index 7368e02436..ff21c848ff 100644 --- a/src/leo.pest +++ b/src/leo.pest @@ -1,4 +1,3 @@ -// file = { SOI ~ NEWLINE* ~ import_section* ~ NEWLINE* ~ EOI } /// Visibility visibility_public = { "public" } @@ -48,6 +47,7 @@ operation_binary = _ { // operation_div_assign = { "/=" } /// Types + ty_u32 = {"u32"} ty_field = {"fe"} ty_bool = {"bool"} @@ -59,6 +59,7 @@ ty = {ty_array | ty_basic | ty_struct} type_list = _{(ty ~ ("," ~ ty)*)?} /// Values + value_number = @{ "-"? ~ ("0" | ASCII_NONZERO_DIGIT ~ ASCII_DIGIT*)} value_u32 = { value_number ~ ty_u32} value_field = { value_number ~ ty_field } @@ -81,12 +82,15 @@ expression_primitive = { value | variable } from_expression = { expression } to_expression = { expression } + range = { from_expression? ~ ".." ~ to_expression } range_or_expression = { range | expression } + access_array = { "[" ~ range_or_expression ~ "]" } access_call = { "(" ~ expression_tuple ~ ")" } access_member = { "." ~ variable } access = { access_array | access_call | access_member } + expression_postfix = { variable ~ access+ } assignee_access = { access_array | access_member } @@ -117,7 +121,6 @@ expression_conditional = { "if" ~ expression ~ "then" ~ expression ~ "else" ~ ex /// Expressions -// Consider structs, conditionals, postfix, primary, inline array, array initializer, and unary expression_term = { ("(" ~ expression ~ ")") | expression_inline_struct @@ -170,6 +173,6 @@ from_import = { "from" ~ "\"" ~ import_source ~ "\"" ~ "import" ~ variable ~ ("a main_import = {"import" ~ "\"" ~ import_source ~ "\"" ~ ("as" ~ variable)? ~ NEWLINE+} import_source = @{(!"\"" ~ ANY)*} -/// Abstract Syntax Tree File +/// Program File file = { SOI ~ NEWLINE* ~ import* ~ NEWLINE* ~ struct_definition* ~ NEWLINE* ~ function_definition* ~ NEWLINE* ~ EOI } diff --git a/src/lib.rs b/src/lib.rs index 6bcefc864d..2a09da9bab 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,14 +1,11 @@ +extern crate from_pest; extern crate pest; +extern crate pest_ast; #[macro_use] extern crate pest_derive; -extern crate from_pest; -// #[macro_use] -extern crate pest_ast; - #[macro_use] extern crate lazy_static; pub mod ast; - pub mod program; diff --git a/src/main.rs b/src/main.rs index 654b3c12e9..5054fee86a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,25 +1,23 @@ use leo::*; +use snarkos_algorithms::snark::{ + create_random_proof, generate_random_parameters, prepare_verifying_key, verify_proof, +}; +use snarkos_curves::bls12_377::{Bls12_377, Fr}; +use snarkos_errors::gadgets::SynthesisError; +use snarkos_models::{ + curves::{Field, PrimeField}, + gadgets::r1cs::{ConstraintSynthesizer, ConstraintSystem} +}; + use from_pest::FromPest; +use rand::thread_rng; use std::{ fs, marker::PhantomData, time::{Duration, Instant}, }; -use snarkos_curves::bls12_377::{Bls12_377, Fr}; -use snarkos_errors::gadgets::SynthesisError; -use snarkos_models::curves::{Field, PrimeField}; -use snarkos_models::gadgets::r1cs::{ConstraintSynthesizer, ConstraintSystem}; - -use snarkos_algorithms::snark::{ - create_random_proof, generate_random_parameters, prepare_verifying_key, verify_proof, -}; - -use rand::thread_rng; - -// use std::env; - pub struct Benchmark { _engine: PhantomData, } diff --git a/src/program/constraints/integer.rs b/src/program/constraints/integer.rs index 8c6696b1bd..7b2cf67abd 100644 --- a/src/program/constraints/integer.rs +++ b/src/program/constraints/integer.rs @@ -10,7 +10,7 @@ use crate::program::{Integer, IntegerExpression, IntegerSpreadOrExpression, Vari use snarkos_models::curves::{Field, PrimeField}; use snarkos_models::gadgets::{ r1cs::ConstraintSystem, - utilities::{alloc::AllocGadget, boolean::Boolean, eq::ConditionalEqGadget, uint32::UInt32}, + utilities::{boolean::Boolean, eq::ConditionalEqGadget, uint32::UInt32}, }; impl> ResolvedProgram { diff --git a/src/program/mod.rs b/src/program/mod.rs index c861ac3753..274f6b930f 100644 --- a/src/program/mod.rs +++ b/src/program/mod.rs @@ -4,15 +4,15 @@ //! @author Collin Chin //! @date 2020 -pub mod types; -pub use self::types::*; - pub mod constraints; pub use self::constraints::*; pub mod imports; pub use self::imports::*; +pub mod types; +pub use self::types::*; + pub mod types_display; pub use self::types_display::*;