4 Commits

Author SHA1 Message Date
zxq5 7b18922cc7 Merge pull request 'Merge compiler and emulator progress from last few months into main.' (#11) from compiler into main
Reviewed-on: #11
2026-02-14 11:54:15 +00:00
zxq5 a0b02cb955 Create tasks.json 2026-02-14 11:50:59 +00:00
zxq5 240f0e553f fixed failing tests
TODO: add comprehensive testing to everything
2026-02-14 11:50:54 +00:00
zxq5 25a59a6b19 fixed clippy lints 2026-02-14 11:50:36 +00:00
7 changed files with 48 additions and 27 deletions
+37
View File
@@ -0,0 +1,37 @@
[
{
"label": "Run Emulator",
"command": "cargo run --bin emulator",
"use_new_terminal": true,
},
{
"label": "Run Compiler",
"command": "cargo run --bin compiler",
"use_new_terminal": true,
},
{
"label": "Run Assembler",
"command": "cargo run --bin assembler",
"use_new_terminal": true,
},
{
"label": "Run Build System (dsx-build)",
"command": "cargo run --bin dsx-build",
"use_new_terminal": true,
},
{
"label": "Build All (Release)",
"command": "cargo build --release",
"use_new_terminal": false,
},
{
"label": "Run Tests",
"command": "cargo test",
"use_new_terminal": true,
},
{
"label": "Profile Emulator with perf",
"command": "cargo build --profile profiling; perf record -g -F 999 target/profiling/emulator; perf script -F +pid | save test.perf",
"use_new_terminal": true,
},
]
+2 -2
View File
@@ -83,7 +83,7 @@ impl MemoryUnit for MainStore {
#[inline] #[inline]
fn read_word(&mut self, addr: u32) -> Result<u32, ProcessorError> { fn read_word(&mut self, addr: u32) -> Result<u32, ProcessorError> {
if addr % 4 != 0 { if !addr.is_multiple_of(4) {
return Err(ProcessorError::BadMemoryAccess(addr)); return Err(ProcessorError::BadMemoryAccess(addr));
} }
@@ -116,7 +116,7 @@ impl MemoryUnit for MainStore {
#[inline] #[inline]
fn write_word(&mut self, addr: u32, value: u32) -> Result<(), ProcessorError> { fn write_word(&mut self, addr: u32, value: u32) -> Result<(), ProcessorError> {
if addr % 4 != 0 { if !addr.is_multiple_of(4) {
return Err(ProcessorError::BadMemoryAccess(addr)); return Err(ProcessorError::BadMemoryAccess(addr));
} }
-1
View File
@@ -290,7 +290,6 @@ impl RegFile {
}) })
} }
#[must_use]
pub const fn get(&self, reg: Register) -> Result<u32, ProcessorError> { pub const fn get(&self, reg: Register) -> Result<u32, ProcessorError> {
Ok(match reg { Ok(match reg {
Register::Rg0 => self.rg0, Register::Rg0 => self.rg0,
@@ -21,10 +21,6 @@ pub struct Processor {
pub cache: Cache, pub cache: Cache,
} }
fn log(message: &str) {
println!("\x1b[32mINFO:\x1b[0m {message}");
}
impl Processor { impl Processor {
#[must_use] #[must_use]
pub fn new(memory: Box<dyn MemoryUnit>, io_devices: Vec<Arc<dyn IODevice>>) -> Self { pub fn new(memory: Box<dyn MemoryUnit>, io_devices: Vec<Arc<dyn IODevice>>) -> Self {
@@ -464,7 +464,7 @@ fn test_shift_left_with_shamt() {
let shl_instr = Instruction::ShiftLeft(RTypeArgs::new( let shl_instr = Instruction::ShiftLeft(RTypeArgs::new(
Some(Register::Rg1), Some(Register::Rg1),
Some(Register::Zero), Some(Register::Zero),
None, Some(Register::Rg1),
Some(2), Some(2),
)); ));
@@ -485,7 +485,7 @@ fn test_shift_right_with_shamt() {
let shr_instr = Instruction::ShiftRight(RTypeArgs::new( let shr_instr = Instruction::ShiftRight(RTypeArgs::new(
Some(Register::Rg1), Some(Register::Rg1),
Some(Register::Zero), Some(Register::Zero),
None, Some(Register::Rg1),
Some(2), Some(2),
)); ));
+6 -14
View File
@@ -117,10 +117,7 @@ impl Editor {
.file_name() .file_name()
.unwrap_or_else(|| OsStr::new("Unnamed!")) .unwrap_or_else(|| OsStr::new("Unnamed!"))
.to_str() .to_str()
.map_or_else( .unwrap_or_else(|| unreachable!("File name should be valid UTF-8."));
|| unreachable!("File name should be valid UTF-8."),
|ext| ext,
);
} }
"Unnamed!" "Unnamed!"
} }
@@ -129,12 +126,9 @@ impl Editor {
if let Some(path) = &self.path { if let Some(path) = &self.path {
return path return path
.extension() .extension()
.map_or_else(|| OsStr::new("Unknown!"), |ext| ext) .unwrap_or_else(|| OsStr::new("Unknown!"))
.to_str() .to_str()
.map_or_else( .unwrap_or_else(|| unreachable!("File name should be valid UTF-8."));
|| unreachable!("File name should be valid UTF-8."),
|ext| ext,
);
} }
"Unknown!" "Unknown!"
} }
@@ -398,7 +392,7 @@ impl Editor {
_ => Syntax::default(), _ => Syntax::default(),
}; };
let ed = CodeEditor::default() let mut editor = CodeEditor::default()
.id_source("editor") .id_source("editor")
.with_fontsize(12.0) .with_fontsize(12.0)
.with_rows(0) .with_rows(0)
@@ -407,8 +401,6 @@ impl Editor {
.with_numlines(true) .with_numlines(true)
.desired_width(available_width - 500.0); .desired_width(available_width - 500.0);
let mut editor = ed.clone();
editor.show(ui, &mut self.text); editor.show(ui, &mut self.text);
} }
@@ -451,7 +443,7 @@ impl Editor {
Some("dsc") => { Some("dsc") => {
let output_path = Path::new(path).with_extension("dsa"); let output_path = Path::new(path).with_extension("dsa");
if let Err(e) = compiler::compile_file(path, &output_path) { if let Err(e) = compiler::compile_file(path, &output_path) {
self.error = Some(format!("Compiler error: {}", e)); self.error = Some(format!("Compiler error: {e}"));
} }
let mut compiler = CompilerEngine::new(); let mut compiler = CompilerEngine::new();
@@ -461,7 +453,7 @@ impl Editor {
let instructions = match compiler.wait_for_result() { let instructions = match compiler.wait_for_result() {
Ok(instructions) => instructions, Ok(instructions) => instructions,
Err(e) => { Err(e) => {
self.error = Some(format!("Assembler error: {}", e)); self.error = Some(format!("Assembler error: {e}"));
return; return;
} }
}; };
+1 -4
View File
@@ -79,10 +79,7 @@ impl Loader {
.file_name() .file_name()
.unwrap_or_else(|| OsStr::new("Unnamed!")) .unwrap_or_else(|| OsStr::new("Unnamed!"))
.to_str() .to_str()
.map_or_else( .unwrap_or_else(|| unreachable!("File name should be valid UTF-8."));
|| unreachable!("File name should be valid UTF-8."),
|ext| ext,
);
} }
"Unnamed!" "Unnamed!"
} }