2024-12-09 07:01:07 -05:00
|
|
|
use crate::{Instruction, Operation};
|
2024-11-26 07:14:30 -05:00
|
|
|
|
|
|
|
pub struct LoadConstant {
|
2024-12-09 07:01:07 -05:00
|
|
|
pub destination: u8,
|
|
|
|
pub constant_index: u8,
|
2024-11-26 07:14:30 -05:00
|
|
|
pub jump_next: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<&Instruction> for LoadConstant {
|
|
|
|
fn from(instruction: &Instruction) -> Self {
|
2024-12-11 06:49:43 -05:00
|
|
|
let destination = instruction.a_field();
|
|
|
|
let constant_index = instruction.b_field();
|
|
|
|
let jump_next = instruction.c_field() != 0;
|
2024-11-28 01:10:49 -05:00
|
|
|
|
2024-11-26 07:14:30 -05:00
|
|
|
LoadConstant {
|
2024-11-28 01:10:49 -05:00
|
|
|
destination,
|
2024-12-08 08:01:15 -05:00
|
|
|
constant_index,
|
|
|
|
jump_next,
|
2024-11-26 07:14:30 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<LoadConstant> for Instruction {
|
|
|
|
fn from(load_constant: LoadConstant) -> Self {
|
2024-12-11 06:49:43 -05:00
|
|
|
let operation = Operation::LoadConstant;
|
2024-12-09 07:01:07 -05:00
|
|
|
let a = load_constant.destination;
|
2024-12-08 08:01:15 -05:00
|
|
|
let b = load_constant.constant_index;
|
2024-12-09 07:01:07 -05:00
|
|
|
let c = load_constant.jump_next as u8;
|
2024-11-28 01:10:49 -05:00
|
|
|
|
2024-12-11 06:49:43 -05:00
|
|
|
Instruction::new(operation, a, b, c, false, false, false)
|
2024-11-26 07:14:30 -05:00
|
|
|
}
|
|
|
|
}
|