diff options
Diffstat (limited to 'macros/src/codegen/local_resources.rs')
-rw-r--r-- | macros/src/codegen/local_resources.rs | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/macros/src/codegen/local_resources.rs b/macros/src/codegen/local_resources.rs index 13891f93..70f75809 100644 --- a/macros/src/codegen/local_resources.rs +++ b/macros/src/codegen/local_resources.rs @@ -9,8 +9,8 @@ use crate::{analyze::Analysis, check::Extra, codegen::util}; /// I.e. the `static` variables and theirs proxies. pub fn codegen( app: &App, - analysis: &Analysis, - extra: &Extra, + _analysis: &Analysis, + _extra: &Extra, ) -> ( // mod_app -- the `static` variables behind the proxies Vec<TokenStream2>, @@ -22,14 +22,10 @@ pub fn codegen( // All local resources declared in the `#[local]' struct for (name, res) in &app.local_resources { - // let expr = &res.expr; // TODO: Extract from tasks???... let cfgs = &res.cfgs; let ty = &res.ty; let mangled_name = util::mark_internal_ident(&util::static_local_resource_ident(name)); - let ty = quote!(rtic::RacyCell<core::mem::MaybeUninit<#ty>>); - let expr = quote!(rtic::RacyCell::new(core::mem::MaybeUninit::uninit())); - let attrs = &res.attrs; // late resources in `util::link_section_uninit` let section = util::link_section_uninit(true); @@ -43,7 +39,28 @@ pub fn codegen( #(#attrs)* #(#cfgs)* #section - static #mangled_name: #ty = #expr; + static #mangled_name: rtic::RacyCell<core::mem::MaybeUninit<#ty>> = rtic::RacyCell::new(core::mem::MaybeUninit::uninit()); + )); + } + + // All declared `local = [NAME: TY = EXPR]` local resources + for (name, task_local) in app.declared_local_resources() { + let cfgs = &task_local.cfgs; + let ty = &task_local.ty; + let expr = &task_local.expr; + let attrs = &task_local.attrs; + + let mangled_name = util::mark_internal_ident(&util::static_local_resource_ident(name)); + + // For future use + // let doc = format!(" RTIC internal: {}:{}", file!(), line!()); + mod_app.push(quote!( + #[allow(non_upper_case_globals)] + // #[doc = #doc] + #[doc(hidden)] + #(#attrs)* + #(#cfgs)* + static #mangled_name: rtic::RacyCell<#ty> = rtic::RacyCell::new(#expr); )); } |