remove uuid dependency

This commit is contained in:
Protryon 2021-02-25 07:40:47 -08:00
parent d85a057ddc
commit ed8d2fb11d
55 changed files with 427 additions and 460 deletions

29
Cargo.lock generated
View File

@ -955,17 +955,6 @@ dependencies = [
"wasi 0.9.0+wasi-snapshot-preview1", "wasi 0.9.0+wasi-snapshot-preview1",
] ]
[[package]]
name = "getrandom"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8"
dependencies = [
"cfg-if 1.0.0",
"libc",
"wasi 0.10.0+wasi-snapshot-preview1",
]
[[package]] [[package]]
name = "gimli" name = "gimli"
version = "0.23.0" version = "0.23.0"
@ -1290,7 +1279,6 @@ dependencies = [
"serde_json", "serde_json",
"thiserror", "thiserror",
"typed-arena", "typed-arena",
"uuid",
] ]
[[package]] [[package]]
@ -1338,7 +1326,6 @@ dependencies = [
"snarkvm-utilities", "snarkvm-utilities",
"thiserror", "thiserror",
"tracing", "tracing",
"uuid",
] ]
[[package]] [[package]]
@ -2148,7 +2135,7 @@ version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03"
dependencies = [ dependencies = [
"getrandom 0.1.15", "getrandom",
"libc", "libc",
"rand_chacha", "rand_chacha",
"rand_core 0.5.1", "rand_core 0.5.1",
@ -2171,7 +2158,7 @@ version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19"
dependencies = [ dependencies = [
"getrandom 0.1.15", "getrandom",
] ]
[[package]] [[package]]
@ -2235,7 +2222,7 @@ version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "de0737333e7a9502c789a36d7c7fa6092a49895d4faa31ca5df163857ded2e9d" checksum = "de0737333e7a9502c789a36d7c7fa6092a49895d4faa31ca5df163857ded2e9d"
dependencies = [ dependencies = [
"getrandom 0.1.15", "getrandom",
"redox_syscall", "redox_syscall",
"rust-argon2", "rust-argon2",
] ]
@ -3231,16 +3218,6 @@ dependencies = [
"percent-encoding", "percent-encoding",
] ]
[[package]]
name = "uuid"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7"
dependencies = [
"getrandom 0.2.2",
"serde",
]
[[package]] [[package]]
name = "vcpkg" name = "vcpkg"
version = "0.2.11" version = "0.2.11"

View File

@ -37,10 +37,6 @@ path = "../ast"
version = "1.2.2" version = "1.2.2"
path = "../grammar" path = "../grammar"
[dependencies.uuid]
version = "0.8"
features = [ "v4", "serde" ]
[dependencies.num-bigint] [dependencies.num-bigint]
version = "0.3" version = "0.3"

46
asg/src/context.rs Normal file
View File

@ -0,0 +1,46 @@
// 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 std::{cell::Cell, unimplemented};
use typed_arena::Arena;
use crate::ArenaNode;
pub struct AsgContextInner<'a> {
pub arena: &'a Arena<ArenaNode<'a>>,
pub next_id: Cell<u32>,
}
impl<'a> AsgContextInner<'a> {
pub fn new(arena: &'a Arena<ArenaNode<'a>>) -> &'a Self {
match arena.alloc(ArenaNode::Inner(AsgContextInner {
arena,
next_id: Cell::new(0),
})) {
ArenaNode::Inner(x) => x,
_ => unimplemented!(),
}
}
pub fn get_id(&self) -> u32 {
let next_id = self.next_id.get();
self.next_id.replace(next_id + 1);
next_id
}
}
pub type AsgContext<'a> = &'a AsgContextInner<'a>;

View File

