mirror of
https://github.com/AleoHQ/leo.git
synced 2024-11-29 11:43:28 +03:00
rename typed -> core-ast 1
This commit is contained in:
parent
4e8bc7f1a8
commit
be2a805d49
@ -30,7 +30,7 @@ use leo_input::LeoInputParser;
|
||||
use leo_package::inputs::InputPairs;
|
||||
use leo_state::verify_local_data_commitment;
|
||||
use leo_symbol_table::SymbolTable;
|
||||
use leo_typed::{Input, LeoTypedAst, MainInput, Program};
|
||||
use leo_typed::{Input, LeoCoreAst, MainInput, Program};
|
||||
|
||||
use snarkos_dpc::{base_dpc::instantiated::Components, SystemParameters};
|
||||
use snarkos_errors::gadgets::SynthesisError;
|
||||
@ -176,7 +176,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> Compiler<F, G> {
|
||||
})?;
|
||||
|
||||
// Use the typed parser to construct the typed syntax tree.
|
||||
let typed_tree = LeoTypedAst::new(&self.package_name, &ast);
|
||||
let typed_tree = LeoCoreAst::new(&self.package_name, &ast);
|
||||
|
||||
self.program = typed_tree.into_repr();
|
||||
self.imported_programs = ImportParser::parse(&self.program)?;
|
||||
@ -227,7 +227,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> Compiler<F, G> {
|
||||
let package_name = &self.package_name;
|
||||
|
||||
// Use the typed parser to construct the typed syntax tree.
|
||||
let typed_tree = LeoTypedAst::new(package_name, &ast);
|
||||
let typed_tree = LeoCoreAst::new(package_name, &ast);
|
||||
|
||||
self.program = typed_tree.into_repr();
|
||||
self.imported_programs = ImportParser::parse(&self.program)?;
|
||||
|
@ -25,7 +25,7 @@ use leo_dynamic_check::DynamicCheck;
|
||||
|
||||
use leo_imports::ImportParser;
|
||||
use leo_symbol_table::SymbolTable;
|
||||
use leo_typed::{Input, LeoTypedAst, Program};
|
||||
use leo_typed::{Input, LeoCoreAst, Program};
|
||||
use std::path::PathBuf;
|
||||
|
||||
const TEST_PROGRAM_PATH: &str = "";
|
||||
@ -49,7 +49,7 @@ impl TestDynamicCheck {
|
||||
let ast = LeoAst::new(&file_path, &*file_string).unwrap();
|
||||
|
||||
// Get typed syntax tree.
|
||||
let typed = LeoTypedAst::new(TEST_PROGRAM_NAME, &ast);
|
||||
let typed = LeoCoreAst::new(TEST_PROGRAM_NAME, &ast);
|
||||
let program = typed.into_repr();
|
||||
|
||||
// Create empty import parser.
|
||||
|
@ -18,7 +18,7 @@ pub mod symbol_table;
|
||||
|
||||
use leo_ast::LeoAst;
|
||||
use leo_symbol_table::{SymbolTable, SymbolTableError};
|
||||
use leo_typed::{Input, LeoTypedAst};
|
||||
use leo_typed::{Input, LeoCoreAst};
|
||||
|
||||
use leo_imports::ImportParser;
|
||||
use std::path::PathBuf;
|
||||
@ -27,7 +27,7 @@ const TEST_PROGRAM_PATH: &str = "";
|
||||
|
||||
/// A helper struct to test a `SymbolTable`.
|
||||
pub struct TestSymbolTable {
|
||||
typed: LeoTypedAst,
|
||||
typed: LeoCoreAst,
|
||||
}
|
||||
|
||||
impl TestSymbolTable {
|
||||
@ -45,7 +45,7 @@ impl TestSymbolTable {
|
||||
let ast = LeoAst::new(&file_path, &*file_string).unwrap();
|
||||
|
||||
// Get typed syntax tree
|
||||
let typed = LeoTypedAst::new(TEST_PROGRAM_PATH, &ast);
|
||||
let typed = LeoCoreAst::new(TEST_PROGRAM_PATH, &ast);
|
||||
|
||||
Self { typed }
|
||||
}
|
||||
|
@ -15,13 +15,13 @@
|
||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use leo_ast::LeoAst;
|
||||
use leo_typed::LeoTypedAst;
|
||||
use leo_typed::LeoCoreAst;
|
||||
|
||||
use criterion::{criterion_group, criterion_main, Criterion};
|
||||
use std::{path::Path, time::Duration};
|
||||
|
||||
fn leo_typed_ast<'ast>(ast: &LeoAst<'ast>) -> LeoTypedAst {
|
||||
LeoTypedAst::new("leo_typed_tree", &ast)
|
||||
fn leo_core_ast<'ast>(ast: &LeoAst<'ast>) -> LeoCoreAst {
|
||||
LeoCoreAst::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 = LeoAst::new(&filepath, program_string).unwrap();
|
||||
|
||||
c.bench_function("LeoTypedAst::big_if_else", |b| b.iter(|| leo_typed_ast(&ast)));
|
||||
c.bench_function("LeoCoreAst::big_if_else", |b| b.iter(|| leo_core_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 = LeoAst::new(&filepath, program_string).unwrap();
|
||||
|
||||
c.bench_function("LeoTypedAst::big_ternary", |b| b.iter(|| leo_typed_ast(&ast)));
|
||||
c.bench_function("LeoCoreAst::big_ternary", |b| b.iter(|| leo_core_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 = LeoAst::new(&filepath, program_string).unwrap();
|
||||
|
||||
c.bench_function("LeoTypedAst::big_circuit", |b| b.iter(|| leo_typed_ast(&ast)));
|
||||
c.bench_function("LeoCoreAst::big_circuit", |b| b.iter(|| leo_core_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 = LeoAst::new(&filepath, program_string).unwrap();
|
||||
|
||||
c.bench_function("LeoTypedAst::long_expr", |b| b.iter(|| leo_typed_ast(&ast)));
|
||||
c.bench_function("LeoCoreAst::long_expr", |b| b.iter(|| leo_core_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 = LeoAst::new(&filepath, program_string).unwrap();
|
||||
|
||||
c.bench_function("LeoTypedAst::long_array", |b| b.iter(|| leo_typed_ast(&ast)));
|
||||
c.bench_function("LeoCoreAst::long_array", |b| b.iter(|| leo_core_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 = LeoAst::new(&filepath, program_string).unwrap();
|
||||
|
||||
c.bench_function("LeoTypedAst::many_foos", |b| b.iter(|| leo_typed_ast(&ast)));
|
||||
c.bench_function("LeoCoreAst::many_foos", |b| b.iter(|| leo_core_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 = LeoAst::new(&filepath, program_string).unwrap();
|
||||
|
||||
c.bench_function("LeoTypedAst::many_assigns", |b| b.iter(|| leo_typed_ast(&ast)));
|
||||
c.bench_function("LeoCoreAst::many_assigns", |b| b.iter(|| leo_core_ast(&ast)));
|
||||
}
|
||||
|
||||
criterion_group!(
|
||||
|
@ -59,29 +59,29 @@ pub use self::types::*;
|
||||
use leo_ast::LeoAst;
|
||||
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
pub struct LeoTypedAst {
|
||||
pub struct LeoCoreAst {
|
||||
typed_ast: Program,
|
||||
}
|
||||
|
||||
impl LeoTypedAst {
|
||||
/// Creates a new typed syntax tree from a given program name and abstract syntax tree.
|
||||
impl LeoCoreAst {
|
||||
/// Creates a new core syntax tree from a given program name and abstract syntax tree.
|
||||
pub fn new<'ast>(program_name: &str, ast: &LeoAst<'ast>) -> Self {
|
||||
Self {
|
||||
typed_ast: Program::from(program_name, ast.as_repr()),
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a reference to the inner typed syntax tree representation.
|
||||
/// Returns a reference to the inner program syntax tree representation.
|
||||
pub fn into_repr(self) -> Program {
|
||||
self.typed_ast
|
||||
}
|
||||
|
||||
/// Serializes the typed syntax tree into a JSON string.
|
||||
/// 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.typed_ast)?)
|
||||
}
|
||||
|
||||
/// Deserializes the JSON string into a typed syntax tree.
|
||||
/// 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 { typed_ast })
|
||||
|
@ -15,10 +15,10 @@
|
||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use leo_ast::{LeoAst, ParserError};
|
||||
use leo_typed::LeoTypedAst;
|
||||
use leo_typed::LeoCoreAst;
|
||||
use std::{env, fs, path::Path};
|
||||
|
||||
fn to_leo_typed_tree(filepath: &Path) -> Result<String, ParserError> {
|
||||
fn to_leo_core_tree(filepath: &Path) -> Result<String, ParserError> {
|
||||
// Loads the Leo code as a string from the given file path.
|
||||
let program_filepath = filepath.to_path_buf();
|
||||
let program_string = LeoAst::load_file(&program_filepath)?;
|
||||
@ -26,11 +26,11 @@ fn to_leo_typed_tree(filepath: &Path) -> Result<String, ParserError> {
|
||||
// Parses the Leo file and constructs an abstract syntax tree.
|
||||
let ast = LeoAst::new(&program_filepath, &program_string)?;
|
||||
|
||||
// Parse the abstract syntax tree and constructs a typed syntax tree.
|
||||
let typed_ast = LeoTypedAst::new("leo_typed_tree", &ast);
|
||||
// Parse the abstract core tree and constructs a typed core tree.
|
||||
let typed_ast = LeoCoreAst::new("leo_typed_tree", &ast);
|
||||
|
||||
// Serializes the typed syntax tree into JSON format.
|
||||
let serialized_typed_tree = LeoTypedAst::to_json_string(&typed_ast)?;
|
||||
// Serializes the typed core tree into JSON format.
|
||||
let serialized_typed_tree = LeoCoreAst::to_json_string(&typed_ast)?;
|
||||
|
||||
Ok(serialized_typed_tree)
|
||||
}
|
||||
@ -51,9 +51,9 @@ fn main() -> Result<(), ParserError> {
|
||||
// Construct the input filepath.
|
||||
let input_filepath = Path::new(&cli_arguments[1]);
|
||||
|
||||
// Construct the serialized typed syntax tree.
|
||||
let serialized_typed_tree = to_leo_typed_tree(&input_filepath)?;
|
||||
println!("{}", serialized_typed_tree);
|
||||
// Construct the serialized core syntax tree.
|
||||
let serialized_core_tree = to_leo_core_tree(&input_filepath)?;
|
||||
println!("{}", serialized_core_tree);
|
||||
|
||||
// Determine the output directory.
|
||||
let output_directory = match cli_arguments.len() == 3 {
|
||||
@ -65,8 +65,8 @@ fn main() -> Result<(), ParserError> {
|
||||
false => format!("./{}.json", input_filepath.file_stem().unwrap().to_str().unwrap()),
|
||||
};
|
||||
|
||||
// Write the serialized abstract syntax tree to the output directory.
|
||||
fs::write(Path::new(&output_directory), serialized_typed_tree)?;
|
||||
// Write the serialized core syntax tree to the output directory.
|
||||
fs::write(Path::new(&output_directory), serialized_core_tree)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ use leo_ast::{definitions::Definition, files::File};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashMap;
|
||||
|
||||
/// A simple program with statement expressions, program arguments and program returns.
|
||||
/// Stores the Leo program abstract syntax tree.
|
||||
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
|
||||
pub struct Program {
|
||||
pub name: String,
|
||||
|
@ -15,13 +15,13 @@
|
||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use leo_ast::LeoAst;
|
||||
use leo_typed::LeoTypedAst;
|
||||
use leo_typed::LeoCoreAst;
|
||||
#[cfg(not(feature = "ci_skip"))]
|
||||
use leo_typed::Program;
|
||||
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
fn to_typed_ast(program_filepath: &Path) -> LeoTypedAst {
|
||||
fn to_typed_ast(program_filepath: &Path) -> LeoCoreAst {
|
||||
// Loads the Leo code as a string from the given file path.
|
||||
let program_string = LeoAst::load_file(program_filepath).unwrap();
|
||||
|
||||
@ -29,7 +29,7 @@ fn to_typed_ast(program_filepath: &Path) -> LeoTypedAst {
|
||||
let ast = LeoAst::new(&program_filepath, &program_string).unwrap();
|
||||
|
||||
// Parse the abstract syntax tree and constructs a typed syntax tree.
|
||||
LeoTypedAst::new("leo_typed_tree", &ast)
|
||||
LeoCoreAst::new("leo_typed_tree", &ast)
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -66,7 +66,7 @@ fn test_deserialize() {
|
||||
|
||||
// Construct a typed syntax tree by deserializing a typed syntax tree JSON file.
|
||||
let serialized_typed_ast = include_str!("expected_typed_ast.json");
|
||||
let typed_ast = LeoTypedAst::from_json_string(serialized_typed_ast).unwrap();
|
||||
let typed_ast = LeoCoreAst::from_json_string(serialized_typed_ast).unwrap();
|
||||
|
||||
assert_eq!(expected_typed_ast, typed_ast);
|
||||
}
|
||||
@ -85,7 +85,7 @@ fn test_serialize_deserialize_serialize() {
|
||||
let serialized_typed_ast = typed_ast.to_json_string().unwrap();
|
||||
|
||||
// Deserializes the typed syntax tree into a LeoTypedAst.
|
||||
let typed_ast = LeoTypedAst::from_json_string(&serialized_typed_ast).unwrap();
|
||||
let typed_ast = LeoCoreAst::from_json_string(&serialized_typed_ast).unwrap();
|
||||
|
||||
// Reserializes the typed syntax tree into JSON format.
|
||||
let reserialized_typed_ast = typed_ast.to_json_string().unwrap();
|
||||
|
Loading…
Reference in New Issue
Block a user