mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-09-11 05:45:30 +03:00
Migrates program
This commit is contained in:
parent
cb83b42cfc
commit
6ad5dc75d5
@ -3,10 +3,10 @@
|
||||
use crate::{
|
||||
constraints::{generate_constraints, generate_test_constraints, ConstrainedValue},
|
||||
errors::CompilerError,
|
||||
GroupType, Program,
|
||||
GroupType,
|
||||
};
|
||||
use leo_ast::{ast, files::File};
|
||||
use leo_types::InputValue;
|
||||
use leo_types::{InputValue, Program};
|
||||
|
||||
use snarkos_errors::gadgets::SynthesisError;
|
||||
use snarkos_models::{
|
||||
|
@ -5,9 +5,8 @@ use crate::{
|
||||
constraints::{new_scope, ConstrainedProgram, ConstrainedValue},
|
||||
errors::{FunctionError, ImportError},
|
||||
field_from_input, group_from_input,
|
||||
types::{Program},
|
||||
GroupType};
|
||||
use leo_types::{Expression, Function, Identifier, InputValue, Integer, Type};
|
||||
use leo_types::{Expression, Function, Identifier, InputValue, Integer, Program, Type};
|
||||
|
||||
use snarkos_models::{
|
||||
curves::{Field, PrimeField},
|
||||
|
@ -2,11 +2,10 @@ use crate::{
|
||||
constraints::{ConstrainedProgram, ConstrainedValue},
|
||||
errors::constraints::ImportError,
|
||||
new_scope,
|
||||
types::Program,
|
||||
GroupType,
|
||||
};
|
||||
use leo_ast::{ast, files::File};
|
||||
use leo_types::{Import};
|
||||
use leo_types::{Import, Program};
|
||||
|
||||
use from_pest::FromPest;
|
||||
use snarkos_models::{
|
||||
|
@ -29,10 +29,9 @@ pub use statement::*;
|
||||
|
||||
use crate::{
|
||||
errors::CompilerError,
|
||||
types::Program,
|
||||
GroupType,
|
||||
};
|
||||
use leo_types::InputValue;
|
||||
use leo_types::{InputValue, Program};
|
||||
|
||||
use snarkos_models::{
|
||||
curves::{Field, PrimeField},
|
||||
|
@ -15,9 +15,3 @@ pub use self::field::*;
|
||||
|
||||
pub mod group;
|
||||
pub use self::group::*;
|
||||
|
||||
pub mod types;
|
||||
pub use self::types::*;
|
||||
|
||||
pub mod types_from;
|
||||
pub use self::types_from::*;
|
||||
|
@ -1,39 +0,0 @@
|
||||
//! A typed Leo program consists of import, circuit, and function definitions.
|
||||
//! Each defined type consists of typed statements and expressions.
|
||||
|
||||
use leo_types::{Circuit, Identifier,Import, Function, TestFunction};
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
/// A simple program with statement expressions, program arguments and program returns.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Program {
|
||||
pub name: Identifier,
|
||||
pub num_parameters: usize,
|
||||
pub imports: Vec<Import>,
|
||||
pub circuits: HashMap<Identifier, Circuit>,
|
||||
pub functions: HashMap<Identifier, Function>,
|
||||
pub tests: HashMap<Identifier, TestFunction>,
|
||||
}
|
||||
|
||||
impl<'ast> Program {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
name: Identifier::new("".into()),
|
||||
num_parameters: 0,
|
||||
imports: vec![],
|
||||
circuits: HashMap::new(),
|
||||
functions: HashMap::new(),
|
||||
tests: HashMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_name(&self) -> String {
|
||||
self.name.name.clone()
|
||||
}
|
||||
|
||||
pub fn name(mut self, name: String) -> Self {
|
||||
self.name = Identifier::new(name);
|
||||
self
|
||||
}
|
||||
}
|
@ -25,6 +25,9 @@ pub use input_value::*;
|
||||
pub mod integer;
|
||||
pub use integer::*;
|
||||
|
||||
pub mod program;
|
||||
pub use program::*;
|
||||
|
||||
pub mod statements;
|
||||
pub use statements::*;
|
||||
|
||||
|
@ -1,16 +1,26 @@
|
||||
//! Logic to convert from an abstract syntax tree (ast) representation to a Leo program.
|
||||
//! A typed Leo program consists of import, circuit, and function definitions.
|
||||
//! Each defined type consists of typed statements and expressions.
|
||||
|
||||
use crate::{types};
|
||||
use crate::{Circuit, Identifier, Import, Function, TestFunction};
|
||||
use leo_ast::{
|
||||
files::File,
|
||||
};
|
||||
use leo_types::{Circuit, Function, Import, Identifier, TestFunction};
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
/// pest ast -> types::Program
|
||||
/// A simple program with statement expressions, program arguments and program returns.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Program {
|
||||
pub name: Identifier,
|
||||
pub num_parameters: usize,
|
||||
pub imports: Vec<Import>,
|
||||
pub circuits: HashMap<Identifier, Circuit>,
|
||||
pub functions: HashMap<Identifier, Function>,
|
||||
pub tests: HashMap<Identifier, TestFunction>,
|
||||
}
|
||||
|
||||
impl<'ast> types::Program {
|
||||
impl<'ast> Program {
|
||||
//! Logic to convert from an abstract syntax tree (ast) representation to a Leo program.
|
||||
pub fn from(file: File<'ast>, name: String) -> Self {
|
||||
// Compiled ast -> aleo program representation
|
||||
let imports = file
|
||||
@ -47,7 +57,7 @@ impl<'ast> types::Program {
|
||||
num_parameters = main_function.inputs.len();
|
||||
}
|
||||
|
||||
types::Program {
|
||||
Self {
|
||||
name: Identifier::new(name),
|
||||
num_parameters,
|
||||
imports,
|
||||
@ -57,3 +67,25 @@ impl<'ast> types::Program {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Program {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
name: Identifier::new("".into()),
|
||||
num_parameters: 0,
|
||||
imports: vec![],
|
||||
circuits: HashMap::new(),
|
||||
functions: HashMap::new(),
|
||||
tests: HashMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_name(&self) -> String {
|
||||
self.name.name.clone()
|
||||
}
|
||||
|
||||
pub fn name(mut self, name: String) -> Self {
|
||||
self.name = Identifier::new(name);
|
||||
self
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user