*_operand.rs: Directly delegate when possible in Display

This commit is contained in:
John 2023-08-23 00:21:54 -05:00
parent 7901c24d80
commit 2f867a67ad
2 changed files with 11 additions and 10 deletions

View File

@ -126,20 +126,21 @@ impl From<SecondaryOperand> for PrimaryOperand {
} }
impl Display for PrimaryOperand { impl Display for PrimaryOperand {
// Turn the operand back into a form which parses into the same type
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self { match self {
Self::Direct(r) => write!(f, "{r}"), Self::Direct(r) => Display::fmt(r, f),
Self::Indirect(r) => write!(f, "@{r}"), Self::Indirect(r) => write!(f, "@{r}"),
Self::PostInc(r) => write!(f, "@{r}+"), Self::PostInc(r) => write!(f, "@{r}+"),
Self::Indexed(r, idx) => write!(f, "{idx}({r})"), Self::Indexed(r, idx) => write!(f, "{idx}({r})"),
Self::Absolute(n) => write!(f, "&{n}"), Self::Absolute(n) => write!(f, "&{n}"),
Self::Immediate(n) => write!(f, "#{n}"), Self::Immediate(n) => write!(f, "#{n}"),
Self::Four => write!(f, "#4"), Self::Four => Display::fmt("#4", f),
Self::Eight => write!(f, "#8"), Self::Eight => Display::fmt("#8", f),
Self::Zero => write!(f, "#0"), Self::Zero => Display::fmt("#0", f),
Self::One => write!(f, "#1"), Self::One => Display::fmt("#1", f),
Self::Two => write!(f, "#2"), Self::Two => Display::fmt("#2", f),
Self::MinusOne => write!(f, "#-1"), Self::MinusOne => Display::fmt("#-1", f),
} }
} }
} }

View File

@ -85,11 +85,11 @@ impl Parsable for SecondaryOperand {
impl Display for SecondaryOperand { impl Display for SecondaryOperand {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self { match self {
Self::Direct(r) => write!(f, "{r}"), Self::Direct(r) => Display::fmt(r, f),
Self::Indexed(r, idx) => write!(f, "{idx}({r})"), Self::Indexed(r, idx) => write!(f, "{idx}({r})"),
Self::Absolute(n) => write!(f, "&{n}"), Self::Absolute(n) => write!(f, "&{n}"),
Self::Zero => write!(f, "#0"), Self::Zero => Display::fmt("#0", f),
Self::One => write!(f, "#1"), Self::One => Display::fmt("#1", f),
} }
} }
} }