[UNVERIFIED] update to spec 1.10, parser rewrite.
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
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: *data
|
||||
});
|
||||
}
|
||||
@@ -6,7 +6,7 @@ pub fn jnz(memory: &mut Vec<u16>, labels: &mut [Option<i16>; 256], program_count
|
||||
std::process::exit(2);
|
||||
}
|
||||
|
||||
if memory.last() != Some(&0) {
|
||||
if memory.pop() != Some(0) {
|
||||
*program_counter = (labels[*data as usize].unwrap() - 1) as u16;
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ pub fn jz(memory: &mut Vec<u16>, labels: &mut [Option<i16>; 256], program_counte
|
||||
std::process::exit(2);
|
||||
}
|
||||
|
||||
if memory.last() == Some(&0) {
|
||||
if memory.pop() == Some(0) {
|
||||
*program_counter = (labels[*data as usize].unwrap() - 1) as u16;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
use crate::errors::RunError;
|
||||
|
||||
pub fn kjnz(memory: &mut Vec<u16>, labels: &mut [Option<i16>; 256], program_counter: &mut u16, data: &u16) {
|
||||
if labels[*data as usize].is_none() {
|
||||
eprintln!("{}", RunError::UnknownLabel(*data));
|
||||
std::process::exit(2);
|
||||
}
|
||||
|
||||
if memory.last() != Some(&0) {
|
||||
*program_counter = (labels[*data as usize].unwrap() - 1) as u16;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
use crate::errors::RunError;
|
||||
|
||||
pub fn kjz(memory: &mut Vec<u16>, labels: &mut [Option<i16>; 256], program_counter: &mut u16, data: &u16) {
|
||||
if labels[*data as usize].is_none() {
|
||||
eprintln!("{}", RunError::UnknownLabel(*data));
|
||||
std::process::exit(2);
|
||||
}
|
||||
|
||||
if memory.last() == Some(&0) {
|
||||
*program_counter = (labels[*data as usize].unwrap() - 1) as u16;
|
||||
}
|
||||
}
|
||||
@@ -32,4 +32,8 @@ pub mod band;
|
||||
pub mod bor;
|
||||
pub mod bxor;
|
||||
pub mod bnand;
|
||||
pub mod not;
|
||||
pub mod not;
|
||||
pub mod kjnz;
|
||||
pub mod kjz;
|
||||
pub mod print;
|
||||
pub mod insert;
|
||||
@@ -0,0 +1,3 @@
|
||||
pub fn print(arg: &String) {
|
||||
println!("{}", arg);
|
||||
}
|
||||
Reference in New Issue
Block a user