diff --git a/.cargo/config.toml b/.cargo/config.toml index aecf592..c5379ea 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,2 +1,7 @@ [build] rustc-wrapper = "sccache" +# Enable to cut unused deps. +# rustflags = ["-D", "unused-crate-dependencies"] + +[future-incompat-report] +frequency = "always" diff --git a/Cargo.toml b/Cargo.toml index b15e2f8..d5039da 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,3 +1,5 @@ +cargo-features = ["codegen-backend"] + [workspace] members = ["emulator", "common", "assembler", "dsa_editor"] resolver = "3" @@ -6,3 +8,10 @@ resolver = "3" version = "0.2.0" edition = "2024" authors = ["zxq5", "nullndvoid"] + +[profile.dev] +codegen-backend = "cranelift" +panic = "abort" # Cranelift does not support stack unwinds. +lto = false +debug = true +incremental = false # sccache does not support caching incremental crates. diff --git a/assembler/src/assembler/parser.rs b/assembler/src/assembler/parser.rs index 7909058..7ac26b2 100644 --- a/assembler/src/assembler/parser.rs +++ b/assembler/src/assembler/parser.rs @@ -113,11 +113,10 @@ impl Parser { let dest = expect_type!(self.next()?, Register)?; let mut offset = Token::Immediate(0); - if let Ok(next) = self.peek_next() { - if expect_type!(next, Immediate).is_ok() { + if let Ok(next) = self.peek_next() + && expect_type!(next, Immediate).is_ok() { offset = self.next()?; } - } args = vec![base, dest, offset]; } @@ -125,11 +124,10 @@ impl Parser { let base = expect_type!(self.next()?, Register)?; let dest = expect_type!(self.next()?, Register, Symbol)?; let mut offset = Token::Immediate(0); - if let Ok(next) = self.peek_next() { - if expect_type!(next, Immediate).is_ok() { + if let Ok(next) = self.peek_next() + && expect_type!(next, Immediate).is_ok() { offset = self.next()?; } - } args = vec![base, dest, offset]; } diff --git a/assembler/src/lib.rs b/assembler/src/lib.rs index 1278fbc..d40c38a 100644 --- a/assembler/src/lib.rs +++ b/assembler/src/lib.rs @@ -23,3 +23,6 @@ pub mod prelude { pub use crate::tooling::brainf; pub use crate::tooling::project; } + +use num_cpus as _; +use threadpool as _; diff --git a/assembler/src/main.rs b/assembler/src/main.rs index 6a5fb35..53d9d84 100644 --- a/assembler/src/main.rs +++ b/assembler/src/main.rs @@ -1,3 +1,7 @@ +use common as _; +use num_cpus as _; +use threadpool as _; + use assembler::{ prelude::*, tooling::{brainf, project}, @@ -19,7 +23,7 @@ fn main() { let mut file = match fs::File::create("brainf.dsb") { Err(e) => { - eprintln!("Failed to create output file: {}", e); + eprintln!("Failed to create output file: {e}"); std::process::exit(1); } Ok(file) => file, @@ -27,7 +31,7 @@ fn main() { for instruction in result { if let Err(e) = file.write(&instruction.encode().to_be_bytes()) { - eprintln!("Failed to write to output file: {}", e); + eprintln!("Failed to write to output file: {e}"); std::process::exit(1); } } @@ -53,7 +57,7 @@ fn main() { for instruction in result { if let Err(e) = fs::write(output_path, instruction.encode().to_be_bytes()) { - eprintln!("Failed to write to output file: {}", e); + eprintln!("Failed to write to output file: {e}"); std::process::exit(1); } } diff --git a/emulator/Cargo.toml b/emulator/Cargo.toml index a8fc9ae..23f7142 100644 --- a/emulator/Cargo.toml +++ b/emulator/Cargo.toml @@ -1,8 +1,3 @@ -cargo-features = ["codegen-backend"] - -[profile.dev] -codegen-backend = "cranelift" - [package] name = "emulator" version = "0.1.0" @@ -22,7 +17,6 @@ required-features = ["config"] common = { path = "../common" } assembler = { path = "../assembler" } dsa_editor = { path = "../dsa_editor" } -eframe = { version = "0.31.1" } egui = "0.31.1" dirs = "6.0.0" discord-presence = { version = "1.6.0", optional = true } @@ -35,7 +29,7 @@ default = ["config"] discord-rpc = ["dep:discord-presence"] config = ["dep:toml", "dep:serde"] -# Add support for Android for the fun of it. +# Add support for Android for the fun of it. Currently crashes lol. [target.'cfg(target_os = "android")'.dependencies] winit = { version = "0.30.11", features = ["android-native-activity"] } # jni = "0.21.1" @@ -43,3 +37,6 @@ winit = { version = "0.30.11", features = ["android-native-activity"] } [target.'cfg(target_os = "android")'.dependencies.eframe] version = "0.31.1" features = ["android-native-activity"] + +[target.'cfg(not(target_os = "android"))'.dependencies.eframe] +version = "0.31.1" diff --git a/emulator/src/emulator/system/emulator.rs b/emulator/src/emulator/system/emulator.rs index ff4762c..fec2a9a 100644 --- a/emulator/src/emulator/system/emulator.rs +++ b/emulator/src/emulator/system/emulator.rs @@ -1,9 +1,5 @@ use std::sync::Arc; -use std::{ - sync::mpsc::{self, Receiver, Sender}, - thread, - time::Duration, -}; +use std::sync::mpsc::{self, Receiver, Sender}; #[allow(unused_imports)] use crate::emulator::misc::rpc::{Activity, RpcClient}; diff --git a/emulator/src/emulator/ui/editor.rs b/emulator/src/emulator/ui/editor.rs index bbf6840..e49ad85 100644 --- a/emulator/src/emulator/ui/editor.rs +++ b/emulator/src/emulator/ui/editor.rs @@ -218,89 +218,89 @@ impl Editor { fn handle_file_dialogs(&mut self, ctx: &egui::Context) { // Handle open dialog - if let Some(dialog) = &mut self.open_file_dialog { - if dialog.show(ctx).selected() { - if let Some(file) = dialog.path() { - // check if the file is a binary file - if file.extension().is_some_and(|ext| ext == "dsb") { - match std::fs::read(file) { - Ok(content) => { - let mut res = String::new(); - for (i, b) in content.iter().enumerate() { - _ = write!(res, "{b:02x}"); - if i % 4 == 3 { - res.push('\n'); - } - } - self.text = res.clone(); - self.buffer = res; - self.path = Some(file.to_path_buf()); - self.unsaved = false; - self.error = None; - } - Err(e) => { - self.error = Some(format!("Failed to read file: {e}")); - } - } - } else { - match std::fs::read_to_string(file) { - Ok(content) => { - self.text = content.clone(); - self.buffer = content; - self.path = Some(file.to_path_buf()); - self.unsaved = false; - self.error = None; - } - Err(e) => { - self.error = Some(format!("Failed to read file: {e}")); - } - } - } - } - self.open_file_dialog = None; - } - } - - // Handle save dialog - if let Some(dialog) = &mut self.save_file_dialog { - if dialog.show(ctx).selected() { - if let Some(file) = dialog.path() { - self.buffer = self.text.clone(); - - let content = if file.extension().is_some_and(|ext| ext == "dsb") { - let mut res = Vec::new(); - for line in self.text.lines() { - for line in line.split_whitespace() { - match u32::from_str_radix(line, 16) { - Ok(num) => res.push(num), - Err(e) => { - self.error = - Some(format!("Failed to parse file: {e}")); - return; - } + if let Some(dialog) = &mut self.open_file_dialog + && dialog.show(ctx).selected() + { + if let Some(file) = dialog.path() { + // check if the file is a binary file + if file.extension().is_some_and(|ext| ext == "dsb") { + match std::fs::read(file) { + Ok(content) => { + let mut res = String::new(); + for (i, b) in content.iter().enumerate() { + _ = write!(res, "{b:02x}"); + if i % 4 == 3 { + res.push('\n'); } } - } - res.into_iter() - .flat_map(u32::to_be_bytes) - .collect::>() - } else { - self.text.clone().as_bytes().to_vec() - }; - - match std::fs::write(file, content) { - Ok(()) => { + self.text = res.clone(); + self.buffer = res; self.path = Some(file.to_path_buf()); self.unsaved = false; self.error = None; } Err(e) => { - self.error = Some(format!("Failed to save file: {e}")); + self.error = Some(format!("Failed to read file: {e}")); + } + } + } else { + match std::fs::read_to_string(file) { + Ok(content) => { + self.text = content.clone(); + self.buffer = content; + self.path = Some(file.to_path_buf()); + self.unsaved = false; + self.error = None; + } + Err(e) => { + self.error = Some(format!("Failed to read file: {e}")); } } } - self.save_file_dialog = None; } + self.open_file_dialog = None; + } + + // Handle save dialog + if let Some(dialog) = &mut self.save_file_dialog + && dialog.show(ctx).selected() + { + if let Some(file) = dialog.path() { + self.buffer = self.text.clone(); + + let content = if file.extension().is_some_and(|ext| ext == "dsb") { + let mut res = Vec::new(); + for line in self.text.lines() { + for line in line.split_whitespace() { + match u32::from_str_radix(line, 16) { + Ok(num) => res.push(num), + Err(e) => { + self.error = + Some(format!("Failed to parse file: {e}")); + return; + } + } + } + } + res.into_iter() + .flat_map(u32::to_be_bytes) + .collect::>() + } else { + self.text.clone().as_bytes().to_vec() + }; + + match std::fs::write(file, content) { + Ok(()) => { + self.path = Some(file.to_path_buf()); + self.unsaved = false; + self.error = None; + } + Err(e) => { + self.error = Some(format!("Failed to save file: {e}")); + } + } + } + self.save_file_dialog = None; } } diff --git a/emulator/src/emulator/ui/loader.rs b/emulator/src/emulator/ui/loader.rs index 191b8f1..75b2bdd 100644 --- a/emulator/src/emulator/ui/loader.rs +++ b/emulator/src/emulator/ui/loader.rs @@ -115,24 +115,24 @@ impl Loader { fn handle_file_dialogs(&mut self, ctx: &egui::Context) { // Handle open dialog - if let Some(dialog) = &mut self.open_file_dialog { - if dialog.show(ctx).selected() { - if let Some(file) = dialog.path() { - // check if the file is a binary file - if file.extension().is_some_and(|ext| ext == "dsb") { - match std::fs::read(file) { - Ok(content) => { - self.output = content; - self.error = None; - } - Err(e) => { - self.error = Some(format!("Failed to read file: {e}")); - } + if let Some(dialog) = &mut self.open_file_dialog + && dialog.show(ctx).selected() + { + if let Some(file) = dialog.path() { + // check if the file is a binary file + if file.extension().is_some_and(|ext| ext == "dsb") { + match std::fs::read(file) { + Ok(content) => { + self.output = content; + self.error = None; + } + Err(e) => { + self.error = Some(format!("Failed to read file: {e}")); } } } - self.open_file_dialog = None; } + self.open_file_dialog = None; } }