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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
use super::env::BuiltinFn;
use super::builtins::{builtin_add, builtin_sub, builtin_mul, builtin_div, builtin_rem, builtin_pow};
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
#[repr(i8)]
pub enum Order {
FnBarrier = 1,
Operators = 2,
AddSub = 3,
MulDiv = 4,
IMul = 5,
Pow = 6,
PowRightAssoc = 7,
Unary = 8,
}
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
#[repr(u8)]
pub enum Assoc {
Left,
Right,
None,
}
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
#[repr(u8)]
pub enum Operator {
Add,
Sub,
Mul,
Div,
Rem,
IMul,
Pow,
}
pub struct OpDesc {
pub pfn: BuiltinFn,
pub pre: Order,
pub assoc: Assoc,
pub unary: bool,
}
static OP_DESC: [OpDesc; 7] = [
OpDesc { pfn: builtin_add, pre: Order::AddSub, assoc: Assoc::Left, unary: true },
OpDesc { pfn: builtin_sub, pre: Order::AddSub, assoc: Assoc::Left, unary: true },
OpDesc { pfn: builtin_mul, pre: Order::MulDiv, assoc: Assoc::Left, unary: false },
OpDesc { pfn: builtin_div, pre: Order::MulDiv, assoc: Assoc::Left, unary: false },
OpDesc { pfn: builtin_rem, pre: Order::MulDiv, assoc: Assoc::Left, unary: false },
OpDesc { pfn: builtin_mul, pre: Order::IMul, assoc: Assoc::Left, unary: false },
OpDesc { pfn: builtin_pow, pre: Order::Pow, assoc: Assoc::Right, unary: false },
];
impl Operator {
#[inline]
pub fn desc(self) -> &'static OpDesc {
&OP_DESC[self as usize]
}
}