jetcrab\bytecode\expressions/
logical.rs1use crate::ast::Node;
2use crate::vm::instructions::Instruction;
3
4pub trait LogicalGenerator {
5 fn generate_logical_expression(&mut self, node: &Node);
6}
7
8pub trait LogicalCore {
9 fn instructions(&mut self) -> &mut Vec<Instruction>;
10 fn visit_node(&mut self, node: &Node);
11}
12
13impl<T> LogicalGenerator for T
14where
15 T: LogicalCore,
16{
17 fn generate_logical_expression(&mut self, node: &Node) {
18 if let Node::LogicalExpression(expr) = node {
19 self.visit_node(&expr.left);
20 self.visit_node(&expr.right);
21 match expr.operator.as_str() {
22 "&&" => self.instructions().push(Instruction::And),
23 "||" => self.instructions().push(Instruction::Or),
24 "??" => self.instructions().push(Instruction::NullishCoalesce),
25 _ => {
26 self.instructions().push(Instruction::And);
27 }
28 }
29 }
30 }
31}