1
0
dust/dust-lang/src/instruction/load_list.rs

36 lines
956 B
Rust
Raw Normal View History

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