From 4c868d1addb82e30ab6e50f12a79121f5bf5d9da Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Mon, 19 Jul 2021 02:10:41 +0100 Subject: [PATCH] jst-lower: Show ZUpdate mode in debug dump Signed-off-by: Ian Jackson --- jstest/jst-lower.rs | 27 +++++++++++++++++++++++---- src/prelude.rs | 2 +- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/jstest/jst-lower.rs b/jstest/jst-lower.rs index f543820b..6981f57a 100644 --- a/jstest/jst-lower.rs +++ b/jstest/jst-lower.rs @@ -46,6 +46,7 @@ pub struct StartPiece { pinned: bool, moveable: PieceMoveable, zlevel: ZLevel, + zupd: ZUSD, } #[derive(Debug,Clone,Default)] @@ -70,13 +71,26 @@ pub struct TestsAccumulator { tera: tera::Tera, } -#[derive(Debug,Clone)] +#[derive(Debug,Clone,EnumDiscriminants)] +#[strum_discriminants(derive(Ord,PartialOrd,Serialize))] pub enum ZUpdateSpec { Auto, Spec(ZLevel), GOnly, } use ZUpdateSpec as ZUS; +use ZUpdateSpecDiscriminants as ZUSD; + +#[ext(pub)] +impl ZUSD { + fn show(&self) -> char { + match self { + ZUSD::Auto => ' ', + ZUSD::Spec => '!', + ZUSD::GOnly => 'g', + } + } +} impl ZUpdateSpec { pub fn next(self, last: &mut zcoord::Mutable, lastg: &mut Generation) @@ -141,6 +155,7 @@ impl Test { target: bool, heavy: bool, updated: bool, + zupd: ZUSD, } let coll = self.pieces.iter().map(|(&id, start)| { @@ -152,6 +167,7 @@ impl Test { id, new_z, old_z, updated, heavy: start.heavy(), target: self.targets.contains(&id), + zupd: start.zupd.into(), } }).collect_vec(); @@ -164,11 +180,12 @@ impl Test { let new = sorted(&|p: &PieceCollated| p.new_z); for (o, n) in izip!(&old, &new).rev() { let pr = |p: &PieceCollated, zl: &ZLevel| { - print!(" {:6} {}{}{} {}", + print!(" {:6} {}{}{} {} {}", p.id.to_string(), if p.target { "T" } else { "_" }, if p.heavy { "H" } else { "_" }, if p.updated { "U" } else { "_" }, + p.zupd.show(), zl.show()); }; pr(o, &o.old_z); print!(" "); @@ -321,9 +338,10 @@ impl TestsAccumulator { let pieces: IndexMap = pieces.into_iter().map( |StartPieceSpec { id, pinned, moveable, zupd }| { + let zupd_d = (&zupd).into(); let id = id.try_into().unwrap(); let zlevel = zupd.next(&mut zlast, &mut zlastg); - (id, StartPiece { pinned, moveable, zlevel }) + (id, StartPiece { pinned, moveable, zlevel, zupd: zupd_d }) } ).collect(); @@ -333,10 +351,11 @@ impl TestsAccumulator { println!("-------------------- {} --------------------", name); for (id,p) in pieces.iter().rev() { - println!(" {:6} {}{} {}", + println!(" {:6} {}{} {} {}", id.to_string(), if targets.contains(id) { "T" } else { "_" }, if p.heavy() { "H" } else { "_" }, + p.zupd.show(), p.zlevel.show()); } diff --git a/src/prelude.rs b/src/prelude.rs index 62ef2587..b73c0b4d 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -95,7 +95,7 @@ pub use serde_with::DeserializeFromStr; pub use serde_with::SerializeDisplay; pub use sha2::{Sha512, Sha512Trunc256}; pub use slotmap::{dense::DenseSlotMap, SparseSecondaryMap, Key as _}; -pub use strum::{EnumCount}; +pub use strum::{EnumCount, EnumDiscriminants}; pub use strum::{EnumString, EnumIter, EnumMessage, EnumProperty}; pub use strum::{IntoEnumIterator, IntoStaticStr}; pub use subtle::ConstantTimeEq; -- 2.30.2