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
// KOS_INIT_FLAG_WEAK not bound:
// No stable/accepted way to create weak symbol here

#[macro_export]
macro_rules! KOS_INIT_FLAG_CALL {
    ($func:expr) => {{
        let mut ret = 0;
        if let Some(func) = $func {
            func();
            ret = 1;
        }
        ret
    }}
}

#[macro_export]
macro_rules! KOS_INIT_FLAG_ALL {
    ($flags:expr, $mask:expr, $func:ident) => {
        $crate::paste::paste! {
            extern "C" { fn $func(); }
            #[no_mangle]
            pub static [<$func _weak>]: Option<unsafe extern "C" fn()> = 
                if (($flags) & $mask) == $mask { None } else { Some($func) };
        }
    };
}

#[macro_export]
macro_rules! KOS_INIT_FLAG_NONE {
    ($flags:expr, $mask:expr, $func:ident) => {
        $crate::paste::paste! {
            extern "C" { fn $func(); }
            #[no_mangle]
            pub static [<$func _weak>]: Option<unsafe extern "C" fn()> = 
                if (($flags) & $mask) != 0 { None } else { Some($func) };
        }
    };
}

#[macro_export]
macro_rules! KOS_INIT_FLAG {
    ($flags:expr, $mask:expr, $func:ident) => {
        $crate::paste::paste! {
            extern "C" { fn $func(); }
            #[no_mangle]
            pub static [<$func _weak>]: Option<unsafe extern "C" fn()> = 
                if (($flags) & $mask) != 0 { Some($func) } else { None };
        }
    };
}