Skip to content

Commit

Permalink
Merge #140
Browse files Browse the repository at this point in the history
140: entry/exception/interrupt: improvements to the `static mut` transformation r=therealprof a=japaric

see individual commits for details

Co-authored-by: Jorge Aparicio <jorge@japaric.io>
  • Loading branch information
bors[bot] and japaric committed Oct 26, 2018
2 parents ac9c053 + 0180258 commit c5d24f8
Showing 1 changed file with 21 additions and 24 deletions.
45 changes: 21 additions & 24 deletions cortex-m-rt/macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,20 +113,19 @@ pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream {
let vars = statics
.into_iter()
.map(|var| {
let attrs = var.attrs;
let ident = var.ident;
// `let` can't shadow a `static mut` so we must give the `static` a different
// name. We'll create a new name by appending an underscore to the original name
// of the `static`.
let mut ident_ = ident.to_string();
ident_.push('_');
let ident_ = Ident::new(&ident_, Span::call_site());
let ty = var.ty;
let expr = var.expr;

quote!(
static mut #ident_: #ty = #expr;
#[allow(non_snake_case)]
let #ident: &'static mut #ty = unsafe { &mut #ident_ };
let #ident: &'static mut #ty = unsafe {
#(#attrs)*
static mut #ident: #ty = #expr;

&mut #ident
};
)
}).collect::<Vec<_>>();

Expand Down Expand Up @@ -401,20 +400,19 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream {
let vars = statics
.into_iter()
.map(|var| {
let attrs = var.attrs;
let ident = var.ident;
// `let` can't shadow a `static mut` so we must give the `static` a different
// name. We'll create a new name by appending an underscore to the original name
// of the `static`.
let mut ident_ = ident.to_string();
ident_.push('_');
let ident_ = Ident::new(&ident_, Span::call_site());
let ty = var.ty;
let expr = var.expr;

quote!(
static mut #ident_: #ty = #expr;
#[allow(non_snake_case)]
let #ident: &mut #ty = unsafe { &mut #ident_ };
let #ident: &mut #ty = unsafe {
#(#attrs)*
static mut #ident: #ty = #expr;

&mut #ident
};
)
}).collect::<Vec<_>>();

Expand Down Expand Up @@ -545,20 +543,19 @@ pub fn interrupt(args: TokenStream, input: TokenStream) -> TokenStream {
let vars = statics
.into_iter()
.map(|var| {
let attrs = var.attrs;
let ident = var.ident;
// `let` can't shadow a `static mut` so we must give the `static` a different
// name. We'll create a new name by appending an underscore to the original name
// of the `static`.
let mut ident_ = ident.to_string();
ident_.push('_');
let ident_ = Ident::new(&ident_, Span::call_site());
let ty = var.ty;
let expr = var.expr;

quote!(
static mut #ident_: #ty = #expr;
#[allow(non_snake_case)]
let #ident: &mut #ty = unsafe { &mut #ident_ };
let #ident: &mut #ty = unsafe {
#(#attrs)*
static mut #ident: #ty = #expr;

&mut #ident
};
)
}).collect::<Vec<_>>();

Expand Down

0 comments on commit c5d24f8

Please sign in to comment.