aboutsummaryrefslogtreecommitdiff
path: root/macros/src/codegen/local_resources.rs
diff options
context:
space:
mode:
authorGravatar Emil Fresk <emil.fresk@gmail.com> 2021-07-07 21:03:56 +0200
committerGravatar Emil Fresk <emil.fresk@gmail.com> 2021-07-07 21:04:31 +0200
commitd7393c5b27fc95f3569d12137ee0c4d03ff7e2ba (patch)
treeb90e094920cb859bb9e401f3acdddcadf675c834 /macros/src/codegen/local_resources.rs
parentef5307d83a1d62df0569d78db75d4006147c927d (diff)
downloadrtic-d7393c5b27fc95f3569d12137ee0c4d03ff7e2ba.tar.gz
rtic-d7393c5b27fc95f3569d12137ee0c4d03ff7e2ba.tar.zst
rtic-d7393c5b27fc95f3569d12137ee0c4d03ff7e2ba.zip
Full local resource syntax working
Diffstat (limited to 'macros/src/codegen/local_resources.rs')
-rw-r--r--macros/src/codegen/local_resources.rs31
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);
));
}