From 2068eae9280881e34b5cc2d76b0b1a61402223e7 Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Wed, 7 Apr 2021 11:06:57 +0200 Subject: Type aliases now work in the app module --- macros/src/codegen/module.rs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'macros/src/codegen/module.rs') diff --git a/macros/src/codegen/module.rs b/macros/src/codegen/module.rs index e15aab1c..ac69a803 100644 --- a/macros/src/codegen/module.rs +++ b/macros/src/codegen/module.rs @@ -21,7 +21,7 @@ pub fn codegen( let app_name = &app.name; let app_path = quote! {crate::#app_name}; - let all_task_names: Vec<_> = app + let all_task_imports: Vec<_> = app .software_tasks .iter() .map(|(name, st)| { @@ -46,6 +46,13 @@ pub fn codegen( quote!() } })) + .chain(app.user_types.iter().map(|ty| { + let t = &ty.ident; + quote! { + #[allow(unused_imports)] + use super::#t; + } + })) .collect(); let mut lt = None; @@ -230,7 +237,7 @@ pub fn codegen( // Spawn caller items.push(quote!( - #(#all_task_names)* + #(#all_task_imports)* #(#cfgs)* /// Spawns the task directly @@ -268,7 +275,7 @@ pub fn codegen( let tq = util::mark_internal_ident(&tq); let t = util::schedule_t_ident(); let m = &monotonic.ident; - let mono_type = &monotonic.ty; + let mono_type = &monotonic.ident; let m_ident = util::monotonic_ident(&monotonic_name); let m_ident = util::mark_internal_ident(&m_ident); let m_isr = &monotonic.args.binds; @@ -300,10 +307,6 @@ pub fn codegen( items.push(quote!( /// Holds methods related to this monotonic pub mod #m { - // #( - // #[allow(unused_imports)] - // use #app_path::#all_task_names as #all_task_names; - // )* use super::*; #[allow(unused_imports)] use #app_path::#tq_marker; @@ -341,7 +344,7 @@ pub fn codegen( where D: rtic::time::duration::Duration + rtic::time::fixed_point::FixedPoint, D::T: Into<<#app_path::#mono_type as rtic::time::Clock>::T>, { - self.reschedule_at(#app_path::#m::now() + duration) + self.reschedule_at(#app_path::monotonics::#m::now() + duration) } pub fn reschedule_at(self, instant: rtic::time::Instant<#app_path::#mono_type>) -> Result @@ -373,7 +376,7 @@ pub fn codegen( let instant = if rtic::export::interrupt::free(|_| unsafe { #app_path::#m_ident.is_none() }) { rtic::time::Instant::new(0) } else { - #app_path::#m::now() + #app_path::monotonics::#m::now() }; spawn_at(instant + duration #(,#untupled)*) -- cgit v1.2.3 From 51500a1d7096395be9162599fae647ec121db91d Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Thu, 8 Apr 2021 09:12:08 +0200 Subject: Fixed UB in `spawn_at` --- examples/type-usage.rs | 2 +- macros/Cargo.toml | 4 +--- macros/src/codegen/module.rs | 16 +++++----------- src/tq.rs | 6 ++++-- 4 files changed, 11 insertions(+), 17 deletions(-) (limited to 'macros/src/codegen/module.rs') diff --git a/examples/type-usage.rs b/examples/type-usage.rs index a7a0d411..9bb7eb8d 100644 --- a/examples/type-usage.rs +++ b/examples/type-usage.rs @@ -1,4 +1,4 @@ -//! examples/smallest.rs +//! examples/type-usage.rs #![no_main] #![no_std] diff --git a/macros/Cargo.toml b/macros/Cargo.toml index 8607ce55..203a2bb1 100644 --- a/macros/Cargo.toml +++ b/macros/Cargo.toml @@ -22,6 +22,4 @@ proc-macro2 = "1" proc-macro-error = "1" quote = "1" syn = "1" -# rtic-syntax = "0.5.0-alpha.2" -rtic-syntax = { path = "../../rtic-syntax", version = "0.5.0-alpha.2" } - +rtic-syntax = "0.5.0-alpha.2" diff --git a/macros/src/codegen/module.rs b/macros/src/codegen/module.rs index ac69a803..50146c02 100644 --- a/macros/src/codegen/module.rs +++ b/macros/src/codegen/module.rs @@ -414,17 +414,11 @@ pub fn codegen( let tq = unsafe { &mut *#app_path::#tq.as_mut_ptr() }; - if let Some(mono) = #app_path::#m_ident.as_mut() { - tq.enqueue_unchecked( - nr, - || #enable_interrupt, - || #pend, - mono) - } else { - // We can only use the timer queue if `init` has returned, and it - // writes the `Some(monotonic)` we are accessing here. - core::hint::unreachable_unchecked() - } + tq.enqueue_unchecked( + nr, + || #enable_interrupt, + || #pend, + #app_path::#m_ident.as_mut()); Ok(SpawnHandle { marker }) }) diff --git a/src/tq.rs b/src/tq.rs index 38640259..985e0f88 100644 --- a/src/tq.rs +++ b/src/tq.rs @@ -42,7 +42,7 @@ where nr: NotReady, enable_interrupt: F1, pend_handler: F2, - mono: &mut Mono, + mono: Option<&mut Mono>, ) where F1: FnOnce(), F2: FnOnce(), @@ -57,7 +57,9 @@ where if if_heap_max_greater_than_nr { if Mono::DISABLE_INTERRUPT_ON_EMPTY_QUEUE && self.0.is_empty() { - mono.enable_timer(); + if let Some(mono) = mono { + mono.enable_timer(); + } enable_interrupt(); } -- cgit v1.2.3