aboutsummaryrefslogtreecommitdiff
path: root/macros/src
diff options
context:
space:
mode:
authorGravatar Andrey Zgarbul <zgarbul.andrey@gmail.com> 2021-04-03 20:30:34 +0300
committerGravatar Andrey Zgarbul <zgarbul.andrey@gmail.com> 2021-07-09 18:44:19 +0300
commite4319de3d526285381f5cc53e14f9a17d123a81a (patch)
treeb8ed1d60401f508f97e8f4cf151b295f11b79d24 /macros/src
parentc67657371b9f27353caae8a8ccf6e94cd0f25110 (diff)
downloadrtic-e4319de3d526285381f5cc53e14f9a17d123a81a.tar.gz
rtic-e4319de3d526285381f5cc53e14f9a17d123a81a.tar.zst
rtic-e4319de3d526285381f5cc53e14f9a17d123a81a.zip
const generics
Diffstat (limited to 'macros/src')
-rw-r--r--macros/src/codegen/dispatchers.rs6
-rw-r--r--macros/src/codegen/software_tasks.rs10
-rw-r--r--macros/src/codegen/timer_queue.rs4
-rw-r--r--macros/src/codegen/util.rs15
4 files changed, 9 insertions, 26 deletions
diff --git a/macros/src/codegen/dispatchers.rs b/macros/src/codegen/dispatchers.rs
index ac550036..c239b0f8 100644
--- a/macros/src/codegen/dispatchers.rs
+++ b/macros/src/codegen/dispatchers.rs
@@ -42,15 +42,13 @@ pub fn codegen(app: &App, analysis: &Analysis, _extra: &Extra) -> Vec<TokenStrea
}
));
- let n = util::capacity_typenum(channel.capacity, true);
+ let n = util::capacity_literal(channel.capacity as usize + 1);
let rq = util::rq_ident(level);
let rq = util::mark_internal_ident(&rq);
let (rq_ty, rq_expr) = {
(
quote!(rtic::export::SCRQ<#t, #n>),
- quote!(rtic::export::Queue(unsafe {
- rtic::export::iQueue::u8_sc()
- })),
+ quote!(rtic::export::Queue::new()),
)
};
diff --git a/macros/src/codegen/software_tasks.rs b/macros/src/codegen/software_tasks.rs
index cfd21e40..0b073359 100644
--- a/macros/src/codegen/software_tasks.rs
+++ b/macros/src/codegen/software_tasks.rs
@@ -32,8 +32,8 @@ pub fn codegen(
let (_, _, _, input_ty) = util::regroup_inputs(inputs);
let cap = task.args.capacity;
- let cap_lit = util::capacity_literal(cap);
- let cap_ty = util::capacity_typenum(cap, true);
+ let cap_lit = util::capacity_literal(cap as usize);
+ let cap_lit_p1 = util::capacity_literal(cap as usize + 1);
// Create free queues and inputs / instants buffers
let fq = util::fq_ident(name);
@@ -41,10 +41,8 @@ pub fn codegen(
let (fq_ty, fq_expr, mk_uninit): (_, _, Box<dyn Fn() -> Option<_>>) = {
(
- quote!(rtic::export::SCFQ<#cap_ty>),
- quote!(rtic::export::Queue(unsafe {
- rtic::export::iQueue::u8_sc()
- })),
+ quote!(rtic::export::SCFQ<#cap_lit_p1>),
+ quote!(rtic::export::Queue::new()),
Box::new(|| util::link_section_uninit()),
)
};
diff --git a/macros/src/codegen/timer_queue.rs b/macros/src/codegen/timer_queue.rs
index 9e30d100..abddbadc 100644
--- a/macros/src/codegen/timer_queue.rs
+++ b/macros/src/codegen/timer_queue.rs
@@ -62,12 +62,12 @@ pub fn codegen(app: &App, analysis: &Analysis, _extra: &Extra) -> Vec<TokenStrea
{
// For future use
// let doc = &format!("Timer queue for {}", monotonic_name);
- let cap = app
+ let cap: u8 = app
.software_tasks
.iter()
.map(|(_name, task)| task.args.capacity)
.sum();
- let n = util::capacity_typenum(cap, false);
+ let n = util::capacity_literal(cap as usize);
let tq_ty =
quote!(core::mem::MaybeUninit<rtic::export::TimerQueue<#mono_type, #t, #n>>);
diff --git a/macros/src/codegen/util.rs b/macros/src/codegen/util.rs
index 86bd6955..c2330d46 100644
--- a/macros/src/codegen/util.rs
+++ b/macros/src/codegen/util.rs
@@ -8,23 +8,10 @@ use syn::{Attribute, Ident, LitInt, PatType};
use crate::check::Extra;
/// Turns `capacity` into an unsuffixed integer literal
-pub fn capacity_literal(capacity: u8) -> LitInt {
+pub fn capacity_literal(capacity: usize) -> 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())