diff options
author | 2017-07-06 23:25:29 -0500 | |
---|---|---|
committer | 2017-07-06 23:25:29 -0500 | |
commit | 3cebf49a2feb10b6dbf7e40e4671dbf7a3d8bedf (patch) | |
tree | d9b842d6f60439370ef81a4015993ed70f9aa7f8 /macros/src/syntax/parse.rs | |
parent | 4b0c3bff871eb6125835fd911891bf503c61c820 (diff) | |
download | rtic-3cebf49a2feb10b6dbf7e40e4671dbf7a3d8bedf.tar.gz rtic-3cebf49a2feb10b6dbf7e40e4671dbf7a3d8bedf.tar.zst rtic-3cebf49a2feb10b6dbf7e40e4671dbf7a3d8bedf.zip |
syntax tweaks, relax check, add set_pending(), deal with imported types
- allow trailing commas in list of resources
- make task.resources optional
- add rtfm::set_pending function which can be used to force an interrupt into
the pending state. This is a replacement of the old rtfm::request.
rtfm::set_pending takes the Interrupt enum provided by the device crate as
argument. (The old rtfm::request took a task function as argument)
- the user may want to use types they imported into the root of the crate. These
types are not available in e.g. `mod idle` so `idle::Resources` *can't* be
defined in that module. To workaround this problem `idle::Resources` will be
defined in the root, with some other name, and then be re-exported in the
`idle` module.
- remove the "a resource only used by one task should be local data" check. In
some cases you do want a resource owned by a single task instead of local
data since `init` can access resources but not a task local data.
Diffstat (limited to 'macros/src/syntax/parse.rs')
-rw-r--r-- | macros/src/syntax/parse.rs | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/macros/src/syntax/parse.rs b/macros/src/syntax/parse.rs index 9cfbd78b..056e804a 100644 --- a/macros/src/syntax/parse.rs +++ b/macros/src/syntax/parse.rs @@ -2,7 +2,7 @@ use std::collections::{HashMap, HashSet}; use syn::{self, DelimToken, Ident, IntTy, Lit, Token, TokenTree}; -use syntax::{App, Idle, Init, Kind, Resource, Resources, Task, Tasks}; +use syntax::{App, Idle, Init, Kind, Resource, Statics, Task, Tasks}; pub fn app(input: &str) -> App { let tts = syn::parse_token_trees(input).unwrap(); @@ -96,7 +96,7 @@ pub fn app(input: &str) -> App { block.delim ); - resources = Some(super::parse::resources(block.tts)); + resources = Some(super::parse::statics(block.tts)); } } "tasks" => { @@ -169,7 +169,7 @@ pub fn idle(tts: Vec<TokenTree>) -> Idle { block.delim ); - local = Some(super::parse::resources(block.tts)); + local = Some(super::parse::statics(block.tts)); } else { panic!("expected block, found {:?}", tt); } @@ -273,7 +273,7 @@ pub fn init(tts: Vec<TokenTree>) -> Init { fn idents(tts: Vec<TokenTree>) -> HashSet<Ident> { let mut idents = HashSet::new(); - let mut tts = tts.into_iter(); + let mut tts = tts.into_iter().peekable(); while let Some(tt) = tts.next() { if let TokenTree::Token(Token::Ident(id)) = tt { assert!(!idents.contains(&id), "ident {} already listed", id); @@ -281,6 +281,10 @@ fn idents(tts: Vec<TokenTree>) -> HashSet<Ident> { if let Some(tt) = tts.next() { assert_eq!(tt, TokenTree::Token(Token::Comma)); + + if tts.peek().is_none() { + break; + } } else { break; } @@ -292,7 +296,7 @@ fn idents(tts: Vec<TokenTree>) -> HashSet<Ident> { idents } -pub fn resources(tts: Vec<TokenTree>) -> Resources { +pub fn statics(tts: Vec<TokenTree>) -> Statics { let mut resources = HashMap::new(); let mut tts = tts.into_iter(); @@ -502,7 +506,7 @@ fn task(tts: Vec<TokenTree>) -> Task { ); } - let resources = resources.expect("resources field is missing"); + let resources = resources.unwrap_or(HashSet::new()); let priority = priority.expect("priority field is missing"); let kind = if let Some(enabled) = enabled { Kind::Interrupt { enabled } |