You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
1.9 KiB
74 lines
1.9 KiB
4 years ago
|
use std::fmt::{self, Display, Formatter};
|
||
|
use std::ops::Not;
|
||
|
|
||
|
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
|
||
|
pub enum Cond {
|
||
|
Equal,
|
||
|
NotEqual,
|
||
|
Zero,
|
||
|
NotZero,
|
||
|
Less,
|
||
|
LessOrEqual,
|
||
|
Greater,
|
||
|
GreaterOrEqual,
|
||
|
Positive,
|
||
|
NonPositive,
|
||
|
Negative,
|
||
|
NonNegative,
|
||
|
Overflow,
|
||
|
NotOverflow,
|
||
|
Carry,
|
||
|
NotCarry,
|
||
|
}
|
||
|
|
||
|
impl Display for Cond {
|
||
|
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
||
|
f.write_str(match self {
|
||
|
Cond::Equal => "eq",
|
||
|
Cond::NotEqual => "ne",
|
||
|
Cond::Zero => "z",
|
||
|
Cond::NotZero => "nz",
|
||
|
Cond::Less => "lt",
|
||
|
Cond::LessOrEqual => "le",
|
||
|
Cond::Greater => "gt",
|
||
|
Cond::GreaterOrEqual => "ge",
|
||
|
Cond::Positive => "pos",
|
||
|
Cond::Negative => "neg",
|
||
|
Cond::NonPositive => "npos",
|
||
|
Cond::NonNegative => "nneg",
|
||
|
Cond::Overflow => "ov",
|
||
|
Cond::Carry => "c",
|
||
|
Cond::NotCarry => "nc",
|
||
|
Cond::NotOverflow => "nov"
|
||
|
})
|
||
|
}
|
||
|
}
|
||
|
|
||
|
impl Not for Cond {
|
||
|
type Output = Cond;
|
||
|
|
||
|
fn not(self) -> Self::Output {
|
||
|
match self {
|
||
|
Cond::Equal => Cond::NotEqual,
|
||
|
Cond::Zero => Cond::NotZero,
|
||
|
Cond::Overflow => Cond::NotOverflow,
|
||
|
Cond::Carry => Cond::NotCarry,
|
||
|
|
||
|
Cond::Positive => Cond::NonPositive,
|
||
|
Cond::Negative => Cond::NonNegative,
|
||
|
Cond::NonPositive => Cond::Positive,
|
||
|
Cond::NonNegative => Cond::Negative,
|
||
|
|
||
|
Cond::NotEqual => Cond::Equal,
|
||
|
Cond::NotZero => Cond::Zero,
|
||
|
Cond::NotOverflow => Cond::Overflow,
|
||
|
Cond::NotCarry => Cond::Carry,
|
||
|
|
||
|
Cond::Less => Cond::GreaterOrEqual,
|
||
|
Cond::Greater => Cond::LessOrEqual,
|
||
|
Cond::LessOrEqual => Cond::Greater,
|
||
|
Cond::GreaterOrEqual => Cond::Less,
|
||
|
}
|
||
|
}
|
||
|
}
|