From f076b33bb91e9cd2cb1f71ba22ebfebab085d3a8 Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Wed, 21 Oct 2020 20:20:26 +0200 Subject: [PATCH] Namespace cleanup --- examples/generics.rs | 4 ++-- examples/shared-with-init.rs | 2 +- examples/static.rs | 10 ++++---- examples/task-local-minimal.rs | 3 ++- examples/task-local.rs | 5 ++-- macros/src/codegen.rs | 35 ++++++---------------------- macros/src/codegen/dispatchers.rs | 2 +- macros/src/codegen/post_init.rs | 5 ++-- macros/src/codegen/resources.rs | 16 +------------ macros/src/codegen/software_tasks.rs | 8 +++---- macros/src/codegen/timer_queue.rs | 4 ++-- 11 files changed, 31 insertions(+), 63 deletions(-) diff --git a/examples/generics.rs b/examples/generics.rs index b13baeb733..16327fb3db 100644 --- a/examples/generics.rs +++ b/examples/generics.rs @@ -36,7 +36,7 @@ mod app { hprintln!("UART0(STATE = {})", *STATE).unwrap(); // second argument has type `resources::shared` - advance(STATE, c.resources.shared); + super::advance(STATE, c.resources.shared); rtic::pend(Interrupt::UART1); @@ -53,7 +53,7 @@ mod app { *c.resources.shared += 0; // second argument has type `Exclusive` - advance(STATE, Exclusive(c.resources.shared)); + super::advance(STATE, Exclusive(c.resources.shared)); } } diff --git a/examples/shared-with-init.rs b/examples/shared-with-init.rs index 049a38bfdb..ec0558862a 100644 --- a/examples/shared-with-init.rs +++ b/examples/shared-with-init.rs @@ -12,9 +12,9 @@ pub struct MustBeSend; #[app(device = lm3s6965)] mod app { + use super::MustBeSend; use cortex_m_semihosting::debug; use lm3s6965::Interrupt; - use super::MustBeSend; #[resources] struct Resources { diff --git a/examples/static.rs b/examples/static.rs index cd46145a4a..3b6cd4cd70 100644 --- a/examples/static.rs +++ b/examples/static.rs @@ -21,7 +21,7 @@ mod app { // Late resources #[resources] struct Resources { - p: Producer<'static, u32, U4>, + ppppp: Producer<'static, u32, U4>, c: Consumer<'static, u32, U4>, } @@ -29,10 +29,10 @@ mod app { fn init(_: init::Context) -> init::LateResources { static mut Q: Queue = Queue(i::Queue::new()); - let (p, c) = Q.split(); + let (ppppp, c) = Q.split(); // Initialization of late resources - init::LateResources { p, c } + init::LateResources { ppppp, c } } #[idle(resources = [c])] @@ -48,10 +48,10 @@ mod app { } } - #[task(binds = UART0, resources = [p])] + #[task(binds = UART0, resources = [ppppp])] fn uart0(c: uart0::Context) { static mut KALLE: u32 = 0; *KALLE += 1; - c.resources.p.enqueue(42).unwrap(); + c.resources.ppppp.enqueue(42).unwrap(); } } diff --git a/examples/task-local-minimal.rs b/examples/task-local-minimal.rs index fd5ac68a29..6e25c10d68 100644 --- a/examples/task-local-minimal.rs +++ b/examples/task-local-minimal.rs @@ -4,11 +4,12 @@ #![no_main] #![no_std] -use cortex_m_semihosting::{debug, hprintln}; use panic_semihosting as _; #[rtic::app(device = lm3s6965)] mod app { + use cortex_m_semihosting::{debug, hprintln}; + #[resources] struct Resources { // A local (move), late resource diff --git a/examples/task-local.rs b/examples/task-local.rs index 8f0dfc792a..462a0d313d 100644 --- a/examples/task-local.rs +++ b/examples/task-local.rs @@ -5,12 +5,13 @@ #![no_main] #![no_std] -use cortex_m_semihosting::{debug, hprintln}; -use lm3s6965::Interrupt; use panic_semihosting as _; #[rtic::app(device = lm3s6965)] mod app { + use cortex_m_semihosting::{debug, hprintln}; + use lm3s6965::Interrupt; + #[resources] struct Resources { // An early resource diff --git a/macros/src/codegen.rs b/macros/src/codegen.rs index c38b47c91e..b975536838 100644 --- a/macros/src/codegen.rs +++ b/macros/src/codegen.rs @@ -73,14 +73,10 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { } )); - let (mod_app_resources, mod_resources, mod_resources_imports) = - resources::codegen(app, analysis, extra); + let (mod_app_resources, mod_resources) = resources::codegen(app, analysis, extra); - let ( - mod_app_hardware_tasks, - root_hardware_tasks, - user_hardware_tasks, - ) = hardware_tasks::codegen(app, analysis, extra); + let (mod_app_hardware_tasks, root_hardware_tasks, user_hardware_tasks) = + hardware_tasks::codegen(app, analysis, extra); let (mod_app_software_tasks, root_software_tasks, user_software_tasks) = software_tasks::codegen(app, analysis, extra); @@ -97,9 +93,11 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { let task_list = analysis.tasks.clone(); let mut tasks = vec![]; + if !task_list.is_empty() { tasks.push(quote!( - enum Tasks { + #[allow(non_camel_case_types)] + pub enum Tasks { #(#task_list),* } )); @@ -107,65 +105,46 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { quote!( /// Implementation details - mod #name { + pub mod #name { /// Always include the device crate which contains the vector table use #device as you_must_enable_the_rt_feature_for_the_pac_in_your_cargo_toml; - /// 2 #(#user_imports)* /// User code from within the module #(#user_code)* /// User code end - /// 3 #(#user)* - /// 4 #(#user_hardware_tasks)* - /// 5 #(#user_software_tasks)* - /// 6 #(#root)* - /// 7 #mod_resources - /// 8 #(#root_hardware_tasks)* - /// 9 #(#root_software_tasks)* - /// 10 /// Unused #(#tasks)* - /// 13 - #(#mod_resources_imports)* - - /// 14 /// app module #(#mod_app)* - /// 15 #(#mod_app_resources)* - /// 16 #(#mod_app_hardware_tasks)* - /// 17 #(#mod_app_software_tasks)* - /// 18 #(#mod_app_dispatchers)* - /// 19 #(#mod_app_timer_queue)* - /// 20 #(#mains)* } ) diff --git a/macros/src/codegen/dispatchers.rs b/macros/src/codegen/dispatchers.rs index bd4061d118..a76f622eff 100644 --- a/macros/src/codegen/dispatchers.rs +++ b/macros/src/codegen/dispatchers.rs @@ -57,7 +57,7 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec Vec { @@ -12,13 +12,14 @@ pub fn codegen(app: &App, analysis: &Analysis) -> Vec { if analysis.late_resources.len() > 0 { // BTreeSet wrapped in a vector for name in analysis.late_resources.first().unwrap() { + let mangled_name = util::mangle_ident(&name); // If it's live let cfgs = app.late_resources[name].cfgs.clone(); if analysis.locations.get(name).is_some() { // Need to also include the cfgs stmts.push(quote!( #(#cfgs)* - #name.as_mut_ptr().write(late.#name); + #mangled_name.as_mut_ptr().write(late.#name); )); } } diff --git a/macros/src/codegen/resources.rs b/macros/src/codegen/resources.rs index d5ec583e2d..0db4f728e2 100644 --- a/macros/src/codegen/resources.rs +++ b/macros/src/codegen/resources.rs @@ -14,12 +14,9 @@ pub fn codegen( Vec, // mod_resources -- the `resources` module TokenStream2, - // mod_resources_imports -- the `resources` module imports - Vec, ) { let mut mod_app = vec![]; let mut mod_resources = vec![]; - let mut mod_resources_imports = vec![]; for (name, res, expr, _) in app.resources(analysis) { let cfgs = &res.cfgs; @@ -86,12 +83,6 @@ pub fn codegen( ) }; - mod_resources_imports.push(quote!( - #[allow(non_camel_case_types)] - #(#cfgs)* - use super::resources::#name; - )); - mod_app.push(util::impl_mutex( extra, cfgs, @@ -107,11 +98,6 @@ pub fn codegen( let mod_resources = if mod_resources.is_empty() { quote!() } else { - // Also import the resource module - mod_resources_imports.push(quote!( - use super::resources; - )); - quote!(mod resources { use rtic::export::Priority; @@ -119,5 +105,5 @@ pub fn codegen( }) }; - (mod_app, mod_resources, mod_resources_imports) + (mod_app, mod_resources) } diff --git a/macros/src/codegen/software_tasks.rs b/macros/src/codegen/software_tasks.rs index f5757a12db..323060c4d7 100644 --- a/macros/src/codegen/software_tasks.rs +++ b/macros/src/codegen/software_tasks.rs @@ -50,7 +50,7 @@ pub fn codegen( mod_app.push(quote!( /// Queue version of a free-list that keeps track of empty slots in /// the following buffers - pub static mut #fq: #fq_ty = #fq_expr; + static mut #fq: #fq_ty = #fq_expr; )); let ref elems = (0..cap) @@ -64,7 +64,7 @@ pub fn codegen( mod_app.push(quote!( #uninit /// Buffer that holds the instants associated to the inputs of a task - pub static mut #instants: + static mut #instants: [core::mem::MaybeUninit<<#m as rtic::Monotonic>::Instant>; #cap_lit] = [#(#elems,)*]; )); @@ -75,7 +75,7 @@ pub fn codegen( mod_app.push(quote!( #uninit /// Buffer that holds the inputs of a task - pub static mut #inputs_ident: [core::mem::MaybeUninit<#input_ty>; #cap_lit] = + static mut #inputs_ident: [core::mem::MaybeUninit<#input_ty>; #cap_lit] = [#(#elems,)*]; )); @@ -113,7 +113,7 @@ pub fn codegen( #(#attrs)* #(#cfgs)* #[allow(non_snake_case)] - pub fn #name(#(#locals_pat,)* #context: #name::Context #(,#inputs)*) { + fn #name(#(#locals_pat,)* #context: #name::Context #(,#inputs)*) { use rtic::Mutex as _; #(#stmts)* diff --git a/macros/src/codegen/timer_queue.rs b/macros/src/codegen/timer_queue.rs index c898a7fd55..c081076eb0 100644 --- a/macros/src/codegen/timer_queue.rs +++ b/macros/src/codegen/timer_queue.rs @@ -31,7 +31,7 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec Vec