use proc_macro2::{Span, TokenStream as TokenStream2}; use quote::quote; use rtic_syntax::ast::App; use syn::Index; use crate::{analyze::Analysis, codegen::util}; /// Generates code that runs after `#[init]` returns pub fn codegen(app: &App, analysis: &Analysis) -> Vec { let mut stmts = vec![]; // Initialize shared resources for (name, res) in &app.shared_resources { let mangled_name = util::static_shared_resource_ident(name); // If it's live let cfgs = res.cfgs.clone(); if analysis.shared_resources.get(name).is_some() { stmts.push(quote!( // We include the cfgs #(#cfgs)* // Resource is a RacyCell> // - `get_mut` to obtain a raw pointer to `MaybeUninit` // - `write` the defined value for the late resource T #mangled_name.get_mut().write(core::mem::MaybeUninit::new(shared_resources.#name)); )); } } // Initialize local resources for (name, res) in &app.local_resources { let mangled_name = util::static_local_resource_ident(name); // If it's live let cfgs = res.cfgs.clone(); if analysis.local_resources.get(name).is_some() { stmts.push(quote!( // We include the cfgs #(#cfgs)* // Resource is a RacyCell> // - `get_mut` to obtain a raw pointer to `MaybeUninit` // - `write` the defined value for the late resource T #mangled_name.get_mut().write(core::mem::MaybeUninit::new(local_resources.#name)); )); } } for (i, (monotonic, _)) in app.monotonics.iter().enumerate() { // For future use // let doc = format!(" RTIC internal: {}:{}", file!(), line!()); // stmts.push(quote!(#[doc = #doc])); #[allow(clippy::cast_possible_truncation)] let idx = Index { index: i as u32, span: Span::call_site(), }; stmts.push(quote!(monotonics.#idx.reset();)); // Store the monotonic let name = util::monotonic_ident(&monotonic.to_string()); stmts.push(quote!(#name.get_mut().write(Some(monotonics.#idx));)); } // Enable the interrupts -- this completes the `init`-ialization phase stmts.push(quote!(rtic::export::interrupt::enable();)); stmts } ass-helper Unnamed repository; edit this file 'description' to name the repository.
aboutsummaryrefslogtreecommitdiff
AgeCommit message (Expand)AuthorFilesLines
2022-06-22Move builtins to src/javascript/jsc/builtinsGravatar Jarred Sumner 72-6/+2285
2022-06-22Tweak test runner outputGravatar Jarred Sumner 1-90/+44
2022-06-22Cleanup some testsGravatar Jarred Sumner 2-8/+46
2022-06-22Update Dockerfile.baseGravatar Jarred Sumner 1-1/+1
2022-06-22Update WebKitGravatar Jarred Sumner 1-0/+0
2022-06-22cleanup websocket testGravatar Jarred Sumner 1-3/+6
2022-06-22Fix `WebSocket` when HTTP server is not runningGravatar Jarred Sumner 14-38/+103
2022-06-22Update build-idGravatar Jarred Sumner 1-1/+1
2022-06-22cleanupGravatar Jarred Sumner 6-719/+3
2022-06-22Update index.d.tsGravatar Jarred Sumner 1-0/+1
2022-06-22types for `bun:jsc`Gravatar Jarred Sumner 2-1/+37
2022-06-22Slightly customize the `events` polyfill so it uses ESMGravatar Jarred Sumner 1-1/+522
2022-06-22Fix memory bugs in escapeHTML & arrayBufferToStringGravatar Jarred Sumner 1-65/+61