forked from n3tael/labast
изменен стиль кода, изменено расположение инструкций
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
use crate::stack::StackVec;
|
||||
|
||||
pub fn and(memory: &mut StackVec) {
|
||||
let a: bool = memory.pop() == 1;
|
||||
let b: bool = memory.pop() == 1;
|
||||
|
||||
let c: u16 = if a && b { 1 } else { 0 };
|
||||
|
||||
memory.push(c);
|
||||
}
|
||||
|
||||
pub fn or(memory: &mut StackVec) {
|
||||
let a: bool = memory.pop() == 1;
|
||||
let b: bool = memory.pop() == 1;
|
||||
|
||||
let c: u16 = if a || b { 1 } else { 0 };
|
||||
|
||||
memory.push(c);
|
||||
}
|
||||
|
||||
pub fn xor(memory: &mut StackVec) {
|
||||
let a: bool = memory.pop() == 1;
|
||||
let b: bool = memory.pop() == 1;
|
||||
|
||||
let c: u16 = if !a != !b { 1 } else { 0 };
|
||||
|
||||
memory.push(c);
|
||||
}
|
||||
|
||||
pub fn nand(memory: &mut StackVec) {
|
||||
let a: bool = memory.pop() == 1;
|
||||
let b: bool = memory.pop() == 1;
|
||||
|
||||
let c: u16 = if !(a && b) { 1 } else { 0 };
|
||||
|
||||
memory.push(c);
|
||||
}
|
||||
|
||||
pub fn not(memory: &mut StackVec) {
|
||||
let a: bool = memory.pop() == 1;
|
||||
|
||||
let c: u16 = if !a { 1 } else { 0 };
|
||||
|
||||
memory.push(c);
|
||||
}
|
||||
Reference in New Issue
Block a user