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) } n> Unnamed repository; edit this file 'description' to name the repository.
aboutsummaryrefslogtreecommitdiff
path: root/src/http_client_async.zig (unfollow)
AgeCommit message (Expand)AuthorFilesLines
2023-08-15fix buildGravatar Dylan Conway 2-0/+4
2023-08-15chore: fix method name typo (#4162)Gravatar Ai Hoshino 1-1/+1
2023-08-15fix importing too long of strings (#4155)Gravatar dave caruso 3-3/+45
2023-08-14Make builtins' source origin use a valid url (#4152)Gravatar dave caruso 4-275/+284
2023-08-14Small docs changeGravatar Colin McDonnell 1-2/+2
2023-08-13fix makefile (#4148)Gravatar dave caruso 1-1/+1
2023-08-12Update Stric guides (#4137)Gravatar Revenity 1-4/+6
2023-08-12Fix worker event loop ref/unref + leak (#4114)Gravatar dave caruso 35-263/+465
2023-08-11Fix using uninitialized variable when formatting `config_path`. (#4129)Gravatar Ai Hoshino 2-1/+21
2023-08-11Deprecate loading `node_modules.bun` (#4131)Gravatar Jarred Sumner 34-2204/+222
2023-08-11`bun-wasm` fixes & improvements (#4126)Gravatar jhmaster 14-44/+252
2023-08-11Support TypeScript's `export type * as Foo from 'bar'` (#4125)Gravatar Jarred Sumner 2-9/+42
2023-08-11Fix wasm buildGravatar Jarred Sumner 1-1/+5
2023-08-10async realpath (#4117)Gravatar Jarred Sumner 6-58/+184
2023-08-10Remove assertionGravatar Jarred Sumner 1-3/+0
2023-08-10More lazily initialize these static stringsGravatar Jarred Sumner 1-5/+7
2023-08-10don't check for trailing slash, var streamGravatar Dylan Conway 3-9/+9
2023-08-10run files without extensions (#4113)Gravatar Dylan Conway 4-11/+46
2023-08-10Fix memory leak in base64url (#4111)Gravatar Jarred Sumner 1-2/+2
2023-08-10Handle thundering herd of setInterval (#4109)Gravatar Jarred Sumner 1-2/+17
2023-08-10fs.zig: create temp files with 0o700, not 0o007 (#4107)Gravatar Adhityaa Chandrasekar 1-1/+1
2023-08-10Update remix guideGravatar Colin McDonnell 1-2/+4
2023-08-10zig fmtGravatar Jarred Sumner 1-4/+4
2023-08-10Fixes #4062 (#4106)Gravatar Jarred Sumner 8-26/+87
2023-08-10bun test: format description of test.each (#4092)Gravatar Jacques 3-13/+311
2023-08-10add util.formatWithOptions (#4090)Gravatar dave caruso 3-9/+30
2023-08-10Fix titleGravatar Colin McDonnell 1-1/+1