Fix some pedantic and nursery lints
This commit is contained in:
parent
a3b1178fd3
commit
c738eb0518
@ -3,7 +3,7 @@ use serde_yaml::Mapping;
|
||||
use thiserror::Error;
|
||||
|
||||
use crate::{
|
||||
card::{Card, CardType},
|
||||
card::{self, Card},
|
||||
m68k::BusError,
|
||||
};
|
||||
|
||||
@ -39,7 +39,7 @@ impl Backplane {
|
||||
return Err(CardAddError::BackplaneFull.into());
|
||||
}
|
||||
self.cards.push(
|
||||
inventory::iter::<CardType>()
|
||||
inventory::iter::<card::Type>()
|
||||
.find(|card_type| card_type.name == type_name)
|
||||
.ok_or(CardAddError::InvalidType)?
|
||||
.new_card(config)?,
|
||||
|
@ -3,12 +3,12 @@ use nullable_result::NullableResult;
|
||||
use serde_yaml::Mapping;
|
||||
use std::fmt::{Debug, Display};
|
||||
|
||||
pub struct CardType {
|
||||
pub struct Type {
|
||||
pub name: &'static str,
|
||||
new: fn(data: &Mapping) -> anyhow::Result<Box<dyn Card>>,
|
||||
}
|
||||
|
||||
impl CardType {
|
||||
impl Type {
|
||||
pub const fn new<T: Card + 'static>(name: &'static str) -> Self {
|
||||
Self {
|
||||
name,
|
||||
@ -21,7 +21,7 @@ impl CardType {
|
||||
}
|
||||
}
|
||||
|
||||
inventory::collect!(CardType);
|
||||
inventory::collect!(Type);
|
||||
|
||||
pub trait Card: Debug + Display {
|
||||
fn new(data: &Mapping) -> anyhow::Result<Self>
|
||||
@ -126,7 +126,7 @@ pub const fn u16_get_be_byte(val: u16, idx: u8) -> u8 {
|
||||
macro_rules! register {
|
||||
($typ: ty, $name: literal) => {
|
||||
paste::paste! {
|
||||
inventory::submit!($crate::card::CardType::new::<$typ>($name));
|
||||
inventory::submit!($crate::card::Type::new::<$typ>($name));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -16,20 +16,20 @@ impl Location {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn displayer<'a>(&'a self, symbol_tables: &'a SymbolTables) -> LocationDisplayer<'a> {
|
||||
LocationDisplayer {
|
||||
pub fn displayer<'a>(&'a self, symbol_tables: &'a SymbolTables) -> Displayer<'a> {
|
||||
Displayer {
|
||||
location: self,
|
||||
symbol_tables,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct LocationDisplayer<'a> {
|
||||
pub struct Displayer<'a> {
|
||||
location: &'a Location,
|
||||
symbol_tables: &'a SymbolTables,
|
||||
}
|
||||
|
||||
impl<'a> Display for LocationDisplayer<'a> {
|
||||
impl<'a> Display for Displayer<'a> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self.location {
|
||||
Location::Symbol((table, sym)) => f.write_fmt(format_args!(
|
||||
|
13
src/main.rs
13
src/main.rs
@ -25,7 +25,6 @@ use disas::DisassemblyError;
|
||||
use indexmap::IndexSet;
|
||||
use itertools::Itertools;
|
||||
use parse_int::parse;
|
||||
use peek::{PeekFormat, PeekSize};
|
||||
use reedline_repl_rs::{
|
||||
clap::{builder::BoolishValueParser, Arg, ArgAction, Command},
|
||||
Repl,
|
||||
@ -201,7 +200,7 @@ fn main() -> Result<(), anyhow::Error> {
|
||||
.get_one::<String>("stop_addr")
|
||||
.map(|s| state.symbol_tables.parse_location_address(s))
|
||||
.transpose()?;
|
||||
if stop_addr.map(|a| state.cpu.pc() == a).unwrap_or(false)
|
||||
if stop_addr.map_or(false, |a| state.cpu.pc() == a)
|
||||
|| state.symbol_tables.breakpoint_set_at(state.cpu.pc())
|
||||
|| state.address_breakpoints.contains(&state.cpu.pc())
|
||||
{
|
||||
@ -252,8 +251,8 @@ fn main() -> Result<(), anyhow::Error> {
|
||||
if fmt_str.len() != 2 {
|
||||
return Err(anyhow!("Peek format length must be 2"));
|
||||
}
|
||||
let fmt = PeekFormat::try_from(fmt_str.chars().next().unwrap())?;
|
||||
let size = PeekSize::try_from(fmt_str.chars().nth(1).unwrap())?;
|
||||
let fmt = peek::Format::try_from(fmt_str.chars().next().unwrap())?;
|
||||
let size = peek::Size::try_from(fmt_str.chars().nth(1).unwrap())?;
|
||||
let count = parse::<u32>(args.get_one::<String>("count").map_or("1", String::as_str))?;
|
||||
let addr = state
|
||||
.symbol_tables
|
||||
@ -262,9 +261,9 @@ fn main() -> Result<(), anyhow::Error> {
|
||||
let bus = state.cpu.bus_mut();
|
||||
for i in 0..count {
|
||||
match size {
|
||||
PeekSize::Byte => data.push(bus.read_byte(addr + i)? as u32),
|
||||
PeekSize::Word => data.push(bus.read_word(addr + (i * 2))? as u32),
|
||||
PeekSize::LongWord => data.push(
|
||||
peek::Size::Byte => data.push(bus.read_byte(addr + i)? as u32),
|
||||
peek::Size::Word => data.push(bus.read_word(addr + (i * 2))? as u32),
|
||||
peek::Size::LongWord => data.push(
|
||||
(bus.read_word(addr + (i * 4))? as u32) << 16
|
||||
| (bus.read_word(addr + (i * 4) + 2)? as u32),
|
||||
),
|
||||
|
43
src/peek.rs
43
src/peek.rs
@ -1,7 +1,7 @@
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub enum PeekFormat {
|
||||
pub enum Format {
|
||||
Octal,
|
||||
Hex,
|
||||
Decimal,
|
||||
@ -9,16 +9,16 @@ pub enum PeekFormat {
|
||||
Binary,
|
||||
}
|
||||
|
||||
impl PeekFormat {
|
||||
pub fn format(self, num: u32, size: PeekSize) -> String {
|
||||
impl Format {
|
||||
pub fn format(self, num: u32, size: Size) -> String {
|
||||
match self {
|
||||
Self::Octal => format!("Oo{:0>width$o}", num, width = size.byte_count()),
|
||||
Self::Hex => format!("0x{:0>width$x}", num, width = size.byte_count() * 2),
|
||||
Self::Decimal => {
|
||||
let num = match size {
|
||||
PeekSize::Byte => num as u8 as i8 as i32,
|
||||
PeekSize::Word => num as u16 as i16 as i32,
|
||||
PeekSize::LongWord => num as i32,
|
||||
Size::Byte => num as u8 as i8 as i32,
|
||||
Size::Word => num as u16 as i16 as i32,
|
||||
Size::LongWord => num as i32,
|
||||
};
|
||||
format!("{}", num)
|
||||
}
|
||||
@ -30,10 +30,10 @@ impl PeekFormat {
|
||||
|
||||
#[derive(Debug, Copy, Clone, Error)]
|
||||
#[error("Invalid peek format")]
|
||||
pub struct InvalidPeekFormat;
|
||||
pub struct InvalidFormat;
|
||||
|
||||
impl TryFrom<char> for PeekFormat {
|
||||
type Error = InvalidPeekFormat;
|
||||
impl TryFrom<char> for Format {
|
||||
type Error = InvalidFormat;
|
||||
|
||||
fn try_from(value: char) -> Result<Self, Self::Error> {
|
||||
match value {
|
||||
@ -42,49 +42,48 @@ impl TryFrom<char> for PeekFormat {
|
||||
'd' => Ok(Self::Decimal),
|
||||
'u' => Ok(Self::UnsignedDecimal),
|
||||
'b' => Ok(Self::Binary),
|
||||
_ => Err(InvalidPeekFormat),
|
||||
_ => Err(InvalidFormat),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub enum PeekSize {
|
||||
pub enum Size {
|
||||
Byte,
|
||||
Word,
|
||||
LongWord,
|
||||
}
|
||||
|
||||
impl PeekSize {
|
||||
impl Size {
|
||||
pub fn byte_count(self) -> usize {
|
||||
match self {
|
||||
PeekSize::Byte => 1,
|
||||
PeekSize::Word => 2,
|
||||
PeekSize::LongWord => 4,
|
||||
Self::Byte => 1,
|
||||
Self::Word => 2,
|
||||
Self::LongWord => 4,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chunk_size(self) -> usize {
|
||||
match self {
|
||||
PeekSize::Byte => 8,
|
||||
PeekSize::Word => 8,
|
||||
PeekSize::LongWord => 4,
|
||||
Self::Byte | Self::Word => 8,
|
||||
Self::LongWord => 4,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, Error)]
|
||||
#[error("Invalid peek size")]
|
||||
pub struct InvalidPeekSize;
|
||||
pub struct InvalidSize;
|
||||
|
||||
impl TryFrom<char> for PeekSize {
|
||||
type Error = InvalidPeekSize;
|
||||
impl TryFrom<char> for Size {
|
||||
type Error = InvalidSize;
|
||||
|
||||
fn try_from(value: char) -> Result<Self, Self::Error> {
|
||||
match value {
|
||||
'b' => Ok(Self::Byte),
|
||||
'w' => Ok(Self::Word),
|
||||
'l' => Ok(Self::LongWord),
|
||||
_ => Err(InvalidPeekSize),
|
||||
_ => Err(InvalidSize),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ impl Card for Rom {
|
||||
.get("image")
|
||||
.map(|name| name.as_str().ok_or_else(|| anyhow!("File name not string")))
|
||||
.transpose()?
|
||||
.map(|name| name.to_string());
|
||||
.map(ToString::to_string);
|
||||
let mut data = Vec::new();
|
||||
if let Some(file_name) = file_name.as_ref() {
|
||||
File::open(file_name)
|
||||
|
@ -27,7 +27,7 @@ impl Card for Storage {
|
||||
.get("image")
|
||||
.map(|name| name.as_str().ok_or_else(|| anyhow!("File name not string")))
|
||||
.transpose()?
|
||||
.map(|name| name.to_string());
|
||||
.map(ToString::to_string);
|
||||
let mut data = Vec::new();
|
||||
if let Some(file_name) = file_name.as_ref() {
|
||||
File::open(file_name)
|
||||
|
Loading…
Reference in New Issue
Block a user