1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#[derive(Copy, Clone, PartialEq, Debug)]
pub enum UnaryOp {
Not,
Negate,
Pop,
Len,
BitFlip,
}
#[derive(Copy, Clone, PartialEq, Debug)]
pub enum BinaryOp {
And,
Divide,
Equal,
Gt,
Gte,
Lt,
Lte,
Minus,
Modulo,
Multiply,
NotEqual,
Or,
Push,
Plus,
BitShift,
BitXor,
BitOr,
BitAnd,
}
impl BinaryOp {
pub fn is_commutative(&self) -> bool {
// NOTE: And and Or are commutative BUT they can't always be treated
// as such due to short circuiting and the possibility for side effects
matches!(self, BinaryOp::Plus | BinaryOp::Multiply | BinaryOp::Equal | BinaryOp::NotEqual)
}
}