mirror of
https://github.com/rtic-rs/rtic.git
synced 2025-12-19 06:15:45 +01:00
Updated examples
More work
This commit is contained in:
parent
355cb82d06
commit
f96b25fdf2
45 changed files with 176 additions and 214 deletions
|
|
@ -1,5 +1,5 @@
|
|||
use proc_macro2::TokenStream as TokenStream2;
|
||||
use quote::{format_ident, quote};
|
||||
use quote::quote;
|
||||
use rtic_syntax::{ast::App, Context};
|
||||
|
||||
use crate::{
|
||||
|
|
@ -24,8 +24,6 @@ pub fn codegen(
|
|||
Vec<TokenStream2>,
|
||||
// user_init -- the `#[init]` function written by the user
|
||||
Option<TokenStream2>,
|
||||
// user_init_imports -- the imports for `#[init]` functio written by the user
|
||||
Vec<TokenStream2>,
|
||||
// call_init -- the call to the user `#[init]` if there's one
|
||||
Option<TokenStream2>,
|
||||
) {
|
||||
|
|
@ -52,7 +50,6 @@ pub fn codegen(
|
|||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let mut user_init_imports = vec![];
|
||||
let late_resources = util::late_resources_ident(&name);
|
||||
|
||||
root_init.push(quote!(
|
||||
|
|
@ -63,12 +60,6 @@ pub fn codegen(
|
|||
}
|
||||
));
|
||||
|
||||
let name_late = format_ident!("{}LateResources", name);
|
||||
user_init_imports.push(quote!(
|
||||
#[allow(non_snake_case)]
|
||||
use super::#name_late;
|
||||
));
|
||||
|
||||
let mut locals_pat = None;
|
||||
let mut locals_new = None;
|
||||
if !init.locals.is_empty() {
|
||||
|
|
@ -90,11 +81,6 @@ pub fn codegen(
|
|||
#(#stmts)*
|
||||
}
|
||||
));
|
||||
user_init_imports.push(quote!(
|
||||
#(#attrs)*
|
||||
#[allow(non_snake_case)]
|
||||
use super::#name;
|
||||
));
|
||||
|
||||
let mut mod_app = None;
|
||||
if !init.args.resources.is_empty() {
|
||||
|
|
@ -103,17 +89,13 @@ pub fn codegen(
|
|||
|
||||
root_init.push(item);
|
||||
mod_app = Some(constructor);
|
||||
|
||||
let name_late = format_ident!("{}Resources", name);
|
||||
user_init_imports.push(quote!(
|
||||
#[allow(non_snake_case)]
|
||||
use super::#name_late;
|
||||
));
|
||||
}
|
||||
|
||||
let app_name = &app.name;
|
||||
let app_path = quote! {crate::#app_name};
|
||||
let locals_new = locals_new.iter();
|
||||
let call_init = Some(
|
||||
quote!(let late = crate::#name(#(#locals_new,)* #name::Context::new(core.into()));),
|
||||
quote!(let late = #app_path::#name(#(#locals_new,)* #name::Context::new(core.into()));),
|
||||
);
|
||||
|
||||
root_init.push(module::codegen(
|
||||
|
|
@ -124,8 +106,8 @@ pub fn codegen(
|
|||
extra,
|
||||
));
|
||||
|
||||
(mod_app, root_init, user_init, user_init_imports, call_init)
|
||||
(mod_app, root_init, user_init, call_init)
|
||||
} else {
|
||||
(None, vec![], None, vec![], None)
|
||||
(None, vec![], None, None)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue