forked from n3tael/labast
11 lines
392 B
Rust
11 lines
392 B
Rust
use crate::errors::RunError;
|
|
|
|
pub fn pick(memory: &mut Vec<u16>, data: &u16) {
|
|
if *data > memory.len() as u16 {
|
|
eprintln!("{}", RunError::PickTooDeep);
|
|
std::process::exit(2);
|
|
}
|
|
|
|
let arg = memory.pop().expect(&format!("{}", RunError::MemoryEmpty));
|
|
memory.push(*memory.get(memory.len() - (arg as usize) - 1).expect(&format!("{}", RunError::PickOutOfBounds)));
|
|
} |