labast/src/instructions/self_modify.rs

29 lines
751 B
Rust

use crate::{errors::RunError, stack::Instruction};
pub fn insert(program: &mut Vec<Instruction>, arg: String, data: u16) {
let args: Vec<char> = arg.chars().collect();
if args[0] == '#' || args[0] == '$' {
eprintln!("{}", RunError::AttemptToInsertHashOrStringInst);
std::process::exit(2);
}
if args[0] == '\n' {
eprintln!("{}", RunError::AttemptToInsertEmptyConst);
std::process::exit(2);
}
if args[0] == '@' || args[1] == ' ' {
eprintln!("{}", RunError::AttemptToInsertALabel);
std::process::exit(2);
}
program.push(Instruction {
name: arg.to_string(),
arg: "\n".to_string(),
data,
ispiped: false,
isdrained: false
});
}