safe_vex/
entry.rs

1//! A safe wrapper for entry function definitions
2
3/// A safe wrapper for entry function definitions
4#[macro_export]
5macro_rules! entry {
6    // user-facing
7    ($($entry:ident => $body:stmt;)*) => {
8        $(
9            $crate::entry!(@internal $entry $body);
10        )*
11    };
12
13    // internal
14
15    // initialisation function
16    (@internal initialize $body:stmt) => {
17        #[inline]
18        #[no_mangle]
19        unsafe extern "C" fn initialize() {
20            $body
21        }
22    };
23
24    // opcontrol function
25    (@internal opcontrol $body:stmt) => {
26        #[inline]
27        #[no_mangle]
28        unsafe extern "C" fn opcontrol() {
29            $body
30        }
31    };
32
33    // autonomous function
34    (@internal autonomous $body:stmt) => {
35        #[inline]
36        #[no_mangle]
37        unsafe extern "C" fn autonomous() {
38            $body
39        }
40    };
41
42    // disabled function
43    (@internal disabled $body:stmt) => {
44        #[inline]
45        #[no_mangle]
46        unsafe extern "C" fn disabled() {
47            $body
48        }
49    };
50
51    // if nothing matches
52    (@internal $invalid:ident $body:stmt) => {
53        compile_error!(concat!("entry macro error: entrypoint `", stringify!($invalid), "` does not exist"));
54    };
55}