Fixes for concurrency and the fibonacci example

This commit is contained in:
Jan-Peter von Hunnius 2025-09-24 09:44:18 +02:00
parent 8fe6f3362c
commit f66f4c5d6c
14 changed files with 341 additions and 811 deletions

45
src/types.rs Normal file
View file

@ -0,0 +1,45 @@
use std::fmt;
/// 12-bit unsigned integer for MCS-4 address space
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub struct U12(u16);
impl U12 {
pub fn new(value: u16) -> Self {
U12(value & 0xFFF)
}
pub fn value(&self) -> u16 {
self.0
}
pub fn inc(&mut self) {
self.0 = (self.0 + 1) & 0xFFF;
}
pub fn set(&mut self, value: u16) {
self.0 = value & 0xFFF;
}
pub fn wrapping_add(&self, value: u16) -> Self {
U12::new(self.0.wrapping_add(value))
}
}
impl fmt::Display for U12 {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:03X}", self.0)
}
}
impl From<u16> for U12 {
fn from(value: u16) -> Self {
U12::new(value)
}
}
impl From<U12> for u16 {
fn from(value: U12) -> Self {
value.value()
}
}