perf: reduce boxing in typed objects

Signed-off-by: ljedrz <ljedrz@gmail.com>
This commit is contained in:
ljedrz 2020-10-19 14:34:09 +02:00
parent a65ff7d820
commit 49e9a48d90
9 changed files with 174 additions and 150 deletions

View File

@ -32,7 +32,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
file_scope: String,
function_scope: String,
expected_type: Option<Type>,
array: Box<Expression>,
array: Expression,
index: RangeOrExpression,
span: Span,
) -> Result<ConstrainedValue<F, G>, ExpressionError> {
@ -41,7 +41,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
file_scope.clone(),
function_scope.clone(),
expected_type,
*array,
array,
span.clone(),
)? {
ConstrainedValue::Array(array) => array,

View File

@ -67,66 +67,66 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
enforce_negate(cs, resolved_value, span)
}
Expression::Add(left, right, span) => {
Expression::Add(left_right, span) => {
let (resolved_left, resolved_right) = self.enforce_binary_expression(
cs,
file_scope,
function_scope,
expected_type,
*left,
*right,
left_right.0,
left_right.1,
span.clone(),
)?;
enforce_add(cs, resolved_left, resolved_right, span)
}
Expression::Sub(left, right, span) => {
Expression::Sub(left_right, span) => {
let (resolved_left, resolved_right) = self.enforce_binary_expression(
cs,
file_scope,
function_scope,
expected_type,
*left,
*right,
left_right.0,
left_right.1,
span.clone(),
)?;
enforce_sub(cs, resolved_left, resolved_right, span)
}
Expression::Mul(left, right, span) => {
Expression::Mul(left_right, span) => {
let (resolved_left, resolved_right) = self.enforce_binary_expression(
cs,
file_scope,
function_scope,
expected_type,
*left,
*right,
left_right.0,
left_right.1,
span.clone(),
)?;
enforce_mul(cs, resolved_left, resolved_right, span)
}
Expression::Div(left, right, span) => {
Expression::Div(left_right, span) => {
let (resolved_left, resolved_right) = self.enforce_binary_expression(
cs,
file_scope,
function_scope,
expected_type,
*left,
*right,
left_right.0,
left_right.1,
span.clone(),
)?;
enforce_div(cs, resolved_left, resolved_right, span)
}
Expression::Pow(left, right, span) => {
Expression::Pow(left_right, span) => {
let (resolved_left, resolved_right) = self.enforce_binary_expression(
cs,
file_scope,
function_scope,
expected_type,
*left,
*right,
left_right.0,
left_right.1,
span.clone(),
)?;
@ -138,72 +138,107 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
self.enforce_expression(cs, file_scope, function_scope, expected_type, *expression)?,
span,
)?),
Expression::Or(left, right, span) => {
Expression::Or(left_right, span) => {
let (resolved_left, resolved_right) = self.enforce_binary_expression(
cs,
file_scope,
function_scope,
expected_type,
*left,
*right,
left_right.0,
left_right.1,
span.clone(),
)?;
Ok(enforce_or(cs, resolved_left, resolved_right, span)?)
}
Expression::And(left, right, span) => {
Expression::And(left_right, span) => {
let (resolved_left, resolved_right) = self.enforce_binary_expression(
cs,
file_scope,
function_scope,
expected_type,
*left,
*right,
left_right.0,
left_right.1,
span.clone(),
)?;
Ok(enforce_and(cs, resolved_left, resolved_right, span)?)
}
Expression::Eq(left, right, span) => {
let (resolved_left, resolved_right) =
self.enforce_binary_expression(cs, file_scope, function_scope, None, *left, *right, span.clone())?;
Expression::Eq(left_right, span) => {
let (resolved_left, resolved_right) = self.enforce_binary_expression(
cs,
file_scope,
function_scope,
None,
left_right.0,
left_right.1,
span.clone(),
)?;
Ok(evaluate_eq(cs, resolved_left, resolved_right, span)?)
}
Expression::Ge(left, right, span) => {
let (resolved_left, resolved_right) =
self.enforce_binary_expression(cs, file_scope, function_scope, None, *left, *right, span.clone())?;
Expression::Ge(left_right, span) => {
let (resolved_left, resolved_right) = self.enforce_binary_expression(
cs,
file_scope,
function_scope,
None,
left_right.0,
left_right.1,
span.clone(),
)?;
Ok(evaluate_ge(cs, resolved_left, resolved_right, span)?)
}
Expression::Gt(left, right, span) => {
let (resolved_left, resolved_right) =
self.enforce_binary_expression(cs, file_scope, function_scope, None, *left, *right, span.clone())?;
Expression::Gt(left_right, span) => {
let (resolved_left, resolved_right) = self.enforce_binary_expression(
cs,
file_scope,
function_scope,
None,
left_right.0,
left_right.1,
span.clone(),
)?;
Ok(evaluate_gt(cs, resolved_left, resolved_right, span)?)
}
Expression::Le(left, right, span) => {
let (resolved_left, resolved_right) =
self.enforce_binary_expression(cs, file_scope, function_scope, None, *left, *right, span.clone())?;
Expression::Le(left_right, span) => {
let (resolved_left, resolved_right) = self.enforce_binary_expression(
cs,
file_scope,
function_scope,
None,
left_right.0,
left_right.1,
span.clone(),
)?;
Ok(evaluate_le(cs, resolved_left, resolved_right, span)?)
}
Expression::Lt(left, right, span) => {
let (resolved_left, resolved_right) =
self.enforce_binary_expression(cs, file_scope, function_scope, None, *left, *right, span.clone())?;
Expression::Lt(left_right, span) => {
let (resolved_left, resolved_right) = self.enforce_binary_expression(
cs,
file_scope,
function_scope,
None,
left_right.0,
left_right.1,
span.clone(),
)?;
Ok(evaluate_lt(cs, resolved_left, resolved_right, span)?)
}
// Conditionals
Expression::IfElse(conditional, first, second, span) => self.enforce_conditional_expression(
Expression::IfElse(triplet, span) => self.enforce_conditional_expression(
cs,
file_scope,
function_scope,
expected_type,
*conditional,
*first,
*second,
triplet.0,
triplet.1,
triplet.2,
span,
),
@ -211,9 +246,15 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
Expression::Array(array, span) => {
self.enforce_array(cs, file_scope, function_scope, expected_type, array, span)
}
Expression::ArrayAccess(array, index, span) => {
self.enforce_array_access(cs, file_scope, function_scope, expected_type, array, *index, span)
}
Expression::ArrayAccess(array_w_index, span) => self.enforce_array_access(
cs,
file_scope,
function_scope,
expected_type,
array_w_index.0,
array_w_index.1,
span,
),
// Tuples
Expression::Tuple(tuple, span) => {

View File

@ -71,13 +71,13 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
Ok(())
}
Assignee::Array(_assignee, range_or_expression) => self.assign_array(
Assignee::Array(assignee_w_range_or_expression) => self.assign_array(
cs,
file_scope,
function_scope,
indicator,
variable_name,
*range_or_expression,
assignee_w_range_or_expression.1,
new_value,
span,
),

View File

@ -24,7 +24,7 @@ use snarkos_models::curves::{Field, PrimeField};
pub fn resolve_assignee(scope: String, assignee: Assignee) -> String {
match assignee {
Assignee::Identifier(name) => new_scope(scope, name.to_string()),
Assignee::Array(array, _index) => resolve_assignee(scope, *array),
Assignee::Array(array_w_index) => resolve_assignee(scope, array_w_index.0),
Assignee::Tuple(tuple, _index) => resolve_assignee(scope, *tuple),
Assignee::CircuitField(circuit_name, _member) => resolve_assignee(scope, *circuit_name),
}

View File

@ -91,15 +91,15 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
results.append(&mut result);
}
Statement::Iteration(index, start, stop, statements, span) => {
Statement::Iteration(index, start_stop, statements, span) => {
let mut result = self.enforce_iteration_statement(
cs,
file_scope,
function_scope,
indicator,
index,
*start,
*stop,
start_stop.0,
start_stop.1,
statements,
return_type,
span,

View File

@ -27,7 +27,7 @@ use std::fmt;
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum Assignee {
Identifier(Identifier),
Array(Box<Assignee>, Box<RangeOrExpression>),
Array(Box<(Assignee, RangeOrExpression)>),
Tuple(Box<Assignee>, usize),
CircuitField(Box<Assignee>, Identifier), // (circuit name, circuit field name)
}
@ -54,7 +54,7 @@ impl<'ast> From<AstAssignee<'ast>> for Assignee {
.into_iter()
.fold(variable, |acc, access| match access {
AstAssigneeAccess::Array(array) => {
Assignee::Array(Box::new(acc), Box::new(RangeOrExpression::from(array.expression)))
Assignee::Array(Box::new((acc, RangeOrExpression::from(array.expression))))
}
AstAssigneeAccess::Tuple(tuple) => {
Assignee::Tuple(Box::new(acc), Expression::get_count_from_ast(tuple.number))
@ -70,7 +70,7 @@ impl fmt::Display for Assignee {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Assignee::Identifier(ref variable) => write!(f, "{}", variable),
Assignee::Array(ref array, ref index) => write!(f, "{}[{}]", array, index),
Assignee::Array(ref array_w_index) => write!(f, "{}[{}]", array_w_index.0, array_w_index.1),
Assignee::Tuple(ref tuple, ref index) => write!(f, "{}.{}", tuple, index),
Assignee::CircuitField(ref circuit_variable, ref member) => write!(f, "{}.{}", circuit_variable, member),
}

View File

@ -69,32 +69,32 @@ pub enum Expression {
Integer(IntegerType, String, Span),
// Number operations
Add(Box<Expression>, Box<Expression>, Span),
Sub(Box<Expression>, Box<Expression>, Span),
Mul(Box<Expression>, Box<Expression>, Span),
Div(Box<Expression>, Box<Expression>, Span),
Pow(Box<Expression>, Box<Expression>, Span),
Add(Box<(Expression, Expression)>, Span),
Sub(Box<(Expression, Expression)>, Span),
Mul(Box<(Expression, Expression)>, Span),
Div(Box<(Expression, Expression)>, Span),
Pow(Box<(Expression, Expression)>, Span),
// Boolean operations
Not(Box<Expression>, Span),
Negate(Box<Expression>, Span),
Or(Box<Expression>, Box<Expression>, Span),
And(Box<Expression>, Box<Expression>, Span),
Eq(Box<Expression>, Box<Expression>, Span),
Ge(Box<Expression>, Box<Expression>, Span),
Gt(Box<Expression>, Box<Expression>, Span),
Le(Box<Expression>, Box<Expression>, Span),
Lt(Box<Expression>, Box<Expression>, Span),
Or(Box<(Expression, Expression)>, Span),
And(Box<(Expression, Expression)>, Span),
Eq(Box<(Expression, Expression)>, Span),
Ge(Box<(Expression, Expression)>, Span),
Gt(Box<(Expression, Expression)>, Span),
Le(Box<(Expression, Expression)>, Span),
Lt(Box<(Expression, Expression)>, Span),
// Conditionals
// (conditional, first_value, second_value, span)
IfElse(Box<Expression>, Box<Expression>, Box<Expression>, Span),
IfElse(Box<(Expression, Expression, Expression)>, Span),
// Arrays
// (array_elements, span)
Array(Vec<SpreadOrExpression>, Span),
// (array_name, range, span)
ArrayAccess(Box<Expression>, Box<RangeOrExpression>, Span),
ArrayAccess(Box<(Expression, RangeOrExpression)>, Span),
// Tuples
// (tuple_elements, span)
@ -123,24 +123,24 @@ impl Expression {
Expression::Field(_, old_span) => *old_span = new_span.clone(),
Expression::Group(value) => value.set_span(new_span),
Expression::Add(_, _, old_span) => *old_span = new_span.clone(),
Expression::Sub(_, _, old_span) => *old_span = new_span.clone(),
Expression::Mul(_, _, old_span) => *old_span = new_span.clone(),
Expression::Div(_, _, old_span) => *old_span = new_span.clone(),
Expression::Pow(_, _, old_span) => *old_span = new_span.clone(),
Expression::Add(_, old_span) => *old_span = new_span.clone(),
Expression::Sub(_, old_span) => *old_span = new_span.clone(),
Expression::Mul(_, old_span) => *old_span = new_span.clone(),
Expression::Div(_, old_span) => *old_span = new_span.clone(),
Expression::Pow(_, old_span) => *old_span = new_span.clone(),
Expression::Not(_, old_span) => *old_span = new_span.clone(),
Expression::Or(_, _, old_span) => *old_span = new_span.clone(),
Expression::And(_, _, old_span) => *old_span = new_span.clone(),
Expression::Eq(_, _, old_span) => *old_span = new_span.clone(),
Expression::Ge(_, _, old_span) => *old_span = new_span.clone(),
Expression::Gt(_, _, old_span) => *old_span = new_span.clone(),
Expression::Le(_, _, old_span) => *old_span = new_span.clone(),
Expression::Lt(_, _, old_span) => *old_span = new_span.clone(),
Expression::Or(_, old_span) => *old_span = new_span.clone(),
Expression::And(_, old_span) => *old_span = new_span.clone(),
Expression::Eq(_, old_span) => *old_span = new_span.clone(),
Expression::Ge(_, old_span) => *old_span = new_span.clone(),
Expression::Gt(_, old_span) => *old_span = new_span.clone(),
Expression::Le(_, old_span) => *old_span = new_span.clone(),
Expression::Lt(_, old_span) => *old_span = new_span.clone(),
Expression::IfElse(_, _, _, old_span) => *old_span = new_span.clone(),
Expression::IfElse(_, old_span) => *old_span = new_span.clone(),
Expression::Array(_, old_span) => *old_span = new_span.clone(),
Expression::ArrayAccess(_, _, old_span) => *old_span = new_span.clone(),
Expression::ArrayAccess(_, old_span) => *old_span = new_span.clone(),
Expression::Tuple(_, old_span) => *old_span = new_span.clone(),
Expression::TupleAccess(_, _, old_span) => *old_span = new_span.clone(),
@ -206,25 +206,25 @@ impl<'ast> fmt::Display for Expression {
// Number operations
Expression::Negate(ref expression, ref _span) => write!(f, "-{}", expression),
Expression::Add(ref left, ref right, ref _span) => write!(f, "{} + {}", left, right),
Expression::Sub(ref left, ref right, ref _span) => write!(f, "{} - {}", left, right),
Expression::Mul(ref left, ref right, ref _span) => write!(f, "{} * {}", left, right),
Expression::Div(ref left, ref right, ref _span) => write!(f, "{} / {}", left, right),
Expression::Pow(ref left, ref right, ref _span) => write!(f, "{} ** {}", left, right),
Expression::Add(ref left_right, ref _span) => write!(f, "{} + {}", left_right.0, left_right.1),
Expression::Sub(ref left_right, ref _span) => write!(f, "{} - {}", left_right.0, left_right.1),
Expression::Mul(ref left_right, ref _span) => write!(f, "{} * {}", left_right.0, left_right.1),
Expression::Div(ref left_right, ref _span) => write!(f, "{} / {}", left_right.0, left_right.1),
Expression::Pow(ref left_right, ref _span) => write!(f, "{} ** {}", left_right.0, left_right.1),
// Boolean operations
Expression::Not(ref expression, ref _span) => write!(f, "!{}", expression),
Expression::Or(ref lhs, ref rhs, ref _span) => write!(f, "{} || {}", lhs, rhs),
Expression::And(ref lhs, ref rhs, ref _span) => write!(f, "{} && {}", lhs, rhs),
Expression::Eq(ref lhs, ref rhs, ref _span) => write!(f, "{} == {}", lhs, rhs),
Expression::Ge(ref lhs, ref rhs, ref _span) => write!(f, "{} >= {}", lhs, rhs),
Expression::Gt(ref lhs, ref rhs, ref _span) => write!(f, "{} > {}", lhs, rhs),
Expression::Le(ref lhs, ref rhs, ref _span) => write!(f, "{} <= {}", lhs, rhs),
Expression::Lt(ref lhs, ref rhs, ref _span) => write!(f, "{} < {}", lhs, rhs),
Expression::Or(ref lhs_rhs, ref _span) => write!(f, "{} || {}", lhs_rhs.0, lhs_rhs.1),
Expression::And(ref lhs_rhs, ref _span) => write!(f, "{} && {}", lhs_rhs.0, lhs_rhs.1),
Expression::Eq(ref lhs_rhs, ref _span) => write!(f, "{} == {}", lhs_rhs.0, lhs_rhs.1),
Expression::Ge(ref lhs_rhs, ref _span) => write!(f, "{} >= {}", lhs_rhs.0, lhs_rhs.1),
Expression::Gt(ref lhs_rhs, ref _span) => write!(f, "{} > {}", lhs_rhs.0, lhs_rhs.1),
Expression::Le(ref lhs_rhs, ref _span) => write!(f, "{} <= {}", lhs_rhs.0, lhs_rhs.1),
Expression::Lt(ref lhs_rhs, ref _span) => write!(f, "{} < {}", lhs_rhs.0, lhs_rhs.1),
// Conditionals
Expression::IfElse(ref first, ref second, ref third, ref _span) => {
write!(f, "if {} then {} else {} fi", first, second, third)
Expression::IfElse(ref triplet, ref _span) => {
write!(f, "if {} then {} else {} fi", triplet.0, triplet.1, triplet.2)
}
// Arrays
@ -238,7 +238,9 @@ impl<'ast> fmt::Display for Expression {
}
write!(f, "]")
}
Expression::ArrayAccess(ref array, ref index, ref _span) => write!(f, "{}[{}]", array, index),
Expression::ArrayAccess(ref array_w_index, ref _span) => {
write!(f, "{}[{}]", array_w_index.0, array_w_index.1)
}
// Tuples
Expression::Tuple(ref tuple, ref _span) => {
@ -318,8 +320,7 @@ impl<'ast> From<PostfixExpression<'ast>> for Expression {
.fold(variable, |acc, access| match access {
// Handle array accesses
Access::Array(array) => Expression::ArrayAccess(
Box::new(acc),
Box::new(RangeOrExpression::from(array.expression)),
Box::new((acc, RangeOrExpression::from(array.expression))),
Span::from(array.span),
),
@ -365,7 +366,7 @@ impl<'ast> From<AstExpression<'ast>> for Expression {
match expression {
AstExpression::Value(value) => Expression::from(value),
AstExpression::Identifier(variable) => Expression::from(variable),
AstExpression::Unary(expression) => Expression::from(expression),
AstExpression::Unary(expression) => Expression::from(*expression),
AstExpression::Binary(expression) => Expression::from(*expression),
AstExpression::Ternary(expression) => Expression::from(*expression),
AstExpression::ArrayInline(expression) => Expression::from(expression),
@ -393,8 +394,7 @@ impl<'ast> From<Assignee<'ast>> for Expression {
Span::from(circuit_member.span),
),
AssigneeAccess::Array(array) => Expression::ArrayAccess(
Box::new(acc),
Box::new(RangeOrExpression::from(array.expression)),
Box::new((acc, RangeOrExpression::from(array.expression))),
Span::from(array.span),
),
AssigneeAccess::Tuple(tuple) => Expression::TupleAccess(
@ -411,74 +411,61 @@ impl<'ast> From<BinaryExpression<'ast>> for Expression {
match expression.operation {
// Boolean operations
BinaryOperation::Or => Expression::Or(
Box::new(Expression::from(expression.left)),
Box::new(Expression::from(expression.right)),
Box::new((Expression::from(expression.left), Expression::from(expression.right))),
Span::from(expression.span),
),
BinaryOperation::And => Expression::And(
Box::new(Expression::from(expression.left)),
Box::new(Expression::from(expression.right)),
Box::new((Expression::from(expression.left), Expression::from(expression.right))),
Span::from(expression.span),
),
BinaryOperation::Eq => Expression::Eq(
Box::new(Expression::from(expression.left)),
Box::new(Expression::from(expression.right)),
Box::new((Expression::from(expression.left), Expression::from(expression.right))),
Span::from(expression.span),
),
BinaryOperation::Ne => {
let span = Span::from(expression.span);
let negated = Expression::Eq(
Box::new(Expression::from(expression.left)),
Box::new(Expression::from(expression.right)),
Box::new((Expression::from(expression.left), Expression::from(expression.right))),
span.clone(),
);
Expression::Not(Box::new(negated), span)
}
BinaryOperation::Ge => Expression::Ge(
Box::new(Expression::from(expression.left)),
Box::new(Expression::from(expression.right)),
Box::new((Expression::from(expression.left), Expression::from(expression.right))),
Span::from(expression.span),
),
BinaryOperation::Gt => Expression::Gt(
Box::new(Expression::from(expression.left)),
Box::new(Expression::from(expression.right)),
Box::new((Expression::from(expression.left), Expression::from(expression.right))),
Span::from(expression.span),
),
BinaryOperation::Le => Expression::Le(
Box::new(Expression::from(expression.left)),
Box::new(Expression::from(expression.right)),
Box::new((Expression::from(expression.left), Expression::from(expression.right))),
Span::from(expression.span),
),
BinaryOperation::Lt => Expression::Lt(
Box::new(Expression::from(expression.left)),
Box::new(Expression::from(expression.right)),
Box::new((Expression::from(expression.left), Expression::from(expression.right))),
Span::from(expression.span),
),
// Number operations
BinaryOperation::Add => Expression::Add(
Box::new(Expression::from(expression.left)),
Box::new(Expression::from(expression.right)),
Box::new((Expression::from(expression.left), Expression::from(expression.right))),
Span::from(expression.span),
),
BinaryOperation::Sub => Expression::Sub(
Box::new(Expression::from(expression.left)),
Box::new(Expression::from(expression.right)),
Box::new((Expression::from(expression.left), Expression::from(expression.right))),
Span::from(expression.span),
),
BinaryOperation::Mul => Expression::Mul(
Box::new(Expression::from(expression.left)),
Box::new(Expression::from(expression.right)),
Box::new((Expression::from(expression.left), Expression::from(expression.right))),
Span::from(expression.span),
),
BinaryOperation::Div => Expression::Div(
Box::new(Expression::from(expression.left)),
Box::new(Expression::from(expression.right)),
Box::new((Expression::from(expression.left), Expression::from(expression.right))),
Span::from(expression.span),
),
BinaryOperation::Pow => Expression::Pow(
Box::new(Expression::from(expression.left)),
Box::new(Expression::from(expression.right)),
Box::new((Expression::from(expression.left), Expression::from(expression.right))),
Span::from(expression.span),
),
}
@ -488,9 +475,11 @@ impl<'ast> From<BinaryExpression<'ast>> for Expression {
impl<'ast> From<TernaryExpression<'ast>> for Expression {
fn from(expression: TernaryExpression<'ast>) -> Self {
Expression::IfElse(
Box::new(Expression::from(expression.first)),
Box::new(Expression::from(expression.second)),
Box::new(Expression::from(expression.third)),
Box::new((
Expression::from(expression.first),
Expression::from(expression.second),
Expression::from(expression.third),
)),
Span::from(expression.span),
)
}
@ -556,11 +545,11 @@ impl<'ast> From<UnaryExpression<'ast>> for Expression {
fn from(expression: UnaryExpression<'ast>) -> Self {
match expression.operation {
UnaryOperation::Not(_) => Expression::Not(
Box::new(Expression::from(*expression.expression)),
Box::new(Expression::from(expression.expression)),
Span::from(expression.span),
),
UnaryOperation::Negate(_) => Expression::Negate(
Box::new(Expression::from(*expression.expression)),
Box::new(Expression::from(expression.expression)),
Span::from(expression.span),
),
}

View File

@ -38,7 +38,7 @@ pub enum Statement {
Definition(Declare, Variables, Vec<Expression>, Span),
Assign(Assignee, Box<Expression>, Span),
Conditional(ConditionalStatement, Span),
Iteration(Identifier, Box<Expression>, Box<Expression>, Vec<Statement>, Span),
Iteration(Identifier, Box<(Expression, Expression)>, Vec<Statement>, Span),
Console(ConsoleFunctionCall),
Expression(Expression, Span),
}
@ -89,8 +89,7 @@ impl<'ast> From<AssignStatement<'ast>> for Statement {
AssignOperation::AddAssign(ref _assign) => Statement::Assign(
Assignee::from(statement.assignee),
Box::new(Expression::Add(
Box::new(converted),
Box::new(Expression::from(statement.expression)),
Box::new((converted, Expression::from(statement.expression))),
Span::from(statement.span.clone()),
)),
Span::from(statement.span),
@ -98,8 +97,7 @@ impl<'ast> From<AssignStatement<'ast>> for Statement {
AssignOperation::SubAssign(ref _assign) => Statement::Assign(
Assignee::from(statement.assignee),
Box::new(Expression::Sub(
Box::new(converted),
Box::new(Expression::from(statement.expression)),
Box::new((converted, Expression::from(statement.expression))),
Span::from(statement.span.clone()),
)),
Span::from(statement.span),
@ -107,8 +105,7 @@ impl<'ast> From<AssignStatement<'ast>> for Statement {
AssignOperation::MulAssign(ref _assign) => Statement::Assign(
Assignee::from(statement.assignee),
Box::new(Expression::Mul(
Box::new(converted),
Box::new(Expression::from(statement.expression)),
Box::new((converted, Expression::from(statement.expression))),
Span::from(statement.span.clone()),
)),
Span::from(statement.span),
@ -116,8 +113,7 @@ impl<'ast> From<AssignStatement<'ast>> for Statement {
AssignOperation::DivAssign(ref _assign) => Statement::Assign(
Assignee::from(statement.assignee),
Box::new(Expression::Div(
Box::new(converted),
Box::new(Expression::from(statement.expression)),
Box::new((converted, Expression::from(statement.expression))),
Span::from(statement.span.clone()),
)),
Span::from(statement.span),
@ -125,8 +121,7 @@ impl<'ast> From<AssignStatement<'ast>> for Statement {
AssignOperation::PowAssign(ref _assign) => Statement::Assign(
Assignee::from(statement.assignee),
Box::new(Expression::Pow(
Box::new(converted),
Box::new(Expression::from(statement.expression)),
Box::new((converted, Expression::from(statement.expression))),
Span::from(statement.span.clone()),
)),
Span::from(statement.span),
@ -142,8 +137,7 @@ impl<'ast> From<ForStatement<'ast>> for Statement {
fn from(statement: ForStatement<'ast>) -> Self {
Statement::Iteration(
Identifier::from(statement.index),
Box::new(Expression::from(statement.start)),
Box::new(Expression::from(statement.stop)),
Box::new((Expression::from(statement.start), Expression::from(statement.stop))),
statement.statements.into_iter().map(Statement::from).collect(),
Span::from(statement.span),
)
@ -199,8 +193,8 @@ impl fmt::Display for Statement {
}
Statement::Assign(ref variable, ref statement, ref _span) => write!(f, "{} = {};", variable, statement),
Statement::Conditional(ref statement, ref _span) => write!(f, "{}", statement),
Statement::Iteration(ref var, ref start, ref stop, ref list, ref _span) => {
writeln!(f, "for {} in {}..{} {{", var, start, stop)?;
Statement::Iteration(ref var, ref start_stop, ref list, ref _span) => {
writeln!(f, "for {} in {}..{} {{", var, start_stop.0, start_stop.1)?;
for l in list {
writeln!(f, "\t\t{}", l)?;
}

View File

@ -12,7 +12,7 @@
{
"Return": [
{
"Add": [
"Add": [[
{
"Implicit": [
"1",
@ -34,7 +34,7 @@
"end": 17
}
]
},
}],
{
"text": " return 1 + 1",
"line": 2,