use melodium_core::*;
use melodium_macro::{check, mel_function, mel_treatment};
#[mel_function]
pub fn equal(a: byte, b: byte) -> bool {
a == b
}
#[mel_function]
pub fn not_equal(a: byte, b: byte) -> bool {
a != b
}
#[mel_treatment(
input a Stream<byte>
input b Stream<byte>
output result Stream<bool>
)]
pub async fn equal() {
while let (Ok(a), Ok(b)) = (a.recv_one_byte().await, b.recv_one_byte().await) {
check!(result.send_one_bool(a == b).await)
}
}
#[mel_treatment(
input a Stream<byte>
input b Stream<byte>
output result Stream<bool>
)]
pub async fn not_equal() {
while let (Ok(a), Ok(b)) = (a.recv_one_byte().await, b.recv_one_byte().await) {
check!(result.send_one_bool(a != b).await)
}
}
#[mel_function]
pub fn and(a: byte, b: byte) -> byte {
a & b
}
#[mel_function]
pub fn or(a: byte, b: byte) -> byte {
a | b
}
#[mel_function]
pub fn xor(a: byte, b: byte) -> byte {
a ^ b
}
#[mel_function]
pub fn not(val: byte) -> byte {
!val
}
#[mel_treatment(
input a Stream<byte>
input b Stream<byte>
output result Stream<byte>
)]
pub async fn and() {
while let (Ok(a), Ok(b)) = (a.recv_one_byte().await, b.recv_one_byte().await) {
check!(result.send_one_byte(a & b).await)
}
}
#[mel_treatment(
input a Stream<byte>
input b Stream<byte>
output result Stream<byte>
)]
pub async fn or() {
while let (Ok(a), Ok(b)) = (a.recv_one_byte().await, b.recv_one_byte().await) {
check!(result.send_one_byte(a | b).await)
}
}
#[mel_treatment(
input a Stream<byte>
input b Stream<byte>
output result Stream<byte>
)]
pub async fn xor() {
while let (Ok(a), Ok(b)) = (a.recv_one_byte().await, b.recv_one_byte().await) {
check!(result.send_one_byte(a ^ b).await)
}
}
#[mel_treatment(
input value Stream<byte>
output not Stream<byte>
)]
pub async fn not() {
while let Ok(values) = value.recv_byte().await {
check!(
not.send_byte(values.into_iter().map(|v| !v).collect())
.await
)
}
}