labast v1.0.4
* Исправлен баг c "quit" * Исправлены "band", "bnand", "bor", "bxor" (спасибо Владу) * Переписан "args" (это вообще не надо было как оказывается, но зато код стал более читабельным) * Исправлен баг с парсером
This commit is contained in:
+10
-13
@@ -1,21 +1,18 @@
|
||||
use crate::{errors::RunError, stack::Stack};
|
||||
|
||||
pub fn args(memory: &mut Vec<u16>, origin_stack: &mut Option<&mut Stack>, data: &u16) {
|
||||
let origin_memory = &mut origin_stack.as_mut().expect(&format!("{}", RunError::RequestArgsInMainModule)).memory;
|
||||
if let Some(origin_stack) = origin_stack.as_mut() {
|
||||
let mut data = *data;
|
||||
|
||||
if *origin_memory == *memory {
|
||||
if data == 0 {
|
||||
data = origin_stack.memory.pop().expect(&format!("{}", RunError::MemoryEmpty));
|
||||
}
|
||||
|
||||
for _ in 0..data {
|
||||
memory.push(origin_stack.memory.pop().expect(&format!("{}", RunError::MemoryEmpty)));
|
||||
}
|
||||
} else {
|
||||
eprintln!("{}", RunError::RequestArgsInMainModule);
|
||||
std::process::exit(2);
|
||||
}
|
||||
|
||||
let quanity: u16;
|
||||
if *data == 0 {
|
||||
quanity = origin_memory.pop().expect(&format!("{}", RunError::MemoryEmpty));
|
||||
} else {
|
||||
quanity = *data;
|
||||
}
|
||||
|
||||
for _ in 0..quanity {
|
||||
memory.push(origin_memory.pop().expect(&format!("{}", RunError::MemoryEmpty)));
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,8 @@
|
||||
use crate::errors::RunError;
|
||||
|
||||
pub fn band(memory: &mut Vec<u16>) {
|
||||
let a: bool = memory.pop().expect(&format!("{}", RunError::MemoryEmpty)) == 1;
|
||||
let b: bool = memory.pop().expect(&format!("{}", RunError::MemoryEmpty)) == 1;
|
||||
let a: u16 = memory.pop().expect(&format!("{}", RunError::MemoryEmpty));
|
||||
let b: u16 = memory.pop().expect(&format!("{}", RunError::MemoryEmpty));
|
||||
|
||||
let c: u16 = if a & b {
|
||||
1
|
||||
} else {
|
||||
0
|
||||
};
|
||||
|
||||
memory.push(c);
|
||||
}
|
||||
memory.push(a & b);
|
||||
}
|
||||
|
||||
@@ -1,14 +1,8 @@
|
||||
use crate::errors::RunError;
|
||||
|
||||
pub fn bnand(memory: &mut Vec<u16>) {
|
||||
let a: bool = memory.pop().expect(&format!("{}", RunError::MemoryEmpty)) == 1;
|
||||
let b: bool = memory.pop().expect(&format!("{}", RunError::MemoryEmpty)) == 1;
|
||||
let a: u16 = memory.pop().expect(&format!("{}", RunError::MemoryEmpty));
|
||||
let b: u16 = memory.pop().expect(&format!("{}", RunError::MemoryEmpty));
|
||||
|
||||
let c: u16 = if !(a & b) {
|
||||
1
|
||||
} else {
|
||||
0
|
||||
};
|
||||
|
||||
memory.push(c);
|
||||
}
|
||||
memory.push(!(a & b));
|
||||
}
|
||||
|
||||
+4
-10
@@ -1,14 +1,8 @@
|
||||
use crate::errors::RunError;
|
||||
|
||||
pub fn bor(memory: &mut Vec<u16>) {
|
||||
let a: bool = memory.pop().expect(&format!("{}", RunError::MemoryEmpty)) == 1;
|
||||
let b: bool = memory.pop().expect(&format!("{}", RunError::MemoryEmpty)) == 1;
|
||||
let a: u16 = memory.pop().expect(&format!("{}", RunError::MemoryEmpty));
|
||||
let b: u16 = memory.pop().expect(&format!("{}", RunError::MemoryEmpty));
|
||||
|
||||
let c: u16 = if a | b {
|
||||
1
|
||||
} else {
|
||||
0
|
||||
};
|
||||
|
||||
memory.push(c);
|
||||
}
|
||||
memory.push(a | b);
|
||||
}
|
||||
|
||||
@@ -1,14 +1,8 @@
|
||||
use crate::errors::RunError;
|
||||
|
||||
pub fn bxor(memory: &mut Vec<u16>) {
|
||||
let a: bool = memory.pop().expect(&format!("{}", RunError::MemoryEmpty)) == 1;
|
||||
let b: bool = memory.pop().expect(&format!("{}", RunError::MemoryEmpty)) == 1;
|
||||
let a: u16 = memory.pop().expect(&format!("{}", RunError::MemoryEmpty));
|
||||
let b: u16 = memory.pop().expect(&format!("{}", RunError::MemoryEmpty));
|
||||
|
||||
let c: u16 = if a ^ b {
|
||||
1
|
||||
} else {
|
||||
0
|
||||
};
|
||||
|
||||
memory.push(c);
|
||||
}
|
||||
memory.push(a ^ b);
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ pub fn exec(mut stack: &mut Stack, arg: &String, mod_name: &String) {
|
||||
let mut temp_stack = Stack::new();
|
||||
|
||||
parse(&mut temp_stack, &lines);
|
||||
|
||||
execute(&mut temp_stack, Some(&mut stack), &arg.clone());
|
||||
|
||||
for item in temp_stack.memory {
|
||||
|
||||
Reference in New Issue
Block a user