From e9788ff9b69a3725f39db4aa31c36946b53bea64 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Fri, 14 Jul 2017 20:47:06 -0500 Subject: [PATCH] rename rtfm! to app! and adapt to changes in rtfm-syntax --- macros/src/check.rs | 36 +++++++++++++++++++----------------- macros/src/error.rs | 1 - macros/src/lib.rs | 16 +++++++--------- src/lib.rs | 2 +- 4 files changed, 27 insertions(+), 28 deletions(-) delete mode 100644 macros/src/error.rs diff --git a/macros/src/check.rs b/macros/src/check.rs index a459ab297e..b8e6edd8b8 100644 --- a/macros/src/check.rs +++ b/macros/src/check.rs @@ -1,10 +1,11 @@ use std::collections::HashMap; use quote::Tokens; -use rtfm_syntax::{Idents, Idle, Init, Statics}; use syn::Ident; +use syntax::check::{self, Idle, Init}; +use syntax::{self, Idents, Statics}; -use error::*; +use syntax::error::*; pub struct App { pub device: Tokens, @@ -22,27 +23,28 @@ pub struct Task { pub resources: Idents, } -pub fn app(app: ::rtfm_syntax::App) -> Result { - let mut tasks = HashMap::new(); - - for (k, v) in app.tasks { - let name = k.clone(); - tasks.insert( - k, - ::check::task(v) - .chain_err(|| format!("checking task `{}`", name))?, - ); - } - +pub fn app(app: check::App) -> Result { let app = App { device: app.device, idle: app.idle, init: app.init, resources: app.resources, - tasks, + tasks: app.tasks + .into_iter() + .map(|(k, v)| { + let name = k.clone(); + Ok(( + k, + ::check::task(v) + .chain_err(|| format!("checking task `{}`", name))?, + )) + }) + .collect::>() + .chain_err(|| "checking `tasks`")?, }; - ::check::resources(&app)?; + ::check::resources(&app) + .chain_err(|| "checking `resources`")?; Ok(app) } @@ -66,7 +68,7 @@ fn resources(app: &App) -> Result<()> { Ok(()) } -fn task(task: ::rtfm_syntax::Task) -> Result { +fn task(task: syntax::check::Task) -> Result { if let Some(priority) = task.priority { Ok(Task { enabled: task.enabled, diff --git a/macros/src/error.rs b/macros/src/error.rs deleted file mode 100644 index c044473728..0000000000 --- a/macros/src/error.rs +++ /dev/null @@ -1 +0,0 @@ -error_chain!(); diff --git a/macros/src/lib.rs b/macros/src/lib.rs index 467cbb9360..b33f43b68e 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -6,21 +6,20 @@ extern crate error_chain; extern crate proc_macro; #[macro_use] extern crate quote; -extern crate rtfm_syntax; +extern crate rtfm_syntax as syntax; extern crate syn; use proc_macro::TokenStream; -use rtfm_syntax::App; +use syntax::App; -use error::*; +use syntax::error::*; mod analyze; mod check; -mod error; mod trans; #[proc_macro] -pub fn rtfm(ts: TokenStream) -> TokenStream { +pub fn app(ts: TokenStream) -> TokenStream { match run(ts) { Err(e) => panic!("{}", error_chain::ChainedError::display(&e)), Ok(ts) => ts, @@ -30,10 +29,9 @@ pub fn rtfm(ts: TokenStream) -> TokenStream { fn run(ts: TokenStream) -> Result { let input = format!("{}", ts); - let app = check::app(App::parse(&input) - .chain_err(|| "parsing the `rtfm!` macro")?).chain_err( - || "checking the application specification", - )?; + let app = App::parse(&input).chain_err(|| "parsing")?; + let app = syntax::check::app(app).chain_err(|| "checking the AST")?; + let app = check::app(app)?; let ownerships = analyze::app(&app); let tokens = trans::app(&app, &ownerships); diff --git a/src/lib.rs b/src/lib.rs index daca2d0d8e..c1c7c8f74e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,7 +10,7 @@ extern crate static_ref; use core::cell::UnsafeCell; -pub use cortex_m_rtfm_macros::rtfm; +pub use cortex_m_rtfm_macros::app; pub use cortex_m::asm::{bkpt, wfi}; pub use cortex_m::interrupt::CriticalSection; pub use cortex_m::interrupt::free as atomic;