use proc_macro2::TokenStream as TokenStream2; use quote::quote; use rtfm_syntax::{ast::App, Context}; use crate::{analyze::Analysis, codegen::util}; pub fn codegen( ctxt: Context, priority: u8, needs_lt: &mut bool, app: &App, analysis: &Analysis, ) -> (TokenStream2, TokenStream2) { let mut lt = None; let resources = match ctxt { Context::Init(core) => &app.inits[&core].args.resources, Context::Idle(core) => &app.idles[&core].args.resources, Context::HardwareTask(name) => &app.hardware_tasks[name].args.resources, Context::SoftwareTask(name) => &app.software_tasks[name].args.resources, }; let mut fields = vec![]; let mut values = vec![]; let mut has_cfgs = false; for (name, access) in resources { let (res, expr) = app.resource(name).expect("UNREACHABLE"); let cfgs = &res.cfgs; has_cfgs |= !cfgs.is_empty(); let mut_ = if access.is_exclusive() { Some(quote!(mut)) } else { None }; let ty = &res.ty; if ctxt.is_init() { if !analysis.ownerships.contains_key(name) { // owned by `init` fields.push(quote!( #(#cfgs)* pub #name: &'static #mut_ #ty )); values.push(quote!( #(#cfgs)* #name: &#mut_ #name )); } else { // owned by someone else lt = Some(quote!('a)); fields.push(quote!( #(#cfgs)* pub #name: &'a mut #ty )); values.push(quote!( #(#cfgs)* #name: &mut #name )); } } else { let ownership = &analysis.ownerships[name]; if ownership.needs_lock(priority) { if mut_.is_none() { 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: resources::#name<'a> )); values.push(quote!( #(#cfgs)* #name: resources::#name::new(priority) )); continue; } } else { let lt = if ctxt.runs_once() { quote!('static) } else { lt = Some(quote!('a)); quote!('a) }; if ownership.is_owned() || mut_.is_none() { fields.push(quote!( #(#cfgs)* pub #name: &#lt #mut_ #ty )); } else { fields.push(quote!( #(#cfgs)* pub #name: &#lt mut #ty )); } } let is_late = expr.is_none(); if is_late { let expr = if mut_.is_some() { quote!(&mut *#name.as_mut_ptr()) } else { quote!(&*#name.as_ptr()) }; values.push(quote!( #(#cfgs)* #name: #expr )); } else { values.push(quote!( #(#cfgs)* #name: &#mut_ #name )); } } } 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 core = ctxt.core(app); let cores = app.args.cores; let cfg_core = util::cfg_core(core, cores); let doc = format!("Resources `{}` has access to", ctxt.ident(app)); let ident = util::resources_ident(ctxt, app); let item = quote!( #cfg_core #[allow(non_snake_case)] #[doc = #doc] pub struct #ident<#lt> { #(#fields,)* } ); let arg = if ctxt.is_init() { None } else { Some(quote!(priority: &#lt rtfm::export::Priority)) }; let constructor = quote!( #cfg_core impl<#lt> #ident<#lt> { #[inline(always)] unsafe fn new(#arg) -> Self { #ident { #(#values,)* } } } ); (item, constructor) } Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/examples/framework-react/src (unfollow)
AgeCommit message (Expand)AuthorFilesLines
2023-01-17Fix image integration not working on Node 18+ (#5871)Gravatar Erika 10-215/+12
2023-01-17Revert "Add missing `noPropertyAccessFromIndexSignature` to strictest tsconfi...Gravatar Bjorn Lu 2-9/+0
2023-01-17Add missing `noPropertyAccessFromIndexSignature` to strictest tsconfig profil...Gravatar Clément Nerma 2-0/+9
2023-01-17Enable skipLibCheck by default (#5872)Gravatar Bjorn Lu 2-1/+8
2023-01-14Handle server restart from Vite plugins (#5849)Gravatar Bjorn Lu 3-28/+72
2023-01-14Fix importing client-side components with alias (#5845)Gravatar Bjorn Lu 4-0/+74
2023-01-13Support envPrefix in Astro config (#5852)Gravatar Rishi Raj Jain 3-3/+8
2023-01-13Implement redesign of portfolio example (#5765)Gravatar Chris Swithinbank 58-804/+1900
2023-01-12[ci] formatGravatar natemoo-re 1-8/+10
2023-01-12Fix announcements CI actions when 2000+ characters (#5844)Gravatar Nate Moore 1-6/+45
2023-01-12[ci] release (beta) (#5792)create-astro@2.0.0-beta.0astro@2.0.0-beta.2@astrojs/webapi@2.0.0-beta.0@astrojs/vue@2.0.0-beta.1@astrojs/vercel@3.0.0-beta.1@astrojs/telemetry@2.0.0-beta.0@astrojs/tailwind@3.0.0-beta.1@astrojs/svelte@2.0.0-beta.1@astrojs/solid-js@2.0.0-beta.0@astrojs/react@2.0.0-beta.0@astrojs/prism@2.0.0-beta.0@astrojs/preact@2.0.0-beta.0@astrojs/partytown@1.0.3-beta.0@astrojs/node@5.0.0-beta.1@astrojs/netlify@2.0.0-beta.2@astrojs/mdx@1.0.0-beta.2@astrojs/markdown-remark@2.0.0-beta.2@astrojs/lit@1.0.2-beta.0@astrojs/image@1.0.0-beta.2@astrojs/deno@4.0.0-beta.2@astrojs/cloudflare@6.0.0-beta.1Gravatar Fred K. Bot 73-156/+547
2023-01-12 Add `.astro/` to `.gitignore` in example projects (#5841)Gravatar Chris Swithinbank 24-98/+46
2023-01-12chore: update changeset for `_astro` directory (#5843)Gravatar Nate Moore 1-2/+2
2023-01-12fix: pass flags to dev (#5840)Gravatar Sam Chen 3-1/+9
2023-01-12chore: update changelogs, add changeset for `_astro` directory (#5842)Gravatar Nate Moore 5-18/+10
2023-01-12[ci] formatGravatar natemoo-re 1-1/+1
2023-01-12fix(core): handle encoded characters when matching routes (#5836)Gravatar Nate Moore 8-2/+85
2023-01-12Handle compiler breaking change (#5803)Gravatar Bjorn Lu 12-328/+109
2023-01-12fix shiki css class replace logic in md and mdx integrations (#5837)Gravatar Giuseppe La Torre 3-3/+9
2023-01-11[ci] formatGravatar matthewp 2-2/+2
2023-01-11Simplify HMR handling (#5811)Gravatar Bjorn Lu 8-108/+46
2023-01-11[Content collections] Remove experimental flag (#5825)Gravatar Ben Holmes 27-103/+58
2023-01-11[Content collections] Improve content config handling (#5824)Gravatar Ben Holmes 5-58/+78
2023-01-11Run sync as part of `astro check` (#5823)Gravatar Chris Swithinbank 3-2/+13
2023-01-11[ci] update lockfile (#5815)Gravatar Fred K. Bot 1-257/+256
2023-01-11Fix order-of-execution bug when generating pages (#5822)Gravatar Nate Moore 2-2/+7
2023-01-11Fix `Code.astro` shiki css class replace logic (#5829)Gravatar Giuseppe La Torre 2-1/+6