2024-11-28 01:10:49 -05:00
|
|
|
use crate::{Destination, Instruction, Operation};
|
2024-11-26 07:14:30 -05:00
|
|
|
|
|
|
|
pub struct LoadSelf {
|
2024-11-28 01:10:49 -05:00
|
|
|
pub destination: Destination,
|
2024-11-26 07:14:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
impl From<&Instruction> for LoadSelf {
|
|
|
|
fn from(instruction: &Instruction) -> Self {
|
2024-11-28 01:10:49 -05:00
|
|
|
let destination = if instruction.a_is_local() {
|
|
|
|
Destination::Local(instruction.a())
|
|
|
|
} else {
|
|
|
|
Destination::Register(instruction.a())
|
|
|
|
};
|
|
|
|
|
|
|
|
LoadSelf { destination }
|
2024-11-26 07:14:30 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<LoadSelf> for Instruction {
|
|
|
|
fn from(load_self: LoadSelf) -> Self {
|
2024-11-28 01:10:49 -05:00
|
|
|
let (a, a_is_local) = match load_self.destination {
|
|
|
|
Destination::Local(local) => (local, true),
|
|
|
|
Destination::Register(register) => (register, false),
|
|
|
|
};
|
|
|
|
|
|
|
|
*Instruction::new(Operation::LoadSelf)
|
|
|
|
.set_a(a)
|
|
|
|
.set_a_is_local(a_is_local)
|
2024-11-26 07:14:30 -05:00
|
|
|
}
|
|
|
|
}
|