use core::sync::atomic::{AtomicUsize, Ordering}; use proc_macro2::{Span, TokenStream as TokenStream2}; use quote::quote; use rtic_syntax::{ast::App, Context}; use syn::{Attribute, Ident, LitInt, PatType}; use crate::check::Extra; /// Turns `capacity` into an unsuffixed integer literal pub fn capacity_literal(capacity: u8) -> LitInt { LitInt::new(&capacity.to_string(), Span::call_site()) } /// Turns `capacity` into a type-level (`typenum`) integer pub fn capacity_typenum(capacity: u8, round_up_to_power_of_two: bool) -> TokenStream2 { let capacity = if round_up_to_power_of_two { capacity.checked_next_power_of_two().expect("UNREACHABLE") } else { capacity }; let ident = Ident::new(&format!("U{}", capacity), Span::call_site()); quote!(rtic::export::consts::#ident) } /// Identifier for the free queue pub fn fq_ident(task: &Ident) -> Ident { Ident::new(&format!("{}_FQ", task.to_string()), Span::call_site()) } /// Generates a `Mutex` implementation pub fn impl_mutex( extra: &Extra, cfgs: &[Attribute], resources_prefix: bool, name: &Ident, ty: TokenStream2, ceiling: u8, ptr: TokenStream2, ) -> TokenStream2 { let (path, priority) = if resources_prefix { (quote!(resources::#name), quote!(self.priority())) } else { (quote!(#name), quote!(self.priority)) }; let device = extra.device; quote!( #(#cfgs)* impl<'a> rtic::Mutex for #path<'a> { type T = #ty; #[inline(always)] fn lock(&mut self, f: impl FnOnce(&mut #ty) -> R) -> R { /// Priority ceiling const CEILING: u8 = #ceiling; unsafe { rtic::export::lock( #ptr, #priority, CEILING, #device::NVIC_PRIO_BITS, f, ) } } } ) } /// Generates an identifier for the `INPUTS` buffer (`spawn` & `schedule` API) pub fn inputs_ident(task: &Ident) -> Ident { Ident::new(&format!("{}_INPUTS", task), Span::call_site()) } /// Generates an identifier for the `INSTANTS` buffer (`schedule` API) pub fn instants_ident(task: &Ident) -> Ident { Ident::new(&format!("{}_INSTANTS", task), Span::call_site()) } pub fn interrupt_ident() -> Ident { let span = Span::call_site(); Ident::new("interrupt", span) } /// Whether `name` is an exception with configurable priority pub fn is_exception(name: &Ident) -> bool { let s = name.to_string(); match &*s { "MemoryManagement" | "BusFault" | "UsageFault" | "SecureFault" | "SVCall" | "DebugMonitor" | "PendSV" | "SysTick" => true, _ => false, } } /// Generates a pre-reexport identifier for the "late resources" struct pub fn late_resources_ident(init: &Ident) -> Ident { Ident::new( &format!("{}LateResources", init.to_string()), Span::call_site(), ) } /// Mangle an ident pub fn mangle_ident(ident: &Ident) -> Ident { Ident::new( &format!("__rtic_internal_{}", ident.to_string()), Span::call_site(), ) } fn link_section_index() -> usize { static INDEX: AtomicUsize = AtomicUsize::new(0); INDEX.fetch_add(1, Ordering::Relaxed) } // NOTE `None` means in shared memory pub fn link_section_uninit(empty_expr: bool) -> Option { let section = if empty_expr { let index = link_section_index(); format!(".uninit.rtic{}", index) } else { format!(".uninit.rtic{}", link_section_index()) }; Some(quote!(#[link_section = #section])) } /// Generates a pre-reexport identifier for the "locals" struct pub fn locals_ident(ctxt: Context, app: &App) -> Ident { let mut s = match ctxt { Context::Init => app.inits.first().unwrap().name.to_string(), Context::Idle => app.idles.first().unwrap().name.to_string(), Context::HardwareTask(ident) | Context::SoftwareTask(ident) => ident.to_string(), }; s.push_str("Locals"); Ident::new(&s, Span::call_site()) } // Regroups the inputs of a task // // `inputs` could be &[`input: Foo`] OR &[`mut x: i32`, `ref y: i64`] pub fn regroup_inputs( inputs: &[PatType], ) -> ( // args e.g. &[`_0`], &[`_0: i32`, `_1: i64`] Vec, // tupled e.g. `_0`, `(_0, _1)` TokenStream2, // untupled e.g. &[`_0`], &[`_0`, `_1`] Vec, // ty e.g. `Foo`, `(i32, i64)` TokenStream2, ) { if inputs.len() == 1 { let ty = &inputs[0].ty; ( vec![quote!(_0: #ty)], quote!(_0), vec![quote!(_0)], quote!(#ty), ) } else { let mut args = vec![]; let mut pats = vec![]; let mut tys = vec![]; for (i, input) in inputs.iter().enumerate() { let i = Ident::new(&format!("_{}", i), Span::call_site()); let ty = &input.ty; args.push(quote!(#i: #ty)); pats.push(quote!(#i)); tys.push(quote!(#ty)); } let tupled = { let pats = pats.clone(); quote!((#(#pats,)*)) }; let ty = quote!((#(#tys,)*)); (args, tupled, pats, ty) } } /// Generates a pre-reexport identifier for the "resources" struct pub fn resources_ident(ctxt: Context, app: &App) -> Ident { let mut s = match ctxt { Context::Init => app.inits.first().unwrap().name.to_string(), Context::Idle => app.idles.first().unwrap().name.to_string(), Context::HardwareTask(ident) | Context::SoftwareTask(ident) => ident.to_string(), }; s.push_str("Resources"); Ident::new(&s, Span::call_site()) } /// Generates an identifier for a ready queue /// /// There may be several task dispatchers, one for each priority level. /// The ready queues are SPSC queues pub fn rq_ident(priority: u8) -> Ident { Ident::new(&format!("P{}_RQ", priority), Span::call_site()) } /// Generates an identifier for the `enum` of `schedule`-able tasks pub fn schedule_t_ident() -> Ident { Ident::new(&format!("SCHED_T"), Span::call_site()) } /// Generates an identifier for the `enum` of `spawn`-able tasks /// /// This identifier needs the same structure as the `RQ` identifier because there's one ready queue /// for each of these `T` enums pub fn spawn_t_ident(priority: u8) -> Ident { Ident::new(&format!("P{}_T", priority), Span::call_site()) } pub fn suffixed(name: &str) -> Ident { let span = Span::call_site(); Ident::new(name, span) } /// Generates an identifier for a timer queue /// /// At most there is one timer queue pub fn tq_ident() -> Ident { Ident::new(&format!("TQ"), Span::call_site()) } ption value='jarred/experiment-bsp'>jarred/experiment-bsp Unnamed repository; edit this file 'description' to name the repository.
aboutsummaryrefslogtreecommitdiff
AgeCommit message (Expand)AuthorFilesLines
2023-08-23Update globals.d.ts (#4276)Gravatar VietnamecDevelopment 1-1/+1
2023-08-23Fix ffi type (#4265)Gravatar Code Hz 2-49/+272
2023-08-23Bunch of streams fixes (#4251)Gravatar Jarred Sumner 31-548/+866
2023-08-23docs: remove broken DNS link which is also not present in the official docs (...Gravatar Quentin 1-1/+0
2023-08-23Fix more types. (#4273)Gravatar xxxhussein 8-16/+22
2023-08-23ask for bun --revision instead bun -v (#4256)Gravatar Jozef Steinhübl 1-1/+1
2023-08-22fix yield (#4264)Gravatar dave caruso 2-1/+17
2023-08-22Fix Bun.inspect typesGravatar Colin McDonnell 1-1/+1
2023-08-21fix fsevents and stub for qwikcity (#4247)Gravatar dave caruso 9-64/+24
2023-08-21fix stdin stream unref and resuming (#4250)Gravatar Dylan Conway 4-19/+26
2023-08-21Docs and types for v0.8.0 (#4199)Gravatar Colin McDonnell 10-37/+487
2023-08-21Bun v0.8Gravatar Jarred Sumner 5-5/+5
2023-08-21Make the code generator less duplicativeGravatar Jarred Sumner 2-84/+39
2023-08-21import errors have `code` set to `ERR_MODULE_NOT_FOUND` and `require` errors ...Gravatar Jarred Sumner 11-19/+122
2023-08-21fetch(stream) add stream support for compressed and uncompressed data (#4127)Gravatar Ciro Spaciari 19-156/+1876
2023-08-21Fix inquirer (#4245)Gravatar dave caruso 2-3/+6
2023-08-21Update module_loader.zigGravatar Jarred Sumner 1-1/+1
2023-08-21Fix(bundler): allow generating exe file in nested path. (#4226)Gravatar Ai Hoshino 3-7/+49
2023-08-21Fix typoGravatar Colin McDonnell 1-1/+1
2023-08-21Fix crypto.EC constructor (#4242)Gravatar dave caruso 2-3/+4
2023-08-21Implement `napi_ref_threadsafe_function` (#4156)Gravatar dave caruso 10-7/+65
2023-08-21feat: Implement Bun.inspect.custom (#4243)Gravatar dave caruso 6-8/+26
2023-08-21Fixes #4089 (#4105)Gravatar Jarred Sumner 3-36/+136
2023-08-2140x faster .toString('hex') (#4237)Gravatar Jarred Sumner 3-17/+105
2023-08-21Fix memory leak in `buffer.toString("hex")` (#4235)Gravatar Jarred Sumner 2-1/+6
2023-08-21Update README.md (#4232)Gravatar xxxhussein 1-1/+1
2023-08-21Add missing header changeGravatar Jarred Sumner 1-1/+1
2023-08-21Add LazyPropertyGravatar Jarred Sumner 1-0/+3
2023-08-21Fix BigIntStats generated classGravatar Jarred Sumner 1-1/+1
2023-08-21RegenerateGravatar Jarred Sumner 1-8/+15
2023-08-21Implement FileGravatar Jarred Sumner 12-12/+387
2023-08-20Fixes #1675 (#4230)Gravatar Jarred Sumner 8-70/+297
2023-08-20Implement `--inspect-brk` (#4222)Gravatar Jarred Sumner 17-41/+101
2023-08-20Fix test failures from 3a9a6c63a (#4231)Gravatar Jarred Sumner 4-32/+34
2023-08-20Fix(bundler): use different alias mappings based on the target. (#4163)Gravatar Ai Hoshino 8-18/+90
2023-08-19Update BunDebugger.cppGravatar Jarred Sumner 1-1/+3
2023-08-19Introduce `bun --inspect-wait`Gravatar Jarred Sumner 3-19/+47
2023-08-19misc non-posix fixesGravatar Jarred Sumner 2-3/+3
2023-08-19Update lockfile.mdGravatar Jarred Sumner 1-1/+8
2023-08-19Update lockfile.mdGravatar Jarred Sumner 1-4/+4
2023-08-19Update lockfile.mdGravatar Jarred Sumner 1-1/+29
2023-08-19Update Dockerfile-distroless (#4210)Gravatar Omar 1-0/+1
2023-08-19Fix symbol visibilityGravatar Jarred Sumner 1-0/+1
2023-08-19[napi] Implement `node_api_create_syntax_error`, `node_api_symbol_for`, `nod...Gravatar Jarred Sumner 5-1/+70
2023-08-19Fix crash impacting sharp & resvg (#4221)Gravatar Jarred Sumner 5-73/+73
2023-08-19Fixes #172 (#4220)Gravatar Jarred Sumner 7-9/+87
2023-08-19Add inline sourcemaps when `--inspect` is enabled (#4213)Gravatar Jarred Sumner 3-3/+64
2023-08-19tty `ReadStream`, `WriteStream`, and readline rawmode (#4179)Gravatar Dylan Conway 23-722/+821
2023-08-18Fix make headers (again)Gravatar Jarred Sumner 1-0/+2