(
&mut self,
left: &ast::Expr,
ops: &[ast::CmpOp],
comparators: &[ast::Expr],
condition: bool,
target_block: BlockIdx,
)
| 6996 | } |
| 6997 | |
| 6998 | fn compile_jump_if_compare( |
| 6999 | &mut self, |
| 7000 | left: &ast::Expr, |
| 7001 | ops: &[ast::CmpOp], |
| 7002 | comparators: &[ast::Expr], |
| 7003 | condition: bool, |
| 7004 | target_block: BlockIdx, |
| 7005 | ) -> CompileResult<()> { |
| 7006 | let compare_range = self.current_source_range; |
| 7007 | let (last_op, mid_ops) = ops.split_last().unwrap(); |
| 7008 | let (last_comparator, mid_comparators) = comparators.split_last().unwrap(); |
| 7009 | |
| 7010 | self.compile_expression(left)?; |
| 7011 | |
| 7012 | if mid_comparators.is_empty() { |
| 7013 | self.compile_expression(last_comparator)?; |
| 7014 | self.set_source_range(compare_range); |
| 7015 | self.compile_addcompare(last_op); |
| 7016 | self.emit_pop_jump_by_condition(condition, target_block); |
| 7017 | return Ok(()); |
| 7018 | } |
| 7019 | |
| 7020 | let cleanup = self.new_block(); |
| 7021 | let end = self.new_block(); |
| 7022 | |
| 7023 | for (op, comparator) in mid_ops.iter().zip(mid_comparators) { |
| 7024 | self.compile_expression(comparator)?; |
| 7025 | self.set_source_range(compare_range); |
| 7026 | emit!(self, Instruction::Swap { i: 2 }); |
| 7027 | emit!(self, Instruction::Copy { i: 2 }); |
| 7028 | self.compile_addcompare(op); |
| 7029 | emit!(self, Instruction::PopJumpIfFalse { delta: cleanup }); |
| 7030 | } |
| 7031 | |
| 7032 | self.compile_expression(last_comparator)?; |
| 7033 | self.set_source_range(compare_range); |
| 7034 | self.compile_addcompare(last_op); |
| 7035 | self.emit_pop_jump_by_condition(condition, target_block); |
| 7036 | emit!(self, PseudoInstruction::Jump { delta: end }); |
| 7037 | |
| 7038 | self.switch_to_block(cleanup); |
| 7039 | emit!(self, Instruction::PopTop); |
| 7040 | if !condition { |
| 7041 | emit!( |
| 7042 | self, |
| 7043 | PseudoInstruction::Jump { |
| 7044 | delta: target_block |
| 7045 | } |
| 7046 | ); |
| 7047 | } |
| 7048 | |
| 7049 | self.switch_to_block(end); |
| 7050 | Ok(()) |
| 7051 | } |
| 7052 | |
| 7053 | fn emit_pop_jump_by_condition(&mut self, condition: bool, target_block: BlockIdx) { |
| 7054 | if condition { |
no test coverage detected