use core::ops::Deref;
use std::collections::BTreeMap;
use syn::{Attribute, Expr, Ident, Pat, PatType, Path, Stmt, Type};
use crate::{Core, Map, Set};
#[derive(Debug)]
pub struct App {
pub args: AppArgs,
pub name: Ident,
pub inits: Inits,
pub idles: Idles,
pub late_resources: Map<LateResource>,
pub resources: Map<Resource>,
pub hardware_tasks: Map<HardwareTask>,
pub software_tasks: Map<SoftwareTask>,
pub extern_interrupts: ExternInterrupts,
pub(crate) _extensible: (),
}
pub type ExternInterrupts = BTreeMap<Core, Map<ExternInterrupt>>;
#[derive(Debug)]
pub struct AppArgs {
pub cores: u8,
pub custom: Map<CustomArg>,
}
#[derive(Debug)]
pub enum CustomArg {
Bool(bool),
UInt(String),
Path(Path),
}
pub type Inits = BTreeMap<u8, Init>;
pub type Idles = BTreeMap<u8, Idle>;
#[derive(Debug)]
pub struct Init {
pub args: InitArgs,
pub attrs: Vec<Attribute>,
pub name: Ident,
pub context: Box<Pat>,
pub returns_late_resources: bool,
pub locals: Map<Local>,
pub stmts: Vec<Stmt>,
pub(crate) _extensible: (),
}
#[derive(Debug, Default)]
pub struct InitArgs {
pub core: u8,
pub late: Set<Ident>,
pub resources: Resources,
pub spawn: Set<Ident>,
pub schedule: Set<Ident>,
pub(crate) _extensible: (),
}
#[derive(Debug)]
pub struct Idle {
pub args: IdleArgs,
pub attrs: Vec<Attribute>,
pub name: Ident,
pub context: Box<Pat>,
pub locals: Map<Local>,
pub stmts: Vec<Stmt>,
pub(crate) _extensible: (),
}
#[derive(Debug)]
pub struct IdleArgs {
pub core: u8,
pub resources: Resources,
pub spawn: Set<Ident>,
pub schedule: Set<Ident>,
pub(crate) _extensible: (),
}
#[derive(Debug)]
pub struct Resource {
pub(crate) late: LateResource,
pub expr: Box<Expr>,
}
impl Deref for Resource {
type Target = LateResource;
fn deref(&self) -> &LateResource {
&self.late
}
}
#[derive(Debug)]
pub struct LateResource {
pub cfgs: Vec<Attribute>,
pub attrs: Vec<Attribute>,
pub shared: bool,
pub ty: Box<Type>,
pub(crate) _extensible: (),
}
#[derive(Debug)]
pub struct SoftwareTask {
pub args: SoftwareTaskArgs,
pub cfgs: Vec<Attribute>,
pub attrs: Vec<Attribute>,
pub context: Box<Pat>,
pub inputs: Vec<PatType>,
pub locals: Map<Local>,
pub stmts: Vec<Stmt>,
pub(crate) _extensible: (),
}
#[derive(Debug)]
pub struct SoftwareTaskArgs {
pub core: u8,
pub capacity: u8,
pub priority: u8,
pub resources: Resources,
pub spawn: Set<Ident>,
pub schedule: Set<Ident>,
pub(crate) _extensible: (),
}
impl Default for SoftwareTaskArgs {
fn default() -> Self {
Self {
core: 0,
capacity: 1,
priority: 1,
resources: Resources::new(),
spawn: Set::new(),
schedule: Set::new(),
_extensible: (),
}
}
}
#[derive(Debug)]
pub struct HardwareTask {
pub args: HardwareTaskArgs,
pub attrs: Vec<Attribute>,
pub context: Box<Pat>,
pub locals: Map<Local>,
pub stmts: Vec<Stmt>,
pub(crate) _extensible: (),
}
#[derive(Debug)]
pub struct HardwareTaskArgs {
pub core: u8,
pub binds: Ident,
pub priority: u8,
pub resources: Resources,
pub spawn: Set<Ident>,
pub schedule: Set<Ident>,
pub(crate) _extensible: (),
}
#[derive(Debug)]
pub struct ExternInterrupt {
pub attrs: Vec<Attribute>,
pub(crate) _extensible: (),
}
#[derive(Debug)]
pub struct Local {
pub attrs: Vec<Attribute>,
pub cfgs: Vec<Attribute>,
pub shared: bool,
pub ty: Box<Type>,
pub expr: Box<Expr>,
pub(crate) _extensible: (),
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum Access {
Exclusive,
Shared,
}
impl Access {
pub fn is_exclusive(&self) -> bool {
*self == Access::Exclusive
}
pub fn is_shared(&self) -> bool {
*self == Access::Shared
}
}
pub type Resources = Map<Access>;