misc: formatting and clippy lint fixes
This commit is contained in:
@@ -1,8 +1,5 @@
|
||||
use std::{
|
||||
sync::{
|
||||
Arc, Mutex, MutexGuard,
|
||||
mpsc::{self, Receiver, Sender},
|
||||
},
|
||||
sync::mpsc::{self, Receiver, Sender},
|
||||
thread,
|
||||
time::Duration,
|
||||
};
|
||||
@@ -48,7 +45,7 @@ pub fn run_emulator(
|
||||
};
|
||||
|
||||
if let Some(cmd) = cmd {
|
||||
println!("Received command: {:?}", cmd);
|
||||
println!("Received command: {cmd:?}");
|
||||
|
||||
match cmd {
|
||||
Command::Start => {
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
use super::*;
|
||||
use crate::emulator::system::memory::*;
|
||||
|
||||
use common::instructions::{
|
||||
args::{ITypeArgs, RTypeArgs},
|
||||
*,
|
||||
};
|
||||
use common::prelude::*;
|
||||
|
||||
fn create_test_processor() -> Processor {
|
||||
let memory = Box::new(MainStore::new());
|
||||
|
||||
@@ -60,7 +60,8 @@ impl Component for Editor {
|
||||
}
|
||||
|
||||
impl Editor {
|
||||
pub fn new(sender: Sender<Command>) -> Self {
|
||||
#[must_use]
|
||||
pub const fn new(sender: Sender<Command>) -> Self {
|
||||
Self {
|
||||
filename: String::new(),
|
||||
text: String::new(),
|
||||
@@ -75,7 +76,7 @@ impl Editor {
|
||||
}
|
||||
}
|
||||
|
||||
fn render_output(&mut self, _state: &mut State, ui: &mut Ui, _ctx: &Context) {
|
||||
fn render_output(&self, _state: &mut State, ui: &mut Ui, _ctx: &Context) {
|
||||
// Output area with synchronized scrolling
|
||||
egui::ScrollArea::vertical()
|
||||
.id_salt("output_scroll")
|
||||
@@ -117,7 +118,7 @@ impl Editor {
|
||||
style.visuals.widgets.inactive.bg_fill =
|
||||
egui::Color32::from_gray(30);
|
||||
ui.label(
|
||||
egui::RichText::new(format!("0x{:04X}", address))
|
||||
egui::RichText::new(format!("0x{address:04X}"))
|
||||
.font(egui::FontId::monospace(12.0)),
|
||||
);
|
||||
},
|
||||
@@ -126,26 +127,26 @@ impl Editor {
|
||||
// Individual bytes column
|
||||
let byte_str = chunk
|
||||
.iter()
|
||||
.map(|b| format!("{:02X}", b))
|
||||
.map(|b| format!("{b:02X}"))
|
||||
.collect::<Vec<_>>()
|
||||
.join(" ");
|
||||
|
||||
ui.label(
|
||||
egui::RichText::new(format!("{:<11}", byte_str))
|
||||
egui::RichText::new(format!("{byte_str:<11}"))
|
||||
.font(egui::FontId::monospace(12.0))
|
||||
.color(egui::Color32::from_rgb(200, 200, 255)),
|
||||
);
|
||||
|
||||
// Hex column
|
||||
ui.label(
|
||||
egui::RichText::new(format!("0x{:08X}", value))
|
||||
egui::RichText::new(format!("0x{value:08X}"))
|
||||
.font(egui::FontId::monospace(12.0))
|
||||
.color(egui::Color32::from_rgb(255, 200, 200)),
|
||||
);
|
||||
|
||||
// Decimal column
|
||||
ui.label(
|
||||
egui::RichText::new(format!("{:10}", value))
|
||||
egui::RichText::new(format!("{value:10}"))
|
||||
.font(egui::FontId::monospace(12.0))
|
||||
.color(egui::Color32::from_rgb(200, 255, 200)),
|
||||
);
|
||||
@@ -184,7 +185,7 @@ impl Editor {
|
||||
ui.painter().text(
|
||||
line_response.rect.left_center() + egui::vec2(5.0, 0.0),
|
||||
egui::Align2::LEFT_CENTER,
|
||||
format!("{:3}", line_num),
|
||||
format!("{line_num:3}"),
|
||||
egui::FontId::monospace(12.0),
|
||||
ui.style().visuals.text_color(),
|
||||
);
|
||||
@@ -229,18 +230,23 @@ impl Editor {
|
||||
|
||||
// error display
|
||||
ui.label(
|
||||
egui::RichText::new(self.error.clone().unwrap_or("".to_string()))
|
||||
egui::RichText::new(self.error.clone().unwrap_or_default())
|
||||
.color(egui::Color32::RED),
|
||||
);
|
||||
|
||||
// number of lines in the file
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
let line_count = self.text.lines().count();
|
||||
ui.label(format!("Lines: {}", line_count));
|
||||
ui.label(format!("Lines: {line_count}"));
|
||||
});
|
||||
});
|
||||
|
||||
ui.horizontal(|ui| {
|
||||
let work_dir = std::env::current_dir().unwrap_or_else(|_| {
|
||||
dirs::home_dir()
|
||||
.expect("Couldn't get your current working directory or your home directory.")
|
||||
});
|
||||
|
||||
ui.spacing_mut().button_padding = egui::vec2(8.0, 4.0);
|
||||
ui.spacing_mut().item_spacing.x = 6.0;
|
||||
|
||||
@@ -249,7 +255,7 @@ impl Editor {
|
||||
if let Some(path) = FileDialog::new()
|
||||
.add_filter("dsafiles", &["dsa", "dsb", "dsc", "dsd"])
|
||||
.add_filter("all", &["*"])
|
||||
.set_directory(std::env::current_dir().unwrap())
|
||||
.set_directory(&work_dir)
|
||||
.pick_file()
|
||||
{
|
||||
if let Ok(content) = std::fs::read_to_string(&path) {
|
||||
@@ -266,11 +272,11 @@ impl Editor {
|
||||
if let Some(path) = FileDialog::new()
|
||||
.add_filter("dsafiles", &["dsa", "dsb", "dsc", "dsd"])
|
||||
.add_filter("all", &["*"])
|
||||
.set_directory(std::env::current_dir().unwrap())
|
||||
.set_directory(&work_dir)
|
||||
.save_file()
|
||||
{
|
||||
if let Err(e) = std::fs::write(&path, &self.text) {
|
||||
self.error = Some(format!("Failed to save file: {}", e));
|
||||
if let Err(why) = std::fs::write(&path, &self.text) {
|
||||
self.error = Some(format!("Failed to save file: {why}"));
|
||||
} else {
|
||||
self.filename = path.display().to_string();
|
||||
}
|
||||
@@ -279,7 +285,7 @@ impl Editor {
|
||||
|
||||
// builds the current file
|
||||
if ui.button("Build").clicked() {
|
||||
let instructions = assembler::assemble(&self.text);
|
||||
let _instructions = assembler::assemble(&self.text);
|
||||
|
||||
// TODO: uncomment this once assembler works!!!
|
||||
// self.output = instructions
|
||||
@@ -322,13 +328,18 @@ impl Editor {
|
||||
}
|
||||
|
||||
fn parse_address(address: &str) -> Option<u32> {
|
||||
if address.starts_with("0x") {
|
||||
u32::from_str_radix(&address[2..], 16).ok()
|
||||
} else if address.starts_with("0b") {
|
||||
u32::from_str_radix(&address[2..], 2).ok()
|
||||
} else if address.starts_with("0o") {
|
||||
u32::from_str_radix(&address[2..], 8).ok()
|
||||
} else {
|
||||
address.parse::<u32>().ok()
|
||||
}
|
||||
address.strip_prefix("0x").map_or_else(
|
||||
|| {
|
||||
address.strip_prefix("0b").map_or_else(
|
||||
|| {
|
||||
address.strip_prefix("0o").map_or_else(
|
||||
|| address.parse::<u32>().ok(),
|
||||
|oct| u32::from_str_radix(oct, 8).ok(),
|
||||
)
|
||||
},
|
||||
|bin| u32::from_str_radix(bin, 2).ok(),
|
||||
)
|
||||
},
|
||||
|hex| u32::from_str_radix(hex, 16).ok(),
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user