Apply clippy suggestions and format code

This commit is contained in:
pjht 2023-03-20 15:04:54 -05:00
parent f0323dab2e
commit 5259bbbe3c
Signed by: pjht
GPG Key ID: 7B5F6AFBEC7EE78E
5 changed files with 22 additions and 24 deletions

View File

@ -123,7 +123,7 @@ impl Backplane {
card: Rc::clone(&cards[interconnect.a_index]),
card_no: interconnect.a_index,
},
)
);
}
Ok(Self {
@ -134,7 +134,7 @@ impl Backplane {
}
pub fn reset(&self) {
for card in self.cards.iter() {
for card in &self.cards {
card.borrow_mut().reset();
}
}
@ -282,9 +282,9 @@ impl Backplane {
fn handle_dma(&self) {
if !self.in_dma.get() {
self.in_dma.set(true);
for card in self.cards.iter() {
for card in &self.cards {
if let Ok(mut card) = card.try_borrow_mut() {
card.handle_dma(self)
card.handle_dma(self);
}
}
self.in_dma.set(false);

View File

@ -120,7 +120,7 @@ pub trait Card: Debug + Display + mopa::Any {
fn handle_dma(&mut self, _backplane: &Backplane) {}
fn try_as_mmu(&mut self) -> Option<&mut dyn MMU> {
fn try_as_mmu(&mut self) -> Option<&mut dyn Mmu> {
None
}
@ -138,7 +138,9 @@ pub trait Card: Debug + Display + mopa::Any {
fn handle_interconnect_message(&mut self, _interconnect_no: usize, _message: Box<dyn Any>) {}
}
pub trait MMU: Card {
mopafy!(Card);
pub trait Mmu: Debug {
fn translate_address(
&mut self,
backplane: &Backplane,
@ -147,7 +149,6 @@ pub trait MMU: Card {
) -> NullableResult<u32, BusError>;
}
mopafy!(Card);
#[allow(dead_code)]
pub const fn u64_set_be_byte(val: u64, idx: u8, byte: u8) -> u64 {

View File

@ -336,7 +336,7 @@ fn main() -> Result<(), anyhow::Error> {
state.cpu.bus_mut().write_word(address, data)?;
} else {
let data = parse::<u8>(args.get_one::<String>("data").unwrap())?;
state.cpu.bus_mut().write_byte(address, data as u8)?;
state.cpu.bus_mut().write_byte(address, data)?;
}
Ok(None)
}
@ -369,7 +369,7 @@ fn main() -> Result<(), anyhow::Error> {
Err(_) => {
break;
}
}
}
}
out.pop(); // Remove trailing newline
Ok(Some(out))
@ -384,7 +384,7 @@ fn main() -> Result<(), anyhow::Error> {
.short('a')
.action(ArgAction::SetTrue)
.requires("file")
.conflicts_with_all(&["delete", "set-active"])
.conflicts_with_all(["delete", "set-active"])
.help("Append the file's symbols to the loaded list of symbols"),
)
.arg(
@ -393,7 +393,7 @@ fn main() -> Result<(), anyhow::Error> {
.short('d')
.action(ArgAction::SetTrue)
.requires("file")
.conflicts_with_all(&["append", "set-active"])
.conflicts_with_all(["append", "set-active"])
.help("Delete the symbol table instead of loading it"),
)
.arg(
@ -403,7 +403,7 @@ fn main() -> Result<(), anyhow::Error> {
.value_parser(BoolishValueParser::new())
.requires("file")
.conflicts_with_all(&["append", "delete"])
.conflicts_with_all(["append", "delete"])
.help("Set whether the symbol table is active or not"),
)
.about("Load symbols from an ELF file, or list symbols if no file provided"),
@ -524,12 +524,12 @@ fn disas_fmt(
symbol_tables: &SymbolTables,
) -> (String, Result<u32, DisassemblyError<DetailedBusError>>) {
let addr_fmt = if let Some((table, symbol, offset)) = symbol_tables.address_to_symbol(addr) {
format!("{}:{} + {} (0x{:x})", table, symbol, offset, addr)
format!("{table}:{symbol} + {offset} (0x{addr:x})")
} else {
format!("0x{:x}", addr)
format!("0x{addr:x}")
};
match cpu.disassemble(addr) {
Ok((ins, new_addr)) => (format!("{}: {}\n", addr_fmt, ins), Ok(new_addr)),
Err(e) => (format!("{}: {}\n", addr_fmt, e), Err(e)),
Ok((ins, new_addr)) => (format!("{addr_fmt}: {ins}\n"), Ok(new_addr)),
Err(e) => (format!("{addr_fmt}: {e}\n"), Err(e)),
}
}

View File

@ -4,7 +4,7 @@ use nullable_result::NullableResult;
use crate::{
backplane::Backplane,
card::{u16_get_be_byte, u32_get_be_byte, u32_set_be_byte, Card, MMU},
card::{u16_get_be_byte, u32_get_be_byte, u32_set_be_byte, Card, Mmu},
m68k::BusError,
register,
};
@ -53,7 +53,7 @@ impl Card for MmuCard {
})
}
fn try_as_mmu(&mut self) -> Option<&mut dyn MMU> {
fn try_as_mmu(&mut self) -> Option<&mut dyn Mmu> {
Some(self)
}
@ -173,10 +173,7 @@ impl Display for MmuCard {
}
}
#[derive(Debug)]
pub struct Mmu;
impl MMU for MmuCard {
impl Mmu for MmuCard {
fn translate_address(
&mut self,
backplane: &Backplane,

View File

@ -27,8 +27,8 @@ struct Config {
bitflags! {
struct Status: u16 {
const BUSY = 0b00000001;
const DATA_READY = 0b00000010;
const BUSY = 0b000_00001;
const DATA_READY = 0b0000_0010;
}
}