mirror of
https://github.com/AleoHQ/leo.git
synced 2024-12-01 10:17:30 +03:00
global consts work, time to add them to reducers and phases
This commit is contained in:
parent
dd06df4b1d
commit
e1a0838888
@ -34,7 +34,6 @@ use crate::{
|
||||
Input,
|
||||
Scope,
|
||||
Statement,
|
||||
Variable,
|
||||
};
|
||||
use leo_ast::{Identifier, PackageAccess, PackageOrPackages, Span};
|
||||
|
||||
@ -277,26 +276,18 @@ impl<'a> Program<'a> {
|
||||
scope.functions.borrow_mut().insert(name.name.clone(), function);
|
||||
}
|
||||
|
||||
println!("Helllo? {:?}", program.global_consts);
|
||||
for (name, global_const) in program.global_consts.iter() {
|
||||
println!("loop over p gcs name {}", name);
|
||||
global_const
|
||||
.variable_names
|
||||
.iter()
|
||||
.for_each(|variable_name| assert!(name.contains(&variable_name.identifier.name)));
|
||||
// TODO re-enable
|
||||
let gc = <&Statement<'a>>::from_ast(scope, global_const, None)?;
|
||||
if let Statement::Definition(gc) = gc {
|
||||
scope.global_consts.borrow_mut().insert(name.clone(), gc);
|
||||
// let split = gc.split();
|
||||
// for (var_name, statement) in split.iter() {
|
||||
// scope.global_consts.borrow_mut().insert(var_name.clone(), statement.get());
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
// Load concrete definitions.
|
||||
// TODO RE-ENABLE
|
||||
let mut global_consts = IndexMap::new();
|
||||
for (name, global_const) in program.global_consts.iter() {
|
||||
global_const
|
||||
@ -401,10 +392,9 @@ pub fn reform_ast<'a>(program: &Program<'a>) -> leo_ast::Program {
|
||||
function.name.borrow_mut().name = identifier.clone();
|
||||
all_functions.insert(identifier, *function);
|
||||
}
|
||||
// TODO RE-ENABLE
|
||||
|
||||
for (name, global_const) in program.global_consts.iter() {
|
||||
let identifier = format!("{}{}", identifiers.next().unwrap(), name);
|
||||
// global_const.variable.borrow_mut().name.name = identifier.clone();
|
||||
all_global_consts.insert(identifier, *global_const);
|
||||
}
|
||||
}
|
||||
|
@ -338,8 +338,13 @@ impl<'a, R: ReconstructingReducerProgram<'a>> ReconstructingDirector<'a, R> {
|
||||
.iter()
|
||||
.map(|(name, c)| (name.clone(), self.reduce_circuit(c)))
|
||||
.collect();
|
||||
let global_consts = input
|
||||
.global_consts
|
||||
.iter()
|
||||
.map(|(name, gc)| (name.clone(), <&DefinitionStatement>::clone(gc))) // TODO REDUCE GC
|
||||
.collect();
|
||||
|
||||
self.reducer
|
||||
.reduce_program(input, imported_modules, functions, circuits)
|
||||
.reduce_program(input, imported_modules, functions, circuits, global_consts)
|
||||
}
|
||||
}
|
||||
|
@ -388,9 +388,8 @@ pub trait ReconstructingReducerProgram<'a>: ReconstructingReducerStatement<'a> {
|
||||
imported_modules: Vec<(String, Program<'a>)>,
|
||||
functions: Vec<(String, &'a Function<'a>)>,
|
||||
circuits: Vec<(String, &'a Circuit<'a>)>,
|
||||
global_consts: Vec<(String, &'a DefinitionStatement<'a>)>,
|
||||
) -> Program<'a> {
|
||||
// TODO
|
||||
use indexmap::IndexMap;
|
||||
Program {
|
||||
context: input.context,
|
||||
id: input.id,
|
||||
@ -399,7 +398,7 @@ pub trait ReconstructingReducerProgram<'a>: ReconstructingReducerStatement<'a> {
|
||||
functions: functions.into_iter().collect(),
|
||||
circuits: circuits.into_iter().collect(),
|
||||
scope: input.scope,
|
||||
global_consts: IndexMap::new(),
|
||||
global_consts: global_consts.into_iter().collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -43,7 +43,6 @@ pub struct Scope<'a> {
|
||||
pub functions: RefCell<IndexMap<String, &'a Function<'a>>>,
|
||||
|
||||
/// Maps global constant name => global const code block.
|
||||
/// TODO fixs
|
||||
pub global_consts: RefCell<IndexMap<String, &'a DefinitionStatement<'a>>>,
|
||||
|
||||
/// Maps circuit name => circuit.
|
||||
@ -62,15 +61,9 @@ impl<'a> Scope<'a> {
|
||||
/// If there is no parent scope, then `None` is returned.
|
||||
///
|
||||
pub fn resolve_variable(&self, name: &str) -> Option<&'a Variable<'a>> {
|
||||
println!("rv n {}", name);
|
||||
if let Some(resolved) = self.variables.borrow().get(name) {
|
||||
Some(*resolved)
|
||||
}
|
||||
// TODO re-enable
|
||||
// else if let Some(resolved) = self.global_consts.borrow().get(name) {
|
||||
// Some(resolved.variable)
|
||||
// }
|
||||
else if let Some(scope) = self.parent_scope.get() {
|
||||
} else if let Some(scope) = self.parent_scope.get() {
|
||||
scope.resolve_variable(name)
|
||||
} else {
|
||||
None
|
||||
|
@ -34,7 +34,6 @@ pub fn generate_constraints<'a, F: PrimeField, G: GroupType<F>, CS: ConstraintSy
|
||||
let mut resolved_program = ConstrainedProgram::<F, G>::new(program.clone());
|
||||
|
||||
for (_, global_const) in program.global_consts.iter() {
|
||||
println!("Yo");
|
||||
resolved_program.enforce_definition_statement(cs, global_const)?;
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,6 @@ use snarkvm_fields::PrimeField;
|
||||
impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
pub fn store_definition(&mut self, variable: &Variable, value: ConstrainedValue<'a, F, G>) {
|
||||
let variable = variable.borrow();
|
||||
|
||||
self.store(variable.id, value);
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
"expected_input": [],
|
||||
"imports": [],
|
||||
"circuits": {},
|
||||
"global_consts": {},
|
||||
"functions": {
|
||||
"{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":10,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\"}\"}": {
|
||||
"annotations": [],
|
||||
|
@ -119,6 +119,7 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
"global_consts": {},
|
||||
"functions": {
|
||||
"{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":13,\\\"line_stop\\\":13,\\\"col_start\\\":10,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\"}\"}": {
|
||||
"annotations": [],
|
||||
|
@ -3,6 +3,7 @@
|
||||
"expected_input": [],
|
||||
"imports": [],
|
||||
"circuits": {},
|
||||
"global_consts": {},
|
||||
"functions": {
|
||||
"{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":10,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\"}\"}": {
|
||||
"annotations": [],
|
||||
|
@ -55,6 +55,7 @@ impl ParserContext {
|
||||
// });
|
||||
}
|
||||
Token::Const => {
|
||||
// TODO separate into own function.
|
||||
let statement = self.parse_definition_statement()?;
|
||||
let variable_names = statement
|
||||
.variable_names
|
||||
|
@ -3,6 +3,7 @@
|
||||
"expected_input": [],
|
||||
"imports": [],
|
||||
"circuits": {},
|
||||
"global_consts": {},
|
||||
"functions": {
|
||||
"{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":10,\\\"col_stop\\\":14,\\\"path\\\":\\\"test\\\"}\"}": {
|
||||
"annotations": [],
|
||||
|
Loading…
Reference in New Issue
Block a user