mindustry logic execution, map- and schematic- parsing and rendering
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
use crate::{lexer::Token, memory::LVar};

super::op_enum! { pub enum ConditionOp {
    Equal,
    NotEqual,
    LessThan,
    LessThanEq,
    GreaterThan,
    GreaterThanEq,
    StrictEqual,
} }

macro_rules! op {
    ($name: ident $op:tt ) => {
        fn $name<'v>(a: &LVar<'v>, b: &LVar<'v>) -> bool {
            if let &LVar::Num(a) = a && let &LVar::Num(b) = b { a $op b } else { false }
        }
    };
}

fn eq<'v>(a: &LVar<'v>, b: &LVar<'v>) -> bool {
    a == b
}
fn ne<'v>(a: &LVar<'v>, b: &LVar<'v>) -> bool {
    a != b
}
op!(lt <);
op!(gt >);
op!(le <=);
op!(ge >=);

super::op_impl!(ConditionOp, ptr type = for<'f> fn(&LVar<'f>, &LVar<'f>) -> bool {
    Equal => eq,
    StrictEqual => eq,
    NotEqual => ne,
    LessThan => lt,
    GreaterThan => gt,
    LessThanEq => le,
    GreaterThanEq => ge,
});