mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-11-23 07:07:07 +03:00
Renames InnerProgram to InternalProgram
This commit is contained in:
parent
96c20c6472
commit
f80c3d236a
@ -110,9 +110,9 @@ pub fn load_asg_from_ast<T: ImportResolver + 'static>(
|
||||
content: leo_ast::Program,
|
||||
resolver: &mut T,
|
||||
) -> Result<Program, AsgConvertError> {
|
||||
InnerProgram::new(&content, resolver)
|
||||
InternalProgram::new(&content, resolver)
|
||||
}
|
||||
|
||||
pub fn load_asg<T: ImportResolver + 'static>(content: &str, resolver: &mut T) -> Result<Program, AsgConvertError> {
|
||||
InnerProgram::new(&load_ast("input.leo", content)?, resolver)
|
||||
InternalProgram::new(&load_ast("input.leo", content)?, resolver)
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ use uuid::Uuid;
|
||||
|
||||
/// Stores the Leo program abstract semantic graph (ASG).
|
||||
#[derive(Clone)]
|
||||
pub struct InnerProgram {
|
||||
pub struct InternalProgram {
|
||||
/// The unique id of the program.
|
||||
pub id: Uuid,
|
||||
|
||||
@ -57,7 +57,7 @@ pub struct InnerProgram {
|
||||
pub scope: Scope,
|
||||
}
|
||||
|
||||
pub type Program = Arc<RefCell<InnerProgram>>;
|
||||
pub type Program = Arc<RefCell<InternalProgram>>;
|
||||
|
||||
/// Enumerates what names are imported from a package.
|
||||
enum ImportSymbol {
|
||||
@ -110,7 +110,7 @@ fn resolve_import_package_access(
|
||||
}
|
||||
}
|
||||
|
||||
impl InnerProgram {
|
||||
impl InternalProgram {
|
||||
/// Returns a new Leo program asg from the given Leo program ast and imports.
|
||||
///
|
||||
/// stages:
|
||||
@ -298,7 +298,7 @@ impl InnerProgram {
|
||||
circuits.insert(name.name.clone(), body);
|
||||
}
|
||||
|
||||
Ok(Arc::new(RefCell::new(InnerProgram {
|
||||
Ok(Arc::new(RefCell::new(InternalProgram {
|
||||
id: Uuid::new_v4(),
|
||||
name: value.name.clone(),
|
||||
test_functions,
|
||||
@ -395,10 +395,13 @@ pub fn reform_ast(program: &Program) -> leo_ast::Program {
|
||||
tests: all_test_functions
|
||||
.into_iter()
|
||||
.map(|(_, (function, ident))| {
|
||||
(function.function.name.borrow().clone(), leo_ast::TestFunction {
|
||||
function: function.function.as_ref().into(),
|
||||
input_file: ident,
|
||||
})
|
||||
(
|
||||
function.function.name.borrow().clone(),
|
||||
leo_ast::TestFunction {
|
||||
function: function.function.as_ref().into(),
|
||||
input_file: ident,
|
||||
},
|
||||
)
|
||||
})
|
||||
.collect(),
|
||||
functions: all_functions
|
||||
@ -417,7 +420,7 @@ pub fn reform_ast(program: &Program) -> leo_ast::Program {
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<leo_ast::Program> for &InnerProgram {
|
||||
impl Into<leo_ast::Program> for &InternalProgram {
|
||||
fn into(self) -> leo_ast::Program {
|
||||
leo_ast::Program {
|
||||
name: self.name.clone(),
|
||||
@ -442,10 +445,13 @@ impl Into<leo_ast::Program> for &InnerProgram {
|
||||
.test_functions
|
||||
.iter()
|
||||
.map(|(_, function)| {
|
||||
(function.0.function.name.borrow().clone(), leo_ast::TestFunction {
|
||||
function: function.0.function.as_ref().into(),
|
||||
input_file: function.1.clone(),
|
||||
})
|
||||
(
|
||||
function.0.function.name.borrow().clone(),
|
||||
leo_ast::TestFunction {
|
||||
function: function.0.function.as_ref().into(),
|
||||
input_file: function.1.clone(),
|
||||
},
|
||||
)
|
||||
})
|
||||
.collect(),
|
||||
}
|
||||
|
@ -157,7 +157,7 @@ pub trait MonoidalReducerProgram<T: Monoid>: MonoidalReducerStatement<T> {
|
||||
|
||||
fn reduce_program(
|
||||
&mut self,
|
||||
input: &InnerProgram,
|
||||
input: &InternalProgram,
|
||||
imported_modules: Vec<T>,
|
||||
test_functions: Vec<T>,
|
||||
functions: Vec<T>,
|
||||
|
@ -19,9 +19,7 @@
|
||||
use crate::{
|
||||
constraints::{generate_constraints, generate_test_constraints},
|
||||
errors::CompilerError,
|
||||
GroupType,
|
||||
OutputBytes,
|
||||
OutputFile,
|
||||
GroupType, OutputBytes, OutputFile,
|
||||
};
|
||||
use leo_ast::{Ast, Input, MainInput, Program};
|
||||
use leo_grammar::Grammar;
|
||||
@ -189,7 +187,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> Compiler<F, G> {
|
||||
tracing::debug!("Program parsing complete\n{:#?}", self.program);
|
||||
|
||||
// Create a new symbol table from the program, imported_programs, and program_input.
|
||||
let asg = leo_asg::InnerProgram::new(&self.program, &mut leo_imports::ImportParser::default())?;
|
||||
let asg = leo_asg::InternalProgram::new(&self.program, &mut leo_imports::ImportParser::default())?;
|
||||
|
||||
tracing::debug!("ASG generation complete");
|
||||
|
||||
|
@ -34,7 +34,7 @@ impl ImportParser {
|
||||
return self.parse_package(package.path(), remaining_segments, span);
|
||||
}
|
||||
let program = Self::parse_import_file(package, span)?;
|
||||
let asg = leo_asg::InnerProgram::new(&program, self)?;
|
||||
let asg = leo_asg::InternalProgram::new(&program, self)?;
|
||||
|
||||
Ok(asg)
|
||||
}
|
||||
|
@ -31,18 +31,18 @@ use snarkvm_utilities::{bytes::ToBytes, to_bytes, FromBytes};
|
||||
use std::convert::TryFrom;
|
||||
|
||||
/// Returns `true` if the path to the local data commitment leaf is a valid path in the record
|
||||
/// commitment merkle tree.
|
||||
/// commitment Merkle tree.
|
||||
pub fn verify_local_data_commitment(
|
||||
system_parameters: &SystemParameters<Components>,
|
||||
ast_input: &AstInput,
|
||||
) -> Result<bool, LocalDataVerificationError> {
|
||||
// verify record commitment.
|
||||
// Verify record commitment.
|
||||
let typed_record = ast_input.get_record();
|
||||
let dpc_record_values = verify_record_commitment(system_parameters, typed_record)?;
|
||||
let record_commitment: Vec<u8> = dpc_record_values.commitment;
|
||||
let record_serial_number: Vec<u8> = dpc_record_values.serial_number;
|
||||
|
||||
// parse typed state values.
|
||||
// Parse typed state values.
|
||||
let typed_state = ast_input.get_state();
|
||||
let state_values = StateValues::try_from(typed_state)?;
|
||||
let leaf_index: u32 = state_values.leaf_index;
|
||||
|
62
wasm/src/asg.rs
Normal file
62
wasm/src/asg.rs
Normal file
@ -0,0 +1,62 @@
|
||||
// Copyright (C) 2019-2021 Aleo Systems Inc.
|
||||
// This file is part of the Leo library.
|
||||
|
||||
// The Leo library is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// The Leo library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// 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_ast::Ast as LeoAst;
|
||||
use leo_grammar::Grammar as LeoGrammar;
|
||||
|
||||
use std::path::Path;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub struct Ast(String);
|
||||
|
||||
#[wasm_bindgen]
|
||||
impl Ast {
|
||||
#[wasm_bindgen(constructor)]
|
||||
pub fn new(filepath: &str, program_name: &str, program_string: &str) -> Self {
|
||||
let grammar = LeoGrammar::new(&Path::new(filepath), &program_string).unwrap();
|
||||
let ast = LeoAst::new(program_name, &grammar).unwrap();
|
||||
Self(ast.to_json_string().unwrap())
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn to_string(&self) -> String {
|
||||
self.0.clone()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
use wasm_bindgen_test::*;
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn ast_test() {
|
||||
let expected = include_str!("../.resources/basic/expected_ast.json");
|
||||
|
||||
let filepath = "../.resources/basic/main.leo";
|
||||
let program_name = "basic";
|
||||
let program_string = include_str!("../.resources/basic/main.leo");
|
||||
|
||||
let candidate = Ast::new(filepath, program_name, program_string).to_string();
|
||||
|
||||
let expected = JsValue::from_str(expected);
|
||||
let candidate = JsValue::from_serde(&candidate).unwrap();
|
||||
|
||||
assert_eq!(expected, candidate);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user