@ -39,7 +39,7 @@ pub const STATE_LEAF_PSEUDO_CIRCUIT: &str = "$InputStateLeaf";
impl<'a> Input<'a> { impl<'a> Input<'a> {
fn make_header(scope: &'a Scope<'a>, name: &str) -> &'a Circuit<'a> { fn make_header(scope: &'a Scope<'a>, name: &str) -> &'a Circuit<'a> {
scope.alloc_circuit(Circuit { scope.alloc_circuit(Circuit {
id: uuid::Uuid::new_v4(), id: scope.context.get_id(),
name: RefCell::new(Identifier::new(name.to_string())), name: RefCell::new(Identifier::new(name.to_string())),
members: RefCell::new(IndexMap::new()), members: RefCell::new(IndexMap::new()),
core_mapping: RefCell::new(None), core_mapping: RefCell::new(None),
@ -68,7 +68,7 @@ impl<'a> Input<'a> {
); );
let container_circuit = input_scope.alloc_circuit(Circuit { let container_circuit = input_scope.alloc_circuit(Circuit {
id: uuid::Uuid::new_v4(), id: scope.context.get_id(),
name: RefCell::new(Identifier::new(CONTAINER_PSEUDO_CIRCUIT.to_string())), name: RefCell::new(Identifier::new(CONTAINER_PSEUDO_CIRCUIT.to_string())),
members: RefCell::new(container_members), members: RefCell::new(container_members),
core_mapping: RefCell::new(None), core_mapping: RefCell::new(None),
@ -83,7 +83,7 @@ impl<'a> Input<'a> {
state_leaf, state_leaf,
container_circuit, container_circuit,
container: input_scope.alloc_variable(RefCell::new(crate::InnerVariable { container: input_scope.alloc_variable(RefCell::new(crate::InnerVariable {
id: uuid::Uuid::new_v4(), id: scope.context.get_id(),
name: Identifier::new("input".to_string()), name: Identifier::new("input".to_string()),
type_: Type::Circuit(container_circuit), type_: Type::Circuit(container_circuit),
mutable: false, mutable: false,

View File

@ -71,9 +71,10 @@ pub use variable::*;
pub mod pass; pub mod pass;
pub use pass::*; pub use pass::*;
pub use leo_ast::{Ast, Identifier, Span}; pub mod context;
pub use context::*;
pub type AsgContext<'a> = &'a Arena<ArenaNode<'a>>; pub use leo_ast::{Ast, Identifier, Span};
use std::path::Path; use std::path::Path;
@ -132,6 +133,10 @@ pub fn load_asg<'a, T: ImportResolver<'a>>(
InternalProgram::new(context, leo_ast::Ast::new("load_ast", &ast)?.as_repr(), resolver) InternalProgram::new(context, leo_ast::Ast::new("load_ast", &ast)?.as_repr(), resolver)
} }
pub fn new_context<'a>() -> Arena<ArenaNode<'a>> { pub fn new_alloc_context<'a>() -> Arena<ArenaNode<'a>> {
Arena::new() Arena::new()
} }
pub fn new_context<'a>(arena: &'a Arena<ArenaNode<'a>>) -> AsgContext<'a> {
AsgContextInner::new(arena)
}

View File

@ -14,7 +14,18 @@
// You should have received a copy of the GNU General Public License // 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/>. // along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::{AsgConvertError, Circuit, Expression, Function, PartialType, Scope, Span, Statement, Variable}; use crate::{
AsgContextInner,
AsgConvertError,
Circuit,
Expression,
Function,
PartialType,
Scope,
Span,
Statement,
Variable,
};
/// A node in the abstract semantic graph. /// A node in the abstract semantic graph.
pub trait Node { pub trait Node {
@ -38,4 +49,5 @@ pub enum ArenaNode<'a> {
Variable(Variable<'a>), Variable(Variable<'a>),
Circuit(Circuit<'a>), Circuit(Circuit<'a>),
Function(Function<'a>), Function(Function<'a>),
Inner(AsgContextInner<'a>),
} }

View File

@ -18,7 +18,6 @@ use crate::{AsgConvertError, Function, Identifier, Node, Scope, Span, Type};
use indexmap::IndexMap; use indexmap::IndexMap;
use std::cell::RefCell; use std::cell::RefCell;
use uuid::Uuid;
#[derive(Clone)] #[derive(Clone)]
pub enum CircuitMember<'a> { pub enum CircuitMember<'a> {
@ -28,7 +27,7 @@ pub enum CircuitMember<'a> {
#[derive(Clone)] #[derive(Clone)]
pub struct Circuit<'a> { pub struct Circuit<'a> {
pub id: Uuid, pub id: u32,
pub name: RefCell<Identifier>, pub name: RefCell<Identifier>,
pub core_mapping: RefCell<Option<String>>, pub core_mapping: RefCell<Option<String>>,
pub scope: &'a Scope<'a>, pub scope: &'a Scope<'a>,
@ -58,7 +57,7 @@ impl<'a> Circuit<'a> {
let new_scope = scope.make_subscope(); let new_scope = scope.make_subscope();
let circuit = scope.alloc_circuit(Circuit { let circuit = scope.alloc_circuit(Circuit {
id: Uuid::new_v4(), id: scope.context.get_id(),
name: RefCell::new(value.circuit_name.clone()), name: RefCell::new(value.circuit_name.clone()),
members: RefCell::new(IndexMap::new()), members: RefCell::new(IndexMap::new()),
core_mapping: RefCell::new(None), core_mapping: RefCell::new(None),

View File

@ -32,7 +32,6 @@ use indexmap::IndexMap;
use leo_ast::FunctionInput; use leo_ast::FunctionInput;
use std::cell::{Cell, RefCell}; use std::cell::{Cell, RefCell};
use uuid::Uuid;
#[derive(Clone, Copy, PartialEq)] #[derive(Clone, Copy, PartialEq)]
pub enum FunctionQualifier { pub enum FunctionQualifier {
@ -43,7 +42,7 @@ pub enum FunctionQualifier {
#[derive(Clone)] #[derive(Clone)]
pub struct Function<'a> { pub struct Function<'a> {
pub id: Uuid, pub id: u32,
pub name: RefCell<Identifier>, pub name: RefCell<Identifier>,
pub output: Type<'a>, pub output: Type<'a>,
pub has_input: bool, pub has_input: bool,
@ -99,7 +98,7 @@ impl<'a> Function<'a> {
.. ..
}) => { }) => {
let variable = scope.alloc_variable(RefCell::new(crate::InnerVariable { let variable = scope.alloc_variable(RefCell::new(crate::InnerVariable {
id: Uuid::new_v4(), id: scope.context.get_id(),
name: identifier.clone(), name: identifier.clone(),
type_: scope.resolve_ast_type(&type_)?, type_: scope.resolve_ast_type(&type_)?,
mutable: *mutable, mutable: *mutable,
@ -117,7 +116,7 @@ impl<'a> Function<'a> {
return Err(AsgConvertError::invalid_self_in_global(&value.span)); return Err(AsgConvertError::invalid_self_in_global(&value.span));
} }
let function = scope.alloc_function(Function { let function = scope.alloc_function(Function {
id: Uuid::new_v4(), id: scope.context.get_id(),
name: RefCell::new(value.identifier.clone()), name: RefCell::new(value.identifier.clone()),
output, output,
has_input, has_input,
@ -137,7 +136,7 @@ impl<'a> Function<'a> {
if self.qualifier != FunctionQualifier::Static { if self.qualifier != FunctionQualifier::Static {
let circuit = self.circuit.get(); let circuit = self.circuit.get();
let self_variable = self.scope.alloc_variable(RefCell::new(crate::InnerVariable { let self_variable = self.scope.alloc_variable(RefCell::new(crate::InnerVariable {
id: Uuid::new_v4(), id: self.scope.context.get_id(),
name: Identifier::new("self".to_string()), name: Identifier::new("self".to_string()),
type_: Type::Circuit(circuit.as_ref().unwrap()), type_: Type::Circuit(circuit.as_ref().unwrap()),
mutable: self.qualifier == FunctionQualifier::MutSelfRef, mutable: self.qualifier == FunctionQualifier::MutSelfRef,

View File

@ -29,7 +29,6 @@ use leo_ast::{Identifier, PackageAccess, PackageOrPackages, Span};
use indexmap::IndexMap; use indexmap::IndexMap;
use std::cell::{Cell, RefCell}; use std::cell::{Cell, RefCell};
use uuid::Uuid;
/// Stores the Leo program abstract semantic graph (ASG). /// Stores the Leo program abstract semantic graph (ASG).
#[derive(Clone)] #[derive(Clone)]
@ -37,7 +36,7 @@ pub struct InternalProgram<'a> {
pub context: AsgContext<'a>, pub context: AsgContext<'a>,
/// The unique id of the program. /// The unique id of the program.
pub id: Uuid, pub id: u32,
/// The program file name. /// The program file name.
pub name: String, pub name: String,
@ -137,7 +136,7 @@ impl<'a> InternalProgram<'a> {
/// 4. resolve all asg nodes /// 4. resolve all asg nodes
/// ///
pub fn new<T: ImportResolver<'a>>( pub fn new<T: ImportResolver<'a>>(
arena: AsgContext<'a>, context: AsgContext<'a>,
program: &leo_ast::Program, program: &leo_ast::Program,
import_resolver: &mut T, import_resolver: &mut T,
) -> Result<Program<'a>, AsgConvertError> { ) -> Result<Program<'a>, AsgConvertError> {
@ -161,7 +160,7 @@ impl<'a> InternalProgram<'a> {
let pretty_package = package.join("."); let pretty_package = package.join(".");
let resolved_package = match wrapped_resolver.resolve_package( let resolved_package = match wrapped_resolver.resolve_package(
arena, context,
&package.iter().map(|x| &**x).collect::<Vec<_>>()[..], &package.iter().map(|x| &**x).collect::<Vec<_>>()[..],
span, span,
)? { )? {
@ -214,9 +213,9 @@ impl<'a> InternalProgram<'a> {
} }
} }
let import_scope = match arena.alloc(ArenaNode::Scope(Scope { let import_scope = match context.arena.alloc(ArenaNode::Scope(Scope {
arena, context,
id: uuid::Uuid::new_v4(), id: context.get_id(),
parent_scope: Cell::new(None), parent_scope: Cell::new(None),
circuit_self: Cell::new(None), circuit_self: Cell::new(None),
variables: RefCell::new(IndexMap::new()), variables: RefCell::new(IndexMap::new()),
@ -230,9 +229,9 @@ impl<'a> InternalProgram<'a> {
}; };
let scope = import_scope.alloc_scope(Scope { let scope = import_scope.alloc_scope(Scope {
arena, context,
input: Cell::new(Some(Input::new(import_scope))), // we use import_scope to avoid recursive scope ref here input: Cell::new(Some(Input::new(import_scope))), // we use import_scope to avoid recursive scope ref here
id: uuid::Uuid::new_v4(), id: context.get_id(),
parent_scope: Cell::new(Some(import_scope)), parent_scope: Cell::new(Some(import_scope)),
circuit_self: Cell::new(None), circuit_self: Cell::new(None),
variables: RefCell::new(IndexMap::new()), variables: RefCell::new(IndexMap::new()),
@ -296,8 +295,8 @@ impl<'a> InternalProgram<'a> {
} }
Ok(InternalProgram { Ok(InternalProgram {
context: arena, context,
id: Uuid::new_v4(), id: context.get_id(),
name: program.name.clone(), name: program.name.clone(),
test_functions, test_functions,
functions, functions,

View File

@ -14,20 +14,18 @@
// You should have received a copy of the GNU General Public License // 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/>. // along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::{ArenaNode, AsgConvertError, Circuit, Expression, Function, Input, Statement, Type, Variable}; use crate::{ArenaNode, AsgContext, AsgConvertError, Circuit, Expression, Function, Input, Statement, Type, Variable};
use indexmap::IndexMap; use indexmap::IndexMap;
use std::cell::{Cell, RefCell}; use std::cell::{Cell, RefCell};
use typed_arena::Arena;
use uuid::Uuid;
/// An abstract data type that track the current bindings for variables, functions, and circuits. /// An abstract data type that track the current bindings for variables, functions, and circuits.
#[derive(Clone)] #[derive(Clone)]
pub struct Scope<'a> { pub struct Scope<'a> {
pub arena: &'a Arena<ArenaNode<'a>>, pub context: AsgContext<'a>,
/// The unique id of the scope. /// The unique id of the scope.
pub id: Uuid, pub id: u32,
/// The parent scope that this scope inherits. /// The parent scope that this scope inherits.
pub parent_scope: Cell<Option<&'a Scope<'a>>>, pub parent_scope: Cell<Option<&'a Scope<'a>>>,
@ -54,42 +52,42 @@ pub struct Scope<'a> {
#[allow(clippy::mut_from_ref)] #[allow(clippy::mut_from_ref)]
impl<'a> Scope<'a> { impl<'a> Scope<'a> {
pub fn alloc_expression(&'a self, expr: Expression<'a>) -> &'a mut Expression<'a> { pub fn alloc_expression(&'a self, expr: Expression<'a>) -> &'a mut Expression<'a> {
match self.arena.alloc(ArenaNode::Expression(expr)) { match self.context.arena.alloc(ArenaNode::Expression(expr)) {
ArenaNode::Expression(e) => e, ArenaNode::Expression(e) => e,
_ => unimplemented!(), _ => unimplemented!(),
} }
} }
pub fn alloc_statement(&'a self, statement: Statement<'a>) -> &'a mut Statement<'a> { pub fn alloc_statement(&'a self, statement: Statement<'a>) -> &'a mut Statement<'a> {
match self.arena.alloc(ArenaNode::Statement(statement)) { match self.context.arena.alloc(ArenaNode::Statement(statement)) {
ArenaNode::Statement(e) => e, ArenaNode::Statement(e) => e,
_ => unimplemented!(), _ => unimplemented!(),
} }
} }
pub fn alloc_variable(&'a self, variable: Variable<'a>) -> &'a mut Variable<'a> { pub fn alloc_variable(&'a self, variable: Variable<'a>) -> &'a mut Variable<'a> {
match self.arena.alloc(ArenaNode::Variable(variable)) { match self.context.arena.alloc(ArenaNode::Variable(variable)) {
ArenaNode::Variable(e) => e, ArenaNode::Variable(e) => e,
_ => unimplemented!(), _ => unimplemented!(),
} }
} }
pub fn alloc_scope(&'a self, scope: Scope<'a>) -> &'a mut Scope<'a> { pub fn alloc_scope(&'a self, scope: Scope<'a>) -> &'a mut Scope<'a> {
match self.arena.alloc(ArenaNode::Scope(scope)) { match self.context.arena.alloc(ArenaNode::Scope(scope)) {
ArenaNode::Scope(e) => e, ArenaNode::Scope(e) => e,
_ => unimplemented!(), _ => unimplemented!(),
} }
} }
pub fn alloc_circuit(&'a self, circuit: Circuit<'a>) -> &'a mut Circuit<'a> { pub fn alloc_circuit(&'a self, circuit: Circuit<'a>) -> &'a mut Circuit<'a> {
match self.arena.alloc(ArenaNode::Circuit(circuit)) { match self.context.arena.alloc(ArenaNode::Circuit(circuit)) {
ArenaNode::Circuit(e) => e, ArenaNode::Circuit(e) => e,
_ => unimplemented!(), _ => unimplemented!(),
} }
} }
pub fn alloc_function(&'a self, function: Function<'a>) -> &'a mut Function<'a> { pub fn alloc_function(&'a self, function: Function<'a>) -> &'a mut Function<'a> {
match self.arena.alloc(ArenaNode::Function(function)) { match self.context.arena.alloc(ArenaNode::Function(function)) {
ArenaNode::Function(e) => e, ArenaNode::Function(e) => e,
_ => unimplemented!(), _ => unimplemented!(),
} }
@ -198,8 +196,8 @@ impl<'a> Scope<'a> {
/// ///
pub fn make_subscope(self: &'a Scope<'a>) -> &'a Scope<'a> { pub fn make_subscope(self: &'a Scope<'a>) -> &'a Scope<'a> {
self.alloc_scope(Scope::<'a> { self.alloc_scope(Scope::<'a> {
arena: self.arena, context: self.context,
id: Uuid::new_v4(), id: self.context.get_id(),
parent_scope: Cell::new(Some(self)), parent_scope: Cell::new(Some(self)),
circuit_self: Cell::new(None), circuit_self: Cell::new(None),
variables: RefCell::new(IndexMap::new()), variables: RefCell::new(IndexMap::new()),

View File

@ -96,7 +96,7 @@ impl<'a> FromAst<'a, leo_ast::DefinitionStatement> for &'a Statement<'a> {
))); )));
} }
variables.push(&*scope.alloc_variable(RefCell::new(InnerVariable { variables.push(&*scope.alloc_variable(RefCell::new(InnerVariable {
id: uuid::Uuid::new_v4(), id: scope.context.get_id(),
name: variable.identifier.clone(), name: variable.identifier.clone(),
type_: type_:
type_.ok_or_else(|| AsgConvertError::unresolved_type(&variable.identifier.name, &statement.span))?, type_.ok_or_else(|| AsgConvertError::unresolved_type(&variable.identifier.name, &statement.span))?,

View File

@ -58,7 +58,7 @@ impl<'a> FromAst<'a, leo_ast::IterationStatement> for &'a Statement<'a> {
let start = <&Expression<'a>>::from_ast(scope, &statement.start, expected_index_type.clone())?; let start = <&Expression<'a>>::from_ast(scope, &statement.start, expected_index_type.clone())?;
let stop = <&Expression<'a>>::from_ast(scope, &statement.stop, expected_index_type)?; let stop = <&Expression<'a>>::from_ast(scope, &statement.stop, expected_index_type)?;
let variable = scope.alloc_variable(RefCell::new(InnerVariable { let variable = scope.alloc_variable(RefCell::new(InnerVariable {
id: uuid::Uuid::new_v4(), id: scope.context.get_id(),
name: statement.variable.clone(), name: statement.variable.clone(),
type_: start type_: start
.get_type() .get_type()

View File

@ -19,8 +19,6 @@ use std::cell::RefCell;
use crate::{Expression, Statement, Type}; use crate::{Expression, Statement, Type};
use leo_ast::Identifier; use leo_ast::Identifier;
use uuid::Uuid;
/// Specifies how a program variable was declared. /// Specifies how a program variable was declared.
#[derive(Clone, Copy, PartialEq)] #[derive(Clone, Copy, PartialEq)]
pub enum VariableDeclaration { pub enum VariableDeclaration {
@ -33,7 +31,7 @@ pub enum VariableDeclaration {
/// Stores information on a program variable. /// Stores information on a program variable.
#[derive(Clone)] #[derive(Clone)]
pub struct InnerVariable<'a> { pub struct InnerVariable<'a> {
pub id: Uuid, pub id: u32,
pub name: Identifier, pub name: Identifier,
pub type_: Type<'a>, pub type_: Type<'a>,
pub mutable: bool, pub mutable: bool,

View File

@ -14,12 +14,10 @@
// You should have received a copy of the GNU General Public License // 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/>. // along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use leo_asg::new_context;
use crate::load_asg; use crate::load_asg;
#[test] #[test]
fn test_implicit_invalid() { fn test_implicit_invalid() {
let program_string = include_str!("implicit_invalid.leo"); let program_string = include_str!("implicit_invalid.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }

View File

@ -14,8 +14,6 @@
// You should have received a copy of the GNU General Public License // 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/>. // along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use leo_asg::new_context;
use crate::load_asg; use crate::load_asg;
// Expressions // Expressions
@ -23,49 +21,49 @@ use crate::load_asg;
#[test] #[test]
fn test_initializer_fail() { fn test_initializer_fail() {
let program_string = include_str!("initializer_fail.leo"); let program_string = include_str!("initializer_fail.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }
#[test] #[test]
fn test_input_nested_3x2_fail() { fn test_input_nested_3x2_fail() {
let program_string = include_str!("input_nested_3x2_fail.leo"); let program_string = include_str!("input_nested_3x2_fail.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }
#[test] #[test]
fn test_input_tuple_3x2_fail() { fn test_input_tuple_3x2_fail() {
let program_string = include_str!("input_tuple_3x2_fail.leo"); let program_string = include_str!("input_tuple_3x2_fail.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }
#[test] #[test]
fn test_multi_fail_initializer() { fn test_multi_fail_initializer() {
let program_string = include_str!("multi_fail_initializer.leo"); let program_string = include_str!("multi_fail_initializer.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }
#[test] #[test]
fn test_multi_inline_fail() { fn test_multi_inline_fail() {
let program_string = include_str!("multi_fail_inline.leo"); let program_string = include_str!("multi_fail_inline.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }
#[test] #[test]
fn test_multi_initializer_fail() { fn test_multi_initializer_fail() {
let program_string = include_str!("multi_initializer_fail.leo"); let program_string = include_str!("multi_initializer_fail.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }
#[test] #[test]
fn test_nested_3x2_value_fail() { fn test_nested_3x2_value_fail() {
let program_string = include_str!("nested_3x2_value_fail.leo"); let program_string = include_str!("nested_3x2_value_fail.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }
#[test] #[test]
fn test_tuple_3x2_value_fail() { fn test_tuple_3x2_value_fail() {
let program_string = include_str!("tuple_3x2_value_fail.leo"); let program_string = include_str!("tuple_3x2_value_fail.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }
// Array type tests // Array type tests
@ -73,65 +71,65 @@ fn test_tuple_3x2_value_fail() {
#[test] #[test]
fn test_type_fail() { fn test_type_fail() {
let program_string = include_str!("type_fail.leo"); let program_string = include_str!("type_fail.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }
#[test] #[test]
fn test_type_nested_value_nested_3x2_fail() { fn test_type_nested_value_nested_3x2_fail() {
let program_string = include_str!("type_nested_value_nested_3x2_fail.leo"); let program_string = include_str!("type_nested_value_nested_3x2_fail.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }
#[test] #[test]
fn test_type_nested_value_nested_4x3x2_fail() { fn test_type_nested_value_nested_4x3x2_fail() {
let program_string = include_str!("type_nested_value_nested_4x3x2_fail.leo"); let program_string = include_str!("type_nested_value_nested_4x3x2_fail.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }
#[test] #[test]
fn test_type_nested_value_tuple_3x2_fail() { fn test_type_nested_value_tuple_3x2_fail() {
let program_string = include_str!("type_nested_value_tuple_3x2_fail.leo"); let program_string = include_str!("type_nested_value_tuple_3x2_fail.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }
#[test] #[test]
fn test_type_nested_value_tuple_4x3x2_fail() { fn test_type_nested_value_tuple_4x3x2_fail() {
let program_string = include_str!("type_nested_value_tuple_4x3x2_fail.leo"); let program_string = include_str!("type_nested_value_tuple_4x3x2_fail.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }
#[test] #[test]
fn test_type_tuple_value_nested_3x2_fail() { fn test_type_tuple_value_nested_3x2_fail() {
let program_string = include_str!("type_tuple_value_nested_3x2_fail.leo"); let program_string = include_str!("type_tuple_value_nested_3x2_fail.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }
#[test] #[test]
fn test_type_tuple_value_nested_3x2_swap_fail() { fn test_type_tuple_value_nested_3x2_swap_fail() {
let program_string = include_str!("type_tuple_value_nested_3x2_swap_fail.leo"); let program_string = include_str!("type_tuple_value_nested_3x2_swap_fail.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }
#[test] #[test]
fn test_type_tuple_value_nested_4x3x2_fail() { fn test_type_tuple_value_nested_4x3x2_fail() {
let program_string = include_str!("type_tuple_value_nested_4x3x2_fail.leo"); let program_string = include_str!("type_tuple_value_nested_4x3x2_fail.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }
#[test] #[test]
fn test_type_tuple_value_tuple_3x2_fail() { fn test_type_tuple_value_tuple_3x2_fail() {
let program_string = include_str!("type_tuple_value_tuple_3x2_fail.leo"); let program_string = include_str!("type_tuple_value_tuple_3x2_fail.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }
#[test] #[test]
fn test_type_tuple_value_tuple_3x2_swap_fail() { fn test_type_tuple_value_tuple_3x2_swap_fail() {
let program_string = include_str!("type_tuple_value_tuple_3x2_swap_fail.leo"); let program_string = include_str!("type_tuple_value_tuple_3x2_swap_fail.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }
#[test] #[test]
fn test_type_tuple_value_tuple_4x3x2_fail() { fn test_type_tuple_value_tuple_4x3x2_fail() {
let program_string = include_str!("type_tuple_value_tuple_4x3x2_fail.leo"); let program_string = include_str!("type_tuple_value_tuple_4x3x2_fail.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }

View File

@ -14,24 +14,22 @@
// You should have received a copy of the GNU General Public License // 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/>. // along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use leo_asg::new_context;
use crate::load_asg; use crate::load_asg;
#[test] #[test]
fn test_not_u32() { fn test_not_u32() {
let program_string = include_str!("not_u32.leo"); let program_string = include_str!("not_u32.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }
#[test] #[test]
fn test_true_or_u32() { fn test_true_or_u32() {
let program_string = include_str!("true_or_u32.leo"); let program_string = include_str!("true_or_u32.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }
#[test] #[test]
fn test_true_and_u32() { fn test_true_and_u32() {
let program_string = include_str!("true_and_u32.leo"); let program_string = include_str!("true_and_u32.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }

View File

@ -14,8 +14,6 @@
// You should have received a copy of the GNU General Public License // 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/>. // along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use leo_asg::new_context;
use crate::load_asg; use crate::load_asg;
// Expressions // Expressions
@ -23,13 +21,13 @@ use crate::load_asg;
#[test] #[test]
fn test_inline_fail() { fn test_inline_fail() {
let program_string = include_str!("inline_fail.leo"); let program_string = include_str!("inline_fail.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }
#[test] #[test]
fn test_inline_undefined() { fn test_inline_undefined() {
let program_string = include_str!("inline_undefined.leo"); let program_string = include_str!("inline_undefined.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }
// Members // Members
@ -37,19 +35,19 @@ fn test_inline_undefined() {
#[test] #[test]
fn test_member_variable_fail() { fn test_member_variable_fail() {
let program_string = include_str!("member_variable_fail.leo"); let program_string = include_str!("member_variable_fail.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }
#[test] #[test]
fn test_member_function_fail() { fn test_member_function_fail() {
let program_string = include_str!("member_function_fail.leo"); let program_string = include_str!("member_function_fail.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }
#[test] #[test]
fn test_member_function_invalid() { fn test_member_function_invalid() {
let program_string = include_str!("member_function_invalid.leo"); let program_string = include_str!("member_function_invalid.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }
#[test] #[test]
@ -66,19 +64,19 @@ fn test_mut_member_function_fail() {
console.assert(a.echo(1u32) == 1u32); console.assert(a.echo(1u32) == 1u32);
}"#; }"#;
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }
#[test] #[test]
fn test_member_static_function_invalid() { fn test_member_static_function_invalid() {
let program_string = include_str!("member_static_function_invalid.leo"); let program_string = include_str!("member_static_function_invalid.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }
#[test] #[test]
fn test_member_static_function_undefined() { fn test_member_static_function_undefined() {
let program_string = include_str!("member_static_function_undefined.leo"); let program_string = include_str!("member_static_function_undefined.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }
// Mutability // Mutability
@ -86,37 +84,37 @@ fn test_member_static_function_undefined() {
#[test] #[test]
fn test_mutate_function_fail() { fn test_mutate_function_fail() {
let program_string = include_str!("mut_function_fail.leo"); let program_string = include_str!("mut_function_fail.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }
#[test] #[test]
fn test_mutate_self_variable_fail() { fn test_mutate_self_variable_fail() {
let program_string = include_str!("mut_self_variable_fail.leo"); let program_string = include_str!("mut_self_variable_fail.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }
#[test] #[test]
fn test_mutate_self_function_fail() { fn test_mutate_self_function_fail() {
let program_string = include_str!("mut_self_function_fail.leo"); let program_string = include_str!("mut_self_function_fail.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }
#[test] #[test]
fn test_mutate_self_static_function_fail() { fn test_mutate_self_static_function_fail() {
let program_string = include_str!("mut_self_static_function_fail.leo"); let program_string = include_str!("mut_self_static_function_fail.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }
#[test] #[test]
fn test_mutate_static_function_fail() { fn test_mutate_static_function_fail() {
let program_string = include_str!("mut_static_function_fail.leo"); let program_string = include_str!("mut_static_function_fail.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }
#[test] #[test]
fn test_mutate_variable_fail() { fn test_mutate_variable_fail() {
let program_string = include_str!("mut_variable_fail.leo"); let program_string = include_str!("mut_variable_fail.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }
// Self // Self
@ -124,17 +122,17 @@ fn test_mutate_variable_fail() {
#[test] #[test]
fn test_self_fail() { fn test_self_fail() {
let program_string = include_str!("self_fail.leo"); let program_string = include_str!("self_fail.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }
#[test] #[test]
fn test_self_member_invalid() { fn test_self_member_invalid() {
let program_string = include_str!("self_member_invalid.leo"); let program_string = include_str!("self_member_invalid.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }
#[test] #[test]
fn test_self_member_undefined() { fn test_self_member_undefined() {
let program_string = include_str!("self_member_undefined.leo"); let program_string = include_str!("self_member_undefined.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }

View File

@ -14,30 +14,28 @@
// You should have received a copy of the GNU General Public License // 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/>. // along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use leo_asg::new_context;
use crate::load_asg; use crate::load_asg;
#[test] #[test]
fn test_log_fail() { fn test_log_fail() {
let program_string = include_str!("log_fail.leo"); let program_string = include_str!("log_fail.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }
#[test] #[test]
fn test_log_parameter_fail_unknown() { fn test_log_parameter_fail_unknown() {
let program_string = include_str!("log_parameter_fail_unknown.leo"); let program_string = include_str!("log_parameter_fail_unknown.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }
#[test] #[test]
fn test_log_parameter_fail_empty() { fn test_log_parameter_fail_empty() {
let program_string = include_str!("log_parameter_fail_empty.leo"); let program_string = include_str!("log_parameter_fail_empty.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }
#[test] #[test]
fn test_log_parameter_fail_none() { fn test_log_parameter_fail_none() {
let program_string = include_str!("log_parameter_fail_empty.leo"); let program_string = include_str!("log_parameter_fail_empty.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }

View File

@ -14,30 +14,28 @@
// You should have received a copy of the GNU General Public License // 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/>. // along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use leo_asg::new_context;
use crate::load_asg; use crate::load_asg;
#[test] #[test]
fn test_core_circuit_invalid() { fn test_core_circuit_invalid() {
let program_string = include_str!("core_package_invalid.leo"); let program_string = include_str!("core_package_invalid.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }
#[test] #[test]
fn test_core_circuit_star_fail() { fn test_core_circuit_star_fail() {
let program_string = include_str!("core_circuit_star_fail.leo"); let program_string = include_str!("core_circuit_star_fail.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }
#[test] #[test]
fn test_core_package_invalid() { fn test_core_package_invalid() {
let program_string = include_str!("core_package_invalid.leo"); let program_string = include_str!("core_package_invalid.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }
#[test] #[test]
fn test_core_unstable_package_invalid() { fn test_core_unstable_package_invalid() {
let program_string = include_str!("core_unstable_package_invalid.leo"); let program_string = include_str!("core_unstable_package_invalid.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }

View File

@ -14,44 +14,42 @@
// You should have received a copy of the GNU General Public License // 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/>. // along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use leo_asg::new_context;
use crate::load_asg; use crate::load_asg;
#[test] #[test]
fn test_multiple_returns_fail() { fn test_multiple_returns_fail() {
let program_string = include_str!("multiple_returns_fail.leo"); let program_string = include_str!("multiple_returns_fail.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }
#[test] #[test]
fn test_multiple_returns_input_ambiguous() { fn test_multiple_returns_input_ambiguous() {
let program_string = include_str!("multiple_returns_input_ambiguous.leo"); let program_string = include_str!("multiple_returns_input_ambiguous.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }
#[test] #[test]
fn test_multiple_returns_fail_conditional() { fn test_multiple_returns_fail_conditional() {
let program_string = include_str!("multiple_returns_fail_conditional.leo"); let program_string = include_str!("multiple_returns_fail_conditional.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }
#[test] #[test]
fn test_scope_fail() { fn test_scope_fail() {
let program_string = include_str!("scope_fail.leo"); let program_string = include_str!("scope_fail.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }
#[test] #[test]
fn test_undefined() { fn test_undefined() {
let program_string = include_str!("undefined.leo"); let program_string = include_str!("undefined.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }
#[test] #[test]
fn test_array_input() { fn test_array_input() {
let program_string = include_str!("array_input.leo"); let program_string = include_str!("array_input.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }
// Test return multidimensional arrays // Test return multidimensional arrays
@ -59,11 +57,11 @@ fn test_array_input() {
#[test] #[test]
fn test_return_array_nested_fail() { fn test_return_array_nested_fail() {
let program_string = include_str!("return_array_nested_fail.leo"); let program_string = include_str!("return_array_nested_fail.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }
#[test] #[test]
fn test_return_array_tuple_fail() { fn test_return_array_tuple_fail() {
let program_string = include_str!("return_array_tuple_fail.leo"); let program_string = include_str!("return_array_tuple_fail.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }

View File

@ -19,17 +19,17 @@ use crate::load_asg;
#[test] #[test]
fn test_both_sign_high() { fn test_both_sign_high() {
let program_string = include_str!("both_sign_high.leo"); let program_string = include_str!("both_sign_high.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }
#[test] #[test]
fn test_both_sign_low() { fn test_both_sign_low() {
let program_string = include_str!("both_sign_low.leo"); let program_string = include_str!("both_sign_low.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }
#[test] #[test]
fn test_both_sign_inferred() { fn test_both_sign_inferred() {
let program_string = include_str!("both_sign_inferred.leo"); let program_string = include_str!("both_sign_inferred.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }

View File

@ -16,27 +16,25 @@
macro_rules! test_int { macro_rules! test_int {
($name: ident) => { ($name: ident) => {
use leo_asg::new_context;
pub struct $name {} pub struct $name {}
// we are not doing constant folding here, so asg doesnt catch this // we are not doing constant folding here, so asg doesnt catch this
// impl $name { // impl $name {
// fn test_negate_min_fail() { // fn test_negate_min_fail() {
// let program_string = include_str!("negate_min.leo"); // let program_string = include_str!("negate_min.leo");
// crate::load_asg(&new_context(), program_string).err().unwrap(); // crate::load_asg(program_string).err().unwrap();
// } // }
// } // }
impl super::IntegerTester for $name { impl super::IntegerTester for $name {
fn test_min_fail() { fn test_min_fail() {
let program_string = include_str!("min_fail.leo"); let program_string = include_str!("min_fail.leo");
crate::load_asg(&new_context(), program_string).err().unwrap(); crate::load_asg(program_string).err().unwrap();
} }
fn test_max_fail() { fn test_max_fail() {
let program_string = include_str!("max_fail.leo"); let program_string = include_str!("max_fail.leo");
crate::load_asg(&new_context(), program_string).err().unwrap(); crate::load_asg(program_string).err().unwrap();
} }
} }
}; };

View File

@ -16,19 +16,17 @@
macro_rules! test_uint { macro_rules! test_uint {
($name: ident) => { ($name: ident) => {
use leo_asg::new_context;
pub struct $name {} pub struct $name {}
impl super::IntegerTester for $name { impl super::IntegerTester for $name {
fn test_min_fail() { fn test_min_fail() {
let program_string = include_str!("min_fail.leo"); let program_string = include_str!("min_fail.leo");
crate::load_asg(&new_context(), program_string).err().unwrap(); crate::load_asg(program_string).err().unwrap();
} }
fn test_max_fail() { fn test_max_fail() {
let program_string = include_str!("max_fail.leo"); let program_string = include_str!("max_fail.leo");
crate::load_asg(&new_context(), program_string).err().unwrap(); crate::load_asg(program_string).err().unwrap();
} }
} }
}; };

View File

@ -14,48 +14,46 @@
// You should have received a copy of the GNU General Public License // 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/>. // along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use leo_asg::new_context;
use crate::load_asg; use crate::load_asg;
#[test] #[test]
fn test_let() { fn test_let() {
let program_string = include_str!("let.leo"); let program_string = include_str!("let.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }
#[test] #[test]
fn test_const_fail() { fn test_const_fail() {
let program_string = include_str!("const.leo"); let program_string = include_str!("const.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }
#[test] #[test]
fn test_array() { fn test_array() {
let program_string = include_str!("array.leo"); let program_string = include_str!("array.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }
#[test] #[test]
fn test_circuit() { fn test_circuit() {
let program_string = include_str!("circuit.leo"); let program_string = include_str!("circuit.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }
#[test] #[test]
fn test_circuit_function_mut() { fn test_circuit_function_mut() {
let program_string = include_str!("circuit_function_mut.leo"); let program_string = include_str!("circuit_function_mut.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }
#[test] #[test]
fn test_circuit_static_function_mut() { fn test_circuit_static_function_mut() {
let program_string = include_str!("circuit_static_function_mut.leo"); let program_string = include_str!("circuit_static_function_mut.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }
#[test] #[test]
fn test_function_input() { fn test_function_input() {
let program_string = include_str!("function_input.leo"); let program_string = include_str!("function_input.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }

View File

@ -14,18 +14,16 @@
// You should have received a copy of the GNU General Public License // 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/>. // along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use leo_asg::new_context;
use crate::load_asg; use crate::load_asg;
#[test] #[test]
fn test_num_returns_fail() { fn test_num_returns_fail() {
let program_string = include_str!("num_returns_fail.leo"); let program_string = include_str!("num_returns_fail.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }
#[test] #[test]
fn test_const_declaration_fail() { fn test_const_declaration_fail() {
let program_string = include_str!("const_declaration_fail.leo"); let program_string = include_str!("const_declaration_fail.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }

View File

@ -26,8 +26,8 @@ mod pass;
const TESTING_FILEPATH: &str = "input.leo"; const TESTING_FILEPATH: &str = "input.leo";
const TESTING_PROGRAM_NAME: &str = "test_program"; const TESTING_PROGRAM_NAME: &str = "test_program";
fn load_asg<'a>(context: AsgContext<'a>, program_string: &str) -> Result<Program<'a>, AsgConvertError> { fn load_asg(program_string: &str) -> Result<Program<'static>, AsgConvertError> {
load_asg_imports(context, program_string, &mut NullImportResolver) load_asg_imports(make_test_context(), program_string, &mut NullImportResolver)
} }
fn load_asg_imports<'a, T: ImportResolver<'a>>( fn load_asg_imports<'a, T: ImportResolver<'a>>(
@ -44,3 +44,9 @@ fn mocked_resolver<'a>(_context: AsgContext<'a>) -> MockedImportResolver<'a> {
let packages = indexmap::IndexMap::new(); let packages = indexmap::IndexMap::new();
MockedImportResolver { packages } MockedImportResolver { packages }
} }
//convenience function for tests, leaks memory
pub(crate) fn make_test_context() -> AsgContext<'static> {
let allocator = Box::leak(Box::new(new_alloc_context()));
new_context(allocator)
}

View File

@ -14,37 +14,35 @@
// You should have received a copy of the GNU General Public License // 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/>. // along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use leo_asg::new_context;
use crate::load_asg; use crate::load_asg;
#[test] #[test]
fn test_valid() { fn test_valid() {
let program_string = include_str!("valid.leo"); let program_string = include_str!("valid.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_implicit_valid() { fn test_implicit_valid() {
let program_string = include_str!("implicit_valid.leo"); let program_string = include_str!("implicit_valid.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_console_assert_pass() { fn test_console_assert_pass() {
let program_string = include_str!("console_assert_pass.leo"); let program_string = include_str!("console_assert_pass.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_ternary() { fn test_ternary() {
let program_string = include_str!("ternary.leo"); let program_string = include_str!("ternary.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_equal() { fn test_equal() {
let program_string = include_str!("equal.leo"); let program_string = include_str!("equal.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }

View File

@ -14,8 +14,6 @@
// You should have received a copy of the GNU General Public License // 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/>. // along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use leo_asg::new_context;
use crate::load_asg; use crate::load_asg;
// Registers // Registers
@ -23,7 +21,7 @@ use crate::load_asg;
#[test] #[test]
fn test_registers() { fn test_registers() {
let program_string = include_str!("registers.leo"); let program_string = include_str!("registers.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
// Expressions // Expressions
@ -31,173 +29,173 @@ fn test_registers() {
#[test] #[test]
fn test_inline() { fn test_inline() {
let program_string = include_str!("inline.leo"); let program_string = include_str!("inline.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_initializer() { fn test_initializer() {
let program_string = include_str!("initializer.leo"); let program_string = include_str!("initializer.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_initializer_input() { fn test_initializer_input() {
let program_string = include_str!("initializer_input.leo"); let program_string = include_str!("initializer_input.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_input_nested_3x2() { fn test_input_nested_3x2() {
let program_string = include_str!("input_nested_3x2.leo"); let program_string = include_str!("input_nested_3x2.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_input_tuple_3x2() { fn test_input_tuple_3x2() {
let program_string = include_str!("input_tuple_3x2.leo"); let program_string = include_str!("input_tuple_3x2.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_multi_initializer() { fn test_multi_initializer() {
let program_string = include_str!("multi_initializer.leo"); let program_string = include_str!("multi_initializer.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_nested_3x2_value() { fn test_nested_3x2_value() {
let program_string = include_str!("nested_3x2_value.leo"); let program_string = include_str!("nested_3x2_value.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_tuple_3x2_value() { fn test_tuple_3x2_value() {
let program_string = include_str!("tuple_3x2_value.leo"); let program_string = include_str!("tuple_3x2_value.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_spread() { fn test_spread() {
let program_string = include_str!("spread.leo"); let program_string = include_str!("spread.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_slice() { fn test_slice() {
let program_string = include_str!("slice.leo"); let program_string = include_str!("slice.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_index_u8() { fn test_index_u8() {
let program_string = include_str!("index_u8.leo"); let program_string = include_str!("index_u8.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_slice_i8() { fn test_slice_i8() {
let program_string = include_str!("slice_i8.leo"); let program_string = include_str!("slice_i8.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_slice_lower() { fn test_slice_lower() {
let program_string = include_str!("slice_lower.leo"); let program_string = include_str!("slice_lower.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_type_nested_value_nested_3x2() { fn test_type_nested_value_nested_3x2() {
let program_string = include_str!("type_nested_value_nested_3x2.leo"); let program_string = include_str!("type_nested_value_nested_3x2.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_type_nested_value_nested_4x3x2() { fn test_type_nested_value_nested_4x3x2() {
let program_string = include_str!("type_nested_value_nested_4x3x2.leo"); let program_string = include_str!("type_nested_value_nested_4x3x2.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_type_nested_value_tuple_3x2() { fn test_type_nested_value_tuple_3x2() {
let program_string = include_str!("type_nested_value_tuple_3x2.leo"); let program_string = include_str!("type_nested_value_tuple_3x2.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_type_nested_value_tuple_4x3x2() { fn test_type_nested_value_tuple_4x3x2() {
let program_string = include_str!("type_nested_value_tuple_4x3x2.leo"); let program_string = include_str!("type_nested_value_tuple_4x3x2.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_type_tuple_value_nested_3x2() { fn test_type_tuple_value_nested_3x2() {
let program_string = include_str!("type_tuple_value_nested_3x2.leo"); let program_string = include_str!("type_tuple_value_nested_3x2.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_type_tuple_value_nested_4x3x2() { fn test_type_tuple_value_nested_4x3x2() {
let program_string = include_str!("type_tuple_value_nested_4x3x2.leo"); let program_string = include_str!("type_tuple_value_nested_4x3x2.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_type_tuple_value_tuple_3x2() { fn test_type_tuple_value_tuple_3x2() {
let program_string = include_str!("type_tuple_value_tuple_3x2.leo"); let program_string = include_str!("type_tuple_value_tuple_3x2.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_type_tuple_value_tuple_4x3x2() { fn test_type_tuple_value_tuple_4x3x2() {
let program_string = include_str!("type_tuple_value_tuple_4x3x2.leo"); let program_string = include_str!("type_tuple_value_tuple_4x3x2.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_input_type_nested_value_nested_3x2() { fn test_input_type_nested_value_nested_3x2() {
let program_string = include_str!("type_input_3x2.leo"); let program_string = include_str!("type_input_3x2.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_input_type_nested_value_nested_4x3x2() { fn test_input_type_nested_value_nested_4x3x2() {
let program_string = include_str!("type_input_4x3x2.leo"); let program_string = include_str!("type_input_4x3x2.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_input_type_nested_value_tuple_3x2() { fn test_input_type_nested_value_tuple_3x2() {
let program_string = include_str!("type_input_3x2.leo"); let program_string = include_str!("type_input_3x2.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_input_type_nested_value_tuple_4x3x2() { fn test_input_type_nested_value_tuple_4x3x2() {
let program_string = include_str!("type_input_4x3x2.leo"); let program_string = include_str!("type_input_4x3x2.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_input_type_tuple_value_nested_3x2() { fn test_input_type_tuple_value_nested_3x2() {
let program_string = include_str!("type_input_3x2.leo"); let program_string = include_str!("type_input_3x2.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_input_type_tuple_value_nested_4x3x2() { fn test_input_type_tuple_value_nested_4x3x2() {
let program_string = include_str!("type_input_4x3x2.leo"); let program_string = include_str!("type_input_4x3x2.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_input_type_tuple_value_tuple_3x2() { fn test_input_type_tuple_value_tuple_3x2() {
let program_string = include_str!("type_input_3x2.leo"); let program_string = include_str!("type_input_3x2.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_input_type_tuple_value_tuple_4x3x2() { fn test_input_type_tuple_value_tuple_4x3x2() {
let program_string = include_str!("type_input_4x3x2.leo"); let program_string = include_str!("type_input_4x3x2.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }

View File

@ -14,20 +14,18 @@
// You should have received a copy of the GNU General Public License // 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/>. // along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use leo_asg::new_context;
use crate::load_asg; use crate::load_asg;
#[test] #[test]
fn test_input_pass() { fn test_input_pass() {
let program_string = include_str!("assert_eq_input.leo"); let program_string = include_str!("assert_eq_input.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_registers() { fn test_registers() {
let program_string = include_str!("output_register.leo"); let program_string = include_str!("output_register.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
// Boolean not ! // Boolean not !
@ -35,19 +33,19 @@ fn test_registers() {
#[test] #[test]
fn test_not_true() { fn test_not_true() {
let program_string = include_str!("not_true.leo"); let program_string = include_str!("not_true.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_not_false() { fn test_not_false() {
let program_string = include_str!("not_false.leo"); let program_string = include_str!("not_false.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_not_mutable() { fn test_not_mutable() {
let program_string = include_str!("not_mutable.leo"); let program_string = include_str!("not_mutable.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
// Boolean or || // Boolean or ||
@ -55,19 +53,19 @@ fn test_not_mutable() {
#[test] #[test]
fn test_true_or_true() { fn test_true_or_true() {
let program_string = include_str!("true_or_true.leo"); let program_string = include_str!("true_or_true.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_true_or_false() { fn test_true_or_false() {
let program_string = include_str!("true_or_false.leo"); let program_string = include_str!("true_or_false.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_false_or_false() { fn test_false_or_false() {
let program_string = include_str!("false_or_false.leo"); let program_string = include_str!("false_or_false.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
// Boolean and && // Boolean and &&
@ -75,19 +73,19 @@ fn test_false_or_false() {
#[test] #[test]
fn test_true_and_true() { fn test_true_and_true() {
let program_string = include_str!("true_and_true.leo"); let program_string = include_str!("true_and_true.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_true_and_false() { fn test_true_and_false() {
let program_string = include_str!("true_and_false.leo"); let program_string = include_str!("true_and_false.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_false_and_false() { fn test_false_and_false() {
let program_string = include_str!("false_and_false.leo"); let program_string = include_str!("false_and_false.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
// All // All
@ -95,5 +93,5 @@ fn test_false_and_false() {
#[test] #[test]
fn test_all() { fn test_all() {
let program_string = include_str!("all.leo"); let program_string = include_str!("all.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }

View File

@ -14,8 +14,6 @@
// You should have received a copy of the GNU General Public License // 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/>. // along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use leo_asg::new_context;
use crate::load_asg; use crate::load_asg;
// Expressions // Expressions
@ -23,7 +21,7 @@ use crate::load_asg;
#[test] #[test]
fn test_inline() { fn test_inline() {
let program_string = include_str!("inline.leo"); let program_string = include_str!("inline.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
// Members // Members
@ -31,19 +29,19 @@ fn test_inline() {
#[test] #[test]
fn test_member_variable() { fn test_member_variable() {
let program_string = include_str!("member_variable.leo"); let program_string = include_str!("member_variable.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_member_variable_and_function() { fn test_member_variable_and_function() {
let program_string = include_str!("member_variable_and_function.leo"); let program_string = include_str!("member_variable_and_function.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_member_function() { fn test_member_function() {
let program_string = include_str!("member_function.leo"); let program_string = include_str!("member_function.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
@ -60,25 +58,25 @@ fn test_mut_member_function() {
console.assert(a.echo(1u32) == 1u32); console.assert(a.echo(1u32) == 1u32);
}"#; }"#;
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_member_function_nested() { fn test_member_function_nested() {
let program_string = include_str!("member_function_nested.leo"); let program_string = include_str!("member_function_nested.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_member_static_function() { fn test_member_static_function() {
let program_string = include_str!("member_static_function.leo"); let program_string = include_str!("member_static_function.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_member_static_function_nested() { fn test_member_static_function_nested() {
let program_string = include_str!("member_static_function_nested.leo"); let program_string = include_str!("member_static_function_nested.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
// Mutability // Mutability
@ -86,19 +84,19 @@ fn test_member_static_function_nested() {
#[test] #[test]
fn test_mutate_self_variable() { fn test_mutate_self_variable() {
let program_string = include_str!("mut_self_variable.leo"); let program_string = include_str!("mut_self_variable.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_mutate_self_variable_conditional() { fn test_mutate_self_variable_conditional() {
let program_string = include_str!("mut_self_variable_conditional.leo"); let program_string = include_str!("mut_self_variable_conditional.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_mutate_variable() { fn test_mutate_variable() {
let program_string = include_str!("mut_variable.leo"); let program_string = include_str!("mut_variable.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
// Self // Self
@ -106,7 +104,7 @@ fn test_mutate_variable() {
#[test] #[test]
fn test_self_member_pass() { fn test_self_member_pass() {
let program_string = include_str!("self_member.leo"); let program_string = include_str!("self_member.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
// All // All
@ -114,13 +112,13 @@ fn test_self_member_pass() {
#[test] #[test]
fn test_pedersen_mock() { fn test_pedersen_mock() {
let program_string = include_str!("pedersen_mock.leo"); let program_string = include_str!("pedersen_mock.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_define_circuit_inside_circuit_function() { fn test_define_circuit_inside_circuit_function() {
let program_string = include_str!("define_circuit_inside_circuit_function.leo"); let program_string = include_str!("define_circuit_inside_circuit_function.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
@ -133,5 +131,5 @@ fn test_circuit_explicit_define() {
let x: One = One {x: 5}; let x: One = One {x: 5};
} }
"#; "#;
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }

View File

@ -14,32 +14,30 @@
// You should have received a copy of the GNU General Public License // 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/>. // along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use leo_asg::new_context;
use crate::load_asg; use crate::load_asg;
#[test] #[test]
fn test_log() { fn test_log() {
let program_string = include_str!("log.leo"); let program_string = include_str!("log.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_log_parameter() { fn test_log_parameter() {
let program_string = include_str!("log_parameter.leo"); let program_string = include_str!("log_parameter.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_log_parameter_many() { fn test_log_parameter_many() {
let program_string = include_str!("log_parameter_many.leo"); let program_string = include_str!("log_parameter_many.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_log_input() { fn test_log_input() {
let program_string = include_str!("log_input.leo"); let program_string = include_str!("log_input.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
// Debug // Debug
@ -47,7 +45,7 @@ fn test_log_input() {
#[test] #[test]
fn test_debug() { fn test_debug() {
let program_string = include_str!("debug.leo"); let program_string = include_str!("debug.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
// Error // Error
@ -55,7 +53,7 @@ fn test_debug() {
#[test] #[test]
fn test_error() { fn test_error() {
let program_string = include_str!("error.leo"); let program_string = include_str!("error.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
// Assertion // Assertion
@ -63,11 +61,11 @@ fn test_error() {
#[test] #[test]
fn test_assert() { fn test_assert() {
let program_string = include_str!("assert.leo"); let program_string = include_str!("assert.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_conditional_assert() { fn test_conditional_assert() {
let program_string = include_str!("conditional_assert.leo"); let program_string = include_str!("conditional_assert.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }

View File

@ -14,24 +14,22 @@
// You should have received a copy of the GNU General Public License // 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/>. // along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use leo_asg::new_context;
use crate::load_asg; use crate::load_asg;
#[test] #[test]
fn test_unstable_blake2s() { fn test_unstable_blake2s() {
let program_string = include_str!("unstable_blake2s.leo"); let program_string = include_str!("unstable_blake2s.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_blake2s_input() { fn test_blake2s_input() {
let program_string = include_str!("blake2s_input.leo"); let program_string = include_str!("blake2s_input.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_blake2s_random() { fn test_blake2s_random() {
let program_string = include_str!("blake2s_random.leo"); let program_string = include_str!("blake2s_random.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }

View File

@ -14,19 +14,17 @@
// You should have received a copy of the GNU General Public License // 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/>. // along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use leo_asg::new_context;
use crate::load_asg; use crate::load_asg;
#[test] #[test]
fn test_out_of_order() { fn test_out_of_order() {
let program_string = include_str!("out_of_order.leo"); let program_string = include_str!("out_of_order.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
// #[test] // #[test]
// #[ignore] // #[ignore]
// fn test_out_of_order_with_import() { // fn test_out_of_order_with_import() {
// let program_string = include_str!("out_of_order_with_import.leo"); // let program_string = include_str!("out_of_order_with_import.leo");
// load_asg(&new_context(), program_string).unwrap(); // load_asg(program_string).unwrap();
// } // }

View File

@ -14,20 +14,18 @@
// You should have received a copy of the GNU General Public License // 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/>. // along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use leo_asg::new_context;
use crate::load_asg; use crate::load_asg;
#[test] #[test]
fn test_negate() { fn test_negate() {
let program_string = include_str!("negate.leo"); let program_string = include_str!("negate.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_add() { fn test_add() {
let program_string = include_str!("add.leo"); let program_string = include_str!("add.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
@ -37,41 +35,41 @@ fn test_add_explicit() {
let c: field = 0field + 1field; let c: field = 0field + 1field;
} }
"#; "#;
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_sub() { fn test_sub() {
let program_string = include_str!("sub.leo"); let program_string = include_str!("sub.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_div() { fn test_div() {
let program_string = include_str!("div.leo"); let program_string = include_str!("div.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_mul() { fn test_mul() {
let program_string = include_str!("mul.leo"); let program_string = include_str!("mul.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_eq() { fn test_eq() {
let program_string = include_str!("eq.leo"); let program_string = include_str!("eq.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_console_assert_pass() { fn test_console_assert_pass() {
let program_string = include_str!("console_assert.leo"); let program_string = include_str!("console_assert.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_ternary() { fn test_ternary() {
let program_string = include_str!("ternary.leo"); let program_string = include_str!("ternary.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }

View File

@ -14,9 +14,7 @@
// You should have received a copy of the GNU General Public License // 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/>. // along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use leo_asg::new_context; use crate::{load_asg, make_test_context};
use crate::load_asg;
use leo_ast::Ast; use leo_ast::Ast;
use leo_grammar::Grammar; use leo_grammar::Grammar;
@ -25,8 +23,7 @@ use std::path::Path;
#[test] #[test]
fn test_basic() { fn test_basic() {
let program_string = include_str!("./circuits/pedersen_mock.leo"); let program_string = include_str!("./circuits/pedersen_mock.leo");
let context = new_context(); let asg = load_asg(program_string).unwrap();
let asg = load_asg(&context, program_string).unwrap();
let reformed_ast = leo_asg::reform_ast(&asg); let reformed_ast = leo_asg::reform_ast(&asg);
println!("{}", reformed_ast); println!("{}", reformed_ast);
// panic!(); // panic!();
@ -51,8 +48,7 @@ fn test_function_rename() {
console.assert(total == 20); console.assert(total == 20);
} }
"#; "#;
let context = new_context(); let asg = load_asg(program_string).unwrap();
let asg = load_asg(&context, program_string).unwrap();
let reformed_ast = leo_asg::reform_ast(&asg); let reformed_ast = leo_asg::reform_ast(&asg);
println!("{}", reformed_ast); println!("{}", reformed_ast);
// panic!(); // panic!();
@ -60,7 +56,7 @@ fn test_function_rename() {
#[test] #[test]
fn test_imports() { fn test_imports() {
let context = new_context(); let context = make_test_context();
let mut imports = crate::mocked_resolver(&context); let mut imports = crate::mocked_resolver(&context);
let test_import = r#" let test_import = r#"
circuit Point { circuit Point {
@ -74,7 +70,7 @@ fn test_imports() {
"#; "#;
imports imports
.packages .packages
.insert("test-import".to_string(), load_asg(&context, test_import).unwrap()); .insert("test-import".to_string(), load_asg(test_import).unwrap());
let program_string = r#" let program_string = r#"
import test-import.foo; import test-import.foo;

View File

@ -14,20 +14,18 @@
// You should have received a copy of the GNU General Public License // 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/>. // along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use leo_asg::new_context;
use crate::load_asg; use crate::load_asg;
#[test] #[test]
fn test_empty() { fn test_empty() {
let program_string = include_str!("empty.leo"); let program_string = include_str!("empty.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_iteration() { fn test_iteration() {
let program_string = include_str!("iteration.leo"); let program_string = include_str!("iteration.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
@ -47,7 +45,7 @@ fn test_const_args() {
console.assert(a == 20u32); console.assert(a == 20u32);
} }
"#; "#;
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
@ -68,7 +66,7 @@ fn test_const_args_used() {
console.assert(a == 6u8); console.assert(a == 6u8);
} }
"#; "#;
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
@ -87,61 +85,61 @@ fn test_const_args_fail() {
console.assert(a == 1u8); console.assert(a == 1u8);
} }
"#; "#;
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }
#[test] #[test]
fn test_iteration_repeated() { fn test_iteration_repeated() {
let program_string = include_str!("iteration_repeated.leo"); let program_string = include_str!("iteration_repeated.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_newlines() { fn test_newlines() {
let program_string = include_str!("newlines.leo"); let program_string = include_str!("newlines.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_multiple_returns() { fn test_multiple_returns() {
let program_string = include_str!("multiple_returns.leo"); let program_string = include_str!("multiple_returns.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_multiple_returns_main() { fn test_multiple_returns_main() {
let program_string = include_str!("multiple_returns_main.leo"); let program_string = include_str!("multiple_returns_main.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_repeated_function_call() { fn test_repeated_function_call() {
let program_string = include_str!("repeated.leo"); let program_string = include_str!("repeated.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_return() { fn test_return() {
let program_string = include_str!("return.leo"); let program_string = include_str!("return.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_undefined() { fn test_undefined() {
let program_string = include_str!("undefined.leo"); let program_string = include_str!("undefined.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }
#[test] #[test]
fn test_value_unchanged() { fn test_value_unchanged() {
let program_string = include_str!("value_unchanged.leo"); let program_string = include_str!("value_unchanged.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_array_input() { fn test_array_input() {
let program_string = include_str!("array_input.leo"); let program_string = include_str!("array_input.leo");
load_asg(&new_context(), program_string).err().unwrap(); load_asg(program_string).err().unwrap();
} }
// Test return multidimensional arrays // Test return multidimensional arrays
@ -149,13 +147,13 @@ fn test_array_input() {
#[test] #[test]
fn test_return_array_nested_pass() { fn test_return_array_nested_pass() {
let program_string = include_str!("return_array_nested_pass.leo"); let program_string = include_str!("return_array_nested_pass.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_return_array_tuple_pass() { fn test_return_array_tuple_pass() {
let program_string = include_str!("return_array_tuple_pass.leo"); let program_string = include_str!("return_array_tuple_pass.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
// Test return tuples // Test return tuples
@ -163,11 +161,11 @@ fn test_return_array_tuple_pass() {
#[test] #[test]
fn test_return_tuple() { fn test_return_tuple() {
let program_string = include_str!("return_tuple.leo"); let program_string = include_str!("return_tuple.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_return_tuple_conditional() { fn test_return_tuple_conditional() {
let program_string = include_str!("return_tuple_conditional.leo"); let program_string = include_str!("return_tuple_conditional.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }

View File

@ -14,14 +14,12 @@
// You should have received a copy of the GNU General Public License // 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/>. // along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use leo_asg::new_context;
use crate::load_asg; use crate::load_asg;
#[test] #[test]
fn test_one() { fn test_one() {
let program_string = include_str!("one.leo"); let program_string = include_str!("one.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
@ -31,79 +29,79 @@ fn test_implicit() {
let element: group = 0; let element: group = 0;
} }
"#; "#;
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_zero() { fn test_zero() {
let program_string = include_str!("zero.leo"); let program_string = include_str!("zero.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_point() { fn test_point() {
let program_string = include_str!("point.leo"); let program_string = include_str!("point.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_x_sign_high() { fn test_x_sign_high() {
let program_string = include_str!("x_sign_high.leo"); let program_string = include_str!("x_sign_high.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_x_sign_low() { fn test_x_sign_low() {
let program_string = include_str!("x_sign_low.leo"); let program_string = include_str!("x_sign_low.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_x_sign_inferred() { fn test_x_sign_inferred() {
let program_string = include_str!("x_sign_inferred.leo"); let program_string = include_str!("x_sign_inferred.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_y_sign_high() { fn test_y_sign_high() {
let program_string = include_str!("y_sign_high.leo"); let program_string = include_str!("y_sign_high.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_y_sign_low() { fn test_y_sign_low() {
let program_string = include_str!("y_sign_low.leo"); let program_string = include_str!("y_sign_low.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_y_sign_inferred() { fn test_y_sign_inferred() {
let program_string = include_str!("y_sign_inferred.leo"); let program_string = include_str!("y_sign_inferred.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_point_input() { fn test_point_input() {
let program_string = include_str!("point_input.leo"); let program_string = include_str!("point_input.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_input() { fn test_input() {
let program_string = include_str!("input.leo"); let program_string = include_str!("input.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_negate() { fn test_negate() {
let program_string = include_str!("negate.leo"); let program_string = include_str!("negate.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_add() { fn test_add() {
let program_string = include_str!("add.leo"); let program_string = include_str!("add.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
@ -113,29 +111,29 @@ fn test_add_explicit() {
let c: group = 0group + 1group; let c: group = 0group + 1group;
} }
"#; "#;
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_sub() { fn test_sub() {
let program_string = include_str!("sub.leo"); let program_string = include_str!("sub.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_console_assert_pass() { fn test_console_assert_pass() {
let program_string = include_str!("assert_eq.leo"); let program_string = include_str!("assert_eq.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_eq() { fn test_eq() {
let program_string = include_str!("eq.leo"); let program_string = include_str!("eq.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_ternary() { fn test_ternary() {
let program_string = include_str!("ternary.leo"); let program_string = include_str!("ternary.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }

View File

@ -14,17 +14,15 @@
// You should have received a copy of the GNU General Public License // 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/>. // along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use leo_asg::new_context; use crate::{load_asg, load_asg_imports, make_test_context, mocked_resolver};
use crate::{load_asg, load_asg_imports, mocked_resolver};
#[test] #[test]
fn test_basic() { fn test_basic() {
let context = new_context(); let context = make_test_context();
let mut imports = mocked_resolver(&context); let mut imports = mocked_resolver(&context);
imports.packages.insert( imports.packages.insert(
"test-import".to_string(), "test-import".to_string(),
load_asg(&context, include_str!("src/test-import.leo")).unwrap(), load_asg(include_str!("src/test-import.leo")).unwrap(),
); );
let program_string = include_str!("basic.leo"); let program_string = include_str!("basic.leo");
load_asg_imports(&context, program_string, &mut imports).unwrap(); load_asg_imports(&context, program_string, &mut imports).unwrap();
@ -32,11 +30,11 @@ fn test_basic() {
#[test] #[test]
fn test_multiple() { fn test_multiple() {
let context = new_context(); let context = make_test_context();
let mut imports = mocked_resolver(&context); let mut imports = mocked_resolver(&context);
imports.packages.insert( imports.packages.insert(
"test-import".to_string(), "test-import".to_string(),
load_asg(&context, include_str!("src/test-import.leo")).unwrap(), load_asg(include_str!("src/test-import.leo")).unwrap(),
); );
let program_string = include_str!("multiple.leo"); let program_string = include_str!("multiple.leo");
load_asg_imports(&context, program_string, &mut imports).unwrap(); load_asg_imports(&context, program_string, &mut imports).unwrap();
@ -44,11 +42,11 @@ fn test_multiple() {
#[test] #[test]
fn test_star() { fn test_star() {
let context = new_context(); let context = make_test_context();
let mut imports = mocked_resolver(&context); let mut imports = mocked_resolver(&context);
imports.packages.insert( imports.packages.insert(
"test-import".to_string(), "test-import".to_string(),
load_asg(&context, include_str!("src/test-import.leo")).unwrap(), load_asg(include_str!("src/test-import.leo")).unwrap(),
); );
let program_string = include_str!("star.leo"); let program_string = include_str!("star.leo");
@ -57,11 +55,11 @@ fn test_star() {
#[test] #[test]
fn test_alias() { fn test_alias() {
let context = new_context(); let context = make_test_context();
let mut imports = mocked_resolver(&context); let mut imports = mocked_resolver(&context);
imports.packages.insert( imports.packages.insert(
"test-import".to_string(), "test-import".to_string(),
load_asg(&context, include_str!("src/test-import.leo")).unwrap(), load_asg(include_str!("src/test-import.leo")).unwrap(),
); );
let program_string = include_str!("alias.leo"); let program_string = include_str!("alias.leo");
@ -71,20 +69,18 @@ fn test_alias() {
// naming tests // naming tests
#[test] #[test]
fn test_name() { fn test_name() {
let context = new_context(); let context = make_test_context();
let mut imports = mocked_resolver(&context); let mut imports = mocked_resolver(&context);
imports.packages.insert( imports.packages.insert(
"hello-world".to_string(), "hello-world".to_string(),
load_asg(&context, include_str!("src/hello-world.leo")).unwrap(), load_asg(include_str!("src/hello-world.leo")).unwrap(),
);
imports.packages.insert(
"a0-f".to_string(),
load_asg(&context, include_str!("src/a0-f.leo")).unwrap(),
);
imports.packages.insert(
"a-9".to_string(),
load_asg(&context, include_str!("src/a-9.leo")).unwrap(),
); );
imports
.packages
.insert("a0-f".to_string(), load_asg(include_str!("src/a0-f.leo")).unwrap());
imports
.packages
.insert("a-9".to_string(), load_asg(include_str!("src/a-9.leo")).unwrap());
let program_string = include_str!("names.leo"); let program_string = include_str!("names.leo");
load_asg_imports(&context, program_string, &mut imports).unwrap(); load_asg_imports(&context, program_string, &mut imports).unwrap();
@ -93,31 +89,31 @@ fn test_name() {
// more complex tests // more complex tests
#[test] #[test]
fn test_many_import() { fn test_many_import() {
let context = new_context(); let context = make_test_context();
let mut imports = mocked_resolver(&context); let mut imports = mocked_resolver(&context);
imports.packages.insert( imports.packages.insert(
"test-import".to_string(), "test-import".to_string(),
load_asg(&context, include_str!("src/test-import.leo")).unwrap(), load_asg(include_str!("src/test-import.leo")).unwrap(),
); );
imports.packages.insert( imports.packages.insert(
"bar".to_string(), "bar".to_string(),
load_asg(&context, include_str!("imports/bar/src/lib.leo")).unwrap(), load_asg(include_str!("imports/bar/src/lib.leo")).unwrap(),
); );
imports.packages.insert( imports.packages.insert(
"bar.baz".to_string(), "bar.baz".to_string(),
load_asg(&context, include_str!("imports/bar/src/baz.leo")).unwrap(), load_asg(include_str!("imports/bar/src/baz.leo")).unwrap(),
); );
imports.packages.insert( imports.packages.insert(
"bar.baz".to_string(), "bar.baz".to_string(),
load_asg(&context, include_str!("imports/bar/src/baz.leo")).unwrap(), load_asg(include_str!("imports/bar/src/baz.leo")).unwrap(),
); );
imports.packages.insert( imports.packages.insert(
"bar.bat.bat".to_string(), "bar.bat.bat".to_string(),
load_asg(&context, include_str!("imports/bar/src/bat/bat.leo")).unwrap(), load_asg(include_str!("imports/bar/src/bat/bat.leo")).unwrap(),
); );
imports.packages.insert( imports.packages.insert(
"car".to_string(), "car".to_string(),
load_asg(&context, include_str!("imports/car/src/lib.leo")).unwrap(), load_asg(include_str!("imports/car/src/lib.leo")).unwrap(),
); );
let program_string = include_str!("many_import.leo"); let program_string = include_str!("many_import.leo");
@ -126,31 +122,31 @@ fn test_many_import() {
#[test] #[test]
fn test_many_import_star() { fn test_many_import_star() {
let context = new_context(); let context = make_test_context();
let mut imports = mocked_resolver(&context); let mut imports = mocked_resolver(&context);
imports.packages.insert( imports.packages.insert(
"test-import".to_string(), "test-import".to_string(),
load_asg(&context, include_str!("src/test-import.leo")).unwrap(), load_asg(include_str!("src/test-import.leo")).unwrap(),
); );
imports.packages.insert( imports.packages.insert(
"bar".to_string(), "bar".to_string(),
load_asg(&context, include_str!("imports/bar/src/lib.leo")).unwrap(), load_asg(include_str!("imports/bar/src/lib.leo")).unwrap(),
); );
imports.packages.insert( imports.packages.insert(
"bar.baz".to_string(), "bar.baz".to_string(),
load_asg(&context, include_str!("imports/bar/src/baz.leo")).unwrap(), load_asg(include_str!("imports/bar/src/baz.leo")).unwrap(),
); );
imports.packages.insert( imports.packages.insert(
"bar.baz".to_string(), "bar.baz".to_string(),
load_asg(&context, include_str!("imports/bar/src/baz.leo")).unwrap(), load_asg(include_str!("imports/bar/src/baz.leo")).unwrap(),
); );
imports.packages.insert( imports.packages.insert(
"bar.bat.bat".to_string(), "bar.bat.bat".to_string(),
load_asg(&context, include_str!("imports/bar/src/bat/bat.leo")).unwrap(), load_asg(include_str!("imports/bar/src/bat/bat.leo")).unwrap(),
); );
imports.packages.insert( imports.packages.insert(
"car".to_string(), "car".to_string(),
load_asg(&context, include_str!("imports/car/src/lib.leo")).unwrap(), load_asg(include_str!("imports/car/src/lib.leo")).unwrap(),
); );
let program_string = include_str!("many_import_star.leo"); let program_string = include_str!("many_import_star.leo");

View File

@ -14,18 +14,16 @@
// You should have received a copy of the GNU General Public License // 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/>. // along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use leo_asg::new_context;
use crate::load_asg; use crate::load_asg;
#[test] #[test]
fn test_input_pass() { fn test_input_pass() {
let program_string = include_str!("main.leo"); let program_string = include_str!("main.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_input_multiple() { fn test_input_multiple() {
let program_string = include_str!("main_multiple.leo"); let program_string = include_str!("main_multiple.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }

View File

@ -14,12 +14,10 @@
// You should have received a copy of the GNU General Public License // 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/>. // along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use leo_asg::new_context;
use crate::load_asg; use crate::load_asg;
#[test] #[test]
fn test_access() { fn test_access() {
let program_string = include_str!("access.leo"); let program_string = include_str!("access.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }

View File

@ -14,18 +14,16 @@
// You should have received a copy of the GNU General Public License // 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/>. // along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use leo_asg::new_context;
use crate::load_asg; use crate::load_asg;
#[test] #[test]
fn test_access_state() { fn test_access_state() {
let program_string = include_str!("access_state.leo"); let program_string = include_str!("access_state.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_access_all() { fn test_access_all() {
let program_string = include_str!("access_all.leo"); let program_string = include_str!("access_all.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }

View File

@ -16,96 +16,94 @@
macro_rules! test_int { macro_rules! test_int {
($name: ident) => { ($name: ident) => {
use leo_asg::new_context;
pub struct $name {} pub struct $name {}
impl $name { impl $name {
fn test_negate() { fn test_negate() {
let program_string = include_str!("negate.leo"); let program_string = include_str!("negate.leo");
crate::load_asg(&new_context(), program_string).unwrap(); crate::load_asg(program_string).unwrap();
} }
fn test_negate_zero() { fn test_negate_zero() {
let program_string = include_str!("negate_zero.leo"); let program_string = include_str!("negate_zero.leo");
crate::load_asg(&new_context(), program_string).unwrap(); crate::load_asg(program_string).unwrap();
} }
} }
impl super::IntegerTester for $name { impl super::IntegerTester for $name {
fn test_min() { fn test_min() {
let program_string = include_str!("min.leo"); let program_string = include_str!("min.leo");
crate::load_asg(&new_context(), program_string).unwrap(); crate::load_asg(program_string).unwrap();
} }
fn test_max() { fn test_max() {
let program_string = include_str!("max.leo"); let program_string = include_str!("max.leo");
crate::load_asg(&new_context(), program_string).unwrap(); crate::load_asg(program_string).unwrap();
} }
fn test_add() { fn test_add() {
let program_string = include_str!("add.leo"); let program_string = include_str!("add.leo");
crate::load_asg(&new_context(), program_string).unwrap(); crate::load_asg(program_string).unwrap();
} }
fn test_sub() { fn test_sub() {
let program_string = include_str!("sub.leo"); let program_string = include_str!("sub.leo");
crate::load_asg(&new_context(), program_string).unwrap(); crate::load_asg(program_string).unwrap();
} }
fn test_mul() { fn test_mul() {
let program_string = include_str!("mul.leo"); let program_string = include_str!("mul.leo");
crate::load_asg(&new_context(), program_string).unwrap(); crate::load_asg(program_string).unwrap();
} }
fn test_div() { fn test_div() {
let program_string = include_str!("div.leo"); let program_string = include_str!("div.leo");
crate::load_asg(&new_context(), program_string).unwrap(); crate::load_asg(program_string).unwrap();
} }
fn test_pow() { fn test_pow() {
let program_string = include_str!("pow.leo"); let program_string = include_str!("pow.leo");
crate::load_asg(&new_context(), program_string).unwrap(); crate::load_asg(program_string).unwrap();
} }
fn test_eq() { fn test_eq() {
let program_string = include_str!("eq.leo"); let program_string = include_str!("eq.leo");
crate::load_asg(&new_context(), program_string).unwrap(); crate::load_asg(program_string).unwrap();
} }
fn test_ne() { fn test_ne() {
let program_string = include_str!("ne.leo"); let program_string = include_str!("ne.leo");
crate::load_asg(&new_context(), program_string).unwrap(); crate::load_asg(program_string).unwrap();
} }
fn test_ge() { fn test_ge() {
let program_string = include_str!("ge.leo"); let program_string = include_str!("ge.leo");
crate::load_asg(&new_context(), program_string).unwrap(); crate::load_asg(program_string).unwrap();
} }
fn test_gt() { fn test_gt() {
let program_string = include_str!("gt.leo"); let program_string = include_str!("gt.leo");
crate::load_asg(&new_context(), program_string).unwrap(); crate::load_asg(program_string).unwrap();
} }
fn test_le() { fn test_le() {
let program_string = include_str!("le.leo"); let program_string = include_str!("le.leo");
crate::load_asg(&new_context(), program_string).unwrap(); crate::load_asg(program_string).unwrap();
} }
fn test_lt() { fn test_lt() {
let program_string = include_str!("lt.leo"); let program_string = include_str!("lt.leo");
crate::load_asg(&new_context(), program_string).unwrap(); crate::load_asg(program_string).unwrap();
} }
fn test_console_assert() { fn test_console_assert() {
let program_string = include_str!("console_assert.leo"); let program_string = include_str!("console_assert.leo");
crate::load_asg(&new_context(), program_string).unwrap(); crate::load_asg(program_string).unwrap();
} }
fn test_ternary() { fn test_ternary() {
let program_string = include_str!("ternary.leo"); let program_string = include_str!("ternary.leo");
crate::load_asg(&new_context(), program_string).unwrap(); crate::load_asg(program_string).unwrap();
} }
} }
}; };

View File

@ -16,84 +16,82 @@
macro_rules! test_uint { macro_rules! test_uint {
($name: ident) => { ($name: ident) => {
use leo_asg::new_context;
pub struct $name {} pub struct $name {}
impl super::IntegerTester for $name { impl super::IntegerTester for $name {
fn test_min() { fn test_min() {
let program_string = include_str!("min.leo"); let program_string = include_str!("min.leo");
crate::load_asg(&new_context(), program_string).unwrap(); crate::load_asg(program_string).unwrap();
} }
fn test_max() { fn test_max() {
let program_string = include_str!("max.leo"); let program_string = include_str!("max.leo");
crate::load_asg(&new_context(), program_string).unwrap(); crate::load_asg(program_string).unwrap();
} }
fn test_add() { fn test_add() {
let program_string = include_str!("add.leo"); let program_string = include_str!("add.leo");
crate::load_asg(&new_context(), program_string).unwrap(); crate::load_asg(program_string).unwrap();
} }
fn test_sub() { fn test_sub() {
let program_string = include_str!("sub.leo"); let program_string = include_str!("sub.leo");
crate::load_asg(&new_context(), program_string).unwrap(); crate::load_asg(program_string).unwrap();
} }
fn test_mul() { fn test_mul() {
let program_string = include_str!("mul.leo"); let program_string = include_str!("mul.leo");
crate::load_asg(&new_context(), program_string).unwrap(); crate::load_asg(program_string).unwrap();
} }
fn test_div() { fn test_div() {
let program_string = include_str!("div.leo"); let program_string = include_str!("div.leo");
crate::load_asg(&new_context(), program_string).unwrap(); crate::load_asg(program_string).unwrap();
} }
fn test_pow() { fn test_pow() {
let program_string = include_str!("pow.leo"); let program_string = include_str!("pow.leo");
crate::load_asg(&new_context(), program_string).unwrap(); crate::load_asg(program_string).unwrap();
} }
fn test_eq() { fn test_eq() {
let program_string = include_str!("eq.leo"); let program_string = include_str!("eq.leo");
crate::load_asg(&new_context(), program_string).unwrap(); crate::load_asg(program_string).unwrap();
} }
fn test_ne() { fn test_ne() {
let program_string = include_str!("ne.leo"); let program_string = include_str!("ne.leo");
crate::load_asg(&new_context(), program_string).unwrap(); crate::load_asg(program_string).unwrap();
} }
fn test_ge() { fn test_ge() {
let program_string = include_str!("ge.leo"); let program_string = include_str!("ge.leo");
crate::load_asg(&new_context(), program_string).unwrap(); crate::load_asg(program_string).unwrap();
} }
fn test_gt() { fn test_gt() {
let program_string = include_str!("gt.leo"); let program_string = include_str!("gt.leo");
crate::load_asg(&new_context(), program_string).unwrap(); crate::load_asg(program_string).unwrap();
} }
fn test_le() { fn test_le() {
let program_string = include_str!("le.leo"); let program_string = include_str!("le.leo");
crate::load_asg(&new_context(), program_string).unwrap(); crate::load_asg(program_string).unwrap();
} }
fn test_lt() { fn test_lt() {
let program_string = include_str!("lt.leo"); let program_string = include_str!("lt.leo");
crate::load_asg(&new_context(), program_string).unwrap(); crate::load_asg(program_string).unwrap();
} }
fn test_console_assert() { fn test_console_assert() {
let program_string = include_str!("console_assert.leo"); let program_string = include_str!("console_assert.leo");
crate::load_asg(&new_context(), program_string).unwrap(); crate::load_asg(program_string).unwrap();
} }
fn test_ternary() { fn test_ternary() {
let program_string = include_str!("ternary.leo"); let program_string = include_str!("ternary.leo");
crate::load_asg(&new_context(), program_string).unwrap(); crate::load_asg(program_string).unwrap();
} }
} }
}; };

View File

@ -14,60 +14,58 @@
// You should have received a copy of the GNU General Public License // 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/>. // along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use leo_asg::new_context;
use crate::load_asg; use crate::load_asg;
#[test] #[test]
fn test_let_mut() { fn test_let_mut() {
let program_string = include_str!("let_mut.leo"); let program_string = include_str!("let_mut.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_let_mut_nested() { fn test_let_mut_nested() {
let program_string = include_str!("let_mut_nested.leo"); let program_string = include_str!("let_mut_nested.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_array_mut() { fn test_array_mut() {
let program_string = include_str!("array_mut.leo"); let program_string = include_str!("array_mut.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_array_tuple_mut() { fn test_array_tuple_mut() {
let program_string = include_str!("array_tuple_mut.leo"); let program_string = include_str!("array_tuple_mut.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_array_splice_mut() { fn test_array_splice_mut() {
let program_string = include_str!("array_splice_mut.leo"); let program_string = include_str!("array_splice_mut.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_circuit_mut() { fn test_circuit_mut() {
let program_string = include_str!("circuit_mut.leo"); let program_string = include_str!("circuit_mut.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_circuit_variable_mut() { fn test_circuit_variable_mut() {
let program_string = include_str!("circuit_variable_mut.leo"); let program_string = include_str!("circuit_variable_mut.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_function_input_mut() { fn test_function_input_mut() {
let program_string = include_str!("function_input_mut.leo"); let program_string = include_str!("function_input_mut.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_swap() { fn test_swap() {
let program_string = include_str!("swap.leo"); let program_string = include_str!("swap.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }

View File

@ -14,42 +14,40 @@
// You should have received a copy of the GNU General Public License // 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/>. // along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use leo_asg::new_context;
use crate::load_asg; use crate::load_asg;
#[test] #[test]
fn test_assert() { fn test_assert() {
let program_string = include_str!("assert.leo"); let program_string = include_str!("assert.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_mutate() { fn test_mutate() {
let program_string = include_str!("mutate.leo"); let program_string = include_str!("mutate.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_for_loop() { fn test_for_loop() {
let program_string = include_str!("for_loop.leo"); let program_string = include_str!("for_loop.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_chain() { fn test_chain() {
let program_string = include_str!("chain.leo"); let program_string = include_str!("chain.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_nested() { fn test_nested() {
let program_string = include_str!("nested.leo"); let program_string = include_str!("nested.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_multiple_returns() { fn test_multiple_returns() {
let program_string = include_str!("multiple_returns.leo"); let program_string = include_str!("multiple_returns.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }

View File

@ -14,8 +14,6 @@
// You should have received a copy of the GNU General Public License // 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/>. // along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use leo_asg::new_context;
use crate::load_asg; use crate::load_asg;
pub mod conditional; pub mod conditional;
@ -25,7 +23,7 @@ pub mod conditional;
#[test] #[test]
fn test_ternary_basic() { fn test_ternary_basic() {
let program_string = include_str!("ternary_basic.leo"); let program_string = include_str!("ternary_basic.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
// Iteration for i {start}..{stop} { statements } // Iteration for i {start}..{stop} { statements }
@ -33,11 +31,11 @@ fn test_ternary_basic() {
#[test] #[test]
fn test_iteration_basic() { fn test_iteration_basic() {
let program_string = include_str!("iteration_basic.leo"); let program_string = include_str!("iteration_basic.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_block() { fn test_block() {
let program_string = include_str!("block.leo"); let program_string = include_str!("block.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }

View File

@ -14,72 +14,70 @@
// You should have received a copy of the GNU General Public License // 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/>. // along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use leo_asg::new_context;
use crate::load_asg; use crate::load_asg;
#[test] #[test]
fn test_tuple_basic() { fn test_tuple_basic() {
let program_string = include_str!("basic.leo"); let program_string = include_str!("basic.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_tuple_access() { fn test_tuple_access() {
let program_string = include_str!("access.leo"); let program_string = include_str!("access.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_tuple_typed() { fn test_tuple_typed() {
let program_string = include_str!("typed.leo"); let program_string = include_str!("typed.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_multiple() { fn test_multiple() {
let program_string = include_str!("multiple.leo"); let program_string = include_str!("multiple.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_multiple_typed() { fn test_multiple_typed() {
let program_string = include_str!("multiple_typed.leo"); let program_string = include_str!("multiple_typed.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_function() { fn test_function() {
let program_string = include_str!("function.leo"); let program_string = include_str!("function.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_function_typed() { fn test_function_typed() {
let program_string = include_str!("function_typed.leo"); let program_string = include_str!("function_typed.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_function_multiple() { fn test_function_multiple() {
let program_string = include_str!("function_multiple.leo"); let program_string = include_str!("function_multiple.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_nested() { fn test_nested() {
let program_string = include_str!("nested.leo"); let program_string = include_str!("nested.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_nested_access() { fn test_nested_access() {
let program_string = include_str!("nested_access.leo"); let program_string = include_str!("nested_access.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }
#[test] #[test]
fn test_nested_typed() { fn test_nested_typed() {
let program_string = include_str!("nested_typed.leo"); let program_string = include_str!("nested_typed.leo");
load_asg(&new_context(), program_string).unwrap(); load_asg(program_string).unwrap();
} }

View File

@ -108,10 +108,6 @@ version = "1.0"
[dependencies.tracing] [dependencies.tracing]
version = "0.1" version = "0.1"
[dependencies.uuid]
version = "0.8"
features = [ "v4", "serde" ]
[dev-dependencies.num-bigint] [dev-dependencies.num-bigint]
version = "0.3" version = "0.3"

View File

@ -47,7 +47,10 @@ use std::{
pub use leo_asg::{new_context, AsgContext as Context, AsgContext}; pub use leo_asg::{new_context, AsgContext as Context, AsgContext};
thread_local! { thread_local! {
static THREAD_GLOBAL_CONTEXT: AsgContext<'static> = Box::leak(Box::new(new_context())); static THREAD_GLOBAL_CONTEXT: AsgContext<'static> = {
let leaked = Box::leak(Box::new(leo_asg::new_alloc_context()));
leo_asg::new_context(leaked)
}
} }
/// Conventience function to return a leaked thread-local global context. Should only be used for transient programs (like cli). /// Conventience function to return a leaked thread-local global context. Should only be used for transient programs (like cli).

View File

@ -26,10 +26,11 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
pub fn evaluate_ref(&mut self, variable_ref: &VariableRef) -> Result<ConstrainedValue<'a, F, G>, ExpressionError> { pub fn evaluate_ref(&mut self, variable_ref: &VariableRef) -> Result<ConstrainedValue<'a, F, G>, ExpressionError> {
// Evaluate the identifier name in the current function scope // Evaluate the identifier name in the current function scope
let variable = variable_ref.variable.borrow(); let variable = variable_ref.variable.borrow();
let result_value = if let Some(value) = self.get(&variable.id) { let result_value = if let Some(value) = self.get(variable.id) {
value.clone() value.clone()
} else { } else {
return Err(ExpressionError::undefined_identifier(variable.name.clone())); // todo: probably can be a panic here instead return Err(ExpressionError::undefined_identifier(variable.name.clone()));
// todo: probably can be a panic here instead
}; };
Ok(result_value) Ok(result_value)

View File

@ -83,7 +83,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
if function.qualifier == FunctionQualifier::MutSelfRef { if function.qualifier == FunctionQualifier::MutSelfRef {
if let (Some(self_var), Some(target)) = (self_var, target) { if let (Some(self_var), Some(target)) = (self_var, target) {
let new_self = self let new_self = self
.get(&self_var.borrow().id) .get(self_var.borrow().id)
.expect("no self variable found in mut self context") .expect("no self variable found in mut self context")
.clone(); .clone();
if let Some(assignable_target) = self.resolve_mut_ref(cs, target)? { if let Some(assignable_target) = self.resolve_mut_ref(cs, target)? {

View File

@ -104,7 +104,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
let variable = target.unwrap(); let variable = target.unwrap();
let variable = variable.borrow(); let variable = variable.borrow();
let mut result = vec![match self.get_mut(&variable.id) { let mut result = vec![match self.get_mut(variable.id) {
Some(value) => value, Some(value) => value,
None => return Err(StatementError::undefined_variable(variable.name.to_string(), span)), None => return Err(StatementError::undefined_variable(variable.name.to_string(), span)),
}]; }];

View File

@ -22,11 +22,10 @@ use leo_asg::Program;
use snarkvm_models::curves::PrimeField; use snarkvm_models::curves::PrimeField;
use indexmap::IndexMap; use indexmap::IndexMap;
use uuid::Uuid;
pub struct ConstrainedProgram<'a, F: PrimeField, G: GroupType<F>> { pub struct ConstrainedProgram<'a, F: PrimeField, G: GroupType<F>> {
pub asg: Program<'a>, pub asg: Program<'a>,
identifiers: IndexMap<Uuid, ConstrainedValue<'a, F, G>>, identifiers: IndexMap<u32, ConstrainedValue<'a, F, G>>,
} }
impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> { impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
@ -37,15 +36,15 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
} }
} }
pub(crate) fn store(&mut self, name: Uuid, value: ConstrainedValue<'a, F, G>) { pub(crate) fn store(&mut self, id: u32, value: ConstrainedValue<'a, F, G>) {
self.identifiers.insert(name, value); self.identifiers.insert(id, value);
} }
pub(crate) fn get(&self, name: &Uuid) -> Option<&ConstrainedValue<'a, F, G>> { pub(crate) fn get(&self, id: u32) -> Option<&ConstrainedValue<'a, F, G>> {
self.identifiers.get(name) self.identifiers.get(&id)
} }
pub(crate) fn get_mut(&mut self, name: &Uuid) -> Option<&mut ConstrainedValue<'a, F, G>> { pub(crate) fn get_mut(&mut self, id: u32) -> Option<&mut ConstrainedValue<'a, F, G>> {
self.identifiers.get_mut(name) self.identifiers.get_mut(&id)
} }
} }

View File

@ -60,7 +60,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
let variable = assignee.target_variable.get().borrow(); let variable = assignee.target_variable.get().borrow();
let mut result = vec![match self.get_mut(&variable.id) { let mut result = vec![match self.get_mut(variable.id) {
Some(value) => value, Some(value) => value,
None => return Err(StatementError::undefined_variable(variable.name.to_string(), span)), None => return Err(StatementError::undefined_variable(variable.name.to_string(), span)),
}]; }];

View File

@ -36,7 +36,7 @@ pub mod statements;
pub mod syntax; pub mod syntax;
pub mod tuples; pub mod tuples;
use leo_asg::{new_context, AsgContext}; use leo_asg::{new_alloc_context, new_context, AsgContext};
use leo_ast::{InputValue, MainInput}; use leo_ast::{InputValue, MainInput};
use leo_compiler::{ use leo_compiler::{
compiler::Compiler, compiler::Compiler,
@ -60,7 +60,8 @@ pub type EdwardsConstrainedValue = ConstrainedValue<'static, Fq, EdwardsGroupTyp
//convenience function for tests, leaks memory //convenience function for tests, leaks memory
pub(crate) fn make_test_context() -> AsgContext<'static> { pub(crate) fn make_test_context() -> AsgContext<'static> {
Box::leak(Box::new(new_context())) let allocator = Box::leak(Box::new(new_alloc_context()));
new_context(allocator)
} }
fn new_compiler() -> EdwardsTestCompiler { fn new_compiler() -> EdwardsTestCompiler {