1
0

37 lines
941 B
Rust
Raw Normal View History

use crate::{Argument, Destination, Instruction, Operation};
2024-11-26 07:14:30 -05:00
pub struct Divide {
pub destination: Destination,
2024-11-26 07:14:30 -05:00
pub left: Argument,
pub right: Argument,
}
impl From<&Instruction> for Divide {
fn from(instruction: &Instruction) -> Self {
2024-12-08 08:01:15 -05:00
let destination = instruction.a_as_destination();
2024-11-26 07:14:30 -05:00
let (left, right) = instruction.b_and_c_as_arguments();
Divide {
destination,
2024-11-26 07:14:30 -05:00
left,
right,
}
}
}
impl From<Divide> for Instruction {
fn from(divide: Divide) -> Self {
2024-12-08 08:01:15 -05:00
let (a, a_options) = divide.destination.as_index_and_a_options();
let (b, b_options) = divide.left.as_index_and_b_options();
let (c, c_options) = divide.right.as_index_and_c_options();
2024-12-08 08:01:15 -05:00
Instruction {
operation: Operation::DIVIDE,
options: a_options | b_options | c_options,
a,
b,
c,
}
2024-11-26 07:14:30 -05:00
}
}