This commit is contained in:
n3tael 2024-02-08 20:29:37 +02:00
parent b3d1380eba
commit de2d98bfec
Signed by: n3tael
GPG Key ID: F305925762F035A8

View File

@ -1,8 +1,9 @@
use crate::stack::StackVec;
use crate::{errors::RunError, stack::StackVec};
pub fn rjmp(memory: &mut StackVec, labels: &mut [Option<i16>; 256], program_counter: &mut u16) {
let start = memory.pop() as usize;
let end = memory.pop() as usize;
let rand = fastrand::usize(start..end + 1);
*program_counter = (labels[fastrand::usize(start..end)].unwrap() - 1) as u16;
*program_counter = (labels[rand].expect(&format!("{}", RunError::UnknownLabel(rand as u16))) - 1) as u16;
}