📝 ♻️ Doc updates & Registers are now sized from consts

This commit is contained in:
François Autin 2023-03-24 18:13:18 +01:00
parent 928628c305
commit 35fdb1e0b0
No known key found for this signature in database
GPG Key ID: 343F5D382E1DD77C

View File

@ -1,3 +1,5 @@
use crate::simulator::machine::{NUM_FP_REGS, NUM_INT_REGS};
use std::ops::{Add, Sub}; use std::ops::{Add, Sub};
pub trait RegisterNum: Add<Output=Self> + Sub<Output=Self> + PartialEq + Copy {} pub trait RegisterNum: Add<Output=Self> + Sub<Output=Self> + PartialEq + Copy {}
@ -20,7 +22,10 @@ impl<U: RegisterNum> Register<U> {
self.register[position as usize] self.register[position as usize]
} }
/// Set value of register *position* to *value* /// Set value of register *position* to *value*
///
/// Checking against trying to set a new value to the 0th register
/// as its value is NOT supposed to change
pub fn set_reg(&mut self, position: usize, value: U) { pub fn set_reg(&mut self, position: usize, value: U) {
if position != 0 { self.register[position] = value; } if position != 0 { self.register[position] = value; }
} }
@ -33,7 +38,7 @@ impl Register<i64> {
/// i64 register constructor /// i64 register constructor
pub fn init() -> Register<i64> { pub fn init() -> Register<i64> {
Register { Register {
register: [0i64; 32] register: [0i64; NUM_INT_REGS]
} }
} }
@ -44,7 +49,7 @@ impl Register<f32> {
/// f32 register constructor /// f32 register constructor
pub fn init() -> Register<f32> { pub fn init() -> Register<f32> {
Register { Register {
register: [0f32; 32] register: [0f32; NUM_FP_REGS]
} }
} }