rant/stdlib/
boolean.rs

1use super::*;
2
3/// `[$and: lhs (bool); rhs (bool); extra* (bool)]`
4///
5/// Returns the logical AND of the operands.
6pub fn and(vm: &mut VM, (lhs, rhs, extra): (bool, bool, VarArgs<bool>)) -> RantStdResult {
7  let result = (lhs && rhs) && extra.iter().all(|b| *b);
8  vm.cur_frame_mut().write(result);
9  Ok(())
10}
11
12/// `[$or: lhs (bool); rhs (bool); extra* (bool)]`
13///
14/// Returns the logical OR of the operands.
15pub fn or(vm: &mut VM, (lhs, rhs, extra): (bool, bool, VarArgs<bool>)) -> RantStdResult {
16  let result = (lhs || rhs) || extra.iter().any(|b| *b);
17  vm.cur_frame_mut().write(result);
18  Ok(())
19}
20
21/// `[$not: val (bool)]`
22///
23/// Gets the inverse of the operand.
24pub fn not(vm: &mut VM, val: bool) -> RantStdResult {
25  vm.cur_frame_mut().write(!val);
26  Ok(())
27}
28
29/// `$xor: lhs (bool); rhs (bool)]`
30///
31/// Retirms the logical XOR of the operands.
32pub fn xor(vm: &mut VM, (lhs, rhs): (bool, bool)) -> RantStdResult {
33  vm.cur_frame_mut().write(lhs ^ rhs);
34  Ok(())
35}