use proc_macro2::TokenStream as TokenStream2; use quote::quote; use rtic_syntax::{ast::App, Context}; use crate::{ analyze::Analysis, check::Extra, codegen::{locals, module, resources_struct, util}, }; /// Generates support code for `#[init]` functions pub fn codegen( core: u8, app: &App, analysis: &Analysis, extra: &Extra, ) -> ( // const_app_idle -- the `${init}Resources` constructor Option, // root_init -- items that must be placed in the root of the crate: // - the `${init}Locals` struct // - the `${init}Resources` struct // - the `${init}LateResources` struct // - the `${init}` module, which contains types like `${init}::Context` Vec, // user_init -- the `#[init]` function written by the user Option, // call_init -- the call to the user `#[init]` if there's one Option, ) { if let Some(init) = app.inits.get(&core) { let cfg_core = util::cfg_core(core, app.args.cores); let mut needs_lt = false; let name = &init.name; let mut root_init = vec![]; let ret = { let late_fields = analysis .late_resources .get(&core) .map(|resources| { resources .iter() .map(|name| { let ty = &app.late_resources[name].ty; let cfgs = &app.late_resources[name].cfgs; quote!( #(#cfgs)* pub #name: #ty ) }) .collect::>() }) .unwrap_or(vec![]); if !late_fields.is_empty() { let late_resources = util::late_resources_ident(&name); root_init.push(quote!( /// Resources initialized at runtime #cfg_core #[allow(non_snake_case)] pub struct #late_resources { #(#late_fields),* } )); Some(quote!(-> #name::LateResources)) } else { None } }; let mut locals_pat = None; let mut locals_new = None; if !init.locals.is_empty() { let (struct_, pat) = locals::codegen(Context::Init(core), &init.locals, core, app); locals_new = Some(quote!(#name::Locals::new())); locals_pat = Some(pat); root_init.push(struct_); } let context = &init.context; let attrs = &init.attrs; let stmts = &init.stmts; let section = util::link_section("text", core); let locals_pat = locals_pat.iter(); let user_init = Some(quote!( #(#attrs)* #cfg_core #[allow(non_snake_case)] #section fn #name(#(#locals_pat,)* #context: #name::Context) #ret { #(#stmts)* } )); let mut const_app = None; if !init.args.resources.is_empty() { let (item, constructor) = resources_struct::codegen(Context::Init(core), 0, &mut needs_lt, app, analysis); root_init.push(item); const_app = Some(constructor); } let locals_new = locals_new.iter(); let call_init = Some( quote!(let late = crate::#name(#(#locals_new,)* #name::Context::new(core.into()));), ); root_init.push(module::codegen(Context::Init(core), needs_lt, app, extra)); (const_app, root_init, user_init, call_init) } else { (None, vec![], None, None) } } mework-alpine Unnamed repository; edit this file 'description' to name the repository.
aboutsummaryrefslogtreecommitdiff
AgeCommit message (Expand)AuthorFilesLines
2022-02-07[ci] collect statsGravatar FredKSchott 1-0/+1
2022-02-06[ci] update lockfile (#2527)Gravatar Fred K. Schott 1-208/+238
2022-02-06[ci] collect statsGravatar FredKSchott 1-0/+1
2022-02-05[ci] collect statsGravatar FredKSchott 1-0/+1
2022-02-04[ci] yarn formatGravatar natemoo-re 1-2/+3
2022-02-04fix: HTML/SVG boolean attributes (#2538)Gravatar Nate Moore 2-3/+21
2022-02-04[ci] yarn formatGravatar matthewp 1-4/+2
2022-02-04fix: import local plugins into markdown (#2534)Gravatar Juan Martín Seery 9-22/+41
2022-02-04[ci] collect statsGravatar FredKSchott 1-0/+1
2022-02-03Append to list of HMR modules, don't override (#2532)Gravatar Matthew Phillips 2-1/+6
2022-02-03add back dev server host support (#2531)Gravatar Fred K. Schott 2-1/+14
2022-02-03simplify status code regexGravatar Fred K. Schott 2-87/+4
2022-02-03Adding StackUp Digital to the list of sponsors (#2521)Gravatar Astroalex 3-0/+10
2022-02-03[ci] collect statsGravatar FredKSchott 1-0/+1
2022-02-03[ci] yarn formatGravatar FredKSchott 2-3/+85
2022-02-02Handles all http error code file names the same as 404 files. (#2525)Gravatar Zade Viggers 2-4/+7
2022-02-02fix(sitemap): remove debug if sitemap disabled (#2514)Gravatar Mark Pinero 1-2/+2
2022-02-02[ci] update lockfile (#2515)Gravatar Fred K. Schott 1-276/+279
2022-02-02[ci] yarn formatGravatar matthewp 1-8/+8
2022-02-02[ci] release (next) (#2523)astro@0.23.0-next.1Gravatar github-actions[bot] 28-34/+41
2022-02-02[ci] yarn formatGravatar matthewp 2-17/+29
2022-02-02Fix support for scss in static build (#2522)Gravatar Matthew Phillips 6-20/+114
2022-02-02[ci] collect statsGravatar FredKSchott 1-0/+1
2022-02-01[ci] yarn formatGravatar matthewp 2-12/+12
2022-02-01[ci] release (next) (#2492)astro@0.23.0-next.0@astrojs/test-static-build-pkg@0.0.2@astrojs/markdown-remark@0.6.1-next.0Gravatar github-actions[bot] 31-43/+93
2022-02-01[ci] collect statsGravatar FredKSchott 1-0/+1
2022-01-31update congratsbot format againGravatar Fred K. Schott 1-1/+1
2022-01-31update congratsbot againGravatar Fred K. Schott 1-1/+1
2022-01-31Remove SVG animation on GitHub/NPM (#2512)Gravatar Nate Moore 1-21/+0
2022-01-31[ci] yarn formatGravatar natemoo-re 2-4/+6
2022-01-31Add Shiki as an alternative to Prism (#2497)Gravatar Juan Martín Seery 26-9/+356
2022-01-31Deprecate unescaped HTML inside of expressions (#2489)Gravatar Nate Moore 9-31/+74