misc: apply clippy lints

This commit is contained in:
2025-06-19 15:51:23 +01:00
parent c1d72e8d4c
commit 81433dcbcd
17 changed files with 134 additions and 127 deletions
+2 -2
View File
@@ -97,7 +97,7 @@ pub fn run_emulator(
// Execute one cycle.
match processor.cycle() {
Ok((addr, instruction)) => {
history.push((addr, instruction.clone()));
history.push((addr, instruction));
}
Err(why) => {
let pcx = processor.get(Register::Pcx);
@@ -148,7 +148,7 @@ pub fn run_emulator(
}
};
history.push(instruction.clone());
history.push(instruction);
// let instruction = match Instruction::decode(cpu_lock.get(Register::Cir))
// {};
+2 -8
View File
@@ -225,19 +225,13 @@ impl Default for State {
}
}
#[derive(Clone, Debug)]
#[derive(Clone, Debug, Default)]
pub struct PersistentState {
pub history: Vec<(u32, Instruction)>,
}
impl Default for PersistentState {
fn default() -> Self {
Self { history: vec![] }
}
}
impl PersistentState {
pub fn update(&mut self, new_state: &PersistentState) {
pub fn update(&mut self, new_state: &Self) {
self.history.extend(new_state.history.clone());
if self.history.len() > 32768 {
let len = self.history.len() - 32768;
@@ -31,7 +31,7 @@ impl Processor {
}
}
pub fn reset(&mut self) {
pub const fn reset(&mut self) {
// set all registers to zero
// run memory.reset()
self.registers.reset();
@@ -166,8 +166,6 @@ impl Executable for Instruction {
fn execute(self, cpu: &mut Processor) {
match self {
// No operation - a blank line.
Self::Nop => {}
// Copies from SrcReg to a.drReg.
Self::Mov(a) => {
*cpu.reg(a.dr) = cpu.get(a.sr1);
@@ -395,11 +393,9 @@ impl Executable for Instruction {
cpu.halted = true;
}
Self::Segment(_) => {}
Self::Data(_) => {}
Self::Segment(_) | Self::Nop | Self::Data(_) => {}
_ => {
println!("unimplemented instruction: {}", self);
eprintln!("WARN: unimplemented instruction: {self}");
todo!()
}
}
+14 -4
View File
@@ -4,7 +4,7 @@ use crate::emulator::{
};
use eframe::egui;
use egui::{Color32, FontId, Margin, RichText, Vec2};
use egui::{Color32, FontId, Vec2};
const VGA_WIDTH: usize = 80;
const VGA_HEIGHT: usize = 25;
@@ -14,11 +14,18 @@ pub struct Display {
}
impl Display {
pub fn new() -> Self {
#[must_use]
pub const fn new() -> Self {
Self { visible: false }
}
}
impl Default for Display {
fn default() -> Self {
Self::new()
}
}
impl Component for Display {
fn name(&self) -> &'static str {
"Display"
@@ -32,13 +39,14 @@ impl Component for Display {
&mut self.visible
}
fn render(&mut self, state: &mut State, ui: &mut egui::Ui, ctx: &egui::Context) {
fn render(&mut self, state: &mut State, ui: &mut egui::Ui, _ctx: &egui::Context) {
let display: Vec<u8> = state.display_view.clone();
let font_id = FontId::monospace(12.0);
let char_width = ui.fonts(|f| f.glyph_width(&font_id, 'W'));
let line_height = ui.fonts(|f| f.row_height(&font_id));
#[expect(clippy::cast_precision_loss)]
let display_size = Vec2::new(
char_width * VGA_WIDTH as f32,
line_height * VGA_HEIGHT as f32,
@@ -56,7 +64,7 @@ impl Component for Display {
let index = y * VGA_WIDTH + x;
if index < display.len() {
let byte = display[index];
let ch = if byte >= 32 && byte <= 126 {
let ch = if (32..=126).contains(&byte) {
byte as char
} else {
' '
@@ -67,7 +75,9 @@ impl Component for Display {
}
}
#[expect(clippy::cast_precision_loss)]
let text_pos = rect.min + Vec2::new(0.0, y as f32 * line_height);
ui.painter().text(
text_pos,
egui::Align2::LEFT_TOP,
+16 -18
View File
@@ -82,7 +82,7 @@ impl Component for Editor {
impl Editor {
#[must_use]
pub fn new(sender: Sender<Command>) -> Self {
pub const fn new(sender: Sender<Command>) -> Self {
Self {
path: None,
text: String::new(),
@@ -176,7 +176,7 @@ impl Editor {
{
if let Ok(contents) = std::fs::read_to_string(&path) {
self.path = Some(path);
self.text = contents.clone();
self.text.clone_from(&contents);
self.buffer = contents;
self.unsaved = false;
}
@@ -294,7 +294,7 @@ impl Editor {
editor.show(ui, &mut self.text);
}
fn render_bottom_bar(&mut self, _state: &mut State, ui: &mut Ui, _ctx: &Context) {
fn render_bottom_bar(&self, _state: &mut State, ui: &mut Ui, _ctx: &Context) {
ui.horizontal(|ui| {
// error display
ui.label(
@@ -337,22 +337,20 @@ impl Editor {
}
// builds the current file
if ui.button("Build").clicked() {
if !self.unsaved {
if let Some(path) = &self.path {
let instructions = match assembler::assemble(path) {
Ok(instructions) => instructions,
Err(error) => {
self.error = Some(error.to_string());
return;
}
};
if ui.button("Build").clicked() && !self.unsaved {
if let Some(path) = &self.path {
let instructions = match assembler::assemble(path) {
Ok(instructions) => instructions,
Err(error) => {
self.error = Some(error.to_string());
return;
}
};
self.output = instructions
.iter()
.flat_map(|i| i.encode().to_be_bytes().to_vec())
.collect();
}
self.output = instructions
.iter()
.flat_map(|i| i.encode().to_be_bytes().to_vec())
.collect();
}
}
+8 -2
View File
@@ -42,7 +42,7 @@ impl Component for History {
for (idx, instruction) in
state.persistent.history.iter().enumerate()
{
ui.label(format!("{}: ", idx));
ui.label(format!("{idx}: "));
// Hex column
let addr = instruction.0;
@@ -65,9 +65,15 @@ impl Component for History {
}
}
impl Default for History {
fn default() -> Self {
Self::new()
}
}
impl History {
#[must_use]
pub fn new() -> Self {
pub const fn new() -> Self {
Self { visible: false }
}
}
+3 -3
View File
@@ -1,5 +1,3 @@
use std::io::Read;
use crate::emulator::{system::model::State, ui::interface::Component};
use common::instructions::Register;
@@ -52,7 +50,9 @@ impl Component for StackInspector {
for (i, value) in
state.stack_view.chunks(4).take(32).enumerate()
{
let value = u32::from_be_bytes(value.try_into().unwrap());
let value = u32::from_be_bytes(value.try_into().expect(
"Could not read 4 byte instruction or data! Something is wrong.",
));
ui.label(format!(
"{} [{}]",
i,