use crate::syntax::{ast::App, Context}; use proc_macro2::TokenStream as TokenStream2; use quote::quote; use crate::codegen::util; /// Generate shared resources structs pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2, TokenStream2) { let mut lt = None; let resources = match ctxt { Context::Init => unreachable!("Tried to generate shared resources struct for init"), Context::Idle => { &app.idle .as_ref() .expect("RTIC-ICE: unable to get idle name") .args .shared_resources } Context::HardwareTask(name) => &app.hardware_tasks[name].args.shared_resources, Context::SoftwareTask(name) => &app.software_tasks[name].args.shared_resources, }; let mut fields = vec![]; let mut values = vec![]; let mut has_cfgs = false; for (name, access) in resources { let res = app.shared_resources.get(name).expect("UNREACHABLE"); let cfgs = &res.cfgs; has_cfgs |= !cfgs.is_empty(); // access hold if the resource is [x] (exclusive) or [&x] (shared) let mut_ = if access.is_exclusive() { Some(quote!(mut)) } else { None }; let ty = &res.ty; let mangled_name = util::static_shared_resource_ident(name); let shared_name = util::need_to_lock_ident(name); if res.properties.lock_free { // Lock free resources of `idle` and `init` get 'static lifetime let lt = if ctxt.runs_once() { quote!('static) } else { lt = Some(quote!('a)); quote!('a) }; fields.push(quote!( #(#cfgs)* pub #name: &#lt #mut_ #ty )); } else if access.is_shared() { lt = Some(quote!('a)); fields.push(quote!( #(#cfgs)* pub #name: &'a #ty )); } else { // Resource proxy lt = Some(quote!('a)); fields.push(quote!( #(#cfgs)* pub #name: shared_resources::#shared_name<'a> )); values.push(quote!( #(#cfgs)* #name: shared_resources::#shared_name::new(priority) )); // continue as the value has been filled, continue; } let expr = if access.is_exclusive() { quote!(&mut *(&mut *#mangled_name.get_mut()).as_mut_ptr()) } else { quote!(&*(&*#mangled_name.get()).as_ptr()) }; values.push(quote!( #(#cfgs)* #name: #expr )); } if lt.is_some() { *needs_lt = true; // The struct could end up empty due to `cfg`s leading to an error due to `'a` being unused if has_cfgs { fields.push(quote!( #[doc(hidden)] pub __marker__: core::marker::PhantomData<&'a ()> )); values.push(quote!(__marker__: core::marker::PhantomData)); } } let doc = format!("Shared resources `{}` has access to", ctxt.ident(app)); let ident = util::shared_resources_ident(ctxt, app); let item = quote!( #[allow(non_snake_case)] #[allow(non_camel_case_types)] #[doc = #doc] pub struct #ident<#lt> { #(#fields,)* } ); let arg = if ctxt.is_init() { None } else { Some(quote!(priority: &#lt rtic::export::Priority)) }; let constructor = quote!( impl<#lt> #ident<#lt> { #[inline(always)] pub unsafe fn new(#arg) -> Self { #ident { #(#values,)* } } } ); (item, constructor) } Unnamed repository; edit this file 'description' to name the repository.
aboutsummaryrefslogtreecommitdiff
path: root/src/bun_js.zig (unfollow)
AgeCommit message (Collapse)AuthorFilesLines
2021-12-31bumpGravatar Jarred Sumner 4-2/+2
2021-12-31[devserver] Log more errors when a websocket connection failsGravatar Jarred Sumner 1-2/+9
2021-12-31Update http.zigGravatar Jarred Sumner 1-2/+2
2021-12-31[devserver] Case-insensitive request header comparison, which fixes issues ↵Gravatar Jarred Sumner 1-11/+3
with proxying Bun
2021-12-31Add unrolled case insensitive string comparisonGravatar Jarred Sumner 1-0/+21
2021-12-31Fix an edgecase that causes a crash in HTTP serverGravatar Jarred Sumner 1-1/+1
2021-12-31[bun install] Slightly more reliable HTTPGravatar Jarred Sumner 3-3/+4
2021-12-31Bump peechy againGravatar Jarred Sumner 2-1/+1
2021-12-30woopsGravatar Jarred Sumner 2-4/+1
2021-12-3012 -> 13Gravatar Jarred Sumner 1-2/+2
2021-12-30Update zig version in DockerfileGravatar Jarred Sumner 3-31/+30
2021-12-30Update settings.jsonGravatar Jarred Sumner 1-1/+1
2021-12-30[JavaScriptCore] Fix crash due to not requesting JIT permission by patchingGravatar Jarred Sumner 1-3/+9
2021-12-30Fix issue with headersGravatar Jarred Sumner 5-3/+17
2021-12-30fix occasional HTTP bugGravatar Jarred Sumner 1-0/+2
2021-12-30Update c.zigGravatar Jarred Sumner 1-1/+1
2021-12-30Update global.zigGravatar Jarred Sumner 1-1/+1
2021-12-30linuxGravatar Jarred Sumner 5-4/+402
2021-12-30Update io_linux.zigGravatar Jarred Sumner 1-1/+1
2021-12-30Update io_linux.zigGravatar Jarred Sumner 1-1/+1
2021-12-30_ => .Gravatar Jarred Sumner 3-5/+5
2021-12-30- => .Gravatar Jarred Sumner 4-6/+6
2021-12-30Update bun.lockbGravatar Jarred Sumner 1-0/+0
2021-12-30Remove network_threadGravatar Jarred Sumner 1-12/+11
2021-12-30linuxGravatar Jarred Sumner 2-6/+7
2021-12-30[internal] Move network_thread into http packageGravatar Jarred Sumner 17-435/+32
2021-12-30Upgrade to latest Zig, remove dependency on patched version of Zig (#96)Gravatar Jarred Sumner 154-6271/+4561
* Prepare to upgrade zig * zig fmt * AllocGate * Update data_url.zig * wip * few files * just headers now? * I think everything works? * Update mimalloc * Update hash_map.zig * Perf improvements to compensate for Allocgate * Bump * :camera: * Update bun.lockb * Less branching * [js parser] Slightly reduce memory usage * Update js_parser.zig * WIP remove unused * [JS parser] WIP support for `with` keyword * Remove more dead code * Fix all the build errors! * cleanup * Move `network_thread` up * Bump peechy * Update README.md
2021-12-29zig fmtGravatar Jarred Sumner 5-8/+3
2021-12-29Update MakefileGravatar Jarred Sumner 1-1/+0