rock_n_rollup_macro/
lib.rs

1use proc_macro::TokenStream;
2use quote::quote;
3use syn::{parse_macro_input, ItemFn};
4
5#[proc_macro_attribute]
6pub fn main(_: TokenStream, input: TokenStream) -> TokenStream {
7    // Parse the input tokens into a syntax tree representing a function
8    let input_fn = parse_macro_input!(input as ItemFn);
9
10    // Extract the name of the input function
11    let fn_name = input_fn.sig.ident.clone();
12
13    let output = quote! {
14        #[export_name = "kernel_run"]
15        pub extern "C" fn kernel_run() {
16            let mut runtime = rock_n_rollup::core::KernelRuntime::default();
17            let mut app = rock_n_rollup::core::Application::new(&mut runtime);
18            #fn_name(&mut app);
19        }
20
21        #input_fn
22    };
23
24    // Return the generated tokens
25    output.into()
26}