aboutsummaryrefslogtreecommitdiff
path: root/macros/src/codegen/post_init.rs
diff options
context:
space:
mode:
authorGravatar Emil Fresk <emil.fresk@gmail.com> 2021-07-06 22:47:48 +0200
committerGravatar Emil Fresk <emil.fresk@gmail.com> 2021-07-06 22:47:48 +0200
commitef5307d83a1d62df0569d78db75d4006147c927d (patch)
tree542ff46adf7600cbd7f908cb62ac3a44e1bfa683 /macros/src/codegen/post_init.rs
parent3f85cb5caf1ae930e6551e139978ceec859a2348 (diff)
downloadrtic-ef5307d83a1d62df0569d78db75d4006147c927d.tar.gz
rtic-ef5307d83a1d62df0569d78db75d4006147c927d.tar.zst
rtic-ef5307d83a1d62df0569d78db75d4006147c927d.zip
Minimal app now compiles
Diffstat (limited to 'macros/src/codegen/post_init.rs')
-rw-r--r--macros/src/codegen/post_init.rs51
1 files changed, 33 insertions, 18 deletions
diff --git a/macros/src/codegen/post_init.rs b/macros/src/codegen/post_init.rs
index 78548bcd..161068d2 100644
--- a/macros/src/codegen/post_init.rs
+++ b/macros/src/codegen/post_init.rs
@@ -9,24 +9,39 @@ use crate::{analyze::Analysis, codegen::util};
pub fn codegen(app: &App, analysis: &Analysis) -> Vec<TokenStream2> {
let mut stmts = vec![];
- // Initialize late resources
- if !analysis.late_resources.is_empty() {
- // BTreeSet wrapped in a vector
- for name in analysis.late_resources.first().unwrap() {
- let mangled_name = util::mark_internal_ident(&name);
- // If it's live
- let cfgs = app.late_resources[name].cfgs.clone();
- if analysis.locations.get(name).is_some() {
- stmts.push(quote!(
- // We include the cfgs
- #(#cfgs)*
- // Late resource is a RacyCell<MaybeUninit<T>>
- // - `get_mut_unchecked` to obtain `MaybeUninit<T>`
- // - `as_mut_ptr` to obtain a raw pointer to `MaybeUninit<T>`
- // - `write` the defined value for the late resource T
- #mangled_name.get_mut_unchecked().as_mut_ptr().write(late.#name);
- ));
- }
+ // Initialize shared resources
+ for (name, res) in &app.shared_resources {
+ let mangled_name = util::mark_internal_ident(&util::static_shared_resource_ident(name));
+ // If it's live
+ let cfgs = res.cfgs.clone();
+ if analysis.shared_resource_locations.get(name).is_some() {
+ stmts.push(quote!(
+ // We include the cfgs
+ #(#cfgs)*
+ // Resource is a RacyCell<MaybeUninit<T>>
+ // - `get_mut_unchecked` to obtain `MaybeUninit<T>`
+ // - `as_mut_ptr` to obtain a raw pointer to `MaybeUninit<T>`
+ // - `write` the defined value for the late resource T
+ #mangled_name.get_mut_unchecked().as_mut_ptr().write(shared_resources.#name);
+ ));
+ }
+ }
+
+ // Initialize local resources
+ for (name, res) in &app.local_resources {
+ let mangled_name = util::mark_internal_ident(&util::static_local_resource_ident(name));
+ // If it's live
+ let cfgs = res.cfgs.clone();
+ if analysis.local_resource_locations.get(name).is_some() {
+ stmts.push(quote!(
+ // We include the cfgs
+ #(#cfgs)*
+ // Resource is a RacyCell<MaybeUninit<T>>
+ // - `get_mut_unchecked` to obtain `MaybeUninit<T>`
+ // - `as_mut_ptr` to obtain a raw pointer to `MaybeUninit<T>`
+ // - `write` the defined value for the late resource T
+ #mangled_name.get_mut_unchecked().as_mut_ptr().write(local_resources.#name);
+ ));
}
}