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

33 lines
819 B
Rust
Raw Normal View History

use crate::{Instruction, Operation};
2024-11-26 07:14:30 -05:00
pub struct LoadConstant {
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 {
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-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 {
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;
let c = load_constant.jump_next as u8;
Instruction { metadata, a, b, c }
2024-11-26 07:14:30 -05:00
}
}