From 0fbc78777ead39adba3950edd8e8b92ae1db3482 Mon Sep 17 00:00:00 2001 From: Kamen Mladenov Date: Mon, 7 Apr 2025 16:00:56 +0300 Subject: feat(guests_macro): Replace parse_fn mod with struct The old method of having functions for every parsing action of a function definition produced messy results. We're replacing it with a struct which will hold a wide assortment of parsed values. This makes the interface much sleaker with only a minor increase in code. The downside is a lot of data gets repeated, however since this struct will only be used in macros, i.e. compile-time, that doesn't matter too much. --- guests_macro/src/lib.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'guests_macro/src/lib.rs') diff --git a/guests_macro/src/lib.rs b/guests_macro/src/lib.rs index 2a35292..5e78ac0 100644 --- a/guests_macro/src/lib.rs +++ b/guests_macro/src/lib.rs @@ -37,23 +37,23 @@ mod parse_fn; /// ``` #[proc_macro_attribute] pub fn proving_entrypoint(_: TokenStream, mut item: TokenStream) -> TokenStream { - let (name, args, ret) = parse_fn::split_fn(&item); + let fd = parse_fn::FunctionDefinition::new(&item); + let fn_type = format!("fn {}{} -> {}", fd.name, fd.args, fd.return_type).replace('\n', " "); // We also need to pass some type information to the host program compile-time. // Put it in the file guests/type.txt. let mut output = File::create("../type.txt").unwrap(); - writeln!(output, "{}", &format!("{args}").replace('\n', " ")); - write!(output, "{}", &format!("{ret}").replace('\n', " ")); + write!(output, "{fn_type}"); item.extend( format!( "#[macro_export] macro_rules! entrypoint_expr {{ () => {{ - make_wrapper!{{{}{} -> {}}} + make_wrapper!{{ {} }} }}; }}", - name, args, ret + fn_type ) .parse::(), ); -- cgit v1.2.3