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
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
use super::get_num;
use crate::{lexer::Token, memory::LVar};

super::op_enum! { pub enum MathOp1 {
    Floor,
    Not,
    Log,
    Abs,
    Rand,
    Ceil,
    Sqrt,
    Sin,
    Cos,
    Tan,
    ASin,
    ACos,
    ATan,
    Log10,
} }

macro_rules! num {
    ($fn: ident $c:expr) => {
        fn $fn(x: &LVar<'_>) -> f64 {
            f64::from($c(get_num!(x)))
        }
    };
}

macro_rules! flbop {
    ($f: expr, $fn: expr) => {
        $fn($f as u64) as f64
    };
}

num!(floor f64::floor);
fn not(x: &LVar<'_>) -> f64 {
    flbop!(get_num!(x), |n: u64| !n)
}
num!(log f64::ln);
num!(abs f64::abs);
const fn rand(_: &LVar<'_>) -> f64 {
    4.0
}
num!(ceil f64::ceil);
num!(sqrt f64::sqrt);
num!(sin f64::sin);
num!(cos f64::cos);
num!(tan f64::tan);
num!(asin f64::asin);
num!(acos f64::acos);
num!(atan f64::atan);
num!(log10 f64::log10);

super::op_impl!(MathOp1, ptr type = for<'v> fn(&LVar<'v>) -> f64 {
    Floor => floor,
    Not => not,
    Log => log,
    Abs => abs,
    Rand => rand,
    Ceil => ceil,
    Sqrt => sqrt,
    Sin => sin,
    Cos => cos,
    Tan => tan,
    ASin => asin,
    ACos => acos,
    ATan => atan,
    Log10 => log10,
});