diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lib.rs | 105 |
1 files changed, 103 insertions, 2 deletions
@@ -19,6 +19,20 @@ pub trait AddressDisplay { fn stringy(&self) -> String; } +/* + * TODO: this should be FromStr. + * that would require newtyping address primitives, though + * + * this is not out of the question, BUT is way more work than + * i want to put in right now + * + * this is one of those "clean it up later" situations + */ +pub trait AddrParse: Sized { + type Err; + fn parse_from(s: &str) -> Result<Self, Self::Err>; +} + pub trait Address where Self: Debug + Display + AddressDisplay + Copy + Clone + Sized + @@ -27,7 +41,7 @@ pub trait Address where Self: AddAssign + SubAssign + WrappingAdd + WrappingSub + CheckedAdd + CheckedSub + - FromStr + + AddrParse + identities::One + identities::Zero { fn to_linear(&self) -> usize; @@ -38,24 +52,68 @@ impl <T> Address for T where T: Sized + Ord + Add<Output=Self> + From<u16> + Int } */ +impl AddrParse for usize { + type Err = std::num::ParseIntError; + fn parse_from(s: &str) -> Result<Self, Self::Err> { + if s.starts_with("0x") { + usize::from_str_radix(&s[2..], 16) + } else { + usize::from_str(s) + } + } +} + impl AddressDisplay for usize { fn stringy(&self) -> String { format!("{:#x}", self) } } +impl AddrParse for u64 { + type Err = std::num::ParseIntError; + fn parse_from(s: &str) -> Result<Self, Self::Err> { + if s.starts_with("0x") { + u64::from_str_radix(&s[2..], 16) + } else { + u64::from_str(s) + } + } +} + impl AddressDisplay for u64 { fn stringy(&self) -> String { format!("{:#x}", self) } } +impl AddrParse for u32 { + type Err = std::num::ParseIntError; + fn parse_from(s: &str) -> Result<Self, Self::Err> { + if s.starts_with("0x") { + u32::from_str_radix(&s[2..], 16) + } else { + u32::from_str(s) + } + } +} + impl AddressDisplay for u32 { fn stringy(&self) -> String { format!("{:#x}", self) } } +impl AddrParse for u16 { + type Err = std::num::ParseIntError; + fn parse_from(s: &str) -> Result<Self, Self::Err> { + if s.starts_with("0x") { + u16::from_str_radix(&s[2..], 16) + } else { + u16::from_str(s) + } + } +} + impl AddressDisplay for u16 { fn stringy(&self) -> String { format!("{:#x}", self) @@ -105,12 +163,24 @@ pub struct ColorSettings { comparison: color::Fg<&'static color::Color>, invalid: color::Fg<&'static color::Color>, platform: color::Fg<&'static color::Color>, - misc: color::Fg<&'static color::Color> + misc: color::Fg<&'static color::Color>, + + register: color::Fg<&'static color::Color>, + + number: color::Fg<&'static color::Color>, + zero: color::Fg<&'static color::Color>, + one: color::Fg<&'static color::Color>, + minus_one: color::Fg<&'static color::Color>, + + function: color::Fg<&'static color::Color>, + symbol: color::Fg<&'static color::Color>, + address: color::Fg<&'static color::Color> } impl Default for ColorSettings { fn default() -> ColorSettings { ColorSettings { + /* arithmetic: color::Fg(&color::LightYellow), stack: color::Fg(&color::Magenta), nop: color::Fg(&color::Blue), @@ -121,6 +191,28 @@ impl Default for ColorSettings { invalid: color::Fg(&color::Red), platform: color::Fg(&color::Cyan), misc: color::Fg(&color::LightCyan), + */ + arithmetic: color::Fg(&color::Yellow), + stack: color::Fg(&color::Magenta), + nop: color::Fg(&color::Blue), + stop: color::Fg(&color::Red), + control: color::Fg(&color::Red), + data: color::Fg(&color::Yellow), + comparison: color::Fg(&color::Yellow), + invalid: color::Fg(&color::Red), + platform: color::Fg(&color::Cyan), + misc: color::Fg(&color::LightCyan), + + register: color::Fg(&color::Cyan), + + number: color::Fg(&color::White), + zero: color::Fg(&color::White), + one: color::Fg(&color::White), + minus_one: color::Fg(&color::White), + + function: color::Fg(&color::LightGreen), + symbol: color::Fg(&color::LightGreen), + address: color::Fg(&color::Green) } } } @@ -134,6 +226,15 @@ impl ColorSettings { pub fn data_op(&self) -> &color::Fg<&'static color::Color> { &self.data } pub fn comparison_op(&self) -> &color::Fg<&'static color::Color> { &self.comparison } pub fn invalid_op(&self) -> &color::Fg<&'static color::Color> { &self.invalid } + + pub fn register(&self) -> &color::Fg<&'static color::Color> { &self.register } + pub fn number(&self) -> &color::Fg<&'static color::Color> { &self.number } + pub fn zero(&self) -> &color::Fg<&'static color::Color> { &self.zero } + pub fn one(&self) -> &color::Fg<&'static color::Color> { &self.one } + pub fn minus_one(&self) -> &color::Fg<&'static color::Color> { &self.minus_one } + pub fn address(&self) -> &color::Fg<&'static color::Color> { &self.address } + pub fn symbol(&self) -> &color::Fg<&'static color::Color> { &self.symbol } + pub fn function(&self) -> &color::Fg<&'static color::Color> { &self.function } } /* |