Use Default trait instead of init_machine()
This commit is contained in:
parent
91f5c6054c
commit
f246e84f91
@ -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::<i64>::init(); r.set_reg(10, -1); r },
|
||||
fp_reg : Register::<f32>::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::<i64>::init(); r.set_reg(10, -1); r },
|
||||
fp_reg : Register::<f32>::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;
|
||||
|
Loading…
Reference in New Issue
Block a user