From f96b25fdf2d7421cc16830a4ccac4ebb3e69cc5d Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Thu, 15 Oct 2020 18:50:17 +0200 Subject: [PATCH 1/4] Updated examples More work --- examples/baseline.rs | 5 +- examples/binds.rs | 5 +- examples/capacity.rs | 5 +- examples/cfg.rs | 7 ++- examples/destructure.rs | 5 +- examples/double_schedule.rs | 2 +- examples/generics.rs | 9 ++- examples/hardware.rs | 5 +- examples/idle.rs | 3 +- examples/init.rs | 3 +- examples/late.rs | 13 ++-- examples/lock.rs | 5 +- examples/message.rs | 3 +- examples/not-sync.rs | 3 +- examples/only-shared-access.rs | 5 +- examples/periodic.rs | 8 +-- examples/peripherals-taken.rs | 3 +- examples/pool.rs | 6 +- examples/preempt.rs | 5 +- examples/ramfunc.rs | 3 +- examples/resource-user-struct.rs | 5 +- examples/resource.rs | 5 +- examples/schedule.rs | 7 ++- examples/shared-with-init.rs | 4 +- examples/spawn.rs | 3 +- examples/spawn2.rs | 3 +- examples/static.rs | 16 +++-- examples/t-binds.rs | 8 +-- examples/t-htask-main.rs | 3 +- examples/t-idle-main.rs | 3 +- examples/t-init-main.rs | 3 +- examples/t-late-not-send.rs | 1 + examples/t-schedule.rs | 3 +- examples/t-stask-main.rs | 3 +- examples/task.rs | 3 +- examples/types.rs | 5 +- macros/src/codegen.rs | 85 +++++++++++--------------- macros/src/codegen/dispatchers.rs | 4 +- macros/src/codegen/hardware_tasks.rs | 24 ++------ macros/src/codegen/idle.rs | 24 ++------ macros/src/codegen/init.rs | 30 ++------- macros/src/codegen/resources.rs | 7 ++- macros/src/codegen/resources_struct.rs | 11 ++-- macros/src/codegen/software_tasks.rs | 19 +----- macros/src/codegen/util.rs | 8 +++ 45 files changed, 176 insertions(+), 214 deletions(-) diff --git a/examples/baseline.rs b/examples/baseline.rs index 0b7e3ea0dd..82f1887e65 100644 --- a/examples/baseline.rs +++ b/examples/baseline.rs @@ -5,13 +5,14 @@ #![no_main] #![no_std] -use cortex_m_semihosting::{debug, hprintln}; -use lm3s6965::Interrupt; use panic_semihosting as _; // NOTE: does NOT properly work on QEMU #[rtic::app(device = lm3s6965, monotonic = rtic::cyccnt::CYCCNT)] mod app { + use cortex_m_semihosting::{debug, hprintln}; + use lm3s6965::Interrupt; + #[init] fn init(cx: init::Context) -> init::LateResources { // omitted: initialization of `CYCCNT` diff --git a/examples/binds.rs b/examples/binds.rs index 42010ae243..f681aa5724 100644 --- a/examples/binds.rs +++ b/examples/binds.rs @@ -5,13 +5,14 @@ #![no_main] #![no_std] -use cortex_m_semihosting::{debug, hprintln}; -use lm3s6965::Interrupt; use panic_semihosting as _; // `examples/interrupt.rs` rewritten to use `binds` #[rtic::app(device = lm3s6965)] mod app { + use cortex_m_semihosting::{debug, hprintln}; + use lm3s6965::Interrupt; + #[init] fn init(_: init::Context) -> init::LateResources { rtic::pend(Interrupt::UART0); diff --git a/examples/capacity.rs b/examples/capacity.rs index f903acbc86..29b4f04e26 100644 --- a/examples/capacity.rs +++ b/examples/capacity.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; + #[init] fn init(_: init::Context) -> init::LateResources { rtic::pend(Interrupt::UART0); diff --git a/examples/cfg.rs b/examples/cfg.rs index c8892eafde..f900286b71 100644 --- a/examples/cfg.rs +++ b/examples/cfg.rs @@ -5,13 +5,14 @@ #![no_main] #![no_std] -use cortex_m_semihosting::debug; -#[cfg(debug_assertions)] -use cortex_m_semihosting::hprintln; use panic_semihosting as _; #[rtic::app(device = lm3s6965)] mod app { + use cortex_m_semihosting::debug; + #[cfg(debug_assertions)] + use cortex_m_semihosting::hprintln; + #[resources] struct Resources { #[cfg(debug_assertions)] // <- `true` when using the `dev` profile diff --git a/examples/destructure.rs b/examples/destructure.rs index e7c53237d3..3c5eabf7c0 100644 --- a/examples/destructure.rs +++ b/examples/destructure.rs @@ -5,12 +5,13 @@ #![no_main] #![no_std] -use cortex_m_semihosting::hprintln; -use lm3s6965::Interrupt; use panic_semihosting as _; #[rtic::app(device = lm3s6965)] mod app { + use cortex_m_semihosting::hprintln; + use lm3s6965::Interrupt; + #[resources] struct Resources { // Some resources to work with diff --git a/examples/double_schedule.rs b/examples/double_schedule.rs index d242c57e4b..78eaac4996 100644 --- a/examples/double_schedule.rs +++ b/examples/double_schedule.rs @@ -6,10 +6,10 @@ #![no_std] use panic_semihosting as _; -use rtic::cyccnt::U32Ext; #[rtic::app(device = lm3s6965, monotonic = rtic::cyccnt::CYCCNT)] mod app { + use rtic::cyccnt::U32Ext; #[resources] struct Resources { diff --git a/examples/generics.rs b/examples/generics.rs index 3107dd1175..b13baeb733 100644 --- a/examples/generics.rs +++ b/examples/generics.rs @@ -5,13 +5,16 @@ #![no_main] #![no_std] -use cortex_m_semihosting::{debug, hprintln}; -use lm3s6965::Interrupt; +use cortex_m_semihosting::hprintln; use panic_semihosting as _; -use rtic::{Exclusive, Mutex}; +use rtic::Mutex; #[rtic::app(device = lm3s6965)] mod app { + use cortex_m_semihosting::{debug, hprintln}; + use lm3s6965::Interrupt; + use rtic::Exclusive; + #[resources] struct Resources { #[init(0)] diff --git a/examples/hardware.rs b/examples/hardware.rs index f6a2d3758e..99e8da2ec6 100644 --- a/examples/hardware.rs +++ b/examples/hardware.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; + #[init] fn init(_: init::Context) -> init::LateResources { // Pends the UART0 interrupt but its handler won't run until *after* diff --git a/examples/idle.rs b/examples/idle.rs index 58c3c87d75..1aac56c28f 100644 --- a/examples/idle.rs +++ b/examples/idle.rs @@ -5,11 +5,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}; + #[init] fn init(_: init::Context) -> init::LateResources { hprintln!("init").unwrap(); diff --git a/examples/init.rs b/examples/init.rs index 6ac284a16a..ca67a2b783 100644 --- a/examples/init.rs +++ b/examples/init.rs @@ -5,11 +5,12 @@ #![no_main] #![no_std] -use cortex_m_semihosting::{debug, hprintln}; use panic_semihosting as _; #[rtic::app(device = lm3s6965, peripherals = true)] mod app { + use cortex_m_semihosting::{debug, hprintln}; + #[init] fn init(cx: init::Context) -> init::LateResources { static mut X: u32 = 0; diff --git a/examples/late.rs b/examples/late.rs index 761c68f5be..d20a69c553 100644 --- a/examples/late.rs +++ b/examples/late.rs @@ -5,21 +5,18 @@ #![no_main] #![no_std] -use cortex_m_semihosting::{debug, hprintln}; -use heapless::{ - consts::*, - i, - spsc::{Consumer, Producer, Queue}, -}; -use lm3s6965::Interrupt; use panic_semihosting as _; #[rtic::app(device = lm3s6965)] mod app { + use cortex_m_semihosting::{debug, hprintln}; use heapless::{ consts::*, - spsc::{Consumer, Producer}, + i, + spsc::{Consumer, Producer, Queue}, }; + use lm3s6965::Interrupt; + // Late resources #[resources] struct Resources { diff --git a/examples/lock.rs b/examples/lock.rs index 669b1aedd8..c4930a28c9 100644 --- a/examples/lock.rs +++ b/examples/lock.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 { #[init(0)] diff --git a/examples/message.rs b/examples/message.rs index 5ff6288af9..4306430ffa 100644 --- a/examples/message.rs +++ b/examples/message.rs @@ -5,11 +5,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}; + #[init] fn init(_: init::Context) -> init::LateResources { foo::spawn(/* no message */).unwrap(); diff --git a/examples/not-sync.rs b/examples/not-sync.rs index 75412e6343..d2616ee935 100644 --- a/examples/not-sync.rs +++ b/examples/not-sync.rs @@ -6,8 +6,6 @@ #![no_std] use core::marker::PhantomData; - -use cortex_m_semihosting::debug; use panic_halt as _; pub struct NotSync { @@ -18,6 +16,7 @@ pub struct NotSync { mod app { use super::NotSync; use core::marker::PhantomData; + use cortex_m_semihosting::debug; #[resources] struct Resources { diff --git a/examples/only-shared-access.rs b/examples/only-shared-access.rs index 91d0b7adca..8d42fd4ddd 100644 --- a/examples/only-shared-access.rs +++ b/examples/only-shared-access.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 { key: u32, diff --git a/examples/periodic.rs b/examples/periodic.rs index 95cd14515e..eedf720c53 100644 --- a/examples/periodic.rs +++ b/examples/periodic.rs @@ -5,15 +5,15 @@ #![no_main] #![no_std] -use cortex_m_semihosting::hprintln; use panic_semihosting as _; -use rtic::cyccnt::{Instant, U32Ext}; - -const PERIOD: u32 = 8_000_000; // NOTE: does NOT work on QEMU! #[rtic::app(device = lm3s6965, monotonic = rtic::cyccnt::CYCCNT)] mod app { + use cortex_m_semihosting::hprintln; + use rtic::cyccnt::{Instant, U32Ext}; + + const PERIOD: u32 = 8_000_000; #[init] fn init(cx: init::Context) -> init::LateResources { diff --git a/examples/peripherals-taken.rs b/examples/peripherals-taken.rs index 09f92427f5..98f06b08a2 100644 --- a/examples/peripherals-taken.rs +++ b/examples/peripherals-taken.rs @@ -3,11 +3,12 @@ #![no_main] #![no_std] -use cortex_m_semihosting::debug; use panic_semihosting as _; #[rtic::app(device = lm3s6965)] mod app { + use cortex_m_semihosting::debug; + #[init] fn init(_: init::Context) -> init::LateResources { assert!(cortex_m::Peripherals::take().is_none()); diff --git a/examples/pool.rs b/examples/pool.rs index 2ad9984129..fc740feafc 100644 --- a/examples/pool.rs +++ b/examples/pool.rs @@ -5,12 +5,10 @@ #![no_main] #![no_std] -use cortex_m_semihosting::{debug, hprintln}; use heapless::{ pool, pool::singleton::{Box, Pool}, }; -use lm3s6965::Interrupt; use panic_semihosting as _; use rtic::app; @@ -19,7 +17,9 @@ pool!(P: [u8; 128]); #[app(device = lm3s6965)] mod app { - use crate::Box; + use crate::{Box, Pool}; + use cortex_m_semihosting::{debug, hprintln}; + use lm3s6965::Interrupt; // Import the memory pool into scope use super::P; diff --git a/examples/preempt.rs b/examples/preempt.rs index f6fc4b052e..ee75c46f18 100644 --- a/examples/preempt.rs +++ b/examples/preempt.rs @@ -3,13 +3,14 @@ #![no_main] #![no_std] -use cortex_m_semihosting::{debug, hprintln}; -use lm3s6965::Interrupt; use panic_semihosting as _; use rtic::app; #[app(device = lm3s6965)] mod app { + use cortex_m_semihosting::{debug, hprintln}; + use lm3s6965::Interrupt; + #[init] fn init(_: init::Context) -> init::LateResources { rtic::pend(Interrupt::GPIOA); diff --git a/examples/ramfunc.rs b/examples/ramfunc.rs index 84d633dd37..4d46c6dd38 100644 --- a/examples/ramfunc.rs +++ b/examples/ramfunc.rs @@ -5,11 +5,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}; + #[init] fn init(_: init::Context) -> init::LateResources { foo::spawn().unwrap(); diff --git a/examples/resource-user-struct.rs b/examples/resource-user-struct.rs index a5bd0ddf5e..ca4ca2af0f 100644 --- a/examples/resource-user-struct.rs +++ b/examples/resource-user-struct.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 { // A resource diff --git a/examples/resource.rs b/examples/resource.rs index 273af26a0e..87ba336705 100644 --- a/examples/resource.rs +++ b/examples/resource.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 { // A resource diff --git a/examples/schedule.rs b/examples/schedule.rs index fa67a56682..f57f53f521 100644 --- a/examples/schedule.rs +++ b/examples/schedule.rs @@ -5,14 +5,15 @@ #![no_main] #![no_std] -use cortex_m::peripheral::DWT; -use cortex_m_semihosting::hprintln; use panic_halt as _; -use rtic::cyccnt::{Instant, U32Ext as _}; // NOTE: does NOT work on QEMU! #[rtic::app(device = lm3s6965, monotonic = rtic::cyccnt::CYCCNT)] mod app { + use cortex_m::peripheral::DWT; + use cortex_m_semihosting::hprintln; + use rtic::cyccnt::{Instant, U32Ext as _}; + #[init()] fn init(mut cx: init::Context) -> init::LateResources { // Initialize (enable) the monotonic timer (CYCCNT) diff --git a/examples/shared-with-init.rs b/examples/shared-with-init.rs index 85c72761bc..049a38bfdb 100644 --- a/examples/shared-with-init.rs +++ b/examples/shared-with-init.rs @@ -5,8 +5,6 @@ #![no_main] #![no_std] -use cortex_m_semihosting::debug; -use lm3s6965::Interrupt; use panic_halt as _; use rtic::app; @@ -14,6 +12,8 @@ pub struct MustBeSend; #[app(device = lm3s6965)] mod app { + use cortex_m_semihosting::debug; + use lm3s6965::Interrupt; use super::MustBeSend; #[resources] diff --git a/examples/spawn.rs b/examples/spawn.rs index 041018ab0b..300b3b3a54 100644 --- a/examples/spawn.rs +++ b/examples/spawn.rs @@ -5,11 +5,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}; + #[init] fn init(_c: init::Context) -> init::LateResources { foo::spawn(1, 2).unwrap(); diff --git a/examples/spawn2.rs b/examples/spawn2.rs index b50a3ee671..070223b897 100644 --- a/examples/spawn2.rs +++ b/examples/spawn2.rs @@ -5,11 +5,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}; + #[init] fn init(_c: init::Context) -> init::LateResources { foo::spawn(1, 2).unwrap(); diff --git a/examples/static.rs b/examples/static.rs index 9c3110c035..cd46145a4a 100644 --- a/examples/static.rs +++ b/examples/static.rs @@ -5,20 +5,18 @@ #![no_main] #![no_std] -use cortex_m_semihosting::{debug, hprintln}; -use heapless::{ - consts::*, - i, - spsc::{Consumer, Producer, Queue}, -}; -use lm3s6965::Interrupt; use panic_semihosting as _; #[rtic::app(device = lm3s6965)] mod app { - use crate::U4; - use crate::{Consumer, Producer}; + use cortex_m_semihosting::{debug, hprintln}; + use heapless::{ + consts::*, + i, + spsc::{Consumer, Producer, Queue}, + }; + use lm3s6965::Interrupt; // Late resources #[resources] diff --git a/examples/t-binds.rs b/examples/t-binds.rs index 3ca4c66ec5..8d52f58a3f 100644 --- a/examples/t-binds.rs +++ b/examples/t-binds.rs @@ -17,18 +17,18 @@ mod app { // Cortex-M exception #[task(binds = SVCall)] fn foo(c: foo::Context) { - foo_trampoline(c) + crate::foo_trampoline(c) } // LM3S6965 interrupt #[task(binds = UART0)] fn bar(c: bar::Context) { - bar_trampoline(c) + crate::bar_trampoline(c) } } #[allow(dead_code)] -fn foo_trampoline(_: foo::Context) {} +fn foo_trampoline(_: app::foo::Context) {} #[allow(dead_code)] -fn bar_trampoline(_: bar::Context) {} +fn bar_trampoline(_: app::bar::Context) {} diff --git a/examples/t-htask-main.rs b/examples/t-htask-main.rs index 1e38e317c4..57076eca49 100644 --- a/examples/t-htask-main.rs +++ b/examples/t-htask-main.rs @@ -3,11 +3,12 @@ #![no_main] #![no_std] -use cortex_m_semihosting::debug; use panic_semihosting as _; #[rtic::app(device = lm3s6965)] mod app { + use cortex_m_semihosting::debug; + #[init] fn init(_: init::Context) -> init::LateResources { rtic::pend(lm3s6965::Interrupt::UART0); diff --git a/examples/t-idle-main.rs b/examples/t-idle-main.rs index 9078628ecd..42dac904e2 100644 --- a/examples/t-idle-main.rs +++ b/examples/t-idle-main.rs @@ -3,11 +3,12 @@ #![no_main] #![no_std] -use cortex_m_semihosting::debug; use panic_semihosting as _; #[rtic::app(device = lm3s6965)] mod app { + use cortex_m_semihosting::debug; + #[init] fn init(_: init::Context) -> init::LateResources { init::LateResources {} diff --git a/examples/t-init-main.rs b/examples/t-init-main.rs index 7c23cc8307..0456e874c0 100644 --- a/examples/t-init-main.rs +++ b/examples/t-init-main.rs @@ -3,11 +3,12 @@ #![no_main] #![no_std] -use cortex_m_semihosting::debug; use panic_semihosting as _; #[rtic::app(device = lm3s6965)] mod app { + use cortex_m_semihosting::debug; + #[init] fn init(_: init::Context) -> init::LateResources { debug::exit(debug::EXIT_SUCCESS); diff --git a/examples/t-late-not-send.rs b/examples/t-late-not-send.rs index 345d9aefa1..8b7b986ffa 100644 --- a/examples/t-late-not-send.rs +++ b/examples/t-late-not-send.rs @@ -14,6 +14,7 @@ pub struct NotSend { #[rtic::app(device = lm3s6965)] mod app { use super::NotSend; + use core::marker::PhantomData; #[resources] struct Resources { diff --git a/examples/t-schedule.rs b/examples/t-schedule.rs index 7c2c420caa..b1faaa6d9c 100644 --- a/examples/t-schedule.rs +++ b/examples/t-schedule.rs @@ -6,10 +6,11 @@ #![no_std] use panic_halt as _; -use rtic::cyccnt::{Instant, U32Ext as _}; #[rtic::app(device = lm3s6965, monotonic = rtic::cyccnt::CYCCNT)] mod app { + use rtic::cyccnt::{Instant, U32Ext as _}; + #[init] fn init(c: init::Context) -> init::LateResources { let _: Result<(), ()> = foo::schedule(c.start + 10.cycles()); diff --git a/examples/t-stask-main.rs b/examples/t-stask-main.rs index 3337c7d383..56dc1af562 100644 --- a/examples/t-stask-main.rs +++ b/examples/t-stask-main.rs @@ -3,11 +3,12 @@ #![no_main] #![no_std] -use cortex_m_semihosting::debug; use panic_semihosting as _; #[rtic::app(device = lm3s6965)] mod app { + use cortex_m_semihosting::debug; + #[init] fn init(_: init::Context) -> init::LateResources { taskmain::spawn().ok(); diff --git a/examples/task.rs b/examples/task.rs index f3d916f30d..60591b9f46 100644 --- a/examples/task.rs +++ b/examples/task.rs @@ -5,11 +5,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}; + #[init] fn init(_: init::Context) -> init::LateResources { foo::spawn().unwrap(); diff --git a/examples/types.rs b/examples/types.rs index b55a98c660..815d309afb 100644 --- a/examples/types.rs +++ b/examples/types.rs @@ -5,12 +5,13 @@ #![no_main] #![no_std] -use cortex_m_semihosting::debug; use panic_semihosting as _; -use rtic::cyccnt; #[rtic::app(device = lm3s6965, peripherals = true, monotonic = rtic::cyccnt::CYCCNT)] mod app { + use cortex_m_semihosting::debug; + use rtic::cyccnt; + #[resources] struct Resources { #[init(0)] diff --git a/macros/src/codegen.rs b/macros/src/codegen.rs index 0cff5bbccc..c38b47c91e 100644 --- a/macros/src/codegen.rs +++ b/macros/src/codegen.rs @@ -22,35 +22,20 @@ mod util; // TODO document the syntax here or in `rtic-syntax` pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { let mut mod_app = vec![]; - let mut mod_app_imports = vec![]; 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 (mod_app_init, root_init, user_init, user_init_imports, call_init) = - init::codegen(app, analysis, extra); + let (mod_app_init, root_init, user_init, call_init) = init::codegen(app, analysis, extra); let post_init_stmts = post_init::codegen(&app, analysis); - let (mod_app_idle, root_idle, user_idle, user_idle_imports, call_idle) = - idle::codegen(app, analysis, extra); - - if user_init.is_some() { - mod_app_imports.push(quote!( - use super::init; - )) - } - if user_idle.is_some() { - mod_app_imports.push(quote!( - use super::idle; - )) - } + let (mod_app_idle, root_idle, user_idle, call_idle) = idle::codegen(app, analysis, extra); user.push(quote!( #user_init @@ -58,11 +43,6 @@ 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)* @@ -100,15 +80,10 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { mod_app_hardware_tasks, root_hardware_tasks, user_hardware_tasks, - user_hardware_tasks_imports, ) = hardware_tasks::codegen(app, analysis, extra); - let ( - mod_app_software_tasks, - root_software_tasks, - user_software_tasks, - user_software_tasks_imports, - ) = software_tasks::codegen(app, analysis, extra); + let (mod_app_software_tasks, root_software_tasks, user_software_tasks) = + software_tasks::codegen(app, analysis, extra); let mod_app_dispatchers = dispatchers::codegen(app, analysis, extra); let mod_app_timer_queue = timer_queue::codegen(app, analysis, extra); @@ -131,54 +106,66 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { } quote!( - #(#user)* - - #(#user_hardware_tasks)* - - #(#user_software_tasks)* - - #(#root)* - - #mod_resources - - #(#root_hardware_tasks)* - - #(#root_software_tasks)* - - /// Unused - #(#tasks)* - /// Implementation details 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; - #(#imports)* + + /// 2 #(#user_imports)* /// User code from within the module #(#user_code)* /// User code end + /// 3 + #(#user)* - #(#user_hardware_tasks_imports)* + /// 4 + #(#user_hardware_tasks)* - #(#user_software_tasks_imports)* + /// 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 bf6986b8d9..bd4061d118 100644 --- a/macros/src/codegen/dispatchers.rs +++ b/macros/src/codegen/dispatchers.rs @@ -90,6 +90,8 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec { @@ -98,7 +100,7 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> 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 mod_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 let Some(m) = extra.monotonic { @@ -50,6 +47,8 @@ pub fn codegen( let symbol = task.args.binds.clone(); let priority = task.args.priority; + let app_name = &app.name; + let app_path = quote! {crate::#app_name}; mod_app.push(quote!( #[allow(non_snake_case)] #[no_mangle] @@ -59,7 +58,7 @@ pub fn codegen( #let_instant rtic::export::run(PRIORITY, || { - crate::#name( + #app_path::#name( #locals_new #name::Context::new(&rtic::export::Priority::new(PRIORITY) #instant) ) @@ -79,13 +78,6 @@ 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); mod_app.push(constructor); @@ -121,13 +113,7 @@ pub fn codegen( #(#stmts)* } )); - - hardware_tasks_imports.push(quote!( - #(#attrs)* - #[allow(non_snake_case)] - use super::#name; - )); } - (mod_app, root, user_tasks, hardware_tasks_imports) + (mod_app, root, user_tasks) } diff --git a/macros/src/codegen/idle.rs b/macros/src/codegen/idle.rs index 5e73329f06..10196806b9 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::{format_ident, quote}; +use quote::quote; use rtic_syntax::{ast::App, Context}; use crate::{ @@ -23,8 +23,6 @@ pub fn codegen( Vec, // user_idle Option, - // user_idle_imports - Vec, // call_idle TokenStream2, ) { @@ -36,8 +34,6 @@ pub fn codegen( let mut locals_pat = None; let mut locals_new = None; - let mut user_idle_imports = vec![]; - let name = &idle.name; if !idle.args.resources.is_empty() { @@ -46,12 +42,6 @@ pub fn codegen( root_idle.push(item); mod_app = Some(constructor); - - let name_resource = format_ident!("{}Resources", name); - user_idle_imports.push(quote!( - #[allow(non_snake_case)] - use super::#name_resource; - )); } if !idle.locals.is_empty() { @@ -83,25 +73,21 @@ pub fn codegen( #(#stmts)* } )); - user_idle_imports.push(quote!( - #(#attrs)* - #[allow(non_snake_case)] - use super::#name; - )); + let app_name = &app.name; + let app_path = quote! {crate::#app_name}; let locals_new = locals_new.iter(); - let call_idle = quote!(crate::#name( + let call_idle = quote!(#app_path::#name( #(#locals_new,)* #name::Context::new(&rtic::export::Priority::new(0)) )); - (mod_app, root_idle, user_idle, user_idle_imports, call_idle) + (mod_app, root_idle, user_idle, call_idle) } else { ( None, vec![], None, - vec![], quote!(loop { rtic::export::wfi() }), diff --git a/macros/src/codegen/init.rs b/macros/src/codegen/init.rs index 465a927d79..922e43b5df 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::{format_ident, quote}; +use quote::quote; use rtic_syntax::{ast::App, Context}; use crate::{ @@ -24,8 +24,6 @@ pub fn codegen( Vec, // user_init -- the `#[init]` function written by the user Option, - // user_init_imports -- the imports for `#[init]` functio written by the user - Vec, // call_init -- the call to the user `#[init]` if there's one Option, ) { @@ -52,7 +50,6 @@ pub fn codegen( }) .collect::>(); - let mut user_init_imports = vec![]; let late_resources = util::late_resources_ident(&name); root_init.push(quote!( @@ -63,12 +60,6 @@ pub fn codegen( } )); - let name_late = format_ident!("{}LateResources", name); - user_init_imports.push(quote!( - #[allow(non_snake_case)] - use super::#name_late; - )); - let mut locals_pat = None; let mut locals_new = None; if !init.locals.is_empty() { @@ -90,11 +81,6 @@ pub fn codegen( #(#stmts)* } )); - user_init_imports.push(quote!( - #(#attrs)* - #[allow(non_snake_case)] - use super::#name; - )); let mut mod_app = None; if !init.args.resources.is_empty() { @@ -103,17 +89,13 @@ pub fn codegen( root_init.push(item); mod_app = Some(constructor); - - let name_late = format_ident!("{}Resources", name); - user_init_imports.push(quote!( - #[allow(non_snake_case)] - use super::#name_late; - )); } + let app_name = &app.name; + let app_path = quote! {crate::#app_name}; let locals_new = locals_new.iter(); let call_init = Some( - quote!(let late = crate::#name(#(#locals_new,)* #name::Context::new(core.into()));), + quote!(let late = #app_path::#name(#(#locals_new,)* #name::Context::new(core.into()));), ); root_init.push(module::codegen( @@ -124,8 +106,8 @@ pub fn codegen( extra, )); - (mod_app, root_init, user_init, user_init_imports, call_init) + (mod_app, root_init, user_init, call_init) } else { - (None, vec![], None, vec![], None) + (None, vec![], None, None) } } diff --git a/macros/src/codegen/resources.rs b/macros/src/codegen/resources.rs index 38ea52459e..d5ec583e2d 100644 --- a/macros/src/codegen/resources.rs +++ b/macros/src/codegen/resources.rs @@ -24,6 +24,7 @@ pub fn codegen( for (name, res, expr, _) in app.resources(analysis) { let cfgs = &res.cfgs; let ty = &res.ty; + let mangled_name = util::mangle_ident(&name); { let section = if expr.is_none() { @@ -47,7 +48,7 @@ pub fn codegen( #(#attrs)* #(#cfgs)* #section - static mut #name: #ty = #expr; + static mut #mangled_name: #ty = #expr; )); } @@ -76,12 +77,12 @@ pub fn codegen( let ptr = if expr.is_none() { quote!( #(#cfgs)* - #name.as_mut_ptr() + #mangled_name.as_mut_ptr() ) } else { quote!( #(#cfgs)* - &mut #name + &mut #mangled_name ) }; diff --git a/macros/src/codegen/resources_struct.rs b/macros/src/codegen/resources_struct.rs index 92d5b66633..ffc727573d 100644 --- a/macros/src/codegen/resources_struct.rs +++ b/macros/src/codegen/resources_struct.rs @@ -36,6 +36,7 @@ pub fn codegen( None }; let ty = &res.ty; + let mangled_name = util::mangle_ident(&name); if ctxt.is_init() { if !analysis.ownerships.contains_key(name) { @@ -47,7 +48,7 @@ pub fn codegen( values.push(quote!( #(#cfgs)* - #name: &#mut_ #name + #name: &#mut_ #mangled_name )); } else { // Owned by someone else @@ -60,7 +61,7 @@ pub fn codegen( values.push(quote!( #(#cfgs)* - #name: &mut #name + #name: &mut #mangled_name )); } } else { @@ -115,9 +116,9 @@ pub fn codegen( let is_late = expr.is_none(); if is_late { let expr = if mut_.is_some() { - quote!(&mut *#name.as_mut_ptr()) + quote!(&mut *#mangled_name.as_mut_ptr()) } else { - quote!(&*#name.as_ptr()) + quote!(&*#mangled_name.as_ptr()) }; values.push(quote!( @@ -127,7 +128,7 @@ pub fn codegen( } else { values.push(quote!( #(#cfgs)* - #name: &#mut_ #name + #name: &#mut_ #mangled_name )); } } diff --git a/macros/src/codegen/software_tasks.rs b/macros/src/codegen/software_tasks.rs index 9918dea10f..f5757a12db 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::{format_ident, quote}; +use quote::quote; use rtic_syntax::{ast::App, Context}; use crate::{ @@ -22,13 +22,10 @@ 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 mod_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; @@ -93,13 +90,6 @@ 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); mod_app.push(constructor); @@ -129,11 +119,6 @@ pub fn codegen( #(#stmts)* } )); - software_tasks_imports.push(quote!( - #(#cfgs)* - #[allow(non_snake_case)] - use super::#name; - )); root.push(module::codegen( Context::SoftwareTask(name), @@ -144,5 +129,5 @@ pub fn codegen( )); } - (mod_app, root, user_tasks, software_tasks_imports) + (mod_app, root, user_tasks) } diff --git a/macros/src/codegen/util.rs b/macros/src/codegen/util.rs index f04ccb23c2..887ee3bdfc 100644 --- a/macros/src/codegen/util.rs +++ b/macros/src/codegen/util.rs @@ -106,6 +106,14 @@ pub fn late_resources_ident(init: &Ident) -> Ident { ) } +/// Mangle an ident +pub fn mangle_ident(ident: &Ident) -> Ident { + Ident::new( + &format!("__rtic_internal_{}", ident.to_string()), + Span::call_site(), + ) +} + fn link_section_index() -> usize { static INDEX: AtomicUsize = AtomicUsize::new(0); From f076b33bb91e9cd2cb1f71ba22ebfebab085d3a8 Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Wed, 21 Oct 2020 20:20:26 +0200 Subject: [PATCH 2/4] 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 Date: Wed, 21 Oct 2020 20:24:06 +0200 Subject: [PATCH 3/4] Hide lock type better to not collide with user types --- macros/src/codegen/util.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/macros/src/codegen/util.rs b/macros/src/codegen/util.rs index 887ee3bdfc..d78da61d13 100644 --- a/macros/src/codegen/util.rs +++ b/macros/src/codegen/util.rs @@ -53,7 +53,7 @@ pub fn impl_mutex( type T = #ty; #[inline(always)] - fn lock(&mut self, f: impl FnOnce(&mut #ty) -> R) -> R { + fn lock(&mut self, f: impl FnOnce(&mut #ty) -> RTIC_INTERNAL_R) -> RTIC_INTERNAL_R { /// Priority ceiling const CEILING: u8 = #ceiling; From 17e976ab495234f9f53f56e6693850af077cf701 Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Wed, 21 Oct 2020 20:33:55 +0200 Subject: [PATCH 4/4] Fix UI tests Fix --- examples/static.rs | 10 +++++----- ui/single/resources-cfg.stderr | 30 +++++++++++++++--------------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/examples/static.rs b/examples/static.rs index 3b6cd4cd70..cd46145a4a 100644 --- a/examples/static.rs +++ b/examples/static.rs @@ -21,7 +21,7 @@ mod app { // Late resources #[resources] struct Resources { - ppppp: Producer<'static, u32, U4>, + p: 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 (ppppp, c) = Q.split(); + let (p, c) = Q.split(); // Initialization of late resources - init::LateResources { ppppp, c } + init::LateResources { p, c } } #[idle(resources = [c])] @@ -48,10 +48,10 @@ mod app { } } - #[task(binds = UART0, resources = [ppppp])] + #[task(binds = UART0, resources = [p])] fn uart0(c: uart0::Context) { static mut KALLE: u32 = 0; *KALLE += 1; - c.resources.ppppp.enqueue(42).unwrap(); + c.resources.p.enqueue(42).unwrap(); } } diff --git a/ui/single/resources-cfg.stderr b/ui/single/resources-cfg.stderr index 0b0c749d00..f47b13535d 100644 --- a/ui/single/resources-cfg.stderr +++ b/ui/single/resources-cfg.stderr @@ -4,7 +4,7 @@ error: duplicate lang item in crate `panic_halt` (which `$CRATE` depends on): `p = note: first definition in `std` loaded from /usr/share/rust/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-f14aca24435a5414.rlib = note: second definition in `panic_halt` loaded from $DIR/target/tests/target/x86_64-unknown-linux-gnu/debug/deps/libpanic_halt-33949299fdfa2375.rmeta -error[E0609]: no field `o1` on type `initResources<'_>` +error[E0609]: no field `o1` on type `app::initResources<'_>` --> $DIR/resources-cfg.rs:47:21 | 47 | c.resources.o1; @@ -12,7 +12,7 @@ error[E0609]: no field `o1` on type `initResources<'_>` | = note: available fields are: `__marker__` -error[E0609]: no field `o4` on type `initResources<'_>` +error[E0609]: no field `o4` on type `app::initResources<'_>` --> $DIR/resources-cfg.rs:48:21 | 48 | c.resources.o4; @@ -20,7 +20,7 @@ error[E0609]: no field `o4` on type `initResources<'_>` | = note: available fields are: `__marker__` -error[E0609]: no field `o5` on type `initResources<'_>` +error[E0609]: no field `o5` on type `app::initResources<'_>` --> $DIR/resources-cfg.rs:49:21 | 49 | c.resources.o5; @@ -28,7 +28,7 @@ error[E0609]: no field `o5` on type `initResources<'_>` | = note: available fields are: `__marker__` -error[E0609]: no field `o6` on type `initResources<'_>` +error[E0609]: no field `o6` on type `app::initResources<'_>` --> $DIR/resources-cfg.rs:50:21 | 50 | c.resources.o6; @@ -36,7 +36,7 @@ error[E0609]: no field `o6` on type `initResources<'_>` | = note: available fields are: `__marker__` -error[E0609]: no field `s3` on type `initResources<'_>` +error[E0609]: no field `s3` on type `app::initResources<'_>` --> $DIR/resources-cfg.rs:51:21 | 51 | c.resources.s3; @@ -44,7 +44,7 @@ error[E0609]: no field `s3` on type `initResources<'_>` | = note: available fields are: `__marker__` -error[E0609]: no field `o2` on type `idleResources<'_>` +error[E0609]: no field `o2` on type `app::idleResources<'_>` --> $DIR/resources-cfg.rs:58:21 | 58 | c.resources.o2; @@ -52,7 +52,7 @@ error[E0609]: no field `o2` on type `idleResources<'_>` | = note: available fields are: `__marker__` -error[E0609]: no field `o4` on type `idleResources<'_>` +error[E0609]: no field `o4` on type `app::idleResources<'_>` --> $DIR/resources-cfg.rs:59:21 | 59 | c.resources.o4; @@ -60,7 +60,7 @@ error[E0609]: no field `o4` on type `idleResources<'_>` | = note: available fields are: `__marker__` -error[E0609]: no field `s1` on type `idleResources<'_>` +error[E0609]: no field `s1` on type `app::idleResources<'_>` --> $DIR/resources-cfg.rs:60:21 | 60 | c.resources.s1; @@ -68,7 +68,7 @@ error[E0609]: no field `s1` on type `idleResources<'_>` | = note: available fields are: `__marker__` -error[E0609]: no field `s3` on type `idleResources<'_>` +error[E0609]: no field `s3` on type `app::idleResources<'_>` --> $DIR/resources-cfg.rs:61:21 | 61 | c.resources.s3; @@ -76,7 +76,7 @@ error[E0609]: no field `s3` on type `idleResources<'_>` | = note: available fields are: `__marker__` -error[E0609]: no field `o3` on type `uart0Resources<'_>` +error[E0609]: no field `o3` on type `app::uart0Resources<'_>` --> $DIR/resources-cfg.rs:68:21 | 68 | c.resources.o3; @@ -84,7 +84,7 @@ error[E0609]: no field `o3` on type `uart0Resources<'_>` | = note: available fields are: `__marker__` -error[E0609]: no field `s1` on type `uart0Resources<'_>` +error[E0609]: no field `s1` on type `app::uart0Resources<'_>` --> $DIR/resources-cfg.rs:69:21 | 69 | c.resources.s1; @@ -92,7 +92,7 @@ error[E0609]: no field `s1` on type `uart0Resources<'_>` | = note: available fields are: `__marker__` -error[E0609]: no field `s2` on type `uart0Resources<'_>` +error[E0609]: no field `s2` on type `app::uart0Resources<'_>` --> $DIR/resources-cfg.rs:70:21 | 70 | c.resources.s2; @@ -100,7 +100,7 @@ error[E0609]: no field `s2` on type `uart0Resources<'_>` | = note: available fields are: `__marker__` -error[E0609]: no field `s3` on type `uart0Resources<'_>` +error[E0609]: no field `s3` on type `app::uart0Resources<'_>` --> $DIR/resources-cfg.rs:71:21 | 71 | c.resources.s3; @@ -108,7 +108,7 @@ error[E0609]: no field `s3` on type `uart0Resources<'_>` | = note: available fields are: `__marker__` -error[E0609]: no field `s2` on type `uart1Resources<'_>` +error[E0609]: no field `s2` on type `app::uart1Resources<'_>` --> $DIR/resources-cfg.rs:76:21 | 76 | c.resources.s2; @@ -116,7 +116,7 @@ error[E0609]: no field `s2` on type `uart1Resources<'_>` | = note: available fields are: `__marker__` -error[E0609]: no field `o5` on type `uart1Resources<'_>` +error[E0609]: no field `o5` on type `app::uart1Resources<'_>` --> $DIR/resources-cfg.rs:77:21 | 77 | c.resources.o5;