Migrates ast to leo-ast module

This commit is contained in:
howardwu 2020-06-06 23:17:40 -07:00
parent e985027e86
commit a72a333877
19 changed files with 93 additions and 10 deletions

12
Cargo.lock generated
View File

@ -497,6 +497,17 @@ dependencies = [
"toml",
]
[[package]]
name = "leo-ast"
version = "0.1.0"
dependencies = [
"from-pest",
"lazy_static",
"pest",
"pest-ast",
"pest_derive",
]
[[package]]
name = "leo-compiler"
version = "0.1.0"
@ -504,6 +515,7 @@ dependencies = [
"from-pest",
"hex",
"lazy_static",
"leo-ast",
"log",
"pest",
"pest-ast",

View File

@ -13,7 +13,7 @@ name = "leo"
path = "leo/main.rs"
[workspace]
members = [ "compiler" ]
members = [ "ast", "compiler" ]
[dependencies]
leo-compiler = { path = "compiler", version = "0.1.0" }

12
ast/Cargo.toml Normal file
View File

@ -0,0 +1,12 @@
[package]
name = "leo-ast"
version = "0.1.0"
authors = ["howardwu <howardwu@berkeley.edu>"]
edition = "2018"
[dependencies]
from-pest = { version = "0.3.1" }
lazy_static = { version = "1.3.0" }
pest = { version = "2.0" }
pest-ast = { version = "0.3.3" }
pest_derive = { version = "2.0" }

1
ast/README.md Normal file
View File

@ -0,0 +1 @@
# leo-ast

View File

@ -0,0 +1,10 @@
#[derive(Clone, Debug, FromPest, PartialEq)]
#[pest_ast(rule(Rule::statement_for))]
pub struct ForStatement<'ast> {
pub index: Identifier<'ast>,
pub start: Expression<'ast>,
pub stop: Expression<'ast>,
pub statements: Vec<Statement<'ast>>,
#[pest_ast(outer())]
pub span: Span<'ast>,
}

11
ast/src/lib.rs Normal file
View File

@ -0,0 +1,11 @@
#[macro_use]
extern crate lazy_static;
#[macro_use]
extern crate pest_derive;
extern crate from_pest;
extern crate pest;
extern crate pest_ast;
pub mod ast;
pub use ast::*;

View File

@ -5,6 +5,8 @@ authors = ["The Aleo Team <hello@aleo.org>"]
edition = "2018"
[dependencies]
leo-ast = { path = "../ast", version = "0.1.0" }
snarkos-algorithms = { git = "ssh://git@github.com/AleoHQ/snarkOS.git", version = "0.8.0" }
snarkos-curves = { git = "ssh://git@github.com/AleoHQ/snarkOS.git", version = "0.8.0" }
snarkos-errors = { git = "ssh://git@github.com/AleoHQ/snarkOS.git", version = "0.8.0" }

View File

@ -1,11 +1,11 @@
//! Compiles a Leo program from a file path.
use crate::{
ast,
constraints::{generate_constraints, generate_test_constraints, ConstrainedValue},
errors::CompilerError,
GroupType, InputValue, Program,
};
use leo_ast::ast;
use snarkos_errors::gadgets::SynthesisError;
use snarkos_models::{

View File

@ -1,11 +1,11 @@
use crate::{
ast,
constraints::{ConstrainedProgram, ConstrainedValue},
errors::constraints::ImportError,
new_scope,
types::Program,
GroupType, Import,
};
use leo_ast::ast;
use from_pest::FromPest;
use snarkos_models::{

View File

@ -1,4 +1,4 @@
use crate::ast::Rule;
use leo_ast::ast::Rule;
use pest::error::Error;

View File

@ -1,5 +1,5 @@
use crate::ast::Rule;
use crate::errors::{FunctionError, ImportError, IntegerError, SyntaxError};
use leo_ast::ast::Rule;
use pest::error::Error;
use std::{io, path::PathBuf};

View File

@ -14,8 +14,6 @@ extern crate pest_ast;
#[macro_use]
extern crate pest_derive;
pub mod ast;
pub mod compiler;
pub mod constraints;

View File

@ -1,6 +1,7 @@
//! Logic to convert from an abstract syntax tree (ast) representation to a Leo program.
use crate::{ast, types, Import, ImportSymbol};
use crate::{types, Import, ImportSymbol};
use leo_ast::ast;
use snarkos_models::gadgets::utilities::{
boolean::Boolean,

2
examples/fibonacci/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/output
/.leo

View File

@ -0,0 +1,3 @@
[package]
name = "fibonacci"
version = "0.1.0"

View File

@ -0,0 +1,14 @@
function fibonacci(i: u32) -> u32 {
if i == 0 {
return 0
} else if i == 1 {
return 1
} else {
return fibonacci(i - 1) + fibonacci(i - 2)
}
}
// The 'fibonacci' main function.
function main() -> u32 {
return fibonacci(1)
}

View File

@ -1,5 +1,22 @@
circuit PedersenHash {
parameters: u32[512]
static function new(parameters: u32[512]) -> Self {
return Self { parameters: parameters }
}
function hash(bits: bool[512]) -> u32 {
let mut digest: u32 = 0;
for i in 0..512 {
let base = if bits[i] ? parameters[i] : 0u32;
digest += base;
}
return digest
}
}
// The 'pedersen_hash' main function.
function main() -> u32 {
let a = 1 / 0;
return a
let parameters = [0u32; 512];
let pedersen = PedersenHash::new(parameters);
let input: bool[512] = [true; 512];
return pedersen.hash(input)
}