mirror of
https://github.com/AleoHQ/leo.git
synced 2025-01-04 16:15:11 +03:00
impl expression operations logical and relational
This commit is contained in:
parent
154fa45b4d
commit
8de889ada5
@ -19,7 +19,9 @@ use leo_static_check::Type;
|
||||
use leo_typed::{Expression as UnresolvedExpression, Span};
|
||||
|
||||
impl Expression {
|
||||
/// Resolve the type of negating `-expression`
|
||||
///
|
||||
/// Returns a new `Expression` negating the `UnresolvedExpression`.
|
||||
///
|
||||
pub(crate) fn negate(
|
||||
frame: &Frame,
|
||||
type_: &Type,
|
||||
|
@ -73,25 +73,25 @@ impl Expression {
|
||||
UnresolvedExpression::Implicit(string, span) => Self::implicit(type_, string, span),
|
||||
|
||||
// Arithmetic Operations
|
||||
UnresolvedExpression::Add(lhs, rhs, span) => Self::add(variable_table, type_, *lhs, *rhs, span),
|
||||
UnresolvedExpression::Sub(lhs, rhs, span) => Self::sub(variable_table, type_, *lhs, *rhs, span),
|
||||
UnresolvedExpression::Mul(lhs, rhs, span) => Self::mul(variable_table, type_, *lhs, *rhs, span),
|
||||
UnresolvedExpression::Div(lhs, rhs, span) => Self::div(variable_table, type_, *lhs, *rhs, span),
|
||||
UnresolvedExpression::Pow(lhs, rhs, span) => Self::pow(variable_table, type_, *lhs, *rhs, span),
|
||||
UnresolvedExpression::Negate(expression, span) => Self::negate(variable_table, type_, *expression, span),
|
||||
UnresolvedExpression::Add(lhs, rhs, span) => Self::add(frame, type_, *lhs, *rhs, span),
|
||||
UnresolvedExpression::Sub(lhs, rhs, span) => Self::sub(frame, type_, *lhs, *rhs, span),
|
||||
UnresolvedExpression::Mul(lhs, rhs, span) => Self::mul(frame, type_, *lhs, *rhs, span),
|
||||
UnresolvedExpression::Div(lhs, rhs, span) => Self::div(frame, type_, *lhs, *rhs, span),
|
||||
UnresolvedExpression::Pow(lhs, rhs, span) => Self::pow(frame, type_, *lhs, *rhs, span),
|
||||
UnresolvedExpression::Negate(expression, span) => Self::negate(frame, type_, *expression, span),
|
||||
|
||||
// Logical Operations
|
||||
UnresolvedExpression::And(lhs, rhs, span) => Self::and(frame, *lhs, *rhs, span),
|
||||
UnresolvedExpression::Or(lhs, rhs, span) => Self::or(frame, *lhs, *rhs, span),
|
||||
UnresolvedExpression::Not(expression, span) => Self::not(frame, *expression, span),
|
||||
|
||||
// Relational Operations
|
||||
UnresolvedExpression::Eq(lhs, rhs, span) => Self::eq(frame, *lhs, *rhs, span),
|
||||
UnresolvedExpression::Ge(lhs, rhs, span) => Self::ge(frame, *lhs, *rhs, span),
|
||||
UnresolvedExpression::Gt(lhs, rhs, span) => Self::gt(frame, *lhs, *rhs, span),
|
||||
UnresolvedExpression::Le(lhs, rhs, span) => Self::le(frame, *lhs, *rhs, span),
|
||||
UnresolvedExpression::Lt(lhs, rhs, span) => Self::lt(frame, *lhs, *rhs, span),
|
||||
|
||||
// // Logical Operations
|
||||
// UnresolvedExpression::And(lhs, rhs, span) => Self::and(variable_table, *lhs, *rhs, span),
|
||||
// UnresolvedExpression::Or(lhs, rhs, span) => Self::or(variable_table, *lhs, *rhs, span),
|
||||
// UnresolvedExpression::Not(expression, span) => Self::not(variable_table, *expression, span),
|
||||
//
|
||||
// // Relational Operations
|
||||
// UnresolvedExpression::Eq(lhs, rhs, span) => Self::eq(variable_table, *lhs, *rhs, span),
|
||||
// UnresolvedExpression::Ge(lhs, rhs, span) => Self::ge(variable_table, *lhs, *rhs, span),
|
||||
// UnresolvedExpression::Gt(lhs, rhs, span) => Self::gt(variable_table, *lhs, *rhs, span),
|
||||
// UnresolvedExpression::Le(lhs, rhs, span) => Self::le(variable_table, *lhs, *rhs, span),
|
||||
// UnresolvedExpression::Lt(lhs, rhs, span) => Self::lt(variable_table, *lhs, *rhs, span),
|
||||
//
|
||||
// // Conditionals
|
||||
// UnresolvedExpression::IfElse(cond, first, second, span) => {
|
||||
// Self::conditional(variable_table, *cond, *first, *second, span)
|
||||
|
@ -13,27 +13,25 @@
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||
use crate::{Expression, ExpressionError, ExpressionValue};
|
||||
use leo_static_check::{SymbolTable, Type};
|
||||
|
||||
use crate::{Expression, ExpressionError, ExpressionValue, Frame};
|
||||
use leo_static_check::Type;
|
||||
use leo_typed::{Expression as UnresolvedExpression, Span};
|
||||
|
||||
impl Expression {
|
||||
/// Resolve the type of `lhs && rhs`
|
||||
///
|
||||
/// Returns a new `Expression` applying logical AND `lhs && rhs`.
|
||||
///
|
||||
pub(crate) fn and(
|
||||
table: &mut SymbolTable,
|
||||
expected_type: Option<Type>,
|
||||
frame: &Frame,
|
||||
lhs: UnresolvedExpression,
|
||||
rhs: UnresolvedExpression,
|
||||
span: Span,
|
||||
) -> Result<Self, ExpressionError> {
|
||||
let type_ = Type::Boolean;
|
||||
|
||||
// Check the expected type if given
|
||||
Type::check_type(&expected_type, &type_, span.clone())?;
|
||||
|
||||
// Resolve lhs and rhs expressions to boolean type
|
||||
let boolean_type = Some(type_.clone());
|
||||
let (lhs_resolved, rhs_resolved) = Self::binary(table, boolean_type, lhs, rhs, span.clone())?;
|
||||
let (lhs_resolved, rhs_resolved) = Self::binary(frame, &type_, lhs, rhs, &span)?;
|
||||
|
||||
Ok(Expression {
|
||||
type_,
|
||||
|
@ -13,26 +13,19 @@
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||
use crate::{Expression, ExpressionError, ExpressionValue, ResolvedNode};
|
||||
use leo_static_check::{SymbolTable, Type};
|
||||
use crate::{Expression, ExpressionError, ExpressionValue, Frame, ResolvedNode};
|
||||
use leo_static_check::Type;
|
||||
use leo_typed::{Expression as UnresolvedExpression, Span};
|
||||
|
||||
impl Expression {
|
||||
/// Resolve the type of `!expression`
|
||||
pub(crate) fn not(
|
||||
table: &mut SymbolTable,
|
||||
expected_type: Option<Type>,
|
||||
expression: UnresolvedExpression,
|
||||
span: Span,
|
||||
) -> Result<Self, ExpressionError> {
|
||||
///
|
||||
/// Returns a new `Expression` applying a logical NOT `!UnresolvedExpression`.
|
||||
///
|
||||
pub(crate) fn not(table: &Frame, expression: UnresolvedExpression, span: Span) -> Result<Self, ExpressionError> {
|
||||
let type_ = Type::Boolean;
|
||||
|
||||
// Check the expected type if given
|
||||
Type::check_type(&expected_type, &type_, span.clone())?;
|
||||
|
||||
// Resolve lhs and rhs expressions to boolean type
|
||||
let boolean_type = Some(type_.clone());
|
||||
let expression_resolved = Self::resolve(table, (boolean_type, expression))?;
|
||||
let expression_resolved = Self::new(table, &type_, expression)?;
|
||||
|
||||
Ok(Expression {
|
||||
type_,
|
||||
|
@ -13,31 +13,29 @@
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||
use crate::{Expression, ExpressionError, ExpressionValue};
|
||||
use leo_static_check::{SymbolTable, Type};
|
||||
|
||||
use crate::{Expression, ExpressionError, ExpressionValue, Frame};
|
||||
use leo_static_check::Type;
|
||||
use leo_typed::{Expression as UnresolvedExpression, Span};
|
||||
|
||||
impl Expression {
|
||||
/// Resolve the type of `lhs || rhs`
|
||||
///
|
||||
/// Returns a new `Expression` applying logical OR `lhs || rhs`.
|
||||
///
|
||||
pub(crate) fn or(
|
||||
table: &mut SymbolTable,
|
||||
expected_type: Option<Type>,
|
||||
frame: &Frame,
|
||||
lhs: UnresolvedExpression,
|
||||
rhs: UnresolvedExpression,
|
||||
span: Span,
|
||||
) -> Result<Self, ExpressionError> {
|
||||
let type_ = Type::Boolean;
|
||||
|
||||
// Check the expected type if given
|
||||
Type::check_type(&expected_type, &type_, span.clone())?;
|
||||
|
||||
// Resolve lhs and rhs expressions to boolean type
|
||||
let boolean_type = Some(type_.clone());
|
||||
let (lhs_resolved, rhs_resolved) = Self::binary(table, boolean_type, lhs, rhs, span.clone())?;
|
||||
let (lhs_resolved, rhs_resolved) = Self::binary(frame, &type_, lhs, rhs, &span)?;
|
||||
|
||||
Ok(Expression {
|
||||
type_,
|
||||
value: ExpressionValue::Or(Box::new(lhs_resolved), Box::new(rhs_resolved), span),
|
||||
value: ExpressionValue::And(Box::new(lhs_resolved), Box::new(rhs_resolved), span),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -13,27 +13,26 @@
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||
use crate::{Expression, ExpressionError, ExpressionValue};
|
||||
use leo_static_check::{SymbolTable, Type};
|
||||
|
||||
use crate::{Expression, ExpressionError, ExpressionValue, Frame};
|
||||
use leo_static_check::Type;
|
||||
use leo_typed::{Expression as UnresolvedExpression, Span};
|
||||
|
||||
impl Expression {
|
||||
/// Resolve the type of `lhs == rhs`
|
||||
///
|
||||
/// Returns a new `Expression` evaluating `lhs == rhs`.
|
||||
///
|
||||
pub(crate) fn eq(
|
||||
table: &mut SymbolTable,
|
||||
expected_type: Option<Type>,
|
||||
frame: &Frame,
|
||||
lhs: UnresolvedExpression,
|
||||
rhs: UnresolvedExpression,
|
||||
span: Span,
|
||||
) -> Result<Self, ExpressionError> {
|
||||
// This expression results in a boolean type
|
||||
// This expression returns a boolean type.
|
||||
let type_ = Type::Boolean;
|
||||
|
||||
// Check the expected type if given
|
||||
Type::check_type(&expected_type, &type_, span.clone())?;
|
||||
|
||||
// Resolve lhs and rhs expressions
|
||||
let (lhs_resolved, rhs_resolved) = Self::binary(table, None, lhs, rhs, span.clone())?;
|
||||
let (lhs_resolved, rhs_resolved) = Self::binary(frame, &type_, lhs, rhs, &span)?;
|
||||
|
||||
Ok(Expression {
|
||||
type_,
|
||||
|
@ -13,34 +13,33 @@
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||
use crate::{Expression, ExpressionError, ExpressionValue};
|
||||
|
||||
use crate::{Expression, ExpressionError, ExpressionValue, Frame};
|
||||
use leo_static_check::{SymbolTable, Type};
|
||||
use leo_typed::{Expression as UnresolvedExpression, Span};
|
||||
|
||||
impl Expression {
|
||||
/// Resolve the type of `lhs >= rhs`
|
||||
///
|
||||
/// Returns a new `Expression` evaluating `lhs >= rhs`.
|
||||
///
|
||||
pub(crate) fn ge(
|
||||
table: &mut SymbolTable,
|
||||
expected_type: Option<Type>,
|
||||
frame: &Frame,
|
||||
lhs: UnresolvedExpression,
|
||||
rhs: UnresolvedExpression,
|
||||
span: Span,
|
||||
) -> Result<Self, ExpressionError> {
|
||||
// This expression results in a boolean type
|
||||
// This expression returns a boolean type.
|
||||
let type_ = Type::Boolean;
|
||||
|
||||
// Check the expected type if given
|
||||
Type::check_type(&expected_type, &type_, span.clone())?;
|
||||
|
||||
// Resolve lhs and rhs expressions
|
||||
let (lhs_resolved, rhs_resolved) = Self::binary(table, None, lhs, rhs, span.clone())?;
|
||||
let (lhs_resolved, rhs_resolved) = Self::binary(frame, &type_, lhs, rhs, &span)?;
|
||||
|
||||
// Check that expressions are integer type
|
||||
lhs_resolved.check_type_integer()?;
|
||||
rhs_resolved.check_type_integer()?;
|
||||
|
||||
Ok(Expression {
|
||||
// This expression results in a boolean type
|
||||
// This expression returns a boolean type.
|
||||
type_,
|
||||
value: ExpressionValue::Ge(Box::new(lhs_resolved), Box::new(rhs_resolved), span),
|
||||
})
|
||||
|
@ -13,34 +13,33 @@
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||
use crate::{Expression, ExpressionError, ExpressionValue};
|
||||
use leo_static_check::{SymbolTable, Type};
|
||||
|
||||
use crate::{Expression, ExpressionError, ExpressionValue, Frame};
|
||||
use leo_static_check::Type;
|
||||
use leo_typed::{Expression as UnresolvedExpression, Span};
|
||||
|
||||
impl Expression {
|
||||
/// Resolve the type of `lhs > rhs`
|
||||
///
|
||||
/// Returns a new `Expression` evaluating `lhs > rhs`.
|
||||
///
|
||||
pub(crate) fn gt(
|
||||
table: &mut SymbolTable,
|
||||
expected_type: Option<Type>,
|
||||
frame: &Frame,
|
||||
lhs: UnresolvedExpression,
|
||||
rhs: UnresolvedExpression,
|
||||
span: Span,
|
||||
) -> Result<Self, ExpressionError> {
|
||||
// This expression results in a boolean type
|
||||
// This expression returns a boolean type.
|
||||
let type_ = Type::Boolean;
|
||||
|
||||
// Check the expected type if given
|
||||
Type::check_type(&expected_type, &type_, span.clone())?;
|
||||
|
||||
// Resolve lhs and rhs expressions
|
||||
let (lhs_resolved, rhs_resolved) = Self::binary(table, None, lhs, rhs, span.clone())?;
|
||||
let (lhs_resolved, rhs_resolved) = Self::binary(frame, &type_, lhs, rhs, &span)?;
|
||||
|
||||
// Check that expressions are integer type
|
||||
lhs_resolved.check_type_integer()?;
|
||||
rhs_resolved.check_type_integer()?;
|
||||
|
||||
Ok(Expression {
|
||||
// This expression results in a boolean type
|
||||
// This expression returns a boolean type.
|
||||
type_: Type::Boolean,
|
||||
value: ExpressionValue::Gt(Box::new(lhs_resolved), Box::new(rhs_resolved), span),
|
||||
})
|
||||
|
@ -13,34 +13,33 @@
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||
use crate::{Expression, ExpressionError, ExpressionValue};
|
||||
use leo_static_check::{SymbolTable, Type};
|
||||
|
||||
use crate::{Expression, ExpressionError, ExpressionValue, Frame};
|
||||
use leo_static_check::Type;
|
||||
use leo_typed::{Expression as UnresolvedExpression, Span};
|
||||
|
||||
impl Expression {
|
||||
/// Resolve the type of `lhs <= rhs`
|
||||
///
|
||||
/// Returns a new `Expression` evaluating `lhs <= rhs`.
|
||||
///
|
||||
pub(crate) fn le(
|
||||
table: &mut SymbolTable,
|
||||
expected_type: Option<Type>,
|
||||
frame: &Frame,
|
||||
lhs: UnresolvedExpression,
|
||||
rhs: UnresolvedExpression,
|
||||
span: Span,
|
||||
) -> Result<Self, ExpressionError> {
|
||||
// This expression results in a boolean type
|
||||
// This expression returns a boolean type.
|
||||
let type_ = Type::Boolean;
|
||||
|
||||
// Check the expected type if given
|
||||
Type::check_type(&expected_type, &type_, span.clone())?;
|
||||
|
||||
// Resolve lhs and rhs expressions
|
||||
let (lhs_resolved, rhs_resolved) = Self::binary(table, None, lhs, rhs, span.clone())?;
|
||||
let (lhs_resolved, rhs_resolved) = Self::binary(frame, &type_, lhs, rhs, &span)?;
|
||||
|
||||
// Check that expressions are integer type
|
||||
lhs_resolved.check_type_integer()?;
|
||||
rhs_resolved.check_type_integer()?;
|
||||
|
||||
Ok(Expression {
|
||||
// This expression results in a boolean type
|
||||
// This expression returns a boolean type.
|
||||
type_: Type::Boolean,
|
||||
value: ExpressionValue::Le(Box::new(lhs_resolved), Box::new(rhs_resolved), span),
|
||||
})
|
||||
|
@ -13,34 +13,33 @@
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||
use crate::{Expression, ExpressionError, ExpressionValue};
|
||||
use leo_static_check::{SymbolTable, Type};
|
||||
|
||||
use crate::{Expression, ExpressionError, ExpressionValue, Frame};
|
||||
use leo_static_check::Type;
|
||||
use leo_typed::{Expression as UnresolvedExpression, Span};
|
||||
|
||||
impl Expression {
|
||||
/// Resolve the type of `lhs < rhs`
|
||||
///
|
||||
/// Returns a new `Expression` evaluating `lhs < rhs`.
|
||||
///
|
||||
pub(crate) fn lt(
|
||||
table: &mut SymbolTable,
|
||||
expected_type: Option<Type>,
|
||||
frame: &Frame,
|
||||
lhs: UnresolvedExpression,
|
||||
rhs: UnresolvedExpression,
|
||||
span: Span,
|
||||
) -> Result<Self, ExpressionError> {
|
||||
// This expression results in a boolean type
|
||||
// This expression returns a boolean type.
|
||||
let type_ = Type::Boolean;
|
||||
|
||||
// Check the expected type if given
|
||||
Type::check_type(&expected_type, &type_, span.clone())?;
|
||||
|
||||
// Resolve lhs and rhs expressions
|
||||
let (lhs_resolved, rhs_resolved) = Self::binary(table, None, lhs, rhs, span.clone())?;
|
||||
let (lhs_resolved, rhs_resolved) = Self::binary(frame, &type_, lhs, rhs, &span)?;
|
||||
|
||||
// Check that expressions are integer type
|
||||
lhs_resolved.check_type_integer()?;
|
||||
rhs_resolved.check_type_integer()?;
|
||||
|
||||
Ok(Expression {
|
||||
// This expression results in a boolean type
|
||||
// This expression returns a boolean type.
|
||||
type_: Type::Boolean,
|
||||
value: ExpressionValue::Lt(Box::new(lhs_resolved), Box::new(rhs_resolved), span),
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user