2024-11-26 07:14:30 -05:00
|
|
|
use crate::{Argument, Instruction, Operation};
|
|
|
|
|
|
|
|
pub struct Test {
|
|
|
|
pub argument: Argument,
|
2024-11-28 05:36:10 -05:00
|
|
|
pub test_value: bool,
|
2024-11-26 07:14:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
impl From<&Instruction> for Test {
|
|
|
|
fn from(instruction: &Instruction) -> Self {
|
2024-12-08 08:01:15 -05:00
|
|
|
let argument = instruction.b_as_argument();
|
2024-12-11 06:49:43 -05:00
|
|
|
let test_value = instruction.c_field() != 0;
|
2024-12-08 08:01:15 -05:00
|
|
|
|
2024-11-26 07:14:30 -05:00
|
|
|
Test {
|
2024-12-08 08:01:15 -05:00
|
|
|
argument,
|
|
|
|
test_value,
|
2024-11-26 07:14:30 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<Test> for Instruction {
|
|
|
|
fn from(test: Test) -> Self {
|
2024-12-11 06:49:43 -05:00
|
|
|
let operation = Operation::Test;
|
|
|
|
let (b, b_is_constant) = test.argument.as_index_and_constant_flag();
|
2024-12-09 07:01:07 -05:00
|
|
|
let c = test.test_value as u8;
|
2024-12-08 08:01:15 -05:00
|
|
|
|
2024-12-11 06:49:43 -05:00
|
|
|
Instruction::new(operation, 0, b, c, b_is_constant, false, false)
|
2024-11-26 07:14:30 -05:00
|
|
|
}
|
|
|
|
}
|