46 lines
892 B
Rust

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);
}