mindustry logic execution, map- and schematic- parsing and rendering
| -rw-r--r-- | lemu/Cargo.toml | 1 | ||||
| -rw-r--r-- | lemu/src/debug/mod.rs | 22 | ||||
| -rw-r--r-- | lemu/src/executor/mod.rs | 21 | ||||
| -rw-r--r-- | lemu/src/memory.rs | 2 |
4 files changed, 38 insertions, 8 deletions
diff --git a/lemu/Cargo.toml b/lemu/Cargo.toml index 714ecfe..2db8388 100644 --- a/lemu/Cargo.toml +++ b/lemu/Cargo.toml @@ -21,6 +21,7 @@ comat = { version = "0.1.2", optional = true } vecto = "0.1.1" [features] +debug = ["comat"] bin = ["fimg/save", "diagnose"] diagnose = ["rust-fuzzy-search", "lerr", "comat"] default = ["bin"] diff --git a/lemu/src/debug/mod.rs b/lemu/src/debug/mod.rs index ef22b45..4d7ba0a 100644 --- a/lemu/src/debug/mod.rs +++ b/lemu/src/debug/mod.rs @@ -1,2 +1,24 @@ pub mod info; pub mod printable; + +/// kill me +pub fn ff(f: f64) -> String { + let mut s = f.to_string().into_bytes(); + if let Some((dot, _)) = s.iter().enumerate().find(|&(_, b)| *b == b'.') { + let mut real = 0; + for b in &mut s[dot..].iter_mut().skip(1) { + match b { + _ if real > 4 => { + s.truncate(dot + real); + break; + } + b'1'..=b'9' => real += 1, + _ => { + s.truncate(dot + real); + break; + } + } + } + } + String::from_utf8(s).unwrap() +} diff --git a/lemu/src/executor/mod.rs b/lemu/src/executor/mod.rs index fb33c91..b855dc9 100644 --- a/lemu/src/executor/mod.rs +++ b/lemu/src/executor/mod.rs @@ -191,6 +191,8 @@ impl<'s, W: Write> ExecutorContext<'s, W> { let (ref mut img, ref mut state) = &mut self.display.displays[to.0]; while let Some(d) = self.display.buffer.pop_front() { use crate::instructions::draw::Apply; + #[cfg(feature = "debug")] + comat::cprintln!("{d:blue}"); d.apply(img.as_mut(), state); } } @@ -253,13 +255,18 @@ impl<'s, W: Write> Executor<'s, W> { // SAFETY: yee match unsafe { self.program.get_unchecked(self.inner.counter) } { PInstr::Instr(i) => { - /* - let mut instr = String::new(); - i.print(&self.debug_info, &mut instr).unwrap(); - let mut mem = String::new(); - self.inner.memory.print(&self.debug_info, &mut mem).unwrap(); - println!("exec '{instr}' ({mem})"); - */ + #[cfg(feature = "debug")] + { + let mut instr = String::new(); + i.print(&self.debug_info, &mut instr).unwrap(); + let mut mem = String::new(); + self.inner.memory.print(&self.debug_info, &mut mem).unwrap(); + comat::cprintln!( + "{black}{:0<2} | {green}{instr} {black}({mem}){reset}", + self.inner.counter + ); + } + i.run(&mut self.inner) } PInstr::Draw(i) => { diff --git a/lemu/src/memory.rs b/lemu/src/memory.rs index 86024c3..9f808f9 100644 --- a/lemu/src/memory.rs +++ b/lemu/src/memory.rs @@ -62,7 +62,7 @@ impl std::fmt::Debug for LAddress { impl std::fmt::Display for LVar<'_> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - Self::Num(n) => write!(f, "{n:.4}"), // yeeeeahhhh + Self::Num(n) => write!(f, "{}", crate::debug::ff(*n)), // yeeeeahhhh Self::String(s) => write!(f, r#""{s}""#), } } |