mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-09-20 10:18:35 +03:00
Add Rem, RemWrapped, and Mod to AST
This commit is contained in:
parent
abdb8c7162
commit
b20aed7d34
@ -44,6 +44,8 @@ pub enum BinaryOperation {
|
||||
Lte,
|
||||
/// Lesser-than relation, i.e. `<`, `.lt()`.
|
||||
Lt,
|
||||
/// Arithmetic modulo, i.e. `.mod()`
|
||||
Mod,
|
||||
/// Multiplication, i.e. `*`, `.mul()`.
|
||||
Mul,
|
||||
/// Wrapping multiplication, i.e. `.mul_wrapped()`.
|
||||
@ -62,6 +64,10 @@ pub enum BinaryOperation {
|
||||
Pow,
|
||||
/// Wrapping exponentiation, i.e. `.pow_wrapped()`.
|
||||
PowWrapped,
|
||||
/// Remainder, i.e. `%`, `.rem()`.
|
||||
Rem,
|
||||
/// Wrapping remainder, i.e. `.rem_wrapped()`.
|
||||
RemWrapped,
|
||||
/// Shift left operation, i.e. `<<`, `.shl()`.
|
||||
Shl,
|
||||
/// Wrapping shift left operation, i.e. `.shl_wrapped()`.
|
||||
@ -95,6 +101,7 @@ impl fmt::Display for BinaryOperation {
|
||||
Self::Gt => ">",
|
||||
Self::Lte => "<=",
|
||||
Self::Lt => "<",
|
||||
Self::Mod => "mod",
|
||||
Self::Mul => "*",
|
||||
Self::MulWrapped => "mul_wrapped",
|
||||
Self::Nand => "NAND",
|
||||
@ -104,6 +111,8 @@ impl fmt::Display for BinaryOperation {
|
||||
Self::BitwiseOr => "|",
|
||||
Self::Pow => "**",
|
||||
Self::PowWrapped => "pow_wrapped",
|
||||
Self::Rem => "%",
|
||||
Self::RemWrapped => "rem_wrapped",
|
||||
Self::Shl => "<<",
|
||||
Self::ShlWrapped => "shl_wrapped",
|
||||
Self::Shr => ">>",
|
||||
@ -118,6 +127,7 @@ impl fmt::Display for BinaryOperation {
|
||||
|
||||
impl BinaryOperation {
|
||||
/// Returns a `BinaryOperation` from the given `Symbol`.
|
||||
/// This is used to resolve native operators invoked as method calls, e.g. `a.add_wrapped(b)`.
|
||||
pub fn from_symbol(symbol: Symbol) -> Option<Self> {
|
||||
Some(match symbol {
|
||||
sym::add => Self::Add,
|
||||
@ -130,6 +140,7 @@ impl BinaryOperation {
|
||||
sym::gt => Self::Gt,
|
||||
sym::lte => Self::Lte,
|
||||
sym::lt => Self::Lt,
|
||||
sym::Mod => Self::Mod,
|
||||
sym::mul => Self::Mul,
|
||||
sym::mul_wrapped => Self::MulWrapped,
|
||||
sym::nand => Self::Nand,
|
||||
@ -138,6 +149,8 @@ impl BinaryOperation {
|
||||
sym::or => Self::BitwiseOr,
|
||||
sym::pow => Self::Pow,
|
||||
sym::pow_wrapped => Self::PowWrapped,
|
||||
sym::rem => Self::Rem,
|
||||
sym::rem_wrapped => Self::RemWrapped,
|
||||
sym::shl => Self::Shl,
|
||||
sym::shl_wrapped => Self::ShlWrapped,
|
||||
sym::shr => Self::Shr,
|
||||
|
@ -33,6 +33,8 @@ pub enum AssignOperation {
|
||||
Mul,
|
||||
/// Dividing-assignment, `/=`.
|
||||
Div,
|
||||
/// Remaindering-assignment, `%=`.
|
||||
Rem,
|
||||
/// Exponentiating assignment `**=`.
|
||||
Pow,
|
||||
/// Logical or assignment `||=`.
|
||||
@ -51,8 +53,6 @@ pub enum AssignOperation {
|
||||
// ShrSigned,
|
||||
/// Shift left assignment `<<=`.
|
||||
Shl,
|
||||
// /// Modulus / remainder assignment.
|
||||
// Mod,
|
||||
}
|
||||
|
||||
impl AssignOperation {
|
||||
@ -63,6 +63,7 @@ impl AssignOperation {
|
||||
AssignOperation::Sub => Some(BinaryOperation::Sub),
|
||||
AssignOperation::Mul => Some(BinaryOperation::Mul),
|
||||
AssignOperation::Div => Some(BinaryOperation::Div),
|
||||
AssignOperation::Rem => Some(BinaryOperation::Rem),
|
||||
AssignOperation::Pow => Some(BinaryOperation::Pow),
|
||||
AssignOperation::Or => Some(BinaryOperation::Or),
|
||||
AssignOperation::And => Some(BinaryOperation::And),
|
||||
@ -72,7 +73,6 @@ impl AssignOperation {
|
||||
AssignOperation::Shr => Some(BinaryOperation::Shr),
|
||||
// AssignOperation::ShrSigned => Some(BinaryOperation::ShrSigned),
|
||||
AssignOperation::Shl => Some(BinaryOperation::Shl),
|
||||
// AssignOperation::Mod => Some(BinaryOperation::Mod),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -85,6 +85,7 @@ impl AsRef<str> for AssignOperation {
|
||||
AssignOperation::Sub => "-=",
|
||||
AssignOperation::Mul => "*=",
|
||||
AssignOperation::Div => "/=",
|
||||
AssignOperation::Rem => "%=",
|
||||
AssignOperation::Pow => "**=",
|
||||
AssignOperation::Or => "||=",
|
||||
AssignOperation::And => "&&=",
|
||||
@ -94,7 +95,6 @@ impl AsRef<str> for AssignOperation {
|
||||
AssignOperation::Shr => ">>=",
|
||||
// AssignOperation::ShrSigned => ">>>=",
|
||||
AssignOperation::Shl => "<<=",
|
||||
// AssignOperation::Mod => "%=",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user