From c718413cb56f9c25d79c71e607079561923b1a05 Mon Sep 17 00:00:00 2001 From: Henrik Tjäder Date: Tue, 19 May 2020 09:55:50 +0000 Subject: Generate mod instead of const, handle import of idle and init --- macros/src/codegen.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'macros/src/codegen.rs') diff --git a/macros/src/codegen.rs b/macros/src/codegen.rs index fe4d59a6..83e5ce8b 100644 --- a/macros/src/codegen.rs +++ b/macros/src/codegen.rs @@ -26,6 +26,7 @@ mod util; // TODO document the syntax here or in `rtic-syntax` pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { let mut const_app = vec![]; + let mut const_app_imports = vec![]; let mut mains = vec![]; let mut root = vec![]; let mut user = vec![]; @@ -41,6 +42,17 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { let (const_app_idle, root_idle, user_idle, call_idle) = idle::codegen(app, analysis, extra); + if user_init.is_some() { + const_app_imports.push(quote!( + use super::init; + )) + } + if user_idle.is_some() { + const_app_imports.push(quote!( + use super::idle; + )) + } + user.push(quote!( #user_init @@ -111,10 +123,11 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { #(#root_software_tasks)* /// Implementation details - // The user can't access the items within this `const` item - const #name: () = { + // the user can't access the items within this `const` item + mod #name { /// Always include the device crate which contains the vector table use #device as _; + #(#const_app_imports)* #(#const_app)* @@ -133,6 +146,6 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { #(#const_app_schedule)* #(#mains)* - }; + } ) } -- cgit v1.2.3 From 46bf583cc21bd8fa34e3163149b4327fcc08057e Mon Sep 17 00:00:00 2001 From: Henrik Tjäder Date: Tue, 19 May 2020 19:03:19 +0000 Subject: Handle user hardware and software tasks and some resources --- macros/src/codegen.rs | 28 +++++++++++++++++++++++++--- macros/src/codegen/hardware_tasks.rs | 19 ++++++++++++++++++- macros/src/codegen/resources.rs | 12 +++++++++++- macros/src/codegen/software_tasks.rs | 18 +++++++++++++++++- 4 files changed, 71 insertions(+), 6 deletions(-) (limited to 'macros/src/codegen.rs') diff --git a/macros/src/codegen.rs b/macros/src/codegen.rs index 83e5ce8b..68f4fee7 100644 --- a/macros/src/codegen.rs +++ b/macros/src/codegen.rs @@ -89,12 +89,12 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { } )); - let (const_app_resources, mod_resources) = resources::codegen(app, analysis, extra); + let (const_app_resources, mod_resources, mod_resources_imports) = resources::codegen(app, analysis, extra); - let (const_app_hardware_tasks, root_hardware_tasks, user_hardware_tasks) = + let (const_app_hardware_tasks, root_hardware_tasks, user_hardware_tasks, user_hardware_tasks_imports) = hardware_tasks::codegen(app, analysis, extra); - let (const_app_software_tasks, root_software_tasks, user_software_tasks) = + let (const_app_software_tasks, root_software_tasks, user_software_tasks, user_software_tasks_imports) = software_tasks::codegen(app, analysis, extra); let const_app_dispatchers = dispatchers::codegen(app, analysis, extra); @@ -110,16 +110,22 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { quote!( #(#user)* + /// USER_HW_TASKS #(#user_hardware_tasks)* + /// USER_SW_TASKS #(#user_software_tasks)* + /// ROOT #(#root)* + /// MOD_RESOURCES #mod_resources + /// root_hardware_tasks #(#root_hardware_tasks)* + /// root_software_tasks #(#root_software_tasks)* /// Implementation details @@ -129,17 +135,33 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { use #device as _; #(#const_app_imports)* + /// User hardware_tasks + #(#user_hardware_tasks_imports)* + + /// User software_tasks + #(#user_software_tasks_imports)* + + /// Mod resources imports + #(#mod_resources_imports)* + + /// Const app #(#const_app)* + /// Const app resources #(#const_app_resources)* + /// Const app hw tasks #(#const_app_hardware_tasks)* + /// Const app sw tasks #(#const_app_software_tasks)* + /// Const app dispatchers #(#const_app_dispatchers)* + /// Const app spawn #(#const_app_spawn)* + /// Const app spawn end #(#const_app_timer_queue)* diff --git a/macros/src/codegen/hardware_tasks.rs b/macros/src/codegen/hardware_tasks.rs index 7f14b5e1..4f60876a 100644 --- a/macros/src/codegen/hardware_tasks.rs +++ b/macros/src/codegen/hardware_tasks.rs @@ -23,10 +23,13 @@ pub fn codegen( Vec, // user_hardware_tasks -- the `#[task]` functions written by the user Vec, + // user_hardware_tasks_imports -- the imports for `#[task]` functions written by the user + Vec, ) { let mut const_app = vec![]; let mut root = vec![]; let mut user_tasks = vec![]; + let mut hardware_tasks_imports = vec![]; for (name, task) in &app.hardware_tasks { let (let_instant, instant) = if app.uses_schedule() { @@ -78,6 +81,13 @@ pub fn codegen( analysis, ); + // Add resources to imports + let name_res = format_ident!("{}Resources", name); + hardware_tasks_imports.push(quote!( + #[allow(non_snake_case)] + use super::#name_res; + )); + root.push(item); const_app.push(constructor); @@ -112,7 +122,14 @@ pub fn codegen( #(#stmts)* } )); + + hardware_tasks_imports.push(quote!( + #(#attrs)* + #[allow(non_snake_case)] + use super::#name; + )); + } - (const_app, root, user_tasks) + (const_app, root, user_tasks, hardware_tasks_imports) } diff --git a/macros/src/codegen/resources.rs b/macros/src/codegen/resources.rs index 4196ee7a..80e63c79 100644 --- a/macros/src/codegen/resources.rs +++ b/macros/src/codegen/resources.rs @@ -14,9 +14,12 @@ pub fn codegen( Vec, // mod_resources -- the `resources` module TokenStream2, + // mod_resources_imports -- the `resources` module imports + Vec, ) { let mut const_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; @@ -82,6 +85,13 @@ pub fn codegen( ) }; + mod_resources_imports.push(quote!( + #[allow(non_camel_case_types)] + #(#cfgs)* + #cfg_core + use super::#name; + )); + const_app.push(util::impl_mutex( extra, cfgs, @@ -104,5 +114,5 @@ pub fn codegen( }) }; - (const_app, mod_resources) + (const_app, mod_resources, mod_resources_imports) } diff --git a/macros/src/codegen/software_tasks.rs b/macros/src/codegen/software_tasks.rs index b56db419..07edd1db 100644 --- a/macros/src/codegen/software_tasks.rs +++ b/macros/src/codegen/software_tasks.rs @@ -22,10 +22,13 @@ pub fn codegen( Vec, // user_software_tasks -- the `#[task]` functions written by the user Vec, + // user_software_tasks_imports -- the imports for `#[task]` functions written by the user + Vec, ) { let mut const_app = vec![]; let mut root = vec![]; let mut user_tasks = vec![]; + let mut software_tasks_imports = vec![]; for (name, task) in &app.software_tasks { let inputs = &task.inputs; @@ -112,6 +115,13 @@ pub fn codegen( analysis, ); + // Add resources to imports + let name_res = format_ident!("{}Resources", name); + software_tasks_imports.push(quote!( + #[allow(non_snake_case)] + use super::#name_res; + )); + root.push(item); const_app.push(constructor); @@ -141,6 +151,12 @@ pub fn codegen( #(#stmts)* } )); + software_tasks_imports.push(quote!( + #(#attrs)* + #(#cfgs)* + #[allow(non_snake_case)] + use super::#name; + )); root.push(module::codegen( Context::SoftwareTask(name), @@ -150,5 +166,5 @@ pub fn codegen( )); } - (const_app, root, user_tasks) + (const_app, root, user_tasks, software_tasks_imports) } -- cgit v1.2.3 From 0c7a619432e50eccfe019819b4ce3b0e6b9062df Mon Sep 17 00:00:00 2001 From: Henrik Tjäder Date: Tue, 26 May 2020 10:55:13 +0000 Subject: Compose the use-statements, reduce debug-printouts --- macros/src/codegen.rs | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) (limited to 'macros/src/codegen.rs') diff --git a/macros/src/codegen.rs b/macros/src/codegen.rs index 68f4fee7..fde9490b 100644 --- a/macros/src/codegen.rs +++ b/macros/src/codegen.rs @@ -30,17 +30,18 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { let mut mains = vec![]; let mut root = vec![]; let mut user = vec![]; + let mut imports = vec![]; // Generate the `main` function let assertion_stmts = assertions::codegen(analysis); let pre_init_stmts = pre_init::codegen(&app, analysis, extra); - let (const_app_init, root_init, user_init, call_init) = init::codegen(app, analysis, extra); + let (const_app_init, root_init, user_init, user_init_imports, call_init) = init::codegen(app, analysis, extra); let post_init_stmts = post_init::codegen(&app, analysis); - let (const_app_idle, root_idle, user_idle, call_idle) = idle::codegen(app, analysis, extra); + let (const_app_idle, root_idle, user_idle, user_idle_imports, call_idle) = idle::codegen(app, analysis, extra); if user_init.is_some() { const_app_imports.push(quote!( @@ -59,6 +60,11 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { #user_idle )); + imports.push(quote!( + #(#user_init_imports)* + #(#user_idle_imports)* + )); + root.push(quote!( #(#root_init)* @@ -105,27 +111,23 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { let const_app_schedule = schedule::codegen(app, extra); + + let user_imports = app.user_imports.clone(); let name = &app.name; let device = extra.device; quote!( #(#user)* - /// USER_HW_TASKS #(#user_hardware_tasks)* - /// USER_SW_TASKS #(#user_software_tasks)* - /// ROOT #(#root)* - /// MOD_RESOURCES #mod_resources - /// root_hardware_tasks #(#root_hardware_tasks)* - /// root_software_tasks #(#root_software_tasks)* /// Implementation details @@ -133,35 +135,27 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { mod #name { /// Always include the device crate which contains the vector table use #device as _; - #(#const_app_imports)* + #(#imports)* + #(#user_imports)* - /// User hardware_tasks #(#user_hardware_tasks_imports)* - /// User software_tasks #(#user_software_tasks_imports)* - /// Mod resources imports #(#mod_resources_imports)* /// Const app #(#const_app)* - /// Const app resources #(#const_app_resources)* - /// Const app hw tasks #(#const_app_hardware_tasks)* - /// Const app sw tasks #(#const_app_software_tasks)* - /// Const app dispatchers #(#const_app_dispatchers)* - /// Const app spawn #(#const_app_spawn)* - /// Const app spawn end #(#const_app_timer_queue)* -- cgit v1.2.3 From a151974245a994ec4c30bb0518677c4b99dce7e9 Mon Sep 17 00:00:00 2001 From: Henrik Tjäder Date: Tue, 8 Sep 2020 15:22:32 +0000 Subject: cfg_core is gone, cargo fmt --- macros/src/codegen.rs | 26 ++++++++++++++++++-------- macros/src/codegen/hardware_tasks.rs | 3 +-- macros/src/codegen/idle.rs | 12 ++++++++---- macros/src/codegen/init.rs | 11 ++++++++--- macros/src/codegen/resources.rs | 1 - macros/src/codegen/software_tasks.rs | 2 +- 6 files changed, 36 insertions(+), 19 deletions(-) (limited to 'macros/src/codegen.rs') diff --git a/macros/src/codegen.rs b/macros/src/codegen.rs index fde9490b..e45f1a38 100644 --- a/macros/src/codegen.rs +++ b/macros/src/codegen.rs @@ -37,11 +37,13 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { let pre_init_stmts = pre_init::codegen(&app, analysis, extra); - let (const_app_init, root_init, user_init, user_init_imports, call_init) = init::codegen(app, analysis, extra); + let (const_app_init, root_init, user_init, user_init_imports, call_init) = + init::codegen(app, analysis, extra); let post_init_stmts = post_init::codegen(&app, analysis); - let (const_app_idle, root_idle, user_idle, user_idle_imports, call_idle) = idle::codegen(app, analysis, extra); + let (const_app_idle, root_idle, user_idle, user_idle_imports, call_idle) = + idle::codegen(app, analysis, extra); if user_init.is_some() { const_app_imports.push(quote!( @@ -95,13 +97,22 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { } )); - let (const_app_resources, mod_resources, mod_resources_imports) = resources::codegen(app, analysis, extra); + let (const_app_resources, mod_resources, mod_resources_imports) = + resources::codegen(app, analysis, extra); - let (const_app_hardware_tasks, root_hardware_tasks, user_hardware_tasks, user_hardware_tasks_imports) = - hardware_tasks::codegen(app, analysis, extra); + let ( + const_app_hardware_tasks, + root_hardware_tasks, + user_hardware_tasks, + user_hardware_tasks_imports, + ) = hardware_tasks::codegen(app, analysis, extra); - let (const_app_software_tasks, root_software_tasks, user_software_tasks, user_software_tasks_imports) = - software_tasks::codegen(app, analysis, extra); + let ( + const_app_software_tasks, + root_software_tasks, + user_software_tasks, + user_software_tasks_imports, + ) = software_tasks::codegen(app, analysis, extra); let const_app_dispatchers = dispatchers::codegen(app, analysis, extra); @@ -111,7 +122,6 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { let const_app_schedule = schedule::codegen(app, extra); - let user_imports = app.user_imports.clone(); let name = &app.name; let device = extra.device; diff --git a/macros/src/codegen/hardware_tasks.rs b/macros/src/codegen/hardware_tasks.rs index 8f2ab2f6..a03fd779 100644 --- a/macros/src/codegen/hardware_tasks.rs +++ b/macros/src/codegen/hardware_tasks.rs @@ -1,5 +1,5 @@ use proc_macro2::TokenStream as TokenStream2; -use quote::{quote, format_ident}; +use quote::{format_ident, quote}; use rtic_syntax::{ast::App, Context}; use crate::{ @@ -128,7 +128,6 @@ pub fn codegen( #[allow(non_snake_case)] use super::#name; )); - } (const_app, root, user_tasks, hardware_tasks_imports) diff --git a/macros/src/codegen/idle.rs b/macros/src/codegen/idle.rs index db454a58..2aa99751 100644 --- a/macros/src/codegen/idle.rs +++ b/macros/src/codegen/idle.rs @@ -1,5 +1,5 @@ use proc_macro2::TokenStream as TokenStream2; -use quote::{quote, format_ident}; +use quote::{format_ident, quote}; use rtic_syntax::{ast::App, Context}; use crate::{ @@ -52,7 +52,6 @@ pub fn codegen( #[allow(non_snake_case)] use super::#name_resource; )); - } if !idle.locals.is_empty() { @@ -81,7 +80,6 @@ pub fn codegen( user_idle_imports.push(quote!( #(#attrs)* #[allow(non_snake_case)] - #cfg_core use super::#name; )); @@ -91,7 +89,13 @@ pub fn codegen( #name::Context::new(&rtic::export::Priority::new(0)) )); - (const_app, root_idle, user_idle, user_idle_imports, call_idle) + ( + const_app, + root_idle, + user_idle, + user_idle_imports, + call_idle, + ) } else { ( None, diff --git a/macros/src/codegen/init.rs b/macros/src/codegen/init.rs index 88a7a23b..b350298c 100644 --- a/macros/src/codegen/init.rs +++ b/macros/src/codegen/init.rs @@ -1,5 +1,5 @@ use proc_macro2::TokenStream as TokenStream2; -use quote::{quote, format_ident}; +use quote::{format_ident, quote}; use rtic_syntax::{ast::App, Context}; use crate::{ @@ -101,7 +101,6 @@ pub fn codegen( )); user_init_imports.push(quote!( #(#attrs)* - #cfg_core #[allow(non_snake_case)] use super::#name; )); @@ -128,7 +127,13 @@ pub fn codegen( root_init.push(module::codegen(Context::Init, needs_lt, app, extra)); - (const_app, root_init, user_init, user_init_imports, call_init) + ( + const_app, + root_init, + user_init, + user_init_imports, + call_init, + ) } else { (None, vec![], None, vec![], None) } diff --git a/macros/src/codegen/resources.rs b/macros/src/codegen/resources.rs index a326e68c..d18a4655 100644 --- a/macros/src/codegen/resources.rs +++ b/macros/src/codegen/resources.rs @@ -88,7 +88,6 @@ pub fn codegen( mod_resources_imports.push(quote!( #[allow(non_camel_case_types)] #(#cfgs)* - #cfg_core use super::resources::#name; )); diff --git a/macros/src/codegen/software_tasks.rs b/macros/src/codegen/software_tasks.rs index 854c083d..9e011152 100644 --- a/macros/src/codegen/software_tasks.rs +++ b/macros/src/codegen/software_tasks.rs @@ -1,5 +1,5 @@ use proc_macro2::TokenStream as TokenStream2; -use quote::{quote, format_ident}; +use quote::{format_ident, quote}; use rtic_syntax::{ast::App, Context}; use crate::{ -- cgit v1.2.3 From 487fea45ce15ea375192f72ddb148dda8414873b Mon Sep 17 00:00:00 2001 From: Henrik Tjäder Date: Thu, 4 Jun 2020 15:43:16 +0000 Subject: Keep user code as-is within the module, add example --- examples/resource-user-struct.rs | 60 ++++++++++++++++++++++++++++++++++++++++ macros/src/codegen.rs | 6 ++++ macros/src/lib.rs | 3 +- 3 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 examples/resource-user-struct.rs (limited to 'macros/src/codegen.rs') diff --git a/examples/resource-user-struct.rs b/examples/resource-user-struct.rs new file mode 100644 index 00000000..132aa349 --- /dev/null +++ b/examples/resource-user-struct.rs @@ -0,0 +1,60 @@ +//! examples/resource.rs + +#![deny(unsafe_code)] +#![deny(warnings)] +#![no_main] +#![no_std] + +use cortex_m_semihosting::{debug, hprintln}; +use lm3s6965::Interrupt; +use panic_semihosting as _; + +#[rtic::app(device = lm3s6965)] +mod app { + #[resources] + struct Resources { + // A resource + #[init(0)] + shared: u32, + } + + // Should not collide with the struct above + struct Resources2 { + // A resource + shared: u32, + } + + #[init] + fn init(_: init::Context) { + rtic::pend(Interrupt::UART0); + rtic::pend(Interrupt::UART1); + } + + // `shared` cannot be accessed from this context + #[idle] + fn idle(_cx: idle::Context) -> ! { + debug::exit(debug::EXIT_SUCCESS); + + // error: no `resources` field in `idle::Context` + // _cx.resources.shared += 1; + + loop {} + } + + // `shared` can be accessed from this context + #[task(binds = UART0, resources = [shared])] + fn uart0(cx: uart0::Context) { + let shared: &mut u32 = cx.resources.shared; + *shared += 1; + + hprintln!("UART0: shared = {}", shared).unwrap(); + } + + // `shared` can be accessed from this context + #[task(binds = UART1, resources = [shared])] + fn uart1(cx: uart1::Context) { + *cx.resources.shared += 1; + + hprintln!("UART1: shared = {}", cx.resources.shared).unwrap(); + } +} diff --git a/macros/src/codegen.rs b/macros/src/codegen.rs index e45f1a38..f97f841a 100644 --- a/macros/src/codegen.rs +++ b/macros/src/codegen.rs @@ -123,6 +123,7 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { let const_app_schedule = schedule::codegen(app, extra); let user_imports = app.user_imports.clone(); + let user_code = app.user_code.clone(); let name = &app.name; let device = extra.device; quote!( @@ -148,6 +149,11 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { #(#imports)* #(#user_imports)* + /// User code from within the module + #(#user_code)* + /// User code end + + #(#user_hardware_tasks_imports)* #(#user_software_tasks_imports)* diff --git a/macros/src/lib.rs b/macros/src/lib.rs index 2a439e1e..94e7eec6 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -35,7 +35,8 @@ mod tests; /// /// The items allowed in the module block are specified below: /// -/// # 1. `struct Resources` +/// # 1. `#[resources] +/// struct ` /// /// This structure contains the declaration of all the resources used by the application. Each field /// in this structure corresponds to a different resource. Each resource may optionally be given an -- cgit v1.2.3 From 3ab2c049c5a4338dac19b7fdb522f3612c69c746 Mon Sep 17 00:00:00 2001 From: Henrik Tjäder Date: Thu, 4 Jun 2020 17:05:25 +0000 Subject: Remove stale comment --- macros/src/codegen.rs | 1 - 1 file changed, 1 deletion(-) (limited to 'macros/src/codegen.rs') diff --git a/macros/src/codegen.rs b/macros/src/codegen.rs index f97f841a..26d7dc2d 100644 --- a/macros/src/codegen.rs +++ b/macros/src/codegen.rs @@ -142,7 +142,6 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { #(#root_software_tasks)* /// Implementation details - // the user can't access the items within this `const` item mod #name { /// Always include the device crate which contains the vector table use #device as _; -- cgit v1.2.3 From 96e6350c0dfae37c3ea8032b4cc3113e37323ae5 Mon Sep 17 00:00:00 2001 From: Henrik Tjäder Date: Thu, 1 Oct 2020 16:17:15 +0000 Subject: Rename const_app to mod_app --- macros/src/codegen.rs | 50 ++++++++++++++++++------------------ macros/src/codegen/hardware_tasks.rs | 10 ++++---- macros/src/codegen/idle.rs | 14 +++------- macros/src/codegen/init.rs | 14 +++------- macros/src/codegen/resources.rs | 10 ++++---- macros/src/codegen/software_tasks.rs | 18 ++++++------- 6 files changed, 52 insertions(+), 64 deletions(-) (limited to 'macros/src/codegen.rs') diff --git a/macros/src/codegen.rs b/macros/src/codegen.rs index 26d7dc2d..f230d395 100644 --- a/macros/src/codegen.rs +++ b/macros/src/codegen.rs @@ -25,8 +25,8 @@ mod util; // TODO document the syntax here or in `rtic-syntax` pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { - let mut const_app = vec![]; - let mut const_app_imports = vec![]; + let mut mod_app = vec![]; + let mut mod_app_imports = vec![]; let mut mains = vec![]; let mut root = vec![]; let mut user = vec![]; @@ -37,21 +37,21 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { let pre_init_stmts = pre_init::codegen(&app, analysis, extra); - let (const_app_init, root_init, user_init, user_init_imports, call_init) = + let (mod_app_init, root_init, user_init, user_init_imports, call_init) = init::codegen(app, analysis, extra); let post_init_stmts = post_init::codegen(&app, analysis); - let (const_app_idle, root_idle, user_idle, user_idle_imports, call_idle) = + let (mod_app_idle, root_idle, user_idle, user_idle_imports, call_idle) = idle::codegen(app, analysis, extra); if user_init.is_some() { - const_app_imports.push(quote!( + mod_app_imports.push(quote!( use super::init; )) } if user_idle.is_some() { - const_app_imports.push(quote!( + mod_app_imports.push(quote!( use super::idle; )) } @@ -73,10 +73,10 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { #(#root_idle)* )); - const_app.push(quote!( - #const_app_init + mod_app.push(quote!( + #mod_app_init - #const_app_idle + #mod_app_idle )); let main = util::suffixed("main"); @@ -97,30 +97,30 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { } )); - let (const_app_resources, mod_resources, mod_resources_imports) = + let (mod_app_resources, mod_resources, mod_resources_imports) = resources::codegen(app, analysis, extra); let ( - const_app_hardware_tasks, + mod_app_hardware_tasks, root_hardware_tasks, user_hardware_tasks, user_hardware_tasks_imports, ) = hardware_tasks::codegen(app, analysis, extra); let ( - const_app_software_tasks, + mod_app_software_tasks, root_software_tasks, user_software_tasks, user_software_tasks_imports, ) = software_tasks::codegen(app, analysis, extra); - let const_app_dispatchers = dispatchers::codegen(app, analysis, extra); + let mod_app_dispatchers = dispatchers::codegen(app, analysis, extra); - let const_app_spawn = spawn::codegen(app, analysis, extra); + let mod_app_spawn = spawn::codegen(app, analysis, extra); - let const_app_timer_queue = timer_queue::codegen(app, analysis, extra); + let mod_app_timer_queue = timer_queue::codegen(app, analysis, extra); - let const_app_schedule = schedule::codegen(app, extra); + let mod_app_schedule = schedule::codegen(app, extra); let user_imports = app.user_imports.clone(); let user_code = app.user_code.clone(); @@ -159,22 +159,22 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { #(#mod_resources_imports)* - /// Const app - #(#const_app)* + /// app module + #(#mod_app)* - #(#const_app_resources)* + #(#mod_app_resources)* - #(#const_app_hardware_tasks)* + #(#mod_app_hardware_tasks)* - #(#const_app_software_tasks)* + #(#mod_app_software_tasks)* - #(#const_app_dispatchers)* + #(#mod_app_dispatchers)* - #(#const_app_spawn)* + #(#mod_app_spawn)* - #(#const_app_timer_queue)* + #(#mod_app_timer_queue)* - #(#const_app_schedule)* + #(#mod_app_schedule)* #(#mains)* } diff --git a/macros/src/codegen/hardware_tasks.rs b/macros/src/codegen/hardware_tasks.rs index a03fd779..25f1df41 100644 --- a/macros/src/codegen/hardware_tasks.rs +++ b/macros/src/codegen/hardware_tasks.rs @@ -14,7 +14,7 @@ pub fn codegen( analysis: &Analysis, extra: &Extra, ) -> ( - // const_app_hardware_tasks -- interrupt handlers and `${task}Resources` constructors + // mod_app_hardware_tasks -- interrupt handlers and `${task}Resources` constructors Vec, // root_hardware_tasks -- items that must be placed in the root of the crate: // - `${task}Locals` structs @@ -26,7 +26,7 @@ pub fn codegen( // user_hardware_tasks_imports -- the imports for `#[task]` functions written by the user Vec, ) { - let mut const_app = vec![]; + let mut mod_app = vec![]; let mut root = vec![]; let mut user_tasks = vec![]; let mut hardware_tasks_imports = vec![]; @@ -52,7 +52,7 @@ pub fn codegen( let symbol = task.args.binds.clone(); let priority = task.args.priority; - const_app.push(quote!( + mod_app.push(quote!( #[allow(non_snake_case)] #[no_mangle] unsafe fn #symbol() { @@ -90,7 +90,7 @@ pub fn codegen( root.push(item); - const_app.push(constructor); + mod_app.push(constructor); } root.push(module::codegen( @@ -130,5 +130,5 @@ pub fn codegen( )); } - (const_app, root, user_tasks, hardware_tasks_imports) + (mod_app, root, user_tasks, hardware_tasks_imports) } diff --git a/macros/src/codegen/idle.rs b/macros/src/codegen/idle.rs index 2aa99751..2e2932d7 100644 --- a/macros/src/codegen/idle.rs +++ b/macros/src/codegen/idle.rs @@ -14,7 +14,7 @@ pub fn codegen( analysis: &Analysis, extra: &Extra, ) -> ( - // const_app_idle -- the `${idle}Resources` constructor + // mod_app_idle -- the `${idle}Resources` constructor Option, // root_idle -- items that must be placed in the root of the crate: // - the `${idle}Locals` struct @@ -31,7 +31,7 @@ pub fn codegen( if app.idles.len() > 0 { let idle = &app.idles.first().unwrap(); let mut needs_lt = false; - let mut const_app = None; + let mut mod_app = None; let mut root_idle = vec![]; let mut locals_pat = None; let mut locals_new = None; @@ -45,7 +45,7 @@ pub fn codegen( resources_struct::codegen(Context::Idle, 0, &mut needs_lt, app, analysis); root_idle.push(item); - const_app = Some(constructor); + mod_app = Some(constructor); let name_resource = format_ident!("{}Resources", name); user_idle_imports.push(quote!( @@ -89,13 +89,7 @@ pub fn codegen( #name::Context::new(&rtic::export::Priority::new(0)) )); - ( - const_app, - root_idle, - user_idle, - user_idle_imports, - call_idle, - ) + (mod_app, root_idle, user_idle, user_idle_imports, call_idle) } else { ( None, diff --git a/macros/src/codegen/init.rs b/macros/src/codegen/init.rs index b350298c..77d186e5 100644 --- a/macros/src/codegen/init.rs +++ b/macros/src/codegen/init.rs @@ -14,7 +14,7 @@ pub fn codegen( analysis: &Analysis, extra: &Extra, ) -> ( - // const_app_idle -- the `${init}Resources` constructor + // mod_app_idle -- the `${init}Resources` constructor Option, // root_init -- items that must be placed in the root of the crate: // - the `${init}Locals` struct @@ -105,13 +105,13 @@ pub fn codegen( use super::#name; )); - let mut const_app = None; + let mut mod_app = None; if !init.args.resources.is_empty() { let (item, constructor) = resources_struct::codegen(Context::Init, 0, &mut needs_lt, app, analysis); root_init.push(item); - const_app = Some(constructor); + mod_app = Some(constructor); let name_late = format_ident!("{}Resources", name); user_init_imports.push(quote!( @@ -127,13 +127,7 @@ pub fn codegen( root_init.push(module::codegen(Context::Init, needs_lt, app, extra)); - ( - const_app, - root_init, - user_init, - user_init_imports, - call_init, - ) + (mod_app, root_init, user_init, user_init_imports, call_init) } else { (None, vec![], None, vec![], None) } diff --git a/macros/src/codegen/resources.rs b/macros/src/codegen/resources.rs index d18a4655..38ea5245 100644 --- a/macros/src/codegen/resources.rs +++ b/macros/src/codegen/resources.rs @@ -10,14 +10,14 @@ pub fn codegen( analysis: &Analysis, extra: &Extra, ) -> ( - // const_app -- the `static [mut]` variables behind the proxies + // mod_app -- the `static [mut]` variables behind the proxies Vec, // mod_resources -- the `resources` module TokenStream2, // mod_resources_imports -- the `resources` module imports Vec, ) { - let mut const_app = vec![]; + let mut mod_app = vec![]; let mut mod_resources = vec![]; let mut mod_resources_imports = vec![]; @@ -42,7 +42,7 @@ pub fn codegen( }; let attrs = &res.attrs; - const_app.push(quote!( + mod_app.push(quote!( #[allow(non_upper_case_globals)] #(#attrs)* #(#cfgs)* @@ -91,7 +91,7 @@ pub fn codegen( use super::resources::#name; )); - const_app.push(util::impl_mutex( + mod_app.push(util::impl_mutex( extra, cfgs, true, @@ -118,5 +118,5 @@ pub fn codegen( }) }; - (const_app, mod_resources, mod_resources_imports) + (mod_app, mod_resources, mod_resources_imports) } diff --git a/macros/src/codegen/software_tasks.rs b/macros/src/codegen/software_tasks.rs index 9e011152..4ae37e4e 100644 --- a/macros/src/codegen/software_tasks.rs +++ b/macros/src/codegen/software_tasks.rs @@ -13,7 +13,7 @@ pub fn codegen( analysis: &Analysis, extra: &Extra, ) -> ( - // const_app_software_tasks -- free queues, buffers and `${task}Resources` constructors + // mod_app_software_tasks -- free queues, buffers and `${task}Resources` constructors Vec, // root_software_tasks -- items that must be placed in the root of the crate: // - `${task}Locals` structs @@ -25,7 +25,7 @@ pub fn codegen( // user_software_tasks_imports -- the imports for `#[task]` functions written by the user Vec, ) { - let mut const_app = vec![]; + let mut mod_app = vec![]; let mut root = vec![]; let mut user_tasks = vec![]; let mut software_tasks_imports = vec![]; @@ -51,7 +51,7 @@ pub fn codegen( Box::new(|| util::link_section_uninit(true)), ) }; - const_app.push(quote!( + mod_app.push(quote!( /// Queue version of a free-list that keeps track of empty slots in /// the following buffers static mut #fq: #fq_ty = #fq_expr; @@ -59,13 +59,13 @@ pub fn codegen( // Generate a resource proxy if needed if let Some(ceiling) = ceiling { - const_app.push(quote!( + mod_app.push(quote!( struct #fq<'a> { priority: &'a rtic::export::Priority, } )); - const_app.push(util::impl_mutex( + mod_app.push(util::impl_mutex( extra, &[], false, @@ -85,7 +85,7 @@ pub fn codegen( let instants = util::instants_ident(name); let uninit = mk_uninit(); - const_app.push(quote!( + mod_app.push(quote!( #uninit /// Buffer that holds the instants associated to the inputs of a task static mut #instants: @@ -96,7 +96,7 @@ pub fn codegen( let uninit = mk_uninit(); let inputs = util::inputs_ident(name); - const_app.push(quote!( + mod_app.push(quote!( #uninit /// Buffer that holds the inputs of a task static mut #inputs: [core::mem::MaybeUninit<#input_ty>; #cap_lit] = @@ -124,7 +124,7 @@ pub fn codegen( root.push(item); - const_app.push(constructor); + mod_app.push(constructor); } // `${task}Locals` @@ -165,5 +165,5 @@ pub fn codegen( )); } - (const_app, root, user_tasks, software_tasks_imports) + (mod_app, root, user_tasks, software_tasks_imports) } -- cgit v1.2.3