safe_vex/entry.rs
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
//! A safe wrapper for entry function definitions
/// A safe wrapper for entry function definitions
#[macro_export]
macro_rules! entry {
// user-facing
($($entry:ident => $body:stmt;)*) => {
$(
$crate::entry!(@internal $entry $body);
)*
};
// internal
// initialisation function
(@internal initialize $body:stmt) => {
#[inline]
#[no_mangle]
unsafe extern "C" fn initialize() {
$body
}
};
// opcontrol function
(@internal opcontrol $body:stmt) => {
#[inline]
#[no_mangle]
unsafe extern "C" fn opcontrol() {
$body
}
};
// autonomous function
(@internal autonomous $body:stmt) => {
#[inline]
#[no_mangle]
unsafe extern "C" fn autonomous() {
$body
}
};
// disabled function
(@internal disabled $body:stmt) => {
#[inline]
#[no_mangle]
unsafe extern "C" fn disabled() {
$body
}
};
// if nothing matches
(@internal $invalid:ident $body:stmt) => {
compile_error!(concat!("entry macro error: entrypoint `", stringify!($invalid), "` does not exist"));
};
}