mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-12-24 18:52:58 +03:00
merge master, clippy fixes
This commit is contained in:
commit
76b8b3f0a6
@ -319,52 +319,52 @@ impl ConstInt {
|
||||
IntegerType::I8 => ConstInt::I8(
|
||||
value
|
||||
.parse()
|
||||
.map_err(|_| LeoError::from(AsgError::invalid_int(&value, span)))?,
|
||||
.map_err(|_| LeoError::from(AsgError::invalid_int(value, span)))?,
|
||||
),
|
||||
IntegerType::I16 => ConstInt::I16(
|
||||
value
|
||||
.parse()
|
||||
.map_err(|_| LeoError::from(AsgError::invalid_int(&value, span)))?,
|
||||
.map_err(|_| LeoError::from(AsgError::invalid_int(value, span)))?,
|
||||
),
|
||||
IntegerType::I32 => ConstInt::I32(
|
||||
value
|
||||
.parse()
|
||||
.map_err(|_| LeoError::from(AsgError::invalid_int(&value, span)))?,
|
||||
.map_err(|_| LeoError::from(AsgError::invalid_int(value, span)))?,
|
||||
),
|
||||
IntegerType::I64 => ConstInt::I64(
|
||||
value
|
||||
.parse()
|
||||
.map_err(|_| LeoError::from(AsgError::invalid_int(&value, span)))?,
|
||||
.map_err(|_| LeoError::from(AsgError::invalid_int(value, span)))?,
|
||||
),
|
||||
IntegerType::I128 => ConstInt::I128(
|
||||
value
|
||||
.parse()
|
||||
.map_err(|_| LeoError::from(AsgError::invalid_int(&value, span)))?,
|
||||
.map_err(|_| LeoError::from(AsgError::invalid_int(value, span)))?,
|
||||
),
|
||||
IntegerType::U8 => ConstInt::U8(
|
||||
value
|
||||
.parse()
|
||||
.map_err(|_| LeoError::from(AsgError::invalid_int(&value, span)))?,
|
||||
.map_err(|_| LeoError::from(AsgError::invalid_int(value, span)))?,
|
||||
),
|
||||
IntegerType::U16 => ConstInt::U16(
|
||||
value
|
||||
.parse()
|
||||
.map_err(|_| LeoError::from(AsgError::invalid_int(&value, span)))?,
|
||||
.map_err(|_| LeoError::from(AsgError::invalid_int(value, span)))?,
|
||||
),
|
||||
IntegerType::U32 => ConstInt::U32(
|
||||
value
|
||||
.parse()
|
||||
.map_err(|_| LeoError::from(AsgError::invalid_int(&value, span)))?,
|
||||
.map_err(|_| LeoError::from(AsgError::invalid_int(value, span)))?,
|
||||
),
|
||||
IntegerType::U64 => ConstInt::U64(
|
||||
value
|
||||
.parse()
|
||||
.map_err(|_| LeoError::from(AsgError::invalid_int(&value, span)))?,
|
||||
.map_err(|_| LeoError::from(AsgError::invalid_int(value, span)))?,
|
||||
),
|
||||
IntegerType::U128 => ConstInt::U128(
|
||||
value
|
||||
.parse()
|
||||
.map_err(|_| LeoError::from(AsgError::invalid_int(&value, span)))?,
|
||||
.map_err(|_| LeoError::from(AsgError::invalid_int(value, span)))?,
|
||||
),
|
||||
})
|
||||
}
|
||||
|
@ -115,7 +115,7 @@ impl<'a> FromAst<'a, leo_ast::ValueExpression> for Constant<'a> {
|
||||
value: ConstValue::Boolean(
|
||||
value
|
||||
.parse::<bool>()
|
||||
.map_err(|_| LeoError::from(AsgError::invalid_boolean(&value, span)))?,
|
||||
.map_err(|_| LeoError::from(AsgError::invalid_boolean(value, span)))?,
|
||||
),
|
||||
}
|
||||
}
|
||||
@ -154,7 +154,7 @@ impl<'a> FromAst<'a, leo_ast::ValueExpression> for Constant<'a> {
|
||||
value: ConstValue::Field(
|
||||
value
|
||||
.parse()
|
||||
.map_err(|_| LeoError::from(AsgError::invalid_int(&value, span)))?,
|
||||
.map_err(|_| LeoError::from(AsgError::invalid_int(value, span)))?,
|
||||
),
|
||||
}
|
||||
}
|
||||
@ -174,7 +174,9 @@ impl<'a> FromAst<'a, leo_ast::ValueExpression> for Constant<'a> {
|
||||
span: Some(value.span().clone()),
|
||||
value: ConstValue::Group(match &**value {
|
||||
leo_ast::GroupValue::Single(value, _) => GroupValue::Single(value.clone()),
|
||||
leo_ast::GroupValue::Tuple(leo_ast::GroupTuple { x, y, .. }) => {
|
||||
leo_ast::GroupValue::Tuple(tuple) => {
|
||||
let x = &tuple.x;
|
||||
let y = &tuple.y;
|
||||
GroupValue::Tuple(x.into(), y.into())
|
||||
}
|
||||
}),
|
||||
@ -195,7 +197,7 @@ impl<'a> FromAst<'a, leo_ast::ValueExpression> for Constant<'a> {
|
||||
value: ConstValue::Field(
|
||||
value
|
||||
.parse()
|
||||
.map_err(|_| LeoError::from(AsgError::invalid_int(&value, span)))?,
|
||||
.map_err(|_| LeoError::from(AsgError::invalid_int(value, span)))?,
|
||||
),
|
||||
},
|
||||
Some(PartialType::Type(Type::Group)) => Constant {
|
||||
@ -268,11 +270,11 @@ impl<'a> Into<leo_ast::ValueExpression> for &Constant<'a> {
|
||||
GroupValue::Single(single) => {
|
||||
leo_ast::GroupValue::Single(single.clone(), self.span.clone().unwrap_or_default())
|
||||
}
|
||||
GroupValue::Tuple(left, right) => leo_ast::GroupValue::Tuple(leo_ast::GroupTuple {
|
||||
GroupValue::Tuple(left, right) => leo_ast::GroupValue::Tuple(Box::new(leo_ast::GroupTuple {
|
||||
x: left.into(),
|
||||
y: right.into(),
|
||||
span: self.span.clone().unwrap_or_default(),
|
||||
}),
|
||||
})),
|
||||
})),
|
||||
ConstValue::Int(int) => leo_ast::ValueExpression::Integer(
|
||||
int.get_int_type(),
|
||||
|
@ -342,7 +342,7 @@ impl<'a> FromAst<'a, leo_ast::Expression> for &'a Expression<'a> {
|
||||
.context
|
||||
.alloc_expression(CallExpression::from_ast(scope, call, expected_type).map(Expression::Call)?),
|
||||
};
|
||||
expression.enforce_parents(&expression);
|
||||
expression.enforce_parents(expression);
|
||||
Ok(expression)
|
||||
}
|
||||
}
|
||||
|
@ -153,7 +153,7 @@ impl<'a> Into<leo_ast::Circuit> for &Circuit<'a> {
|
||||
CircuitMember::Variable(type_) => {
|
||||
leo_ast::CircuitMember::CircuitVariable(Identifier::new((&**name).into()), type_.into())
|
||||
}
|
||||
CircuitMember::Function(func) => leo_ast::CircuitMember::CircuitFunction((*func).into()),
|
||||
CircuitMember::Function(func) => leo_ast::CircuitMember::CircuitFunction(Box::new((*func).into())),
|
||||
})
|
||||
.collect();
|
||||
leo_ast::Circuit {
|
||||
|
@ -90,24 +90,18 @@ impl<'a> Function<'a> {
|
||||
FunctionInput::MutSelfKeyword(_) => {
|
||||
qualifier = FunctionQualifier::MutSelfRef;
|
||||
}
|
||||
FunctionInput::Variable(leo_ast::FunctionInputVariable {
|
||||
type_,
|
||||
identifier,
|
||||
const_,
|
||||
mutable,
|
||||
..
|
||||
}) => {
|
||||
FunctionInput::Variable(input_variable) => {
|
||||
let variable = scope.context.alloc_variable(RefCell::new(crate::InnerVariable {
|
||||
id: scope.context.get_id(),
|
||||
name: identifier.clone(),
|
||||
type_: scope.resolve_ast_type(&type_, &value.span)?,
|
||||
mutable: *mutable,
|
||||
const_: *const_,
|
||||
name: input_variable.identifier.clone(),
|
||||
type_: scope.resolve_ast_type(&input_variable.type_, &value.span)?,
|
||||
mutable: input_variable.mutable,
|
||||
const_: input_variable.const_,
|
||||
declaration: crate::VariableDeclaration::Parameter,
|
||||
references: vec![],
|
||||
assignments: vec![],
|
||||
}));
|
||||
arguments.insert(identifier.name.to_string(), Cell::new(&*variable));
|
||||
arguments.insert(input_variable.identifier.name.to_string(), Cell::new(&*variable));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -190,13 +184,13 @@ impl<'a> Into<leo_ast::Function> for &Function<'a> {
|
||||
.iter()
|
||||
.map(|(_, variable)| {
|
||||
let variable = variable.get().borrow();
|
||||
leo_ast::FunctionInput::Variable(leo_ast::FunctionInputVariable {
|
||||
leo_ast::FunctionInput::Variable(Box::new(leo_ast::FunctionInputVariable {
|
||||
identifier: variable.name.clone(),
|
||||
mutable: variable.mutable,
|
||||
const_: variable.const_,
|
||||
type_: (&variable.type_).into(),
|
||||
span: Span::default(),
|
||||
})
|
||||
}))
|
||||
})
|
||||
.collect();
|
||||
let (body, span) = match self.body.get() {
|
||||
|
@ -118,7 +118,7 @@ fn resolve_import_package_access(
|
||||
PackageAccess::Multiple(packages) => {
|
||||
package_segments.push(packages.name.name.to_string());
|
||||
for subaccess in packages.accesses.iter() {
|
||||
resolve_import_package_access(output, package_segments.clone(), &subaccess);
|
||||
resolve_import_package_access(output, package_segments.clone(), subaccess);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -281,7 +281,7 @@ impl<'a> Program<'a> {
|
||||
.for_each(|variable_name| assert!(name.contains(&variable_name.identifier.name.to_string())));
|
||||
let gc = <&Statement<'a>>::from_ast(scope, global_const, None)?;
|
||||
if let Statement::Definition(gc) = gc {
|
||||
scope.global_consts.borrow_mut().insert(name.clone(), &gc);
|
||||
scope.global_consts.borrow_mut().insert(name.clone(), gc);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -308,6 +308,6 @@ impl<'a, T: Monoid, R: MonoidalReducerProgram<'a, T>> MonoidalDirector<'a, T, R>
|
||||
let circuits = input.circuits.iter().map(|(_, c)| self.reduce_circuit(c)).collect();
|
||||
|
||||
self.reducer
|
||||
.reduce_program(&input, imported_modules, functions, circuits)
|
||||
.reduce_program(input, imported_modules, functions, circuits)
|
||||
}
|
||||
}
|
||||
|
@ -79,12 +79,12 @@ impl<'a> FromAst<'a, leo_ast::AssignStatement> for &'a Statement<'a> {
|
||||
}
|
||||
} else {
|
||||
scope
|
||||
.resolve_variable(&name)
|
||||
.ok_or_else(|| LeoError::from(AsgError::unresolved_reference(name, &span)))?
|
||||
.resolve_variable(name)
|
||||
.ok_or_else(|| LeoError::from(AsgError::unresolved_reference(name, span)))?
|
||||
};
|
||||
|
||||
if !variable.borrow().mutable {
|
||||
return Err(LeoError::from(AsgError::immutable_assignment(&name, &statement.span)));
|
||||
return Err(LeoError::from(AsgError::immutable_assignment(name, &statement.span)));
|
||||
}
|
||||
let mut target_type: Option<PartialType> = Some(variable.borrow().type_.clone().into());
|
||||
|
||||
@ -120,7 +120,7 @@ impl<'a> FromAst<'a, leo_ast::AssignStatement> for &'a Statement<'a> {
|
||||
let left = match left {
|
||||
ConstValue::Int(x) => x.to_usize().ok_or_else(|| {
|
||||
LeoError::from(AsgError::invalid_assign_index(
|
||||
&name,
|
||||
name,
|
||||
&x.to_string(),
|
||||
&statement.span,
|
||||
))
|
||||
@ -130,7 +130,7 @@ impl<'a> FromAst<'a, leo_ast::AssignStatement> for &'a Statement<'a> {
|
||||
let right = match right {
|
||||
ConstValue::Int(x) => x.to_usize().ok_or_else(|| {
|
||||
LeoError::from(AsgError::invalid_assign_index(
|
||||
&name,
|
||||
name,
|
||||
&x.to_string(),
|
||||
&statement.span,
|
||||
))
|
||||
@ -141,7 +141,7 @@ impl<'a> FromAst<'a, leo_ast::AssignStatement> for &'a Statement<'a> {
|
||||
target_type = Some(PartialType::Array(item.clone(), Some((right - left) as usize)))
|
||||
} else {
|
||||
return Err(LeoError::from(AsgError::invalid_backwards_assignment(
|
||||
&name,
|
||||
name,
|
||||
left,
|
||||
right,
|
||||
&statement.span,
|
||||
@ -149,7 +149,7 @@ impl<'a> FromAst<'a, leo_ast::AssignStatement> for &'a Statement<'a> {
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => return Err(LeoError::from(AsgError::index_into_non_array(&name, &statement.span))),
|
||||
_ => return Err(LeoError::from(AsgError::index_into_non_array(name, &statement.span))),
|
||||
}
|
||||
|
||||
AssignAccess::ArrayRange(Cell::new(left), Cell::new(right))
|
||||
@ -157,7 +157,7 @@ impl<'a> FromAst<'a, leo_ast::AssignStatement> for &'a Statement<'a> {
|
||||
AstAssigneeAccess::ArrayIndex(index) => {
|
||||
target_type = match target_type.clone() {
|
||||
Some(PartialType::Array(item, _)) => item.map(|x| *x),
|
||||
_ => return Err(LeoError::from(AsgError::index_into_non_array(&name, &statement.span))),
|
||||
_ => return Err(LeoError::from(AsgError::index_into_non_array(name, &statement.span))),
|
||||
};
|
||||
AssignAccess::ArrayIndex(Cell::new(<&Expression<'a>>::from_ast(
|
||||
scope,
|
||||
@ -169,12 +169,12 @@ impl<'a> FromAst<'a, leo_ast::AssignStatement> for &'a Statement<'a> {
|
||||
let index = index
|
||||
.value
|
||||
.parse::<usize>()
|
||||
.map_err(|_| LeoError::from(AsgError::parse_index_error(&span)))?;
|
||||
.map_err(|_| LeoError::from(AsgError::parse_index_error(span)))?;
|
||||
target_type = match target_type {
|
||||
Some(PartialType::Tuple(types)) => types.get(index).cloned().ok_or_else(|| {
|
||||
LeoError::from(AsgError::tuple_index_out_of_bounds(index, &statement.span))
|
||||
})?,
|
||||
_ => return Err(LeoError::from(AsgError::index_into_non_tuple(&name, &statement.span))),
|
||||
_ => return Err(LeoError::from(AsgError::index_into_non_tuple(name, &statement.span))),
|
||||
};
|
||||
AssignAccess::Tuple(index)
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ impl<'a> FromAst<'a, leo_ast::Block> for BlockStatement<'a> {
|
||||
|
||||
let mut output = vec![];
|
||||
for item in statement.statements.iter() {
|
||||
output.push(Cell::new(<&'a Statement<'a>>::from_ast(&new_scope, item, None)?));
|
||||
output.push(Cell::new(<&'a Statement<'a>>::from_ast(new_scope, item, None)?));
|
||||
}
|
||||
Ok(BlockStatement {
|
||||
parent: Cell::new(None),
|
||||
|
@ -58,7 +58,7 @@ impl<'a> FromAst<'a, leo_ast::DefinitionStatement> for &'a Statement<'a> {
|
||||
let type_ = statement
|
||||
.type_
|
||||
.as_ref()
|
||||
.map(|x| scope.resolve_ast_type(&x, &statement.span))
|
||||
.map(|x| scope.resolve_ast_type(x, &statement.span))
|
||||
.transpose()?;
|
||||
|
||||
let value = <&Expression<'a>>::from_ast(scope, &statement.value, type_.clone().map(Into::into))?;
|
||||
|
@ -87,7 +87,7 @@ impl<'a> FromAst<'a, leo_ast::Statement> for &'a Statement<'a> {
|
||||
.context
|
||||
.alloc_statement(Statement::Return(ReturnStatement::from_ast(scope, statement, None)?)),
|
||||
Definition(statement) => Self::from_ast(scope, statement, None)?,
|
||||
Assign(statement) => Self::from_ast(scope, statement, None)?,
|
||||
Assign(statement) => Self::from_ast(scope, &**statement, None)?,
|
||||
Conditional(statement) => {
|
||||
scope
|
||||
.context
|
||||
@ -95,7 +95,7 @@ impl<'a> FromAst<'a, leo_ast::Statement> for &'a Statement<'a> {
|
||||
scope, statement, None,
|
||||
)?))
|
||||
}
|
||||
Iteration(statement) => Self::from_ast(scope, statement, None)?,
|
||||
Iteration(statement) => Self::from_ast(scope, &**statement, None)?,
|
||||
Console(statement) => scope
|
||||
.context
|
||||
.alloc_statement(Statement::Console(ConsoleStatement::from_ast(scope, statement, None)?)),
|
||||
@ -119,9 +119,9 @@ impl<'a> Into<leo_ast::Statement> for &Statement<'a> {
|
||||
match self {
|
||||
Return(statement) => leo_ast::Statement::Return(statement.into()),
|
||||
Definition(statement) => leo_ast::Statement::Definition(statement.into()),
|
||||
Assign(statement) => leo_ast::Statement::Assign(statement.into()),
|
||||
Assign(statement) => leo_ast::Statement::Assign(Box::new(statement.into())),
|
||||
Conditional(statement) => leo_ast::Statement::Conditional(statement.into()),
|
||||
Iteration(statement) => leo_ast::Statement::Iteration(statement.into()),
|
||||
Iteration(statement) => leo_ast::Statement::Iteration(Box::new(statement.into())),
|
||||
Console(statement) => leo_ast::Statement::Console(statement.into()),
|
||||
Expression(statement) => leo_ast::Statement::Expression(statement.into()),
|
||||
Block(statement) => leo_ast::Statement::Block(statement.into()),
|
||||
|
@ -15,6 +15,7 @@
|
||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use leo_asg::*;
|
||||
use leo_errors::LeoError;
|
||||
use leo_parser::parse_ast;
|
||||
|
||||
mod fail;
|
||||
@ -22,7 +23,7 @@ mod pass;
|
||||
|
||||
const TESTING_FILEPATH: &str = "input.leo";
|
||||
|
||||
fn load_asg(program_string: &str) -> Result<Program<'static>, AsgConvertError> {
|
||||
fn load_asg(program_string: &str) -> Result<Program<'static>, LeoError> {
|
||||
load_asg_imports(make_test_context(), program_string, &mut NullImportResolver)
|
||||
}
|
||||
|
||||
@ -30,7 +31,7 @@ fn load_asg_imports<'a, T: ImportResolver<'a>>(
|
||||
context: AsgContext<'a>,
|
||||
program_string: &str,
|
||||
imports: &mut T,
|
||||
) -> Result<Program<'a>, AsgConvertError> {
|
||||
) -> Result<Program<'a>, LeoError> {
|
||||
let ast = parse_ast(&TESTING_FILEPATH, program_string)?;
|
||||
Program::new(context, &ast.as_repr(), imports)
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ pub enum CircuitMember {
|
||||
// (variable_name, variable_type)
|
||||
CircuitVariable(Identifier, Type),
|
||||
// (function)
|
||||
CircuitFunction(Function),
|
||||
CircuitFunction(Box<Function>),
|
||||
}
|
||||
|
||||
impl fmt::Display for CircuitMember {
|
||||
|
@ -17,7 +17,7 @@
|
||||
use tendril::StrTendril;
|
||||
|
||||
use super::*;
|
||||
use crate::{Char, CharValue, GroupTuple};
|
||||
use crate::{Char, CharValue};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub enum ValueExpression {
|
||||
@ -69,7 +69,8 @@ impl Node for ValueExpression {
|
||||
| String(_, span) => span,
|
||||
Char(character) => &character.span,
|
||||
Group(group) => match &**group {
|
||||
GroupValue::Single(_, span) | GroupValue::Tuple(GroupTuple { span, .. }) => span,
|
||||
GroupValue::Single(_, span) => span,
|
||||
GroupValue::Tuple(tuple) => &tuple.span,
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -85,7 +86,8 @@ impl Node for ValueExpression {
|
||||
| String(_, span) => *span = new_span,
|
||||
Char(character) => character.span = new_span,
|
||||
Group(group) => match &mut **group {
|
||||
GroupValue::Single(_, span) | GroupValue::Tuple(GroupTuple { span, .. }) => *span = new_span,
|
||||
GroupValue::Single(_, span) => *span = new_span,
|
||||
GroupValue::Tuple(tuple) => tuple.span = new_span,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -25,8 +25,8 @@ use std::fmt;
|
||||
pub enum FunctionInput {
|
||||
SelfKeyword(SelfKeyword),
|
||||
ConstSelfKeyword(ConstSelfKeyword),
|
||||
MutSelfKeyword(MutSelfKeyword),
|
||||
Variable(FunctionInputVariable),
|
||||
MutSelfKeyword(Box<MutSelfKeyword>),
|
||||
Variable(Box<FunctionInputVariable>),
|
||||
}
|
||||
|
||||
impl FunctionInput {
|
||||
|
@ -29,7 +29,7 @@ use tendril::StrTendril;
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub enum GroupValue {
|
||||
Single(#[serde(with = "crate::common::tendril_json")] StrTendril, Span),
|
||||
Tuple(GroupTuple),
|
||||
Tuple(Box<GroupTuple>),
|
||||
}
|
||||
|
||||
impl GroupValue {
|
||||
@ -54,7 +54,7 @@ impl<'ast> From<InputGroupValue<'ast>> for GroupValue {
|
||||
|
||||
match ast_group.value {
|
||||
InputGroupRepresentation::Single(number) => GroupValue::Single(number.to_string().into(), span),
|
||||
InputGroupRepresentation::Tuple(tuple) => GroupValue::Tuple(GroupTuple::from(tuple)),
|
||||
InputGroupRepresentation::Tuple(tuple) => GroupValue::Tuple(Box::new(GroupTuple::from(tuple))),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ use std::fmt;
|
||||
pub enum PackageAccess {
|
||||
Star { span: Span },
|
||||
SubPackage(Box<Package>),
|
||||
Symbol(ImportSymbol),
|
||||
Symbol(Box<ImportSymbol>),
|
||||
Multiple(Packages),
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@ pub enum InputValue {
|
||||
Boolean(bool),
|
||||
Char(CharValue),
|
||||
Field(String),
|
||||
Group(GroupValue),
|
||||
Group(Box<GroupValue>),
|
||||
Integer(IntegerType, String),
|
||||
Array(Vec<InputValue>),
|
||||
Tuple(Vec<InputValue>),
|
||||
@ -80,7 +80,7 @@ impl InputValue {
|
||||
}
|
||||
|
||||
fn from_group(group: InputGroupValue) -> Self {
|
||||
InputValue::Group(GroupValue::from(group))
|
||||
InputValue::Group(Box::new(GroupValue::from(group)))
|
||||
}
|
||||
|
||||
fn from_field(field: FieldValue) -> Self {
|
||||
|
@ -48,7 +48,7 @@ impl Canonicalizer {
|
||||
let mut left = Box::new(start);
|
||||
|
||||
for access in accesses.iter() {
|
||||
match self.canonicalize_assignee_access(&access) {
|
||||
match self.canonicalize_assignee_access(access) {
|
||||
AssigneeAccess::ArrayIndex(index) => {
|
||||
left = Box::new(Expression::ArrayAccess(ArrayAccessExpression {
|
||||
array: left,
|
||||
@ -274,6 +274,11 @@ impl Canonicalizer {
|
||||
span: call.span.clone(),
|
||||
});
|
||||
}
|
||||
Expression::Identifier(identifier) => {
|
||||
if identifier.name.as_ref() == "Self" && self.circuit_name.is_some() {
|
||||
return Expression::Identifier(self.circuit_name.as_ref().unwrap().clone());
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
@ -288,7 +293,7 @@ impl Canonicalizer {
|
||||
|
||||
AssigneeAccess::ArrayRange(left, right)
|
||||
}
|
||||
AssigneeAccess::ArrayIndex(index) => AssigneeAccess::ArrayIndex(self.canonicalize_expression(&index)),
|
||||
AssigneeAccess::ArrayIndex(index) => AssigneeAccess::ArrayIndex(self.canonicalize_expression(index)),
|
||||
_ => access.clone(),
|
||||
}
|
||||
}
|
||||
@ -311,7 +316,7 @@ impl Canonicalizer {
|
||||
let statements = block
|
||||
.statements
|
||||
.iter()
|
||||
.map(|block_statement| self.canonicalize_statement(&block_statement))
|
||||
.map(|block_statement| self.canonicalize_statement(block_statement))
|
||||
.collect();
|
||||
|
||||
Block {
|
||||
@ -349,12 +354,12 @@ impl Canonicalizer {
|
||||
let assignee = self.canonicalize_assignee(&assign.assignee);
|
||||
let value = self.canonicalize_expression(&assign.value);
|
||||
|
||||
Statement::Assign(AssignStatement {
|
||||
Statement::Assign(Box::new(AssignStatement {
|
||||
assignee,
|
||||
value,
|
||||
operation: assign.operation,
|
||||
span: assign.span.clone(),
|
||||
})
|
||||
}))
|
||||
}
|
||||
Statement::Conditional(conditional) => {
|
||||
let condition = self.canonicalize_expression(&conditional.condition);
|
||||
@ -376,14 +381,14 @@ impl Canonicalizer {
|
||||
let stop = self.canonicalize_expression(&iteration.stop);
|
||||
let block = self.canonicalize_block(&iteration.block);
|
||||
|
||||
Statement::Iteration(IterationStatement {
|
||||
Statement::Iteration(Box::new(IterationStatement {
|
||||
variable: iteration.variable.clone(),
|
||||
start,
|
||||
stop,
|
||||
inclusive: iteration.inclusive,
|
||||
block,
|
||||
span: iteration.span.clone(),
|
||||
})
|
||||
}))
|
||||
}
|
||||
Statement::Console(console_function_call) => {
|
||||
let function = match &console_function_call.function {
|
||||
@ -436,14 +441,14 @@ impl Canonicalizer {
|
||||
output = Some(Type::Circuit(self.circuit_name.as_ref().unwrap().clone()));
|
||||
}
|
||||
|
||||
return CircuitMember::CircuitFunction(Function {
|
||||
return CircuitMember::CircuitFunction(Box::new(Function {
|
||||
annotations: function.annotations.clone(),
|
||||
identifier: function.identifier.clone(),
|
||||
input,
|
||||
output,
|
||||
block,
|
||||
span: function.span.clone(),
|
||||
});
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -51,34 +51,32 @@ impl<R: ReconstructingReducer> ReconstructingDirector<R> {
|
||||
// Expressions
|
||||
pub fn reduce_expression(&mut self, expression: &Expression) -> Result<Expression, LeoError> {
|
||||
let new = match expression {
|
||||
Expression::Identifier(identifier) => Expression::Identifier(self.reduce_identifier(&identifier)?),
|
||||
Expression::Value(value) => self.reduce_value(&value)?,
|
||||
Expression::Binary(binary) => Expression::Binary(self.reduce_binary(&binary)?),
|
||||
Expression::Unary(unary) => Expression::Unary(self.reduce_unary(&unary)?),
|
||||
Expression::Ternary(ternary) => Expression::Ternary(self.reduce_ternary(&ternary)?),
|
||||
Expression::Cast(cast) => Expression::Cast(self.reduce_cast(&cast)?),
|
||||
Expression::Identifier(identifier) => Expression::Identifier(self.reduce_identifier(identifier)?),
|
||||
Expression::Value(value) => self.reduce_value(value)?,
|
||||
Expression::Binary(binary) => Expression::Binary(self.reduce_binary(binary)?),
|
||||
Expression::Unary(unary) => Expression::Unary(self.reduce_unary(unary)?),
|
||||
Expression::Ternary(ternary) => Expression::Ternary(self.reduce_ternary(ternary)?),
|
||||
Expression::Cast(cast) => Expression::Cast(self.reduce_cast(cast)?),
|
||||
|
||||
Expression::ArrayInline(array_inline) => Expression::ArrayInline(self.reduce_array_inline(&array_inline)?),
|
||||
Expression::ArrayInit(array_init) => Expression::ArrayInit(self.reduce_array_init(&array_init)?),
|
||||
Expression::ArrayAccess(array_access) => Expression::ArrayAccess(self.reduce_array_access(&array_access)?),
|
||||
Expression::ArrayInline(array_inline) => Expression::ArrayInline(self.reduce_array_inline(array_inline)?),
|
||||
Expression::ArrayInit(array_init) => Expression::ArrayInit(self.reduce_array_init(array_init)?),
|
||||
Expression::ArrayAccess(array_access) => Expression::ArrayAccess(self.reduce_array_access(array_access)?),
|
||||
Expression::ArrayRangeAccess(array_range_access) => {
|
||||
Expression::ArrayRangeAccess(self.reduce_array_range_access(&array_range_access)?)
|
||||
Expression::ArrayRangeAccess(self.reduce_array_range_access(array_range_access)?)
|
||||
}
|
||||
|
||||
Expression::TupleInit(tuple_init) => Expression::TupleInit(self.reduce_tuple_init(&tuple_init)?),
|
||||
Expression::TupleAccess(tuple_access) => Expression::TupleAccess(self.reduce_tuple_access(&tuple_access)?),
|
||||
Expression::TupleInit(tuple_init) => Expression::TupleInit(self.reduce_tuple_init(tuple_init)?),
|
||||
Expression::TupleAccess(tuple_access) => Expression::TupleAccess(self.reduce_tuple_access(tuple_access)?),
|
||||
|
||||
Expression::CircuitInit(circuit_init) => Expression::CircuitInit(self.reduce_circuit_init(&circuit_init)?),
|
||||
Expression::CircuitInit(circuit_init) => Expression::CircuitInit(self.reduce_circuit_init(circuit_init)?),
|
||||
Expression::CircuitMemberAccess(circuit_member_access) => {
|
||||
Expression::CircuitMemberAccess(self.reduce_circuit_member_access(&circuit_member_access)?)
|
||||
Expression::CircuitMemberAccess(self.reduce_circuit_member_access(circuit_member_access)?)
|
||||
}
|
||||
Expression::CircuitStaticFunctionAccess(circuit_static_fn_access) => {
|
||||
Expression::CircuitStaticFunctionAccess(
|
||||
self.reduce_circuit_static_fn_access(&circuit_static_fn_access)?,
|
||||
)
|
||||
Expression::CircuitStaticFunctionAccess(self.reduce_circuit_static_fn_access(circuit_static_fn_access)?)
|
||||
}
|
||||
|
||||
Expression::Call(call) => Expression::Call(self.reduce_call(&call)?),
|
||||
Expression::Call(call) => Expression::Call(self.reduce_call(call)?),
|
||||
};
|
||||
|
||||
self.reducer.reduce_expression(expression, new)
|
||||
@ -94,7 +92,7 @@ impl<R: ReconstructingReducer> ReconstructingDirector<R> {
|
||||
|
||||
pub fn reduce_group_value(&mut self, group_value: &GroupValue) -> Result<GroupValue, LeoError> {
|
||||
let new = match group_value {
|
||||
GroupValue::Tuple(group_tuple) => GroupValue::Tuple(self.reduce_group_tuple(&group_tuple)?),
|
||||
GroupValue::Tuple(group_tuple) => GroupValue::Tuple(Box::new(self.reduce_group_tuple(group_tuple)?)),
|
||||
_ => group_value.clone(),
|
||||
};
|
||||
|
||||
@ -108,9 +106,9 @@ impl<R: ReconstructingReducer> ReconstructingDirector<R> {
|
||||
pub fn reduce_value(&mut self, value: &ValueExpression) -> Result<Expression, LeoError> {
|
||||
let new = match value {
|
||||
ValueExpression::Group(group_value) => {
|
||||
Expression::Value(ValueExpression::Group(Box::new(self.reduce_group_value(&group_value)?)))
|
||||
Expression::Value(ValueExpression::Group(Box::new(self.reduce_group_value(group_value)?)))
|
||||
}
|
||||
ValueExpression::String(string, span) => self.reduce_string(string, &span)?,
|
||||
ValueExpression::String(string, span) => self.reduce_string(string, span)?,
|
||||
_ => Expression::Value(value.clone()),
|
||||
};
|
||||
|
||||
@ -285,14 +283,14 @@ impl<R: ReconstructingReducer> ReconstructingDirector<R> {
|
||||
// Statements
|
||||
pub fn reduce_statement(&mut self, statement: &Statement) -> Result<Statement, LeoError> {
|
||||
let new = match statement {
|
||||
Statement::Return(return_statement) => Statement::Return(self.reduce_return(&return_statement)?),
|
||||
Statement::Definition(definition) => Statement::Definition(self.reduce_definition(&definition)?),
|
||||
Statement::Assign(assign) => Statement::Assign(self.reduce_assign(&assign)?),
|
||||
Statement::Conditional(conditional) => Statement::Conditional(self.reduce_conditional(&conditional)?),
|
||||
Statement::Iteration(iteration) => Statement::Iteration(self.reduce_iteration(&iteration)?),
|
||||
Statement::Console(console) => Statement::Console(self.reduce_console(&console)?),
|
||||
Statement::Expression(expression) => Statement::Expression(self.reduce_expression_statement(&expression)?),
|
||||
Statement::Block(block) => Statement::Block(self.reduce_block(&block)?),
|
||||
Statement::Return(return_statement) => Statement::Return(self.reduce_return(return_statement)?),
|
||||
Statement::Definition(definition) => Statement::Definition(self.reduce_definition(definition)?),
|
||||
Statement::Assign(assign) => Statement::Assign(Box::new(self.reduce_assign(assign)?)),
|
||||
Statement::Conditional(conditional) => Statement::Conditional(self.reduce_conditional(conditional)?),
|
||||
Statement::Iteration(iteration) => Statement::Iteration(Box::new(self.reduce_iteration(iteration)?)),
|
||||
Statement::Console(console) => Statement::Console(self.reduce_console(console)?),
|
||||
Statement::Expression(expression) => Statement::Expression(self.reduce_expression_statement(expression)?),
|
||||
Statement::Block(block) => Statement::Block(self.reduce_block(block)?),
|
||||
};
|
||||
|
||||
self.reducer.reduce_statement(statement, new)
|
||||
@ -335,8 +333,8 @@ impl<R: ReconstructingReducer> ReconstructingDirector<R> {
|
||||
|
||||
AssigneeAccess::ArrayRange(left, right)
|
||||
}
|
||||
AssigneeAccess::ArrayIndex(index) => AssigneeAccess::ArrayIndex(self.reduce_expression(&index)?),
|
||||
AssigneeAccess::Member(identifier) => AssigneeAccess::Member(self.reduce_identifier(&identifier)?),
|
||||
AssigneeAccess::ArrayIndex(index) => AssigneeAccess::ArrayIndex(self.reduce_expression(index)?),
|
||||
AssigneeAccess::Member(identifier) => AssigneeAccess::Member(self.reduce_identifier(identifier)?),
|
||||
_ => access.clone(),
|
||||
};
|
||||
|
||||
@ -451,7 +449,7 @@ impl<R: ReconstructingReducer> ReconstructingDirector<R> {
|
||||
|
||||
let mut global_consts = IndexMap::new();
|
||||
for (name, definition) in program.global_consts.iter() {
|
||||
global_consts.insert(name.clone(), self.reduce_definition(&definition)?);
|
||||
global_consts.insert(name.clone(), self.reduce_definition(definition)?);
|
||||
}
|
||||
|
||||
self.reducer
|
||||
@ -471,7 +469,7 @@ impl<R: ReconstructingReducer> ReconstructingDirector<R> {
|
||||
pub fn reduce_function_input(&mut self, input: &FunctionInput) -> Result<FunctionInput, LeoError> {
|
||||
let new = match input {
|
||||
FunctionInput::Variable(function_input_variable) => {
|
||||
FunctionInput::Variable(self.reduce_function_input_variable(function_input_variable)?)
|
||||
FunctionInput::Variable(Box::new(self.reduce_function_input_variable(function_input_variable)?))
|
||||
}
|
||||
_ => input.clone(),
|
||||
};
|
||||
@ -508,11 +506,11 @@ impl<R: ReconstructingReducer> ReconstructingDirector<R> {
|
||||
pub fn reduce_circuit_member(&mut self, circuit_member: &CircuitMember) -> Result<CircuitMember, LeoError> {
|
||||
let new = match circuit_member {
|
||||
CircuitMember::CircuitVariable(identifier, type_) => CircuitMember::CircuitVariable(
|
||||
self.reduce_identifier(&identifier)?,
|
||||
self.reduce_type(&type_, &identifier.span)?,
|
||||
self.reduce_identifier(identifier)?,
|
||||
self.reduce_type(type_, &identifier.span)?,
|
||||
),
|
||||
CircuitMember::CircuitFunction(function) => {
|
||||
CircuitMember::CircuitFunction(self.reduce_function(&function)?)
|
||||
CircuitMember::CircuitFunction(Box::new(self.reduce_function(function)?))
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -26,9 +26,9 @@ use std::fmt;
|
||||
pub enum Statement {
|
||||
Return(ReturnStatement),
|
||||
Definition(DefinitionStatement),
|
||||
Assign(AssignStatement),
|
||||
Assign(Box<AssignStatement>),
|
||||
Conditional(ConditionalStatement),
|
||||
Iteration(IterationStatement),
|
||||
Iteration(Box<IterationStatement>),
|
||||
Console(ConsoleStatement),
|
||||
Expression(ExpressionStatement),
|
||||
Block(Block),
|
||||
|
@ -70,8 +70,8 @@ impl Type {
|
||||
(Type::Char, Type::Char) => true,
|
||||
(Type::Field, Type::Field) => true,
|
||||
(Type::Group, Type::Group) => true,
|
||||
(Type::IntegerType(left), Type::IntegerType(right)) => left.eq(&right),
|
||||
(Type::Circuit(left), Type::Circuit(right)) => left.eq(&right),
|
||||
(Type::IntegerType(left), Type::IntegerType(right)) => left.eq(right),
|
||||
(Type::Circuit(left), Type::Circuit(right)) => left.eq(right),
|
||||
(Type::SelfType, Type::SelfType) => true,
|
||||
(Type::Array(left_type, left_dim), Type::Array(right_type, right_dim)) => {
|
||||
// Convert array dimensions to owned.
|
||||
|
@ -183,7 +183,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> Compiler<'a, F, G> {
|
||||
state_string: &str,
|
||||
state_path: &Path,
|
||||
) -> Result<(), LeoError> {
|
||||
let input_syntax_tree = LeoInputParser::parse_file(&input_string).map_err(|mut e| {
|
||||
let input_syntax_tree = LeoInputParser::parse_file(input_string).map_err(|mut e| {
|
||||
e.set_path(
|
||||
input_path.to_str().unwrap_or_default(),
|
||||
&input_string.lines().map(|x| x.to_string()).collect::<Vec<String>>()[..],
|
||||
@ -191,7 +191,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> Compiler<'a, F, G> {
|
||||
|
||||
e
|
||||
})?;
|
||||
let state_syntax_tree = LeoInputParser::parse_file(&state_string).map_err(|mut e| {
|
||||
let state_syntax_tree = LeoInputParser::parse_file(state_string).map_err(|mut e| {
|
||||
e.set_path(
|
||||
state_path.to_str().unwrap_or_default(),
|
||||
&state_string.lines().map(|x| x.to_string()).collect::<Vec<String>>()[..],
|
||||
@ -315,14 +315,14 @@ impl<'a, F: PrimeField, G: GroupType<F>> Compiler<'a, F, G> {
|
||||
/// Synthesizes the circuit with program input to verify correctness.
|
||||
///
|
||||
pub fn compile_constraints<CS: ConstraintSystem<F>>(&self, cs: &mut CS) -> Result<Output, LeoError> {
|
||||
generate_constraints::<F, G, CS>(cs, &self.asg.as_ref().unwrap(), &self.program_input)
|
||||
generate_constraints::<F, G, CS>(cs, self.asg.as_ref().unwrap(), &self.program_input)
|
||||
}
|
||||
|
||||
///
|
||||
/// Synthesizes the circuit for test functions with program input.
|
||||
///
|
||||
pub fn compile_test_constraints(self, input_pairs: InputPairs) -> Result<(u32, u32), LeoError> {
|
||||
generate_test_constraints::<F, G>(&self.asg.as_ref().unwrap(), input_pairs, &self.output_directory)
|
||||
generate_test_constraints::<F, G>(self.asg.as_ref().unwrap(), input_pairs, &self.output_directory)
|
||||
}
|
||||
|
||||
///
|
||||
|
@ -51,13 +51,13 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
let parameter = match args.parameters.get(arg_index) {
|
||||
Some(index) => index,
|
||||
None => {
|
||||
return Err(LeoError::from(CompilerError::from(
|
||||
return Err(LeoError::from(
|
||||
CompilerError::console_container_parameter_length_mismatch(
|
||||
arg_index + 1,
|
||||
args.parameters.len(),
|
||||
&args.span,
|
||||
),
|
||||
)));
|
||||
));
|
||||
}
|
||||
};
|
||||
out.push(self.enforce_expression(cs, parameter.get())?.to_string());
|
||||
@ -69,15 +69,15 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
substring.push('}');
|
||||
escape_right_bracket = true;
|
||||
} else {
|
||||
return Err(LeoError::from(CompilerError::from(
|
||||
CompilerError::console_fmt_expected_escaped_right_brace(&args.span),
|
||||
return Err(LeoError::from(CompilerError::console_fmt_expected_escaped_right_brace(
|
||||
&args.span,
|
||||
)));
|
||||
}
|
||||
}
|
||||
}
|
||||
_ if in_container => {
|
||||
return Err(LeoError::from(CompilerError::from(
|
||||
CompilerError::console_fmt_expected_left_or_right_brace(&args.span),
|
||||
return Err(LeoError::from(CompilerError::console_fmt_expected_left_or_right_brace(
|
||||
&args.span,
|
||||
)));
|
||||
}
|
||||
_ => substring.push(*scalar),
|
||||
@ -92,13 +92,13 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
|
||||
// Check that containers and parameters match
|
||||
if arg_index != args.parameters.len() {
|
||||
return Err(LeoError::from(CompilerError::from(
|
||||
return Err(LeoError::from(
|
||||
CompilerError::console_container_parameter_length_mismatch(
|
||||
arg_index,
|
||||
args.parameters.len(),
|
||||
&args.span,
|
||||
),
|
||||
)));
|
||||
));
|
||||
}
|
||||
|
||||
Ok(out.join(""))
|
||||
|
@ -46,7 +46,7 @@ pub fn generate_constraints<'a, F: PrimeField, G: GroupType<F>, CS: ConstraintSy
|
||||
|
||||
match main {
|
||||
Some(function) => {
|
||||
let result = resolved_program.enforce_main_function(cs, &function, input)?;
|
||||
let result = resolved_program.enforce_main_function(cs, function, input)?;
|
||||
Ok(result)
|
||||
}
|
||||
_ => Err(CompilerError::no_main_function(Backtrace::new()).into()),
|
||||
@ -111,7 +111,7 @@ pub fn generate_test_constraints<'a, F: PrimeField, G: GroupType<F>>(
|
||||
}
|
||||
}
|
||||
}
|
||||
None => default.ok_or(LeoError::from(CompilerError::no_test_input(Backtrace::new())))?,
|
||||
None => default.ok_or_else(|| LeoError::from(CompilerError::no_test_input(Backtrace::new())))?,
|
||||
};
|
||||
|
||||
// parse input files to abstract syntax trees
|
||||
|
@ -101,7 +101,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
.len()
|
||||
.try_into()
|
||||
.map_err(|_| LeoError::from(CompilerError::array_length_out_of_bounds(span)))?;
|
||||
self.array_bounds_check(cs, &&index_resolved, array_len, span)?;
|
||||
self.array_bounds_check(cs, &index_resolved, array_len, span)?;
|
||||
}
|
||||
|
||||
let mut current_value = array.pop().unwrap();
|
||||
|
@ -44,7 +44,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
)
|
||||
};
|
||||
|
||||
let return_value = self.enforce_function(&mut cs.ns(name_unique), &function, target, arguments)?;
|
||||
let return_value = self.enforce_function(&mut cs.ns(name_unique), function, target, arguments)?;
|
||||
|
||||
Ok(return_value)
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
span,
|
||||
)?)),
|
||||
Type::Array(type_, len) => self.allocate_array(cs, name, &*type_, *len, input_option, span),
|
||||
Type::Tuple(types) => self.allocate_tuple(cs, &name, types, input_option, span),
|
||||
Type::Tuple(types) => self.allocate_tuple(cs, name, types, input_option, span),
|
||||
_ => unimplemented!("main function input not implemented for type {}", type_), // Should not happen.
|
||||
}
|
||||
}
|
||||
@ -106,7 +106,9 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
(Type::Field, InputValue::Field(value)) => {
|
||||
Ok(ConstrainedValue::Field(FieldType::constant(cs, value, span)?))
|
||||
}
|
||||
(Type::Group, InputValue::Group(value)) => Ok(ConstrainedValue::Group(G::constant(&value.into(), span)?)),
|
||||
(Type::Group, InputValue::Group(value)) => {
|
||||
Ok(ConstrainedValue::Group(G::constant(&(*value).into(), span)?))
|
||||
}
|
||||
(Type::Integer(integer_type), InputValue::Integer(input_type, value)) => {
|
||||
let parsed = ConstInt::parse(integer_type, &value, span)?;
|
||||
let parsed_type = parsed.get_int_type();
|
||||
|
@ -40,7 +40,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
|
||||
if let Some(asg_input) = asg_input {
|
||||
let value =
|
||||
self.allocate_input_keyword(cs, &function.name.borrow().span, &asg_input.container_circuit, input)?;
|
||||
self.allocate_input_keyword(cs, &function.name.borrow().span, asg_input.container_circuit, input)?;
|
||||
|
||||
self.store(asg_input.container.borrow().id, value);
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
cs.ns(|| format!("select result {} {}:{}", i, span.line_start, span.col_start)),
|
||||
&indicator,
|
||||
&result,
|
||||
&value,
|
||||
value,
|
||||
)
|
||||
.map_err(|_| {
|
||||
LeoError::from(CompilerError::statement_select_fail(
|
||||
|
@ -52,9 +52,8 @@ impl OutputFile {
|
||||
let mut file = File::create(&path)
|
||||
.map_err(|e| LeoError::from(CompilerError::output_file_io_error(eyre!(e), Backtrace::new())))?;
|
||||
|
||||
Ok(file
|
||||
.write_all(bytes)
|
||||
.map_err(|e| LeoError::from(CompilerError::output_file_io_error(eyre!(e), Backtrace::new())))?)
|
||||
file.write_all(bytes)
|
||||
.map_err(|e| LeoError::from(CompilerError::output_file_io_error(eyre!(e), Backtrace::new())))
|
||||
}
|
||||
|
||||
/// Removes the output file at the given path if it exists. Returns `true` on success,
|
||||
|
@ -149,49 +149,49 @@ impl<R: ReconstructingReducer, O: CombinerOptions> CombineAstAsgDirector<R, O> {
|
||||
|
||||
pub fn reduce_expression(&mut self, ast: &AstExpression, asg: &AsgExpression) -> Result<AstExpression, LeoError> {
|
||||
let new = match (ast, asg) {
|
||||
(AstExpression::Value(value), AsgExpression::Constant(const_)) => self.reduce_value(&value, &const_)?,
|
||||
(AstExpression::Value(value), AsgExpression::Constant(const_)) => self.reduce_value(value, const_)?,
|
||||
(AstExpression::Binary(ast), AsgExpression::Binary(asg)) => {
|
||||
AstExpression::Binary(self.reduce_binary(&ast, &asg)?)
|
||||
AstExpression::Binary(self.reduce_binary(ast, asg)?)
|
||||
}
|
||||
(AstExpression::Unary(ast), AsgExpression::Unary(asg)) => {
|
||||
AstExpression::Unary(self.reduce_unary(&ast, &asg)?)
|
||||
AstExpression::Unary(self.reduce_unary(ast, asg)?)
|
||||
}
|
||||
(AstExpression::Ternary(ast), AsgExpression::Ternary(asg)) => {
|
||||
AstExpression::Ternary(self.reduce_ternary(&ast, &asg)?)
|
||||
AstExpression::Ternary(self.reduce_ternary(ast, asg)?)
|
||||
}
|
||||
(AstExpression::Cast(ast), AsgExpression::Cast(asg)) => AstExpression::Cast(self.reduce_cast(&ast, &asg)?),
|
||||
(AstExpression::Cast(ast), AsgExpression::Cast(asg)) => AstExpression::Cast(self.reduce_cast(ast, asg)?),
|
||||
|
||||
(AstExpression::ArrayInline(ast), AsgExpression::ArrayInline(asg)) => {
|
||||
AstExpression::ArrayInline(self.reduce_array_inline(&ast, &asg)?)
|
||||
AstExpression::ArrayInline(self.reduce_array_inline(ast, asg)?)
|
||||
}
|
||||
(AstExpression::ArrayInit(ast), AsgExpression::ArrayInit(asg)) => {
|
||||
AstExpression::ArrayInit(self.reduce_array_init(&ast, &asg)?)
|
||||
AstExpression::ArrayInit(self.reduce_array_init(ast, asg)?)
|
||||
}
|
||||
(AstExpression::ArrayAccess(ast), AsgExpression::ArrayAccess(asg)) => {
|
||||
AstExpression::ArrayAccess(self.reduce_array_access(&ast, &asg)?)
|
||||
AstExpression::ArrayAccess(self.reduce_array_access(ast, asg)?)
|
||||
}
|
||||
(AstExpression::ArrayRangeAccess(ast), AsgExpression::ArrayRangeAccess(asg)) => {
|
||||
AstExpression::ArrayRangeAccess(self.reduce_array_range_access(&ast, &asg)?)
|
||||
AstExpression::ArrayRangeAccess(self.reduce_array_range_access(ast, asg)?)
|
||||
}
|
||||
|
||||
(AstExpression::TupleInit(ast), AsgExpression::TupleInit(asg)) => {
|
||||
AstExpression::TupleInit(self.reduce_tuple_init(&ast, &asg)?)
|
||||
AstExpression::TupleInit(self.reduce_tuple_init(ast, asg)?)
|
||||
}
|
||||
(AstExpression::TupleAccess(ast), AsgExpression::TupleAccess(asg)) => {
|
||||
AstExpression::TupleAccess(self.reduce_tuple_access(&ast, &asg)?)
|
||||
AstExpression::TupleAccess(self.reduce_tuple_access(ast, asg)?)
|
||||
}
|
||||
|
||||
(AstExpression::CircuitInit(ast), AsgExpression::CircuitInit(asg)) => {
|
||||
AstExpression::CircuitInit(self.reduce_circuit_init(&ast, &asg)?)
|
||||
AstExpression::CircuitInit(self.reduce_circuit_init(ast, asg)?)
|
||||
}
|
||||
(AstExpression::CircuitMemberAccess(ast), AsgExpression::CircuitAccess(asg)) => {
|
||||
AstExpression::CircuitMemberAccess(self.reduce_circuit_member_access(&ast, &asg)?)
|
||||
AstExpression::CircuitMemberAccess(self.reduce_circuit_member_access(ast, asg)?)
|
||||
}
|
||||
(AstExpression::CircuitStaticFunctionAccess(ast), AsgExpression::CircuitAccess(asg)) => {
|
||||
AstExpression::CircuitStaticFunctionAccess(self.reduce_circuit_static_fn_access(&ast, &asg)?)
|
||||
AstExpression::CircuitStaticFunctionAccess(self.reduce_circuit_static_fn_access(ast, asg)?)
|
||||
}
|
||||
|
||||
(AstExpression::Call(ast), AsgExpression::Call(asg)) => AstExpression::Call(self.reduce_call(&ast, &asg)?),
|
||||
(AstExpression::Call(ast), AsgExpression::Call(asg)) => AstExpression::Call(self.reduce_call(ast, asg)?),
|
||||
_ => ast.clone(),
|
||||
};
|
||||
|
||||
@ -293,7 +293,7 @@ impl<R: ReconstructingReducer, O: CombinerOptions> CombineAstAsgDirector<R, O> {
|
||||
ast: &AstCastExpression,
|
||||
asg: &AsgCastExpression,
|
||||
) -> Result<AstCastExpression, LeoError> {
|
||||
let inner = self.reduce_expression(&ast.inner, &asg.inner.get())?;
|
||||
let inner = self.reduce_expression(&ast.inner, asg.inner.get())?;
|
||||
let target_type = self.reduce_type(&ast.target_type, &asg.target_type, &ast.span)?;
|
||||
|
||||
self.ast_reducer.reduce_cast(ast, inner, target_type)
|
||||
@ -411,11 +411,11 @@ impl<R: ReconstructingReducer, O: CombinerOptions> CombineAstAsgDirector<R, O> {
|
||||
ConstValue::Group(group) => {
|
||||
let group_value = match group {
|
||||
AsgGroupValue::Single(_) => AstGroupValue::Single(tendril.clone(), span.clone()),
|
||||
AsgGroupValue::Tuple(x, y) => AstGroupValue::Tuple(GroupTuple {
|
||||
AsgGroupValue::Tuple(x, y) => AstGroupValue::Tuple(Box::new(GroupTuple {
|
||||
x: x.into(),
|
||||
y: y.into(),
|
||||
span: span.clone(),
|
||||
}),
|
||||
})),
|
||||
};
|
||||
new = ValueExpression::Group(Box::new(group_value));
|
||||
}
|
||||
@ -472,7 +472,7 @@ impl<R: ReconstructingReducer, O: CombinerOptions> CombineAstAsgDirector<R, O> {
|
||||
) -> Result<AstStatement, LeoError> {
|
||||
let new = match (ast_statement, asg_statement) {
|
||||
(AstStatement::Assign(ast), AsgStatement::Assign(asg)) => {
|
||||
AstStatement::Assign(self.reduce_assign(ast, asg)?)
|
||||
AstStatement::Assign(Box::new(self.reduce_assign(ast, asg)?))
|
||||
}
|
||||
(AstStatement::Block(ast), AsgStatement::Block(asg)) => AstStatement::Block(self.reduce_block(ast, asg)?),
|
||||
(AstStatement::Conditional(ast), AsgStatement::Conditional(asg)) => {
|
||||
@ -488,7 +488,7 @@ impl<R: ReconstructingReducer, O: CombinerOptions> CombineAstAsgDirector<R, O> {
|
||||
AstStatement::Expression(self.reduce_expression_statement(ast, asg)?)
|
||||
}
|
||||
(AstStatement::Iteration(ast), AsgStatement::Iteration(asg)) => {
|
||||
AstStatement::Iteration(self.reduce_iteration(ast, asg)?)
|
||||
AstStatement::Iteration(Box::new(self.reduce_iteration(ast, asg)?))
|
||||
}
|
||||
(AstStatement::Return(ast), AsgStatement::Return(asg)) => {
|
||||
AstStatement::Return(self.reduce_return(ast, asg)?)
|
||||
@ -518,7 +518,7 @@ impl<R: ReconstructingReducer, O: CombinerOptions> CombineAstAsgDirector<R, O> {
|
||||
AstAssignAccess::ArrayRange(left, right)
|
||||
}
|
||||
(AstAssignAccess::ArrayIndex(ast_index), AsgAssignAccess::ArrayIndex(asg_index)) => {
|
||||
let index = self.reduce_expression(&ast_index, asg_index.get())?;
|
||||
let index = self.reduce_expression(ast_index, asg_index.get())?;
|
||||
AstAssignAccess::ArrayIndex(index)
|
||||
}
|
||||
_ => ast.clone(),
|
||||
@ -571,7 +571,7 @@ impl<R: ReconstructingReducer, O: CombinerOptions> CombineAstAsgDirector<R, O> {
|
||||
block = self.reduce_block(&ast.block, asg_block)?;
|
||||
} else {
|
||||
return Err(LeoError::from(AstError::asg_statement_not_block(
|
||||
&asg.span.as_ref().unwrap(),
|
||||
asg.span.as_ref().unwrap(),
|
||||
)));
|
||||
}
|
||||
let next = match (ast.next.as_ref(), asg.next.get()) {
|
||||
@ -589,7 +589,7 @@ impl<R: ReconstructingReducer, O: CombinerOptions> CombineAstAsgDirector<R, O> {
|
||||
) -> Result<AstConsoleStatement, LeoError> {
|
||||
let function = match (&ast.function, &asg.function) {
|
||||
(AstConsoleFunction::Assert(ast_expression), AsgConsoleFunction::Assert(asg_expression)) => {
|
||||
AstConsoleFunction::Assert(self.reduce_expression(&ast_expression, asg_expression.get())?)
|
||||
AstConsoleFunction::Assert(self.reduce_expression(ast_expression, asg_expression.get())?)
|
||||
}
|
||||
(AstConsoleFunction::Error(ast_console_args), AsgConsoleFunction::Error(asg_format))
|
||||
| (AstConsoleFunction::Log(ast_console_args), AsgConsoleFunction::Log(asg_format)) => {
|
||||
@ -597,7 +597,7 @@ impl<R: ReconstructingReducer, O: CombinerOptions> CombineAstAsgDirector<R, O> {
|
||||
for (ast_parameter, asg_parameter) in
|
||||
ast_console_args.parameters.iter().zip(asg_format.parameters.iter())
|
||||
{
|
||||
parameters.push(self.reduce_expression(&ast_parameter, asg_parameter.get())?);
|
||||
parameters.push(self.reduce_expression(ast_parameter, asg_parameter.get())?);
|
||||
}
|
||||
|
||||
let args = AstConsoleArgs {
|
||||
@ -638,14 +638,14 @@ impl<R: ReconstructingReducer, O: CombinerOptions> CombineAstAsgDirector<R, O> {
|
||||
let asg_type = AsgType::Tuple(types);
|
||||
|
||||
type_ = match &ast.type_ {
|
||||
Some(ast_type) => Some(self.reduce_type(&ast_type, &asg_type, &ast.span)?),
|
||||
Some(ast_type) => Some(self.reduce_type(ast_type, &asg_type, &ast.span)?),
|
||||
None if self.options.type_inference_enabled() => Some((&asg_type).into()),
|
||||
_ => None,
|
||||
};
|
||||
} else {
|
||||
type_ = match &ast.type_ {
|
||||
Some(ast_type) => {
|
||||
Some(self.reduce_type(&ast_type, &asg.variables.first().unwrap().borrow().type_, &ast.span)?)
|
||||
Some(self.reduce_type(ast_type, &asg.variables.first().unwrap().borrow().type_, &ast.span)?)
|
||||
}
|
||||
None if self.options.type_inference_enabled() => {
|
||||
Some((&asg.variables.first().unwrap().borrow().type_).into())
|
||||
@ -681,7 +681,7 @@ impl<R: ReconstructingReducer, O: CombinerOptions> CombineAstAsgDirector<R, O> {
|
||||
block = self.reduce_block(&ast.block, asg_block)?;
|
||||
} else {
|
||||
return Err(LeoError::from(AstError::asg_statement_not_block(
|
||||
&asg.span.as_ref().unwrap(),
|
||||
asg.span.as_ref().unwrap(),
|
||||
)));
|
||||
}
|
||||
|
||||
@ -774,7 +774,7 @@ impl<R: ReconstructingReducer, O: CombinerOptions> CombineAstAsgDirector<R, O> {
|
||||
)
|
||||
}
|
||||
(AstCircuitMember::CircuitFunction(ast_function), AsgCircuitMember::Function(asg_function)) => {
|
||||
AstCircuitMember::CircuitFunction(self.reduce_function(ast_function, asg_function)?)
|
||||
AstCircuitMember::CircuitFunction(Box::new(self.reduce_function(ast_function, asg_function)?))
|
||||
}
|
||||
_ => ast.clone(),
|
||||
};
|
||||
|
@ -65,7 +65,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
.len()
|
||||
.try_into()
|
||||
.map_err(|_| LeoError::from(CompilerError::array_length_out_of_bounds(&span)))?;
|
||||
self.array_bounds_check(cs, &&index_resolved, array_len, &span)?;
|
||||
self.array_bounds_check(cs, &index_resolved, array_len, &span)?;
|
||||
}
|
||||
|
||||
for (i, item) in input.iter_mut().enumerate() {
|
||||
@ -114,7 +114,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
unique_namespace,
|
||||
&index_comparison,
|
||||
&temp_item,
|
||||
&item,
|
||||
item,
|
||||
)
|
||||
.map_err(|e| {
|
||||
LeoError::from(CompilerError::cannot_enforce_expression(
|
||||
@ -159,7 +159,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
.len()
|
||||
.try_into()
|
||||
.map_err(|_| LeoError::from(CompilerError::array_length_out_of_bounds(&span)))?;
|
||||
self.array_bounds_check(cs, &&index_resolved, array_len, &span)?;
|
||||
self.array_bounds_check(cs, &index_resolved, array_len, &span)?;
|
||||
}
|
||||
|
||||
for (i, item) in context.input.iter_mut().enumerate() {
|
||||
@ -205,7 +205,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
item
|
||||
};
|
||||
let value =
|
||||
ConstrainedValue::conditionally_select(unique_namespace, &index_comparison, &temp_item, &item)
|
||||
ConstrainedValue::conditionally_select(unique_namespace, &index_comparison, &temp_item, item)
|
||||
.map_err(|e| {
|
||||
LeoError::from(CompilerError::cannot_enforce_expression(
|
||||
"conditional select".to_string(),
|
||||
|
@ -93,7 +93,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
);
|
||||
let branch_2_indicator = Boolean::and(
|
||||
&mut cs.ns(|| format!("branch 2 {}:{}", &span.line_start, &span.col_start)),
|
||||
&outer_indicator,
|
||||
outer_indicator,
|
||||
&inner_indicator,
|
||||
)
|
||||
.map_err(|_| LeoError::from(CompilerError::statement_indicator_calculation(branch_2_name, &span)))?;
|
||||
|
@ -91,33 +91,57 @@ impl Address {
|
||||
Ok(ConstrainedValue::Address(address))
|
||||
}
|
||||
|
||||
pub(crate) fn alloc_helper<Fn: FnOnce() -> Result<T, SynthesisError>, T: Borrow<String>>(
|
||||
pub(crate) fn alloc_helper<
|
||||
F: PrimeField,
|
||||
CS: ConstraintSystem<F>,
|
||||
Fn: FnOnce() -> Result<T, SynthesisError>,
|
||||
T: Borrow<String>,
|
||||
>(
|
||||
cs: CS,
|
||||
value_gen: Fn,
|
||||
) -> Result<AleoAddress<Components>, SynthesisError> {
|
||||
let address_string = match value_gen() {
|
||||
Ok(value) => {
|
||||
let string_value = value.borrow().clone();
|
||||
Ok(string_value)
|
||||
}
|
||||
_ => Err(SynthesisError::AssignmentMissing),
|
||||
}?;
|
||||
|
||||
if cs.is_in_setup_mode() {
|
||||
Ok(AleoAddress::<Components>::default())
|
||||
} else {
|
||||
let address_string = value_gen()?.borrow().clone();
|
||||
AleoAddress::from_str(&address_string).map_err(|_| SynthesisError::AssignmentMissing)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: PrimeField> AllocGadget<String, F> for Address {
|
||||
fn alloc<Fn: FnOnce() -> Result<T, SynthesisError>, T: Borrow<String>, CS: ConstraintSystem<F>>(
|
||||
cs: CS,
|
||||
fn alloc_constant<Fn: FnOnce() -> Result<T, SynthesisError>, T: Borrow<String>, CS: ConstraintSystem<F>>(
|
||||
_cs: CS,
|
||||
value_gen: Fn,
|
||||
) -> Result<Self, SynthesisError> {
|
||||
let address = Self::alloc_helper(value_gen)?;
|
||||
let address = {
|
||||
let address_string = value_gen()?.borrow().clone();
|
||||
AleoAddress::from_str(&address_string).map_err(|_| SynthesisError::AssignmentMissing)?
|
||||
};
|
||||
let mut address_bytes = vec![];
|
||||
address
|
||||
.write_le(&mut address_bytes)
|
||||
.map_err(|_| SynthesisError::AssignmentMissing)?;
|
||||
|
||||
let bytes = UInt8::alloc_vec(cs, &address_bytes[..])?;
|
||||
let bytes = UInt8::constant_vec(&address_bytes[..]);
|
||||
|
||||
Ok(Address {
|
||||
address: Some(address),
|
||||
bytes,
|
||||
})
|
||||
}
|
||||
|
||||
fn alloc<Fn: FnOnce() -> Result<T, SynthesisError>, T: Borrow<String>, CS: ConstraintSystem<F>>(
|
||||
mut cs: CS,
|
||||
value_gen: Fn,
|
||||
) -> Result<Self, SynthesisError> {
|
||||
let address = Self::alloc_helper(cs.ns(|| "allocate the address"), value_gen)?;
|
||||
let mut address_bytes = vec![];
|
||||
address
|
||||
.write_le(&mut address_bytes)
|
||||
.map_err(|_| SynthesisError::AssignmentMissing)?;
|
||||
|
||||
let bytes = UInt8::alloc_vec(cs.ns(|| "allocate the address bytes"), &address_bytes[..])?;
|
||||
|
||||
Ok(Address {
|
||||
address: Some(address),
|
||||
@ -126,16 +150,16 @@ impl<F: PrimeField> AllocGadget<String, F> for Address {
|
||||
}
|
||||
|
||||
fn alloc_input<Fn: FnOnce() -> Result<T, SynthesisError>, T: Borrow<String>, CS: ConstraintSystem<F>>(
|
||||
cs: CS,
|
||||
mut cs: CS,
|
||||
value_gen: Fn,
|
||||
) -> Result<Self, SynthesisError> {
|
||||
let address = Self::alloc_helper(value_gen)?;
|
||||
let address = Self::alloc_helper(cs.ns(|| "allocate the address"), value_gen)?;
|
||||
let mut address_bytes = vec![];
|
||||
address
|
||||
.write_le(&mut address_bytes)
|
||||
.map_err(|_| SynthesisError::AssignmentMissing)?;
|
||||
|
||||
let bytes = UInt8::alloc_input_vec_le(cs, &address_bytes[..])?;
|
||||
let bytes = UInt8::alloc_input_vec_le(cs.ns(|| "allocate the address bytes"), &address_bytes[..])?;
|
||||
|
||||
Ok(Address {
|
||||
address: Some(address),
|
||||
|
@ -66,9 +66,9 @@ pub(crate) fn group_from_input<'a, F: PrimeField, G: GroupType<F>, CS: Constrain
|
||||
let group = allocate_group(
|
||||
cs,
|
||||
name,
|
||||
option.map(|x| match x {
|
||||
option.map(|x| match *x {
|
||||
leo_ast::GroupValue::Single(s, _) => GroupValue::Single(s),
|
||||
leo_ast::GroupValue::Tuple(leo_ast::GroupTuple { x, y, .. }) => GroupValue::Tuple((&x).into(), (&y).into()),
|
||||
leo_ast::GroupValue::Tuple(tuple) => GroupValue::Tuple((&tuple.x).into(), (&tuple.y).into()),
|
||||
}),
|
||||
span,
|
||||
)?;
|
||||
|
@ -125,7 +125,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> fmt::Display for ConstrainedValue<'a, F
|
||||
|
||||
write!(f, "({})", values)
|
||||
}
|
||||
ConstrainedValue::CircuitExpression(ref circuit, ref members) => {
|
||||
ConstrainedValue::CircuitExpression(circuit, ref members) => {
|
||||
write!(f, "{} {{", circuit.name.borrow())?;
|
||||
for (i, member) in members.iter().enumerate() {
|
||||
write!(f, "{}: {}", member.0, member.1)?;
|
||||
|
@ -14,5 +14,5 @@
|
||||
// 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/>.
|
||||
|
||||
pub mod asg;
|
||||
pub use self::asg::*;
|
||||
pub mod asg_errors;
|
||||
pub use self::asg_errors::*;
|
||||
|
@ -14,5 +14,5 @@
|
||||
// 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/>.
|
||||
|
||||
pub mod ast;
|
||||
pub use self::ast::*;
|
||||
pub mod ast_errors;
|
||||
pub use self::ast_errors::*;
|
||||
|
@ -14,5 +14,5 @@
|
||||
// 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/>.
|
||||
|
||||
pub mod compiler;
|
||||
pub use self::compiler::*;
|
||||
pub mod compiler_errors;
|
||||
pub use self::compiler_errors::*;
|
||||
|
@ -14,5 +14,5 @@
|
||||
// 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/>.
|
||||
|
||||
pub mod import;
|
||||
pub use self::import::*;
|
||||
pub mod import_errors;
|
||||
pub use self::import_errors::*;
|
||||
|
@ -14,5 +14,5 @@
|
||||
// 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/>.
|
||||
|
||||
pub mod package;
|
||||
pub use self::package::*;
|
||||
pub mod package_errors;
|
||||
pub use self::package_errors::*;
|
||||
|
@ -14,5 +14,5 @@
|
||||
// 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/>.
|
||||
|
||||
pub mod parser;
|
||||
pub use self::parser::*;
|
||||
pub mod parser_errors;
|
||||
pub use self::parser_errors::*;
|
||||
|
@ -14,5 +14,5 @@
|
||||
// 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/>.
|
||||
|
||||
pub mod snarkvm;
|
||||
pub use self::snarkvm::*;
|
||||
pub mod snarkvm_errors;
|
||||
pub use self::snarkvm_errors::*;
|
||||
|
@ -14,5 +14,5 @@
|
||||
// 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/>.
|
||||
|
||||
pub mod state;
|
||||
pub use self::state::*;
|
||||
pub mod state_errors;
|
||||
pub use self::state_errors::*;
|
||||
|
@ -511,7 +511,7 @@ rest-of-block-comment = "*" rest-of-block-comment-after-star
|
||||
/ not-star rest-of-block-comment
|
||||
```
|
||||
|
||||
Go to: _[rest-of-block-comment](#user-content-rest-of-block-comment), [rest-of-block-comment-after-star](#user-content-rest-of-block-comment-after-star), [not-star](#user-content-not-star)_;
|
||||
Go to: _[not-star](#user-content-not-star), [rest-of-block-comment](#user-content-rest-of-block-comment), [rest-of-block-comment-after-star](#user-content-rest-of-block-comment-after-star)_;
|
||||
|
||||
|
||||
<a name="rest-of-block-comment-after-star"></a>
|
||||
@ -521,7 +521,7 @@ rest-of-block-comment-after-star = "/"
|
||||
/ not-star-or-slash rest-of-block-comment
|
||||
```
|
||||
|
||||
Go to: _[not-star-or-slash](#user-content-not-star-or-slash), [rest-of-block-comment](#user-content-rest-of-block-comment), [rest-of-block-comment-after-star](#user-content-rest-of-block-comment-after-star)_;
|
||||
Go to: _[rest-of-block-comment-after-star](#user-content-rest-of-block-comment-after-star), [not-star-or-slash](#user-content-not-star-or-slash), [rest-of-block-comment](#user-content-rest-of-block-comment)_;
|
||||
|
||||
|
||||
<a name="end-of-line-comment"></a>
|
||||
@ -772,7 +772,7 @@ character-literal-element = not-single-quote-or-backslash
|
||||
/ unicode-character-escape
|
||||
```
|
||||
|
||||
Go to: _[simple-character-escape](#user-content-simple-character-escape), [unicode-character-escape](#user-content-unicode-character-escape), [not-single-quote-or-backslash](#user-content-not-single-quote-or-backslash), [ascii-character-escape](#user-content-ascii-character-escape)_;
|
||||
Go to: _[unicode-character-escape](#user-content-unicode-character-escape), [simple-character-escape](#user-content-simple-character-escape), [not-single-quote-or-backslash](#user-content-not-single-quote-or-backslash), [ascii-character-escape](#user-content-ascii-character-escape)_;
|
||||
|
||||
|
||||
<a name="single-quote-escape"></a>
|
||||
@ -827,7 +827,7 @@ simple-character-escape = single-quote-escape
|
||||
/ null-character-escape
|
||||
```
|
||||
|
||||
Go to: _[carriage-return-escape](#user-content-carriage-return-escape), [single-quote-escape](#user-content-single-quote-escape), [backslash-escape](#user-content-backslash-escape), [line-feed-escape](#user-content-line-feed-escape), [horizontal-tab-escape](#user-content-horizontal-tab-escape), [null-character-escape](#user-content-null-character-escape), [double-quote-escape](#user-content-double-quote-escape)_;
|
||||
Go to: _[horizontal-tab-escape](#user-content-horizontal-tab-escape), [backslash-escape](#user-content-backslash-escape), [null-character-escape](#user-content-null-character-escape), [line-feed-escape](#user-content-line-feed-escape), [single-quote-escape](#user-content-single-quote-escape), [double-quote-escape](#user-content-double-quote-escape), [carriage-return-escape](#user-content-carriage-return-escape)_;
|
||||
|
||||
|
||||
<a name="ascii-character-escape"></a>
|
||||
@ -835,7 +835,7 @@ Go to: _[carriage-return-escape](#user-content-carriage-return-escape), [single-
|
||||
ascii-character-escape = %s"\x" octal-digit hexadecimal-digit
|
||||
```
|
||||
|
||||
Go to: _[hexadecimal-digit](#user-content-hexadecimal-digit), [octal-digit](#user-content-octal-digit)_;
|
||||
Go to: _[octal-digit](#user-content-octal-digit), [hexadecimal-digit](#user-content-hexadecimal-digit)_;
|
||||
|
||||
|
||||
<a name="unicode-character-escape"></a>
|
||||
@ -863,7 +863,7 @@ string-literal-element = not-double-quote-or-backslash
|
||||
/ unicode-character-escape
|
||||
```
|
||||
|
||||
Go to: _[not-double-quote-or-backslash](#user-content-not-double-quote-or-backslash), [simple-character-escape](#user-content-simple-character-escape), [unicode-character-escape](#user-content-unicode-character-escape), [ascii-character-escape](#user-content-ascii-character-escape)_;
|
||||
Go to: _[not-double-quote-or-backslash](#user-content-not-double-quote-or-backslash), [simple-character-escape](#user-content-simple-character-escape), [ascii-character-escape](#user-content-ascii-character-escape), [unicode-character-escape](#user-content-unicode-character-escape)_;
|
||||
|
||||
|
||||
The ones above are all the atomic literals
|
||||
@ -883,7 +883,7 @@ atomic-literal = untyped-literal
|
||||
/ string-literal
|
||||
```
|
||||
|
||||
Go to: _[string-literal](#user-content-string-literal), [product-group-literal](#user-content-product-group-literal), [unsigned-literal](#user-content-unsigned-literal), [field-literal](#user-content-field-literal), [address-literal](#user-content-address-literal), [boolean-literal](#user-content-boolean-literal), [untyped-literal](#user-content-untyped-literal), [character-literal](#user-content-character-literal), [signed-literal](#user-content-signed-literal)_;
|
||||
Go to: _[signed-literal](#user-content-signed-literal), [unsigned-literal](#user-content-unsigned-literal), [field-literal](#user-content-field-literal), [product-group-literal](#user-content-product-group-literal), [boolean-literal](#user-content-boolean-literal), [address-literal](#user-content-address-literal), [string-literal](#user-content-string-literal), [untyped-literal](#user-content-untyped-literal), [character-literal](#user-content-character-literal)_;
|
||||
|
||||
|
||||
After defining the (mostly) alphanumeric tokens above,
|
||||
@ -927,7 +927,17 @@ token = keyword
|
||||
/ symbol
|
||||
```
|
||||
|
||||
Go to: _[atomic-literal](#user-content-atomic-literal), [identifier](#user-content-identifier), [symbol](#user-content-symbol), [package-name](#user-content-package-name), [annotation-name](#user-content-annotation-name), [keyword](#user-content-keyword)_;
|
||||
Go to: _[atomic-literal](#user-content-atomic-literal), [package-name](#user-content-package-name), [annotation-name](#user-content-annotation-name), [symbol](#user-content-symbol), [identifier](#user-content-identifier), [keyword](#user-content-keyword)_;
|
||||
|
||||
|
||||
Tokens, comments, and whitespace are lexemes, i.e. lexical units.
|
||||
|
||||
<a name="lexeme"></a>
|
||||
```abnf
|
||||
lexeme = token / comment / whitespace
|
||||
```
|
||||
|
||||
Go to: _[whitespace](#user-content-whitespace), [comment](#user-content-comment), [token](#user-content-token)_;
|
||||
|
||||
|
||||
|
||||
@ -984,7 +994,7 @@ group-type = %s"group"
|
||||
arithmetic-type = integer-type / field-type / group-type
|
||||
```
|
||||
|
||||
Go to: _[field-type](#user-content-field-type), [group-type](#user-content-group-type), [integer-type](#user-content-integer-type)_;
|
||||
Go to: _[integer-type](#user-content-integer-type), [field-type](#user-content-field-type), [group-type](#user-content-group-type)_;
|
||||
|
||||
|
||||
The arithmetic types, along with the boolean, address, and character types,
|
||||
@ -1050,7 +1060,7 @@ or a tuple of one or more dimensions.
|
||||
array-type = "[" type ";" array-dimensions "]"
|
||||
```
|
||||
|
||||
Go to: _[array-dimensions](#user-content-array-dimensions), [type](#user-content-type)_;
|
||||
Go to: _[type](#user-content-type), [array-dimensions](#user-content-array-dimensions)_;
|
||||
|
||||
|
||||
<a name="array-dimensions"></a>
|
||||
@ -1071,7 +1081,7 @@ i.e. types whose values contain (sub-)values
|
||||
aggregate-type = tuple-type / array-type / circuit-type
|
||||
```
|
||||
|
||||
Go to: _[tuple-type](#user-content-tuple-type), [array-type](#user-content-array-type), [circuit-type](#user-content-circuit-type)_;
|
||||
Go to: _[circuit-type](#user-content-circuit-type), [tuple-type](#user-content-tuple-type), [array-type](#user-content-array-type)_;
|
||||
|
||||
|
||||
Scalar and aggregate types form all the types.
|
||||
@ -1081,7 +1091,7 @@ Scalar and aggregate types form all the types.
|
||||
type = scalar-type / aggregate-type
|
||||
```
|
||||
|
||||
Go to: _[aggregate-type](#user-content-aggregate-type), [scalar-type](#user-content-scalar-type)_;
|
||||
Go to: _[scalar-type](#user-content-scalar-type), [aggregate-type](#user-content-aggregate-type)_;
|
||||
|
||||
|
||||
The lexical grammar given earlier defines product group literals.
|
||||
@ -1159,7 +1169,7 @@ primary-expression = identifier
|
||||
/ circuit-expression
|
||||
```
|
||||
|
||||
Go to: _[tuple-expression](#user-content-tuple-expression), [literal](#user-content-literal), [expression](#user-content-expression), [circuit-expression](#user-content-circuit-expression), [identifier](#user-content-identifier), [array-expression](#user-content-array-expression)_;
|
||||
Go to: _[expression](#user-content-expression), [array-expression](#user-content-array-expression), [literal](#user-content-literal), [identifier](#user-content-identifier), [circuit-expression](#user-content-circuit-expression), [tuple-expression](#user-content-tuple-expression)_;
|
||||
|
||||
|
||||
Tuple expressions construct tuples.
|
||||
@ -1220,7 +1230,7 @@ Go to: _[expression](#user-content-expression), [array-dimensions](#user-content
|
||||
array-construction = array-inline-construction / array-repeat-construction
|
||||
```
|
||||
|
||||
Go to: _[array-repeat-construction](#user-content-array-repeat-construction), [array-inline-construction](#user-content-array-inline-construction)_;
|
||||
Go to: _[array-inline-construction](#user-content-array-inline-construction), [array-repeat-construction](#user-content-array-repeat-construction)_;
|
||||
|
||||
|
||||
<a name="array-expression"></a>
|
||||
@ -1248,7 +1258,7 @@ circuit-construction = circuit-type "{"
|
||||
"}"
|
||||
```
|
||||
|
||||
Go to: _[circuit-inline-element](#user-content-circuit-inline-element), [circuit-type](#user-content-circuit-type)_;
|
||||
Go to: _[circuit-type](#user-content-circuit-type), [circuit-inline-element](#user-content-circuit-inline-element)_;
|
||||
|
||||
|
||||
<a name="circuit-inline-element"></a>
|
||||
@ -1307,7 +1317,7 @@ postfix-expression = primary-expression
|
||||
/ postfix-expression "[" [expression] ".." [expression] "]"
|
||||
```
|
||||
|
||||
Go to: _[circuit-type](#user-content-circuit-type), [postfix-expression](#user-content-postfix-expression), [primary-expression](#user-content-primary-expression), [identifier](#user-content-identifier), [function-arguments](#user-content-function-arguments), [natural](#user-content-natural), [expression](#user-content-expression)_;
|
||||
Go to: _[natural](#user-content-natural), [identifier](#user-content-identifier), [circuit-type](#user-content-circuit-type), [primary-expression](#user-content-primary-expression), [function-arguments](#user-content-function-arguments), [postfix-expression](#user-content-postfix-expression), [expression](#user-content-expression)_;
|
||||
|
||||
|
||||
Unary operators have the highest operator precedence.
|
||||
@ -1321,7 +1331,7 @@ unary-expression = postfix-expression
|
||||
/ "-" unary-expression
|
||||
```
|
||||
|
||||
Go to: _[unary-expression](#user-content-unary-expression), [postfix-expression](#user-content-postfix-expression)_;
|
||||
Go to: _[postfix-expression](#user-content-postfix-expression), [unary-expression](#user-content-unary-expression)_;
|
||||
|
||||
|
||||
Next in the operator precedence is exponentiation,
|
||||
@ -1347,7 +1357,7 @@ multiplicative-expression = exponential-expression
|
||||
/ multiplicative-expression "/" exponential-expression
|
||||
```
|
||||
|
||||
Go to: _[multiplicative-expression](#user-content-multiplicative-expression), [exponential-expression](#user-content-exponential-expression)_;
|
||||
Go to: _[exponential-expression](#user-content-exponential-expression), [multiplicative-expression](#user-content-multiplicative-expression)_;
|
||||
|
||||
|
||||
Then there are addition and subtraction, both left-assocative.
|
||||
@ -1359,7 +1369,7 @@ additive-expression = multiplicative-expression
|
||||
/ additive-expression "-" multiplicative-expression
|
||||
```
|
||||
|
||||
Go to: _[multiplicative-expression](#user-content-multiplicative-expression), [additive-expression](#user-content-additive-expression)_;
|
||||
Go to: _[additive-expression](#user-content-additive-expression), [multiplicative-expression](#user-content-multiplicative-expression)_;
|
||||
|
||||
|
||||
Next in the precedence order are ordering relations.
|
||||
@ -1398,7 +1408,7 @@ conjunctive-expression = equality-expression
|
||||
/ conjunctive-expression "&&" equality-expression
|
||||
```
|
||||
|
||||
Go to: _[conjunctive-expression](#user-content-conjunctive-expression), [equality-expression](#user-content-equality-expression)_;
|
||||
Go to: _[equality-expression](#user-content-equality-expression), [conjunctive-expression](#user-content-conjunctive-expression)_;
|
||||
|
||||
|
||||
Next come disjunctive expressions, left-associative.
|
||||
@ -1409,7 +1419,7 @@ disjunctive-expression = conjunctive-expression
|
||||
/ disjunctive-expression "||" conjunctive-expression
|
||||
```
|
||||
|
||||
Go to: _[disjunctive-expression](#user-content-disjunctive-expression), [conjunctive-expression](#user-content-conjunctive-expression)_;
|
||||
Go to: _[conjunctive-expression](#user-content-conjunctive-expression), [disjunctive-expression](#user-content-disjunctive-expression)_;
|
||||
|
||||
|
||||
Finally we have conditional expressions.
|
||||
@ -1422,7 +1432,7 @@ conditional-expression = disjunctive-expression
|
||||
":" conditional-expression
|
||||
```
|
||||
|
||||
Go to: _[expression](#user-content-expression), [conditional-expression](#user-content-conditional-expression), [disjunctive-expression](#user-content-disjunctive-expression)_;
|
||||
Go to: _[expression](#user-content-expression), [disjunctive-expression](#user-content-disjunctive-expression), [conditional-expression](#user-content-conditional-expression)_;
|
||||
|
||||
|
||||
Those above are all the expressions.
|
||||
@ -1455,7 +1465,7 @@ statement = expression-statement
|
||||
/ block
|
||||
```
|
||||
|
||||
Go to: _[assignment-statement](#user-content-assignment-statement), [expression-statement](#user-content-expression-statement), [conditional-statement](#user-content-conditional-statement), [block](#user-content-block), [loop-statement](#user-content-loop-statement), [constant-declaration](#user-content-constant-declaration), [console-statement](#user-content-console-statement), [variable-declaration](#user-content-variable-declaration), [return-statement](#user-content-return-statement)_;
|
||||
Go to: _[constant-declaration](#user-content-constant-declaration), [block](#user-content-block), [variable-declaration](#user-content-variable-declaration), [conditional-statement](#user-content-conditional-statement), [return-statement](#user-content-return-statement), [assignment-statement](#user-content-assignment-statement), [expression-statement](#user-content-expression-statement), [loop-statement](#user-content-loop-statement), [console-statement](#user-content-console-statement)_;
|
||||
|
||||
|
||||
<a name="block"></a>
|
||||
@ -1498,7 +1508,7 @@ variable-declaration = %s"let" identifier-or-identifiers [ ":" type ]
|
||||
"=" expression ";"
|
||||
```
|
||||
|
||||
Go to: _[expression](#user-content-expression), [identifier-or-identifiers](#user-content-identifier-or-identifiers), [type](#user-content-type)_;
|
||||
Go to: _[type](#user-content-type), [expression](#user-content-expression), [identifier-or-identifiers](#user-content-identifier-or-identifiers)_;
|
||||
|
||||
|
||||
<a name="constant-declaration"></a>
|
||||
@ -1507,7 +1517,7 @@ constant-declaration = %s"const" identifier-or-identifiers [ ":" type ]
|
||||
"=" expression ";"
|
||||
```
|
||||
|
||||
Go to: _[type](#user-content-type), [expression](#user-content-expression), [identifier-or-identifiers](#user-content-identifier-or-identifiers)_;
|
||||
Go to: _[identifier-or-identifiers](#user-content-identifier-or-identifiers), [type](#user-content-type), [expression](#user-content-expression)_;
|
||||
|
||||
|
||||
<a name="identifier-or-identifiers"></a>
|
||||
@ -1530,7 +1540,7 @@ Note that blocks are required in all branches, not merely statements.
|
||||
branch = %s"if" expression block
|
||||
```
|
||||
|
||||
Go to: _[expression](#user-content-expression), [block](#user-content-block)_;
|
||||
Go to: _[block](#user-content-block), [expression](#user-content-expression)_;
|
||||
|
||||
|
||||
<a name="conditional-statement"></a>
|
||||
@ -1596,7 +1606,7 @@ console-call = assert-call
|
||||
/ print-call
|
||||
```
|
||||
|
||||
Go to: _[print-call](#user-content-print-call), [assert-call](#user-content-assert-call)_;
|
||||
Go to: _[assert-call](#user-content-assert-call), [print-call](#user-content-print-call)_;
|
||||
|
||||
|
||||
<a name="assert-call"></a>
|
||||
@ -1638,7 +1648,7 @@ annotation = annotation-name
|
||||
[ "(" identifier *( "," identifier ) ")" ]
|
||||
```
|
||||
|
||||
Go to: _[identifier](#user-content-identifier), [annotation-name](#user-content-annotation-name)_;
|
||||
Go to: _[annotation-name](#user-content-annotation-name), [identifier](#user-content-identifier)_;
|
||||
|
||||
|
||||
A function declaration defines a function.
|
||||
@ -1655,7 +1665,7 @@ function-declaration = *annotation %s"function" identifier
|
||||
block
|
||||
```
|
||||
|
||||
Go to: _[type](#user-content-type), [identifier](#user-content-identifier), [function-parameters](#user-content-function-parameters), [block](#user-content-block)_;
|
||||
Go to: _[block](#user-content-block), [identifier](#user-content-identifier), [function-parameters](#user-content-function-parameters), [type](#user-content-type)_;
|
||||
|
||||
|
||||
<a name="function-parameters"></a>
|
||||
@ -1665,7 +1675,7 @@ function-parameters = self-parameter
|
||||
/ function-inputs
|
||||
```
|
||||
|
||||
Go to: _[self-parameter](#user-content-self-parameter), [function-inputs](#user-content-function-inputs)_;
|
||||
Go to: _[function-inputs](#user-content-function-inputs), [self-parameter](#user-content-self-parameter)_;
|
||||
|
||||
|
||||
<a name="self-parameter"></a>
|
||||
@ -1706,7 +1716,7 @@ member-variable-declarations = *( identifier ":" type ( "," / ";" ) )
|
||||
identifier ":" type ( [ "," ] / ";" )
|
||||
```
|
||||
|
||||
Go to: _[identifier](#user-content-identifier), [type](#user-content-type)_;
|
||||
Go to: _[type](#user-content-type), [identifier](#user-content-identifier)_;
|
||||
|
||||
|
||||
A circuit member function declaration consists of a function declaration.
|
||||
@ -1756,7 +1766,7 @@ by using an explicit package name before the package path.
|
||||
import-declaration = %s"import" package-name "." package-path ";"
|
||||
```
|
||||
|
||||
Go to: _[package-name](#user-content-package-name), [package-path](#user-content-package-path)_;
|
||||
Go to: _[package-path](#user-content-package-path), [package-name](#user-content-package-name)_;
|
||||
|
||||
|
||||
<a name="package-path"></a>
|
||||
@ -1782,7 +1792,7 @@ declaration = import-declaration
|
||||
/ constant-declaration
|
||||
```
|
||||
|
||||
Go to: _[circuit-declaration](#user-content-circuit-declaration), [constant-declaration](#user-content-constant-declaration), [import-declaration](#user-content-import-declaration), [function-declaration](#user-content-function-declaration)_;
|
||||
Go to: _[function-declaration](#user-content-function-declaration), [circuit-declaration](#user-content-circuit-declaration), [constant-declaration](#user-content-constant-declaration), [import-declaration](#user-content-import-declaration)_;
|
||||
|
||||
|
||||
<a name="file"></a>
|
||||
|
@ -611,6 +611,10 @@ token = keyword
|
||||
/ annotation-name
|
||||
/ symbol
|
||||
|
||||
; Tokens, comments, and whitespace are lexemes, i.e. lexical units.
|
||||
|
||||
lexeme = token / comment / whitespace
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
; Syntactic Grammar
|
||||
|
@ -61,7 +61,7 @@ impl<'a> ImportResolver<'a> for ImportParser<'a> {
|
||||
self.partial_imports.insert(full_path.clone());
|
||||
let program = imports
|
||||
.parse_package(context, path, package_segments, span)
|
||||
.map_err(|x| -> LeoError { x.into() })?;
|
||||
.map_err(|x| -> LeoError { x })?;
|
||||
self.partial_imports.remove(&full_path);
|
||||
self.imports.insert(full_path, program.clone());
|
||||
Ok(Some(program))
|
||||
|
@ -111,16 +111,16 @@ impl<'a> ImportParser<'a> {
|
||||
|
||||
// Check if the package name was found in both the source and imports directory.
|
||||
match (matched_source_entry, matched_import_entry) {
|
||||
(Some(_), Some(_)) => Err(LeoError::from(ImportError::conflicting_imports(package_name, &span))),
|
||||
(Some(_), Some(_)) => Err(LeoError::from(ImportError::conflicting_imports(package_name, span))),
|
||||
(Some(source_entry), None) => self.parse_package_access(context, &source_entry, &segments[1..], span),
|
||||
(None, Some(import_entry)) => self.parse_package_access(context, &import_entry, &segments[1..], span),
|
||||
(None, None) => Err(LeoError::from(ImportError::unknown_package(package_name, &span))),
|
||||
(None, None) => Err(LeoError::from(ImportError::unknown_package(package_name, span))),
|
||||
}
|
||||
} else {
|
||||
// Enforce local package access with no found imports directory
|
||||
match matched_source_entry {
|
||||
Some(source_entry) => self.parse_package_access(context, &source_entry, &segments[1..], span),
|
||||
None => Err(LeoError::from(ImportError::unknown_package(package_name, &span))),
|
||||
None => Err(LeoError::from(ImportError::unknown_package(package_name, span))),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ impl<'a> ImportParser<'a> {
|
||||
// Build the package abstract syntax tree.
|
||||
let program_string = &std::fs::read_to_string(&file_path)
|
||||
.map_err(|x| LeoError::from(ImportError::io_error(file_path_str, x, span)))?;
|
||||
let mut program = leo_parser::parse(&file_path_str, &program_string)?;
|
||||
let mut program = leo_parser::parse(file_path_str, program_string)?;
|
||||
program.name = file_name;
|
||||
let mut ast = leo_ast::Ast::new(program);
|
||||
ast.canonicalize()?;
|
||||
|
@ -191,7 +191,7 @@ impl InputParserError {
|
||||
expected, actual
|
||||
);
|
||||
|
||||
Self::new_from_span(message, &span)
|
||||
Self::new_from_span(message, span)
|
||||
}
|
||||
|
||||
pub fn section(header: Header) -> Self {
|
||||
|
@ -32,7 +32,7 @@ pub enum GroupCoordinate<'ast> {
|
||||
impl<'ast> GroupCoordinate<'ast> {
|
||||
pub fn span(&self) -> &Span<'ast> {
|
||||
match self {
|
||||
GroupCoordinate::Number(number) => &number.span(),
|
||||
GroupCoordinate::Number(number) => number.span(),
|
||||
GroupCoordinate::SignHigh(sign_high) => &sign_high.span,
|
||||
GroupCoordinate::SignLow(sign_low) => &sign_low.span,
|
||||
GroupCoordinate::Inferred(inferred) => &inferred.span,
|
||||
|
@ -39,13 +39,13 @@ pub enum Value<'ast> {
|
||||
impl<'ast> Value<'ast> {
|
||||
pub fn span(&self) -> &Span<'ast> {
|
||||
match self {
|
||||
Value::Address(value) => &value.span(),
|
||||
Value::Address(value) => value.span(),
|
||||
Value::Boolean(value) => &value.span,
|
||||
Value::Char(value) => &value.span,
|
||||
Value::Field(value) => &value.span,
|
||||
Value::Group(value) => &value.span,
|
||||
Value::Implicit(value) => &value.span(),
|
||||
Value::Integer(value) => &value.span(),
|
||||
Value::Implicit(value) => value.span(),
|
||||
Value::Integer(value) => value.span(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -144,10 +144,10 @@ pub fn write_token_and_username(token: &str, username: &str) -> Result<(), io::E
|
||||
}
|
||||
|
||||
let mut credentials = File::create(&LEO_CREDENTIALS_PATH.to_path_buf())?;
|
||||
credentials.write_all(&token.as_bytes())?;
|
||||
credentials.write_all(token.as_bytes())?;
|
||||
|
||||
let mut username_file = File::create(&LEO_USERNAME_PATH.to_path_buf())?;
|
||||
username_file.write_all(&username.as_bytes())?;
|
||||
username_file.write_all(username.as_bytes())?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ impl Updater {
|
||||
.repo_owner(Self::LEO_REPO_OWNER)
|
||||
.repo_name(Self::LEO_REPO_NAME)
|
||||
.bin_name(Self::LEO_BIN_NAME)
|
||||
.current_version(&env!("CARGO_PKG_VERSION"))
|
||||
.current_version(env!("CARGO_PKG_VERSION"))
|
||||
.show_download_progress(show_output)
|
||||
.no_confirm(true)
|
||||
.show_output(show_output)
|
||||
@ -69,7 +69,7 @@ impl Updater {
|
||||
.repo_owner(Self::LEO_REPO_OWNER)
|
||||
.repo_name(Self::LEO_REPO_NAME)
|
||||
.bin_name(Self::LEO_BIN_NAME)
|
||||
.current_version(&env!("CARGO_PKG_VERSION"))
|
||||
.current_version(env!("CARGO_PKG_VERSION"))
|
||||
.build()?;
|
||||
|
||||
let current_version = updater.current_version();
|
||||
|
@ -78,8 +78,8 @@ impl InputFile {
|
||||
|
||||
// Have to handle error mapping this way because of rust error: https://github.com/rust-lang/rust/issues/42424.
|
||||
match file.write_all(self.template().as_bytes()) {
|
||||
Ok(_) => return Ok(()),
|
||||
Err(e) => return Err(PackageError::io_error_input_file(eyre!(e), Backtrace::new()).into()),
|
||||
Ok(_) => Ok(()),
|
||||
Err(e) => Err(PackageError::io_error_input_file(eyre!(e), Backtrace::new()).into()),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -77,8 +77,8 @@ impl StateFile {
|
||||
|
||||
// Have to handle error mapping this way because of rust error: https://github.com/rust-lang/rust/issues/42424.
|
||||
match file.write_all(self.template().as_bytes()) {
|
||||
Ok(_) => return Ok(()),
|
||||
Err(e) => return Err(PackageError::io_error_state_file(eyre!(e), Backtrace::new()).into()),
|
||||
Ok(_) => Ok(()),
|
||||
Err(e) => Err(PackageError::io_error_state_file(eyre!(e), Backtrace::new()).into()),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -87,9 +87,7 @@ impl ChecksumFile {
|
||||
// Have to handle error mapping this way because of rust error: https://github.com/rust-lang/rust/issues/42424.
|
||||
match fs::remove_file(&path) {
|
||||
Ok(_) => Ok(true),
|
||||
Err(_) => {
|
||||
return Err(PackageError::failed_to_remove_checksum_file(path.into_owned(), Backtrace::new()).into());
|
||||
}
|
||||
Err(_) => Err(PackageError::failed_to_remove_checksum_file(path.into_owned(), Backtrace::new()).into()),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -87,9 +87,7 @@ impl CircuitFile {
|
||||
// Have to handle error mapping this way because of rust error: https://github.com/rust-lang/rust/issues/42424.
|
||||
match fs::remove_file(&path) {
|
||||
Ok(_) => Ok(true),
|
||||
Err(_) => {
|
||||
return Err(PackageError::failed_to_remove_circuit_file(path.into_owned(), Backtrace::new()).into());
|
||||
}
|
||||
Err(_) => Err(PackageError::failed_to_remove_circuit_file(path.into_owned(), Backtrace::new()).into()),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -90,9 +90,7 @@ impl ProofFile {
|
||||
// Have to handle error mapping this way because of rust error: https://github.com/rust-lang/rust/issues/42424.
|
||||
match fs::remove_file(&path) {
|
||||
Ok(_) => Ok(true),
|
||||
Err(_) => {
|
||||
return Err(PackageError::failed_to_remove_proof_file(path.into_owned(), Backtrace::new()).into());
|
||||
}
|
||||
Err(_) => Err(PackageError::failed_to_remove_proof_file(path.into_owned(), Backtrace::new()).into()),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -91,11 +91,7 @@ impl ProvingKeyFile {
|
||||
// Have to handle error mapping this way because of rust error: https://github.com/rust-lang/rust/issues/42424.
|
||||
match fs::remove_file(&path) {
|
||||
Ok(_) => Ok(true),
|
||||
Err(_) => {
|
||||
return Err(
|
||||
PackageError::failed_to_remove_proving_key_file(path.into_owned(), Backtrace::new()).into(),
|
||||
);
|
||||
}
|
||||
Err(_) => Err(PackageError::failed_to_remove_proving_key_file(path.into_owned(), Backtrace::new()).into()),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -92,9 +92,7 @@ impl VerificationKeyFile {
|
||||
match fs::remove_file(&path) {
|
||||
Ok(_) => Ok(true),
|
||||
Err(_) => {
|
||||
return Err(
|
||||
PackageError::failed_to_remove_verification_key_file(path.into_owned(), Backtrace::new()).into(),
|
||||
);
|
||||
Err(PackageError::failed_to_remove_verification_key_file(path.into_owned(), Backtrace::new()).into())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -125,14 +125,14 @@ impl Package {
|
||||
}
|
||||
|
||||
// Check if the input file already exists.
|
||||
let input_file = InputFile::new(&package_name);
|
||||
let input_file = InputFile::new(package_name);
|
||||
if input_file.exists_at(path) {
|
||||
existing_files.push(input_file.filename());
|
||||
result = false;
|
||||
}
|
||||
|
||||
// Check if the state file already exists.
|
||||
let state_file = StateFile::new(&package_name);
|
||||
let state_file = StateFile::new(package_name);
|
||||
if state_file.exists_at(path) {
|
||||
existing_files.push(state_file.filename());
|
||||
result = false;
|
||||
@ -159,24 +159,24 @@ impl Package {
|
||||
}
|
||||
|
||||
// Check if the manifest file exists.
|
||||
if !Manifest::exists_at(&path) {
|
||||
if !Manifest::exists_at(path) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if the input file exists.
|
||||
let input_file = InputFile::new(&package_name);
|
||||
if !input_file.exists_at(&path) {
|
||||
let input_file = InputFile::new(package_name);
|
||||
if !input_file.exists_at(path) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if the state file exists.
|
||||
let state_file = StateFile::new(&package_name);
|
||||
if !state_file.exists_at(&path) {
|
||||
let state_file = StateFile::new(package_name);
|
||||
if !state_file.exists_at(path) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if the main file exists.
|
||||
if !MainFile::exists_at(&path) {
|
||||
if !MainFile::exists_at(path) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -199,34 +199,34 @@ impl Package {
|
||||
// Next, initialize this directory as a Leo package.
|
||||
{
|
||||
// Create the manifest file.
|
||||
Manifest::new(&package_name, author)?.write_to(&path)?;
|
||||
Manifest::new(package_name, author)?.write_to(path)?;
|
||||
|
||||
// Verify that the .gitignore file does not exist.
|
||||
if !Gitignore::exists_at(&path) {
|
||||
if !Gitignore::exists_at(path) {
|
||||
// Create the .gitignore file.
|
||||
Gitignore::new().write_to(&path)?;
|
||||
Gitignore::new().write_to(path)?;
|
||||
}
|
||||
|
||||
// Verify that the README.md file does not exist.
|
||||
if !README::exists_at(&path) {
|
||||
if !README::exists_at(path) {
|
||||
// Create the README.md file.
|
||||
README::new(package_name).write_to(&path)?;
|
||||
README::new(package_name).write_to(path)?;
|
||||
}
|
||||
|
||||
// Create the source directory.
|
||||
SourceDirectory::create(&path)?;
|
||||
SourceDirectory::create(path)?;
|
||||
|
||||
// Create the input directory.
|
||||
InputsDirectory::create(&path)?;
|
||||
InputsDirectory::create(path)?;
|
||||
|
||||
// Create the input file in the inputs directory.
|
||||
InputFile::new(&package_name).write_to(&path)?;
|
||||
InputFile::new(package_name).write_to(path)?;
|
||||
|
||||
// Create the state file in the inputs directory.
|
||||
StateFile::new(&package_name).write_to(&path)?;
|
||||
StateFile::new(package_name).write_to(path)?;
|
||||
|
||||
// Create the main file in the source directory.
|
||||
MainFile::new(&package_name).write_to(&path)?;
|
||||
MainFile::new(package_name).write_to(path)?;
|
||||
}
|
||||
// Next, verify that a valid Leo package has been initialized in this directory
|
||||
{
|
||||
@ -245,7 +245,7 @@ impl Package {
|
||||
|
||||
/// Removes the package at the given path
|
||||
pub fn remove_imported_package(package_name: &str, path: &Path) -> Result<(), LeoError> {
|
||||
Ok(ImportsDirectory::remove_import(path, package_name)?)
|
||||
ImportsDirectory::remove_import(path, package_name)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -103,8 +103,11 @@ impl Manifest {
|
||||
|
||||
// Have to handle error mapping this way because of rust error: https://github.com/rust-lang/rust/issues/42424.
|
||||
match file.write_all(self.template().as_bytes()) {
|
||||
Ok(v) => return Ok(v),
|
||||
Err(e) => return Err(PackageError::io_error_manifest_file(eyre!(e), Backtrace::new()).into()),
|
||||
Ok(v) => Ok(v),
|
||||
Err(e) => Err(LeoError::from(PackageError::io_error_manifest_file(
|
||||
eyre!(e),
|
||||
Backtrace::new(),
|
||||
))),
|
||||
}
|
||||
}
|
||||
|
||||
@ -143,9 +146,11 @@ impl TryFrom<&Path> for Manifest {
|
||||
let mut file = match File::open(path.clone()) {
|
||||
Ok(file) => file,
|
||||
Err(e) => {
|
||||
return Err(
|
||||
PackageError::failed_to_open_manifest_file(MANIFEST_FILENAME, eyre!(e), Backtrace::new()).into(),
|
||||
);
|
||||
return Err(PackageError::failed_to_open_manifest_file(
|
||||
MANIFEST_FILENAME,
|
||||
eyre!(e),
|
||||
Backtrace::new(),
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
@ -157,17 +162,18 @@ impl TryFrom<&Path> for Manifest {
|
||||
MANIFEST_FILENAME,
|
||||
eyre!(e),
|
||||
Backtrace::new(),
|
||||
)
|
||||
.into());
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
let mut buffer = String::with_capacity(size);
|
||||
// Have to handle error mapping this way because of rust error: https://github.com/rust-lang/rust/issues/42424.
|
||||
if let Err(e) = file.read_to_string(&mut buffer) {
|
||||
return Err(
|
||||
PackageError::failed_to_read_manifest_file(MANIFEST_FILENAME, eyre!(e), Backtrace::new()).into(),
|
||||
);
|
||||
return Err(PackageError::failed_to_read_manifest_file(
|
||||
MANIFEST_FILENAME,
|
||||
eyre!(e),
|
||||
Backtrace::new(),
|
||||
));
|
||||
}
|
||||
|
||||
// Determine if the old remote format is being used, and update to new convention
|
||||
@ -261,22 +267,22 @@ author = "{author}"
|
||||
MANIFEST_FILENAME,
|
||||
eyre!(e),
|
||||
Backtrace::new(),
|
||||
)
|
||||
.into());
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
// Have to handle error mapping this way because of rust error: https://github.com/rust-lang/rust/issues/42424.
|
||||
if let Err(e) = file.write_all(refactored_toml.as_bytes()) {
|
||||
return Err(
|
||||
PackageError::failed_to_write_manifest_file(MANIFEST_FILENAME, eyre!(e), Backtrace::new()).into(),
|
||||
);
|
||||
return Err(PackageError::failed_to_write_manifest_file(
|
||||
MANIFEST_FILENAME,
|
||||
eyre!(e),
|
||||
Backtrace::new(),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
// Read the toml file
|
||||
toml::from_str(&final_toml).map_err(|e| {
|
||||
PackageError::failed_to_parse_manifest_file(MANIFEST_FILENAME, eyre!(e), Backtrace::new()).into()
|
||||
})
|
||||
toml::from_str(&final_toml)
|
||||
.map_err(|e| PackageError::failed_to_parse_manifest_file(MANIFEST_FILENAME, eyre!(e), Backtrace::new()))
|
||||
}
|
||||
}
|
||||
|
@ -166,7 +166,7 @@ impl ZipFile {
|
||||
}
|
||||
|
||||
// Have to handle error mapping this way because of rust error: https://github.com/rust-lang/rust/issues/42424.
|
||||
if let Err(_) = fs::remove_file(&path) {
|
||||
if fs::remove_file(&path).is_err() {
|
||||
return Err(PackageError::failed_to_remove_zip_file(path.into_owned(), Backtrace::new()).into());
|
||||
}
|
||||
|
||||
|
@ -15,10 +15,10 @@
|
||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use leo_ast::Ast;
|
||||
use leo_parser::errors::SyntaxError;
|
||||
use leo_errors::LeoError;
|
||||
use std::{env, fs, path::Path};
|
||||
|
||||
fn to_leo_tree(filepath: &Path) -> Result<String, SyntaxError> {
|
||||
fn to_leo_tree(filepath: &Path) -> Result<String, LeoError> {
|
||||
// Loads the Leo code as a string from the given file path.
|
||||
let program_filepath = filepath.to_path_buf();
|
||||
let program_string = fs::read_to_string(&program_filepath).expect("failed to open input file");
|
||||
@ -31,7 +31,7 @@ fn to_leo_tree(filepath: &Path) -> Result<String, SyntaxError> {
|
||||
Ok(serialized_leo_ast)
|
||||
}
|
||||
|
||||
fn main() -> Result<(), SyntaxError> {
|
||||
fn main() -> Result<(), LeoError> {
|
||||
// Parse the command-line arguments as strings.
|
||||
let cli_arguments = env::args().collect::<Vec<String>>();
|
||||
|
||||
@ -48,7 +48,7 @@ fn main() -> Result<(), SyntaxError> {
|
||||
let input_filepath = Path::new(&cli_arguments[1]);
|
||||
|
||||
// Construct the serialized syntax tree.
|
||||
let serialized_leo_tree = to_leo_tree(&input_filepath)?;
|
||||
let serialized_leo_tree = to_leo_tree(input_filepath)?;
|
||||
println!("{}", serialized_leo_tree);
|
||||
|
||||
// Determine the output directory.
|
||||
|
@ -562,11 +562,11 @@ impl ParserContext {
|
||||
pub fn parse_tuple_expression(&mut self, span: &Span) -> SyntaxResult<Expression> {
|
||||
if let Some((left, right, span)) = self.eat_group_partial().transpose()? {
|
||||
return Ok(Expression::Value(ValueExpression::Group(Box::new(GroupValue::Tuple(
|
||||
GroupTuple {
|
||||
Box::new(GroupTuple {
|
||||
span,
|
||||
x: left,
|
||||
y: right,
|
||||
},
|
||||
}),
|
||||
)))));
|
||||
}
|
||||
let mut args = Vec::new();
|
||||
|
@ -195,17 +195,17 @@ impl ParserContext {
|
||||
})
|
||||
} else if self.eat(Token::As).is_some() {
|
||||
let alias = self.expect_ident()?;
|
||||
Ok(PackageAccess::Symbol(ImportSymbol {
|
||||
Ok(PackageAccess::Symbol(Box::new(ImportSymbol {
|
||||
span: &name.span + &alias.span,
|
||||
symbol: name,
|
||||
alias: Some(alias),
|
||||
}))
|
||||
})))
|
||||
} else {
|
||||
Ok(PackageAccess::Symbol(ImportSymbol {
|
||||
Ok(PackageAccess::Symbol(Box::new(ImportSymbol {
|
||||
span: name.span.clone(),
|
||||
symbol: name,
|
||||
alias: None,
|
||||
}))
|
||||
})))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -237,7 +237,7 @@ impl ParserContext {
|
||||
base.name = format_tendril!("{}{}", base.name, next.name);
|
||||
base.span = base.span + next.span;
|
||||
}
|
||||
x if KEYWORD_TOKENS.contains(&x) => {
|
||||
x if KEYWORD_TOKENS.contains(x) => {
|
||||
let next = self.expect_loose_identifier()?;
|
||||
base.name = format_tendril!("{}{}", base.name, next.name);
|
||||
base.span = base.span + next.span;
|
||||
@ -378,7 +378,7 @@ impl ParserContext {
|
||||
let peeked_token = &peeked.token;
|
||||
if peeked_token == &Token::Function || peeked_token == &Token::At {
|
||||
let function = self.parse_function_declaration()?;
|
||||
Ok(CircuitMember::CircuitFunction(function.1))
|
||||
Ok(CircuitMember::CircuitFunction(Box::new(function.1)))
|
||||
} else {
|
||||
Err(LeoError::from(ParserError::unexpected(
|
||||
peeked_token.to_string(),
|
||||
@ -427,7 +427,9 @@ impl ParserContext {
|
||||
// Handle `mut self`.
|
||||
name.span = &mutable.span + &name.span;
|
||||
name.name = "mut self".to_string().into();
|
||||
return Ok(FunctionInput::MutSelfKeyword(MutSelfKeyword { identifier: name }));
|
||||
return Ok(FunctionInput::MutSelfKeyword(Box::new(MutSelfKeyword {
|
||||
identifier: name,
|
||||
})));
|
||||
} else if let Some(const_) = &const_ {
|
||||
// Handle `const self`.
|
||||
name.span = &const_.span + &name.span;
|
||||
@ -446,13 +448,13 @@ impl ParserContext {
|
||||
|
||||
self.expect(Token::Colon)?;
|
||||
let type_ = self.parse_type()?.0;
|
||||
Ok(FunctionInput::Variable(FunctionInputVariable {
|
||||
Ok(FunctionInput::Variable(Box::new(FunctionInputVariable {
|
||||
const_: const_.is_some(),
|
||||
mutable: const_.is_none(),
|
||||
type_,
|
||||
span: name.span.clone(),
|
||||
identifier: name,
|
||||
}))
|
||||
})))
|
||||
}
|
||||
|
||||
///
|
||||
|
@ -91,7 +91,7 @@ impl ParserContext {
|
||||
match &self.peek()?.token {
|
||||
Token::Return => Ok(Statement::Return(self.parse_return_statement()?)),
|
||||
Token::If => Ok(Statement::Conditional(self.parse_conditional_statement()?)),
|
||||
Token::For => Ok(Statement::Iteration(self.parse_loop_statement()?)),
|
||||
Token::For => Ok(Statement::Iteration(Box::new(self.parse_loop_statement()?))),
|
||||
Token::Console => Ok(Statement::Console(self.parse_console_statement()?)),
|
||||
Token::Let | Token::Const => Ok(Statement::Definition(self.parse_definition_statement()?)),
|
||||
Token::LeftCurly => Ok(Statement::Block(self.parse_block()?)),
|
||||
@ -109,7 +109,7 @@ impl ParserContext {
|
||||
let value = self.parse_expression()?;
|
||||
let assignee = Self::construct_assignee(expr)?;
|
||||
self.expect(Token::Semicolon)?;
|
||||
Ok(Statement::Assign(AssignStatement {
|
||||
Ok(Statement::Assign(Box::new(AssignStatement {
|
||||
span: &assignee.span + value.span(),
|
||||
assignee,
|
||||
operation: match operator.token {
|
||||
@ -131,7 +131,7 @@ impl ParserContext {
|
||||
_ => unimplemented!(),
|
||||
},
|
||||
value,
|
||||
}))
|
||||
})))
|
||||
} else {
|
||||
self.expect(Token::Semicolon)?;
|
||||
Ok(Statement::Expression(ExpressionStatement {
|
||||
@ -289,7 +289,7 @@ impl ParserContext {
|
||||
"log" => ConsoleFunction::Log(self.parse_console_args()?),
|
||||
x => {
|
||||
return Err(LeoError::from(ParserError::unexpected_ident(
|
||||
&x,
|
||||
x,
|
||||
&["assert", "error", "log"],
|
||||
&function.span,
|
||||
)));
|
||||
|
@ -101,7 +101,7 @@ impl Token {
|
||||
return None;
|
||||
}
|
||||
|
||||
if let Ok(ascii_number) = u8::from_str_radix(&hex_string, 16) {
|
||||
if let Ok(ascii_number) = u8::from_str_radix(hex_string, 16) {
|
||||
// According to RFC, we allow only values less than 128.
|
||||
if ascii_number > 127 {
|
||||
return None;
|
||||
@ -123,7 +123,7 @@ impl Token {
|
||||
return None;
|
||||
}
|
||||
|
||||
if let Ok(hex) = u32::from_str_radix(&unicode_number, 16) {
|
||||
if let Ok(hex) = u32::from_str_radix(unicode_number, 16) {
|
||||
if let Some(character) = std::char::from_u32(hex) {
|
||||
// scalar
|
||||
return Some(Char::Scalar(character));
|
||||
|
15
tests/compiler/address/branch.leo
Normal file
15
tests/compiler/address/branch.leo
Normal file
@ -0,0 +1,15 @@
|
||||
/*
|
||||
namespace: Compile
|
||||
expectation: Pass
|
||||
input_file: inputs/branch.in
|
||||
*/
|
||||
|
||||
|
||||
function main (x: address, y: bool) -> bool {
|
||||
let z = aleo18cw5zdez3zhypev3tnfhmwvhre9ramwle4up947gcyy5rnmjw5yqn93wsr;
|
||||
if y {
|
||||
z = aleo1f2gs8g0qpumlgzpvmkw3q07y6xrwsdr0lqsu9h9fgnh8d7e44v9qhpgpkj;
|
||||
}
|
||||
|
||||
return z == aleo1f2gs8g0qpumlgzpvmkw3q07y6xrwsdr0lqsu9h9fgnh8d7e44v9qhpgpkj;
|
||||
}
|
12
tests/compiler/address/index.leo
Normal file
12
tests/compiler/address/index.leo
Normal file
@ -0,0 +1,12 @@
|
||||
/*
|
||||
namespace: Compile
|
||||
expectation: Pass
|
||||
input_file: inputs/index.in
|
||||
*/
|
||||
|
||||
function main (x: u32) -> bool {
|
||||
const y = [aleo1x0rh2cudq93fhukrsce8sgvcphddv4qs0clph64stpg0hstfds9qjvxcg6; 3];
|
||||
let z = y[x];
|
||||
|
||||
return z == y[0];
|
||||
}
|
6
tests/compiler/address/inputs/branch.in
Normal file
6
tests/compiler/address/inputs/branch.in
Normal file
@ -0,0 +1,6 @@
|
||||
[main]
|
||||
x: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;
|
||||
y: bool = true;
|
||||
|
||||
[registers]
|
||||
a: bool = false;
|
5
tests/compiler/address/inputs/index.in
Normal file
5
tests/compiler/address/inputs/index.in
Normal file
@ -0,0 +1,5 @@
|
||||
[main]
|
||||
x: u32 = 0;
|
||||
|
||||
[registers]
|
||||
a: bool = false;
|
21
tests/expectations/compiler/compiler/address/branch.leo.out
Normal file
21
tests/expectations/compiler/compiler/address/branch.leo.out
Normal file
@ -0,0 +1,21 @@
|
||||
---
|
||||
namespace: Compile
|
||||
expectation: Pass
|
||||
outputs:
|
||||
- circuit:
|
||||
num_public_variables: 0
|
||||
num_private_variables: 1024
|
||||
num_constraints: 1536
|
||||
at: 5afd1d58b6826912fe5cba06b60d9a7debdbad9e922b8a78ed49f7a7ca0ac65e
|
||||
bt: db77c3470cf1b3c80c2e3b1b3ddc59d9891912489bfcf39b7f67c2f314ca7f6d
|
||||
ct: d0993682df5b495f4a6784882e0f007dbc378adb35007d250e2c098975f4d32e
|
||||
output:
|
||||
- input_file: inputs/branch.in
|
||||
output:
|
||||
registers:
|
||||
a:
|
||||
type: bool
|
||||
value: "true"
|
||||
initial_ast: a7748573e4731753b76889c6d4c28e9589e114860a163da87957cf20b916f733
|
||||
canonicalized_ast: a7748573e4731753b76889c6d4c28e9589e114860a163da87957cf20b916f733
|
||||
type_inferenced_ast: af3663710ad6278c3d2e28a753d62084505746cd49de11949fe5e8e390ffcc60
|
21
tests/expectations/compiler/compiler/address/index.leo.out
Normal file
21
tests/expectations/compiler/compiler/address/index.leo.out
Normal file
@ -0,0 +1,21 @@
|
||||
---
|
||||
namespace: Compile
|
||||
expectation: Pass
|
||||
outputs:
|
||||
- circuit:
|
||||
num_public_variables: 0
|
||||
num_private_variables: 1694
|
||||
num_constraints: 2719
|
||||
at: f9a9bc8304df327c7b16f088b61ac518fb3a7b6457ccc35a1ab9eab4565a1981
|
||||
bt: 045eba0fdd405714f788492fd5914b053e0ece622e9a542270d8cfe85c0ee291
|
||||
ct: e8fa4a33a657c70a7cecc7e9b284157b369b7ea57879948e108daf93e778551c
|
||||
output:
|
||||
- input_file: inputs/index.in
|
||||
output:
|
||||
registers:
|
||||
a:
|
||||
type: bool
|
||||
value: "true"
|
||||
initial_ast: 8934e4c1d645f6f98fe59f48bbf687623e811c99e504e87c6989bc00af62194a
|
||||
canonicalized_ast: 8934e4c1d645f6f98fe59f48bbf687623e811c99e504e87c6989bc00af62194a
|
||||
type_inferenced_ast: 70af835aeaec1d5bc1c4a3186635260ff44743e0d3a7aa5ac9f2c98ec03bd23e
|
@ -17,5 +17,5 @@ outputs:
|
||||
type: bool
|
||||
value: "true"
|
||||
initial_ast: 4c74b65863cddde8ce523495358ab619ec48645dcb8409658a3fb3d7a3821d6d
|
||||
canonicalized_ast: b5697d5884139da5a68861213ff3c7660f694e682078e1bd350856206e0289b8
|
||||
type_inferenced_ast: ff4b8f91f014277d6bb2d8d82c31361e5a5c5a46ed87a1e61f0c2e2e8d5fd254
|
||||
canonicalized_ast: 45dc35a683e14503f8a1fc40280f05e7d096b49896f115ffa649e76b9cd80941
|
||||
type_inferenced_ast: 11af72cfc90adc12c3412e3067ad285a2279de0f4f12af5081dbe27c58b5a3bf
|
||||
|
Loading…
Reference in New Issue
Block a user