From ba8e36ea90cc5f7a3fc7ee1f63a652f3974f9c74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Autin?= Date: Mon, 27 Mar 2023 11:35:04 +0200 Subject: [PATCH] :rotating_lights: Small lint fixes --- src/main.rs | 3 ++- src/simulator/machine.rs | 14 +++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index cc181fe..9fe5976 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,6 +17,7 @@ use kernel::system::System; use simulator::machine::Machine; fn main() { - let machine = Machine::init_machine(); + let mut machine = Machine::init_machine(); let system = System::default(); + machine.run() } diff --git a/src/simulator/machine.rs b/src/simulator/machine.rs index 2048455..fdb9b0f 100644 --- a/src/simulator/machine.rs +++ b/src/simulator/machine.rs @@ -13,7 +13,7 @@ use std::{ io::Write, - fs::File, ops::Add + fs::File }; use crate::simulator::{ print, @@ -24,7 +24,10 @@ use crate::simulator::{ register::* }; -/// Exceptions +/// # Exceptions +/// +/// Textual names of the exceptions that can be generated by user program +/// execution, for debugging purpose. /// todo: is this really supposed to stand in machine.rs? pub enum ExceptionType { /// Everything ok @@ -46,6 +49,7 @@ pub enum ExceptionType { NumExceptionTypes } +/// ID of the stack register pub const STACK_REG: usize = 2; /// Number of available Integer registers pub const NUM_INT_REGS: usize = 32; @@ -154,7 +158,7 @@ impl Machine { /// ### Parameters /// /// - **machine** contains the memory - pub fn extract_memory(&self){ + pub fn _extract_memory(&self){ let file_path = "burritos_memory.txt"; let write_to_file = |path| -> std::io::Result { let mut file = File::create(path)?; @@ -228,8 +232,8 @@ impl Machine { panic!("ERROR : number max of instructions rushed"); } let mut val: [u8; 4] = [0; 4]; - for i in 0..4 { - val[i] = self.main_memory[self.pc as usize + i]; + for (i, elem) in val.iter_mut().enumerate() { + *elem = self.main_memory[self.pc as usize + i]; } let val = u32::from_be_bytes(val) as u64;