parse boolean later in program

This commit is contained in:
collin 2020-06-24 15:33:05 -07:00
parent 0159b1c0cc
commit 5f0b3e2b0c
2 changed files with 5 additions and 8 deletions

View File

@ -6,6 +6,7 @@ use crate::{
enforce_or, enforce_or,
errors::ExpressionError, errors::ExpressionError,
evaluate_not, evaluate_not,
new_bool_constant,
new_scope, new_scope,
FieldType, FieldType,
GroupType, GroupType,
@ -902,7 +903,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
Expression::Integer(integer) => Ok(ConstrainedValue::Integer(integer)), Expression::Integer(integer) => Ok(ConstrainedValue::Integer(integer)),
Expression::Field(field, span) => Ok(ConstrainedValue::Field(FieldType::constant(field, span)?)), Expression::Field(field, span) => Ok(ConstrainedValue::Field(FieldType::constant(field, span)?)),
Expression::Group(group_affine, span) => Ok(ConstrainedValue::Group(G::constant(group_affine, span)?)), Expression::Group(group_affine, span) => Ok(ConstrainedValue::Group(G::constant(group_affine, span)?)),
Expression::Boolean(bool) => Ok(ConstrainedValue::Boolean(bool)), Expression::Boolean(boolean, span) => Ok(ConstrainedValue::Boolean(new_bool_constant(boolean, span)?)),
Expression::Implicit(value, span) => Self::enforce_number_implicit(expected_types, value, span), Expression::Implicit(value, span) => Self::enforce_number_implicit(expected_types, value, span),
// Binary operations // Binary operations

View File

@ -16,8 +16,6 @@ use leo_ast::{
values::{BooleanValue, FieldValue, GroupValue, IntegerValue, NumberImplicitValue, Value}, values::{BooleanValue, FieldValue, GroupValue, IntegerValue, NumberImplicitValue, Value},
}; };
use snarkos_models::gadgets::utilities::boolean::Boolean;
use std::fmt; use std::fmt;
/// Expression that evaluates to a value /// Expression that evaluates to a value
@ -30,7 +28,7 @@ pub enum Expression {
Integer(Integer), Integer(Integer),
Field(String, Span), Field(String, Span),
Group(String, Span), Group(String, Span),
Boolean(Boolean), Boolean(String, Span),
Implicit(String, Span), Implicit(String, Span),
// Number operations // Number operations
@ -125,7 +123,7 @@ impl<'ast> fmt::Display for Expression {
Expression::Integer(ref integer) => write!(f, "{}", integer), Expression::Integer(ref integer) => write!(f, "{}", integer),
Expression::Field(ref field, ref _span) => write!(f, "{}", field), Expression::Field(ref field, ref _span) => write!(f, "{}", field),
Expression::Group(ref group, ref _span) => write!(f, "{}", group), Expression::Group(ref group, ref _span) => write!(f, "{}", group),
Expression::Boolean(ref bool) => write!(f, "{}", bool.get_value().unwrap()), Expression::Boolean(ref bool, ref _span) => write!(f, "{}", bool),
Expression::Implicit(ref value, ref _span) => write!(f, "{}", value), Expression::Implicit(ref value, ref _span) => write!(f, "{}", value),
// Number operations // Number operations
@ -438,9 +436,7 @@ impl<'ast> From<GroupValue<'ast>> for Expression {
impl<'ast> From<BooleanValue<'ast>> for Expression { impl<'ast> From<BooleanValue<'ast>> for Expression {
fn from(boolean: BooleanValue<'ast>) -> Self { fn from(boolean: BooleanValue<'ast>) -> Self {
Expression::Boolean(Boolean::Constant( Expression::Boolean(boolean.value, Span::from(boolean.span))
boolean.value.parse::<bool>().expect("unable to parse boolean"),
))
} }
} }