Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] safe creation of &'static mut references #49

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ version = "0.2.0"
[dependencies]
error-chain = "0.10.0"
quote = "0.3.15"
rtfm-syntax = "0.2.0"
# rtfm-syntax = "0.2.0"
rtfm-syntax = { git = "https://github.com/japaric/rtfm-syntax", branch = "root" }
syn = "0.11.11"

[lib]
Expand Down
2 changes: 2 additions & 0 deletions macros/src/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub struct App {
pub idle: Idle,
pub init: Init,
pub resources: Statics,
pub root: Option<Path>,
pub tasks: Tasks,
}

Expand Down Expand Up @@ -60,6 +61,7 @@ pub fn app(app: check::App) -> Result<App> {
idle: app.idle,
init: app.init,
resources: app.resources,
root: app.root,
tasks: app.tasks
.into_iter()
.map(|(k, v)| {
Expand Down
44 changes: 35 additions & 9 deletions macros/src/trans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub fn app(app: &App, ownerships: &Ownerships) -> Tokens {
let mut root = vec![];
let mut main = vec![];

::trans::root(app, &mut main);
::trans::init(app, &mut main, &mut root);
::trans::idle(app, ownerships, &mut main, &mut root);
::trans::resources(app, ownerships, &mut root);
Expand Down Expand Up @@ -309,18 +310,34 @@ fn init(app: &App, main: &mut Vec<Tokens>, root: &mut Vec<Tokens>) {
}

let init = &app.init.path;
main.push(quote! {
// type check
let init: fn(#(#tys,)*) #ret = #init;
// TODO DRY
if app.root.is_some() {
main.push(quote! {
// type check
let init: fn(#(#tys,)* &'static mut _) #ret = #init;

#krate::atomic(unsafe { &mut #krate::Threshold::new(0) }, |_t| unsafe {
let _late_resources = init(#(#exprs,)* &mut *(&mut root as *mut _));
#(#late_resource_init)*

#(#exceptions)*
#(#interrupts)*
});
});
} else {
main.push(quote! {
// type check
let init: fn(#(#tys,)*) #ret = #init;

#krate::atomic(unsafe { &mut #krate::Threshold::new(0) }, |_t| unsafe {
let _late_resources = init(#(#exprs,)*);
#(#late_resource_init)*
#krate::atomic(unsafe { &mut #krate::Threshold::new(0) }, |_t| unsafe {
let _late_resources = init(#(#exprs,)*);
#(#late_resource_init)*

#(#exceptions)*
#(#interrupts)*
#(#exceptions)*
#(#interrupts)*
});
});
});
}
}

fn resources(app: &App, ownerships: &Ownerships, root: &mut Vec<Tokens>) {
Expand Down Expand Up @@ -539,6 +556,15 @@ fn resources(app: &App, ownerships: &Ownerships, root: &mut Vec<Tokens>) {
});
}

fn root(app: &App, main: &mut Vec<Tokens>) {
if let Some(root) = app.root.as_ref() {
main.push(quote! {
let root: fn() -> _ = #root;
let mut root = root();
});
}
}

fn tasks(app: &App, ownerships: &Ownerships, root: &mut Vec<Tokens>) {
let device = &app.device;
let krate = krate();
Expand Down