diff --git a/src/simulator/machine.rs b/src/simulator/machine.rs index f9986e5..6f73b1c 100644 --- a/src/simulator/machine.rs +++ b/src/simulator/machine.rs @@ -107,27 +107,9 @@ pub struct Machine { impl Machine { /// Machine constructor + #[deprecated] pub fn init_machine() -> Machine { - let mut shiftmask : [u64 ; 64] = [0 ; 64]; - let mut value : u64 = 0xffffffff; - - value = (value << 32) + value; - for item in &mut shiftmask { - *item = value; - value >>= 1; - } - - Machine { - pc : 0, - sp: 0, - int_reg : { let mut r = Register::::init(); r.set_reg(10, -1); r }, - fp_reg : Register::::init(), - main_memory : vec![0_u8; MEM_SIZE], - shiftmask, - interrupt: Interrupt::new(), - registers_trace : String::from(""), - status: MachineStatus::SystemMode - } + Self::default() } /// Read from main memory of the machine @@ -685,6 +667,32 @@ impl Machine { } } +impl Default for Machine { + /// Machine constructor + fn default() -> Self { + let mut shiftmask : [u64 ; 64] = [0 ; 64]; + let mut value : u64 = 0xffffffff; + + value = (value << 32) + value; + for item in &mut shiftmask { + *item = value; + value >>= 1; + } + + Machine { + pc : 0, + sp: 0, + int_reg : { let mut r = Register::::init(); r.set_reg(10, -1); r }, + fp_reg : Register::::init(), + main_memory : vec![0_u8; MEM_SIZE], + shiftmask, + interrupt: Interrupt::new(), + registers_trace : String::from(""), + status: MachineStatus::SystemMode + } + } +} + #[cfg(test)] mod test { use std::fs;