diff options
| author | Kamen Mladenov <kamen@syndamia.com> | 2025-04-07 16:00:56 +0300 |
|---|---|---|
| committer | Kamen Mladenov <kamen@syndamia.com> | 2025-04-07 17:41:20 +0300 |
| commit | 0fbc78777ead39adba3950edd8e8b92ae1db3482 (patch) | |
| tree | 75db691d4f61fd8c375e583d3b26a35fbfa8ead3 /guests_macro/src/lib.rs | |
| parent | 7498d604be92a0b1a7a5603e0295f194aa8b05e7 (diff) | |
| download | zkVMs-benchmarks-0fbc78777ead39adba3950edd8e8b92ae1db3482.tar zkVMs-benchmarks-0fbc78777ead39adba3950edd8e8b92ae1db3482.tar.gz zkVMs-benchmarks-0fbc78777ead39adba3950edd8e8b92ae1db3482.zip | |
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.
Diffstat (limited to 'guests_macro/src/lib.rs')
| -rw-r--r-- | guests_macro/src/lib.rs | 10 |
1 files changed, 5 insertions, 5 deletions
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::<TokenStream>(), ); |
