mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-11-23 20:22:51 +01:00
rename rtfm! to app! and adapt to changes in rtfm-syntax
This commit is contained in:
parent
98596554b3
commit
e9788ff9b6
4 changed files with 27 additions and 28 deletions
|
@ -1,10 +1,11 @@
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use quote::Tokens;
|
use quote::Tokens;
|
||||||
use rtfm_syntax::{Idents, Idle, Init, Statics};
|
|
||||||
use syn::Ident;
|
use syn::Ident;
|
||||||
|
use syntax::check::{self, Idle, Init};
|
||||||
|
use syntax::{self, Idents, Statics};
|
||||||
|
|
||||||
use error::*;
|
use syntax::error::*;
|
||||||
|
|
||||||
pub struct App {
|
pub struct App {
|
||||||
pub device: Tokens,
|
pub device: Tokens,
|
||||||
|
@ -22,27 +23,28 @@ pub struct Task {
|
||||||
pub resources: Idents,
|
pub resources: Idents,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn app(app: ::rtfm_syntax::App) -> Result<App> {
|
pub fn app(app: check::App) -> Result<App> {
|
||||||
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))?,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
let app = App {
|
let app = App {
|
||||||
device: app.device,
|
device: app.device,
|
||||||
idle: app.idle,
|
idle: app.idle,
|
||||||
init: app.init,
|
init: app.init,
|
||||||
resources: app.resources,
|
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::<Result<_>>()
|
||||||
|
.chain_err(|| "checking `tasks`")?,
|
||||||
};
|
};
|
||||||
|
|
||||||
::check::resources(&app)?;
|
::check::resources(&app)
|
||||||
|
.chain_err(|| "checking `resources`")?;
|
||||||
|
|
||||||
Ok(app)
|
Ok(app)
|
||||||
}
|
}
|
||||||
|
@ -66,7 +68,7 @@ fn resources(app: &App) -> Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn task(task: ::rtfm_syntax::Task) -> Result<Task> {
|
fn task(task: syntax::check::Task) -> Result<Task> {
|
||||||
if let Some(priority) = task.priority {
|
if let Some(priority) = task.priority {
|
||||||
Ok(Task {
|
Ok(Task {
|
||||||
enabled: task.enabled,
|
enabled: task.enabled,
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
error_chain!();
|
|
|
@ -6,21 +6,20 @@ extern crate error_chain;
|
||||||
extern crate proc_macro;
|
extern crate proc_macro;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate quote;
|
extern crate quote;
|
||||||
extern crate rtfm_syntax;
|
extern crate rtfm_syntax as syntax;
|
||||||
extern crate syn;
|
extern crate syn;
|
||||||
|
|
||||||
use proc_macro::TokenStream;
|
use proc_macro::TokenStream;
|
||||||
use rtfm_syntax::App;
|
use syntax::App;
|
||||||
|
|
||||||
use error::*;
|
use syntax::error::*;
|
||||||
|
|
||||||
mod analyze;
|
mod analyze;
|
||||||
mod check;
|
mod check;
|
||||||
mod error;
|
|
||||||
mod trans;
|
mod trans;
|
||||||
|
|
||||||
#[proc_macro]
|
#[proc_macro]
|
||||||
pub fn rtfm(ts: TokenStream) -> TokenStream {
|
pub fn app(ts: TokenStream) -> TokenStream {
|
||||||
match run(ts) {
|
match run(ts) {
|
||||||
Err(e) => panic!("{}", error_chain::ChainedError::display(&e)),
|
Err(e) => panic!("{}", error_chain::ChainedError::display(&e)),
|
||||||
Ok(ts) => ts,
|
Ok(ts) => ts,
|
||||||
|
@ -30,10 +29,9 @@ pub fn rtfm(ts: TokenStream) -> TokenStream {
|
||||||
fn run(ts: TokenStream) -> Result<TokenStream> {
|
fn run(ts: TokenStream) -> Result<TokenStream> {
|
||||||
let input = format!("{}", ts);
|
let input = format!("{}", ts);
|
||||||
|
|
||||||
let app = check::app(App::parse(&input)
|
let app = App::parse(&input).chain_err(|| "parsing")?;
|
||||||
.chain_err(|| "parsing the `rtfm!` macro")?).chain_err(
|
let app = syntax::check::app(app).chain_err(|| "checking the AST")?;
|
||||||
|| "checking the application specification",
|
let app = check::app(app)?;
|
||||||
)?;
|
|
||||||
|
|
||||||
let ownerships = analyze::app(&app);
|
let ownerships = analyze::app(&app);
|
||||||
let tokens = trans::app(&app, &ownerships);
|
let tokens = trans::app(&app, &ownerships);
|
||||||
|
|
|
@ -10,7 +10,7 @@ extern crate static_ref;
|
||||||
|
|
||||||
use core::cell::UnsafeCell;
|
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::asm::{bkpt, wfi};
|
||||||
pub use cortex_m::interrupt::CriticalSection;
|
pub use cortex_m::interrupt::CriticalSection;
|
||||||
pub use cortex_m::interrupt::free as atomic;
|
pub use cortex_m::interrupt::free as atomic;
|
||||||
|
|
Loading…
Reference in a new issue