ft(interpreter): set flags for arithmatic operations

This commit is contained in:
2025-06-11 15:55:33 +09:00
parent c9bf8fdc46
commit 11a365a8b1
3 changed files with 47 additions and 17 deletions

View File

@@ -27,8 +27,8 @@ pub enum ImmediateOperand {
}
impl ImmediateOperand {
// Sign-extend [`Self::Byte`] into [`Self::Word`].
// Returns [`Self::Word`], if already a word.
/// Sign-extend [`Self::Byte`] into [`Self::Word`].
/// Returns [`Self::Word`], if already a word.
pub fn sign_extend(self) -> Self {
match self {
Self::Byte(_) => {
@@ -42,8 +42,8 @@ impl ImmediateOperand {
}
}
// Interprets [`Self::Byte`] as [`Self::Word`].
// Returns word, if already a [`Self::Word`].
/// Interprets [`Self::Byte`] as [`Self::Word`].
/// Returns word, if already a [`Self::Word`].
pub fn as_word(self) -> Self {
match self {
Self::Byte(b) => Self::Word(b as Word),
@@ -51,7 +51,7 @@ impl ImmediateOperand {
}
}
// Flip most significant bit.
/// Flip most significant bit.
pub fn flip_sign(self) -> Self {
match self {
Self::Byte(b) => Self::Byte(b ^ (1 << 7)),
@@ -59,7 +59,7 @@ impl ImmediateOperand {
}
}
// Check if value is zero.
/// Check if inner value is zero.
pub fn zero(&self) -> bool {
match self {
Self::Byte(byte) => return *byte == 0,
@@ -67,7 +67,7 @@ impl ImmediateOperand {
}
}
// Check if leasy significant byte has even number of 1's.
/// Check if leasy significant byte has even number of 1's.
pub fn parity(&self) -> bool {
match self {
Self::Byte(byte) => return byte.count_ones() % 2 != 0,