use crate::prelude::Snapshotable;
#[derive(Clone, Default, PartialEq)]
#[cfg_attr(debug_assertions, derive(Debug))]
pub struct IntegerRegisters([u64; 31]);
impl Snapshotable for IntegerRegisters {
type Snapshot = [u64; 32];
fn snapshot(&self) -> Self::Snapshot {
let mut regs = [0; 32];
regs[1..].copy_from_slice(&self.0);
regs
}
}
impl std::ops::Index<usize> for IntegerRegisters {
type Output = u64;
fn index(&self, index: usize) -> &Self::Output {
match index {
0 => &0,
_ => &self.0[index - 1],
}
}
}
impl std::ops::IndexMut<usize> for IntegerRegisters {
fn index_mut(&mut self, index: usize) -> &mut Self::Output {
static mut DISCARD_VALUE: u64 = 0;
match index {
0 => unsafe { &mut DISCARD_VALUE },
_ => &mut self.0[index - 1],
}
}
}