rename core-ast -> ast

This commit is contained in:
collin 2020-10-30 17:31:09 -07:00
parent ffcd93f781
commit a8c5885836
240 changed files with 233 additions and 233 deletions

42
Cargo.lock generated
View File

@ -1229,13 +1229,27 @@ version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
[[package]]
name = "leo-ast"
version = "1.0.3"
dependencies = [
"criterion",
"leo-grammar",
"leo-input",
"pest",
"serde",
"serde_json",
"snarkos-errors",
"snarkos-models",
]
[[package]]
name = "leo-compiler"
version = "1.0.3"
dependencies = [
"bincode",
"hex",
"leo-core-ast",
"leo-ast",
"leo-core-packages",
"leo-gadgets",
"leo-grammar",
@ -1264,25 +1278,11 @@ dependencies = [
"tracing-subscriber",
]
[[package]]
name = "leo-core-ast"
version = "1.0.3"
dependencies = [
"criterion",
"leo-grammar",
"leo-input",
"pest",
"serde",
"serde_json",
"snarkos-errors",
"snarkos-models",
]
[[package]]
name = "leo-core-packages"
version = "1.0.3"
dependencies = [
"leo-core-ast",
"leo-ast",
"leo-gadgets",
"rand",
"rand_xorshift",
@ -1327,7 +1327,7 @@ dependencies = [
name = "leo-imports"
version = "1.0.3"
dependencies = [
"leo-core-ast",
"leo-ast",
"leo-grammar",
"thiserror",
"tracing",
@ -1362,8 +1362,8 @@ dependencies = [
"env_logger 0.8.1",
"from-pest",
"lazy_static",
"leo-ast",
"leo-compiler",
"leo-core-ast",
"leo-gadgets",
"leo-imports",
"leo-input",
@ -1414,7 +1414,7 @@ dependencies = [
name = "leo-state"
version = "1.0.3"
dependencies = [
"leo-core-ast",
"leo-ast",
"leo-input",
"rand",
"rand_xorshift",
@ -1433,7 +1433,7 @@ dependencies = [
name = "leo-symbol-table"
version = "1.0.3"
dependencies = [
"leo-core-ast",
"leo-ast",
"leo-core-packages",
"leo-grammar",
"leo-imports",
@ -1445,7 +1445,7 @@ dependencies = [
name = "leo-type-inference"
version = "1.0.3"
dependencies = [
"leo-core-ast",
"leo-ast",
"leo-grammar",
"leo-imports",
"leo-symbol-table",

View File

@ -26,8 +26,8 @@ path = "leo/main.rs"
[workspace]
members = [
"ast",
"compiler",
"core-ast",
"core-packages",
"gadgets",
"grammar",
@ -40,12 +40,12 @@ members = [
"type-inference",
]
[dependencies.leo-compiler]
path = "./compiler"
[dependencies.leo-ast]
path = "./ast"
version = "1.0.3"
[dependencies.leo-core-ast]
path = "./core-ast"
[dependencies.leo-compiler]
path = "./compiler"
version = "1.0.3"
[dependencies.leo-gadgets]

View File

@ -1,5 +1,5 @@
[package]
name = "leo-core-ast"
name = "leo-ast"
version = "1.0.3"
authors = [ "The Aleo Team <hello@aleo.org>" ]
description = "Core AST of the Leo programming language"
@ -18,12 +18,12 @@ license = "GPL-3.0"
edition = "2018"
[[bin]]
name = "leo_core_ast"
name = "leo_ast"
path = "src/main.rs"
[[bench]]
name = "core_ast"
path = "benches/core_ast.rs"
name = "leo_ast"
path = "benches/leo_ast.rs"
harness = false
[dependencies.leo-grammar]

View File

@ -14,14 +14,14 @@
// You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use leo_core_ast::LeoCoreAst;
use leo_ast::LeoAst;
use leo_grammar::Grammar;
use criterion::{criterion_group, criterion_main, Criterion};
use std::{path::Path, time::Duration};
fn leo_core_ast<'ast>(ast: &Grammar<'ast>) -> LeoCoreAst {
LeoCoreAst::new("leo_core_tree", &ast)
fn leo_ast<'ast>(ast: &Grammar<'ast>) -> LeoAst {
LeoAst::new("leo_core_tree", &ast)
}
fn bench_big_if_else(c: &mut Criterion) {
@ -29,7 +29,7 @@ fn bench_big_if_else(c: &mut Criterion) {
let program_string = include_str!("./big_if_else.leo");
let ast = Grammar::new(&filepath, program_string).unwrap();
c.bench_function("LeoCoreAst::big_if_else", |b| b.iter(|| leo_core_ast(&ast)));
c.bench_function("LeoAst::big_if_else", |b| b.iter(|| leo_ast(&ast)));
}
fn bench_big_ternary(c: &mut Criterion) {
@ -37,7 +37,7 @@ fn bench_big_ternary(c: &mut Criterion) {
let program_string = include_str!("./big_ternary.leo");
let ast = Grammar::new(&filepath, program_string).unwrap();
c.bench_function("LeoCoreAst::big_ternary", |b| b.iter(|| leo_core_ast(&ast)));
c.bench_function("LeoAst::big_ternary", |b| b.iter(|| leo_ast(&ast)));
}
fn bench_big_circuit(c: &mut Criterion) {
@ -45,7 +45,7 @@ fn bench_big_circuit(c: &mut Criterion) {
let program_string = include_str!("./big_circuit.leo");
let ast = Grammar::new(&filepath, program_string).unwrap();
c.bench_function("LeoCoreAst::big_circuit", |b| b.iter(|| leo_core_ast(&ast)));
c.bench_function("LeoAst::big_circuit", |b| b.iter(|| leo_ast(&ast)));
}
fn bench_long_expr(c: &mut Criterion) {
@ -53,7 +53,7 @@ fn bench_long_expr(c: &mut Criterion) {
let program_string = include_str!("./long_expr.leo");
let ast = Grammar::new(&filepath, program_string).unwrap();
c.bench_function("LeoCoreAst::long_expr", |b| b.iter(|| leo_core_ast(&ast)));
c.bench_function("LeoAst::long_expr", |b| b.iter(|| leo_ast(&ast)));
}
fn bench_long_array(c: &mut Criterion) {
@ -61,7 +61,7 @@ fn bench_long_array(c: &mut Criterion) {
let program_string = include_str!("./long_array.leo");
let ast = Grammar::new(&filepath, program_string).unwrap();
c.bench_function("LeoCoreAst::long_array", |b| b.iter(|| leo_core_ast(&ast)));
c.bench_function("LeoAst::long_array", |b| b.iter(|| leo_ast(&ast)));
}
fn bench_many_foos(c: &mut Criterion) {
@ -69,7 +69,7 @@ fn bench_many_foos(c: &mut Criterion) {
let program_string = include_str!("./many_foos.leo");
let ast = Grammar::new(&filepath, program_string).unwrap();
c.bench_function("LeoCoreAst::many_foos", |b| b.iter(|| leo_core_ast(&ast)));
c.bench_function("LeoAst::many_foos", |b| b.iter(|| leo_ast(&ast)));
}
fn bench_many_assigns(c: &mut Criterion) {
@ -77,7 +77,7 @@ fn bench_many_assigns(c: &mut Criterion) {
let program_string = include_str!("./many_assigns.leo");
let ast = Grammar::new(&filepath, program_string).unwrap();
c.bench_function("LeoCoreAst::many_assigns", |b| b.iter(|| leo_core_ast(&ast)));
c.bench_function("LeoAst::many_assigns", |b| b.iter(|| leo_ast(&ast)));
}
criterion_group!(

View File

@ -16,9 +16,9 @@
//! The core abstract syntax tree (ast) for a Leo program.
//!
//! This module contains the [`LeoCoreAst`] type, a wrapper around the [`Program`] type.
//! The [`LeoCoreAst`] type is intended to be parsed and modified by different passes
//! of the Leo compiler. The Leo compiler can generate a set of R1CS constraints from any [`LeoCoreAst`].
//! This module contains the [`LeoAst`] type, a wrapper around the [`Program`] type.
//! The [`LeoAst`] type is intended to be parsed and modified by different passes
//! of the Leo compiler. The Leo compiler can generate a set of R1CS constraints from any [`LeoAst`].
pub mod annotation;
pub use self::annotation::*;
@ -63,36 +63,36 @@ use leo_grammar::Grammar;
/// The core abstract syntax tree (ast) for a Leo program.
///
/// The [`LeoCoreAst`] type represents a Leo program as a series of recursive data types.
/// The [`LeoAst`] type represents a Leo program as a series of recursive data types.
/// These data types form a tree that begins from a [`Program`] type root.
///
/// A new [`LeoCoreAst`] can be created from a [`LeoAst`] generated by the pest parser in the `ast` module.
/// A new [`LeoAst`] can be created from a [`Grammar`] generated by the pest parser in the `ast` module.
#[derive(Debug, Eq, PartialEq)]
pub struct LeoCoreAst {
core_ast: Program,
pub struct LeoAst {
ast: Program,
}
impl LeoCoreAst {
impl LeoAst {
/// Creates a new core syntax tree from a given program name and abstract syntax tree.
pub fn new<'ast>(program_name: &str, ast: &Grammar<'ast>) -> Self {
Self {
core_ast: Program::from(program_name, ast.as_repr()),
ast: Program::from(program_name, ast.as_repr()),
}
}
/// Returns a reference to the inner program syntax tree representation.
pub fn into_repr(self) -> Program {
self.core_ast
self.ast
}
/// Serializes the core syntax tree into a JSON string.
pub fn to_json_string(&self) -> Result<String, serde_json::Error> {
Ok(serde_json::to_string_pretty(&self.core_ast)?)
Ok(serde_json::to_string_pretty(&self.ast)?)
}
/// Deserializes the JSON string into a core syntax tree.
pub fn from_json_string(json: &str) -> Result<Self, serde_json::Error> {
let typed_ast: Program = serde_json::from_str(json)?;
Ok(Self { core_ast: typed_ast })
Ok(Self { ast: typed_ast })
}
}

View File

@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use leo_core_ast::LeoCoreAst;
use leo_ast::LeoAst;
use leo_grammar::{Grammar, ParserError};
use std::{env, fs, path::Path};
@ -27,10 +27,10 @@ fn to_leo_core_tree(filepath: &Path) -> Result<String, ParserError> {
let ast = Grammar::new(&program_filepath, &program_string)?;
// Parse the pest ast and constructs a core ast.
let core_ast = LeoCoreAst::new("leo_core_tree", &ast);
let core_ast = LeoAst::new("leo_core_tree", &ast);
// Serializes the core tree into JSON format.
let serialized_core_ast = LeoCoreAst::to_json_string(&core_ast)?;
let serialized_core_ast = LeoAst::to_json_string(&core_ast)?;
Ok(serialized_core_ast)
}
@ -43,7 +43,7 @@ fn main() -> Result<(), ParserError> {
if cli_arguments.len() < 2 || cli_arguments.len() > 3 {
eprintln!("Warning - an invalid number of command-line arguments were provided.");
println!(
"\nCommand-line usage:\n\n\tleo_core_ast {{PATH/TO/INPUT_FILENAME}}.leo {{PATH/TO/OUTPUT_DIRECTORY (optional)}}\n"
"\nCommand-line usage:\n\n\tleo_ast {{PATH/TO/INPUT_FILENAME}}.leo {{PATH/TO/OUTPUT_DIRECTORY (optional)}}\n"
);
return Ok(()); // Exit innocently
}

View File

@ -14,14 +14,14 @@
// You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use leo_core_ast::LeoCoreAst;
use leo_ast::LeoAst;
#[cfg(not(feature = "ci_skip"))]
use leo_core_ast::Program;
use leo_ast::Program;
use leo_grammar::Grammar;
use std::path::{Path, PathBuf};
fn to_core_ast(program_filepath: &Path) -> LeoCoreAst {
fn to_core_ast(program_filepath: &Path) -> LeoAst {
// Loads the Leo code as a string from the given file path.
let program_string = Grammar::load_file(program_filepath).unwrap();
@ -29,7 +29,7 @@ fn to_core_ast(program_filepath: &Path) -> LeoCoreAst {
let ast = Grammar::new(&program_filepath, &program_string).unwrap();
// Parses the pest ast and constructs a core ast.
LeoCoreAst::new("leo_core_tree", &ast)
LeoAst::new("leo_core_tree", &ast)
}
#[test]
@ -66,7 +66,7 @@ fn test_deserialize() {
// Construct a core ast by deserializing a core ast JSON file.
let serialized_typed_ast = include_str!("expected_core_ast.json");
let core_ast = LeoCoreAst::from_json_string(serialized_typed_ast).unwrap();
let core_ast = LeoAst::from_json_string(serialized_typed_ast).unwrap();
assert_eq!(expected_core_ast, core_ast);
}
@ -84,8 +84,8 @@ fn test_serialize_deserialize_serialize() {
// Serializes the core ast into JSON format.
let serialized_core_ast = core_ast.to_json_string().unwrap();
// Deserializes the serialized core ast into a LeoCoreAst.
let core_ast = LeoCoreAst::from_json_string(&serialized_core_ast).unwrap();
// Deserializes the serialized core ast into a LeoAst.
let core_ast = LeoAst::from_json_string(&serialized_core_ast).unwrap();
// Reserializes the core ast into JSON format.
let reserialized_core_ast = core_ast.to_json_string().unwrap();

View File

@ -17,8 +17,8 @@ include = [ "Cargo.toml", "src", "README.md", "LICENSE.md" ]
license = "GPL-3.0"
edition = "2018"
[dependencies.leo-core-ast]
path = "../core-ast"
[dependencies.leo-ast]
path = "../ast"
version = "1.0.3"
[dependencies.leo-core-packages]
@ -124,4 +124,4 @@ default-features = false
[features]
default = [ ]
ci_skip = [ "leo-grammar/ci_skip", "leo-core-ast/ci_skip" ]
ci_skip = [ "leo-grammar/ci_skip", "leo-ast/ci_skip" ]

View File

@ -23,7 +23,7 @@ use crate::{
OutputBytes,
OutputFile,
};
use leo_core_ast::{Input, LeoCoreAst, MainInput, Program};
use leo_ast::{Input, LeoAst, MainInput, Program};
use leo_grammar::Grammar;
use leo_imports::ImportParser;
use leo_input::LeoInputParser;
@ -184,7 +184,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> Compiler<F, G> {
})?;
// Construct the core ast from the pest ast.
let core_ast = LeoCoreAst::new(&self.package_name, &pest_ast);
let core_ast = LeoAst::new(&self.package_name, &pest_ast);
// Store the main program file.
self.program = core_ast.into_repr();
@ -244,7 +244,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> Compiler<F, G> {
let package_name = &self.package_name;
// Construct the core ast from the pest ast.
let core_ast = LeoCoreAst::new(package_name, &ast);
let core_ast = LeoAst::new(package_name, &ast);
// Store the main program file.
self.program = core_ast.into_repr();

View File

@ -17,7 +17,7 @@
//! Enforces an assert equals statement in a compiled Leo program.
use crate::{errors::ConsoleError, program::ConstrainedProgram, value::ConstrainedValue, GroupType};
use leo_core_ast::{Expression, Span, Type};
use leo_ast::{Expression, Span, Type};
use snarkos_models::{
curves::{Field, PrimeField},

View File

@ -17,7 +17,7 @@
//! Evaluates a macro in a compiled Leo program.
use crate::{errors::ConsoleError, program::ConstrainedProgram, GroupType};
use leo_core_ast::{ConsoleFunction, ConsoleFunctionCall};
use leo_ast::{ConsoleFunction, ConsoleFunctionCall};
use snarkos_models::{
curves::{Field, PrimeField},

View File

@ -17,7 +17,7 @@
//! Evaluates a formatted string in a compiled Leo program.
use crate::{errors::ConsoleError, program::ConstrainedProgram, GroupType};
use leo_core_ast::FormattedString;
use leo_ast::FormattedString;
use snarkos_models::{
curves::{Field, PrimeField},

View File

@ -25,7 +25,7 @@ use crate::{
OutputBytes,
OutputFile,
};
use leo_core_ast::{Input, Program};
use leo_ast::{Input, Program};
use leo_imports::ImportParser;
use leo_input::LeoInputParser;
use leo_package::inputs::InputPairs;

View File

@ -21,7 +21,7 @@ use crate::{
value::ConstrainedValue,
GroupType,
};
use leo_core_ast::Identifier;
use leo_ast::Identifier;
use snarkos_models::curves::{Field, PrimeField};

View File

@ -22,7 +22,7 @@ use crate::{
value::ConstrainedValue,
GroupType,
};
use leo_core_ast::Program;
use leo_ast::Program;
use leo_imports::ImportParser;
use snarkos_models::curves::{Field, PrimeField};

View File

@ -15,7 +15,7 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::errors::ExpressionError;
use leo_core_ast::{Error as FormattedError, Span};
use leo_ast::{Error as FormattedError, Span};
use std::path::Path;

View File

@ -15,7 +15,7 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::errors::{AddressError, BooleanError, FieldError, FunctionError, GroupError, IntegerError, ValueError};
use leo_core_ast::{Error as FormattedError, Identifier, Span};
use leo_ast::{Error as FormattedError, Identifier, Span};
use leo_core_packages::LeoCorePackageError;
use snarkos_errors::gadgets::SynthesisError;

View File

@ -25,7 +25,7 @@ use crate::errors::{
StatementError,
ValueError,
};
use leo_core_ast::{Error as FormattedError, Span};
use leo_ast::{Error as FormattedError, Span};
use std::path::Path;

View File

@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use leo_core_ast::{Error as FormattedError, Identifier, ImportSymbol, Span};
use leo_ast::{Error as FormattedError, Identifier, ImportSymbol, Span};
use leo_core_packages::LeoCorePackageError;
#[derive(Debug, Error)]

View File

@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use leo_core_ast::{Error as FormattedError, Span};
use leo_ast::{Error as FormattedError, Span};
use std::path::Path;

View File

@ -15,7 +15,7 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::errors::{AddressError, BooleanError, ConsoleError, ExpressionError, IntegerError, ValueError};
use leo_core_ast::{Error as FormattedError, Span, Type};
use leo_ast::{Error as FormattedError, Span, Type};
use std::path::Path;

View File

@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use leo_core_ast::{Error as FormattedError, Span};
use leo_ast::{Error as FormattedError, Span};
use snarkos_errors::{gadgets::SynthesisError, objects::account::AccountError};
use std::path::Path;

View File

@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use leo_core_ast::{Error as FormattedError, Span};
use leo_ast::{Error as FormattedError, Span};
use snarkos_errors::gadgets::SynthesisError;
use std::path::Path;

View File

@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use leo_core_ast::{Error as FormattedError, Span};
use leo_ast::{Error as FormattedError, Span};
use snarkos_errors::gadgets::SynthesisError;
use std::path::Path;

View File

@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use leo_core_ast::{Error as FormattedError, Span};
use leo_ast::{Error as FormattedError, Span};
use snarkos_errors::gadgets::SynthesisError;
use std::path::Path;

Some files were not shown because too many files have changed in this diff Show More