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

38 lines
947 B
Rust
Raw Normal View History

use crate::{Destination, Instruction, Operation};
2024-11-26 07:14:30 -05:00
pub struct LoadConstant {
pub destination: Destination,
2024-11-26 07:14:30 -05:00
pub constant_index: u16,
pub jump_next: bool,
}
impl From<&Instruction> for LoadConstant {
fn from(instruction: &Instruction) -> Self {
2024-12-08 08:01:15 -05:00
let destination = instruction.a_as_destination();
let constant_index = instruction.b;
let jump_next = instruction.c != 0;
2024-11-26 07:14:30 -05:00
LoadConstant {
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-08 08:01:15 -05:00
let (a, options) = load_constant.destination.as_index_and_a_options();
let b = load_constant.constant_index;
let c = load_constant.jump_next as u16;
2024-12-08 08:01:15 -05:00
Instruction {
operation: Operation::LOAD_CONSTANT,
options,
a,
b,
c,
}
2024-11-26 07:14:30 -05:00
}
}