Skip to content
Snippets Groups Projects
Select Git revision
  • b47e562abaa2d0e055d47d4c7162d9cbf5af8d43
  • master default protected
2 results

assign.rs

Blame
  • lib.rs 2.83 KiB
    //! Parser of the `app!` macro used by the Real Time For the Masses (RTFM)
    //! framework
    #![deny(missing_debug_implementations)]
    #![deny(missing_docs)]
    // #![deny(warnings)]
    
    #[macro_use]
    extern crate error_chain;
    #[macro_use]
    extern crate quote;
    extern crate syn;
    
    pub mod check;
    pub mod error;
    
    mod parse;
    mod util;
    
    use std::collections::{HashMap, HashSet};
    
    use quote::Tokens;
    use syn::{Ident, Path, Ty};
    
    use error::*;
    
    /// A rust expression
    pub type Expr = Tokens;
    
    /// `[$($ident),*]`
    pub type Resources = HashSet<Ident>;
    
    /// `$(static $Ident: $Ty = $expr;)*`
    pub type Statics = HashMap<Ident, Static>;
    
    /// `$($Ident: { .. },)*`
    pub type Tasks = HashMap<Ident, Task>;
    
    /// `app! { .. }`
    #[derive(Debug)]
    pub struct App {
        /// `device: $path`
        pub device: Path,
        /// `idle: { $Idle }`
        pub idle: Option<Idle>,
        /// `init: { $Init }`
        pub init: Option<Init>,
        /// `resources: $Resources`
        pub resources: Option<Statics>,
        /// `tasks: { $Tasks }`
        pub tasks: Option<Tasks>,
        _extensible: (),
    }
    
    /// `idle: { .. }`
    #[derive(Debug)]
    pub struct Idle {
        /// `path: $Path`
        pub path: Option<Path>,
        /// `resources: $Resources`
        pub resources: Option<Resources>,
        _extensible: (),
    }
    
    /// `init: { .. }`
    #[derive(Debug)]
    pub struct Init {
        /// `path: $Path`
        pub path: Option<Path>,
        _extensible: (),
    }
    
    /// `$Ident: { .. }`
    #[derive(Debug)]
    pub struct Task {
        /// `enabled: $bool`
        pub enabled: Option<bool>,
        /// `path: $Path`
        pub path: Option<Path>,
        /// `priority: $u8`
        pub priority: Option<u8>,
        /// `resources: $Resources`
        pub resources: Option<Resources>,
        _extensible: (),
    }
    
    /// `static $Ident: $Ty = $Expr;`
    #[derive(Debug)]
    pub struct Static {
        /// `$Expr`
        pub expr: Expr,
        /// `$Ty`
        pub ty: Ty,
        _extensible: (),
    }
    
    impl App {
        /// Parses the contents of the `app! { .. }` macro
        pub fn parse(input: &str) -> Result<Self> {
            parse::app(input)
        }
    }
    
    /// Crc related
    
    /// `$($Ident: $Path,)*`
    pub type Crcs = HashMap<Ident, Path>;
    
    /// Input port binding
    #[derive(Debug)]
    pub enum IpTo {
        /// Input port connecting to inner Crc
        Crc(Path),
        /// Input port connecting to method
        Method(Ident),
    }
    
    /// `$($Ident: Ident ($Ty) -> $Ty )*`
    pub type Ips = HashMap<Ident, (Option<Ty>, Ty, Option<Resources>)>;
    
    /// `$($Ident: $Ty = $Expr < $Path,)*`
    //pub type Ops = HashMap<Ident, (Ty, Expr, Path)>;
    pub type Ops = HashMap<Ident, (Option<Ty>, Ty)>;
    
    /// `cro! { .. }`
    #[derive(Debug)]
    pub struct Cro {
        /// Input ports (should not be None, given we have interrupts at top level)
        pub ips: Option<Ips>,
        /// Output ports (should not be None, given we treat peripherals as Crcs)
        pub ops: Option<Ops>,
    }
    
    impl Cro {
        /// Parses the contents of the `sys! { .. }` macro
        pub fn parse(input: &str) -> Result<Self> {
            parse::cro(input)
        }
    }