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-09 07:01:07 -05:00
|
|
|
let destination = instruction.a;
|
2024-12-08 08:01:15 -05:00
|
|
|
let constant_index = instruction.b;
|
|
|
|
let jump_next = instruction.c != 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-09 07:01:07 -05:00
|
|
|
let metadata = Operation::LoadConstant as u8;
|
|
|
|
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-09 07:01:07 -05:00
|
|
|
Instruction { metadata, a, b, c }
|
2024-11-26 07:14:30 -05:00
|
|
|
}
|
|
|
|
}
|