(&mut self, expression: &ast::Expr)
| 7779 | } |
| 7780 | |
| 7781 | fn compile_expression(&mut self, expression: &ast::Expr) -> CompileResult<()> { |
| 7782 | trace!("Compiling {expression:?}"); |
| 7783 | let range = expression.range(); |
| 7784 | self.set_source_range(range); |
| 7785 | |
| 7786 | match &expression { |
| 7787 | ast::Expr::Call(ast::ExprCall { |
| 7788 | func, arguments, .. |
| 7789 | }) => self.compile_call(func, arguments)?, |
| 7790 | ast::Expr::BoolOp(ast::ExprBoolOp { op, values, .. }) => { |
| 7791 | self.compile_bool_op(op, values)? |
| 7792 | } |
| 7793 | ast::Expr::BinOp(ast::ExprBinOp { |
| 7794 | left, op, right, .. |
| 7795 | }) => { |
| 7796 | // optimize_format_str: 'format' % (args,) → f-string bytecode |
| 7797 | if matches!(op, ast::Operator::Mod) |
| 7798 | && let ast::Expr::StringLiteral(s) = left.as_ref() |
| 7799 | && let ast::Expr::Tuple(ast::ExprTuple { elts, .. }) = right.as_ref() |
| 7800 | && !elts.iter().any(|e| matches!(e, ast::Expr::Starred(_))) |
| 7801 | && self.try_optimize_format_str(s.value.to_str(), elts, range)? |
| 7802 | { |
| 7803 | return Ok(()); |
| 7804 | } |
| 7805 | self.compile_expression(left)?; |
| 7806 | self.compile_expression(right)?; |
| 7807 | |
| 7808 | // Restore full expression range before emitting the operation |
| 7809 | self.set_source_range(range); |
| 7810 | self.compile_op(op, false); |
| 7811 | } |
| 7812 | ast::Expr::Subscript(ast::ExprSubscript { |
| 7813 | value, slice, ctx, .. |
| 7814 | }) => { |
| 7815 | self.compile_subscript(value, slice, *ctx)?; |
| 7816 | } |
| 7817 | ast::Expr::UnaryOp(ast::ExprUnaryOp { op, operand, .. }) => { |
| 7818 | self.compile_expression(operand)?; |
| 7819 | |
| 7820 | // Restore full expression range before emitting the operation |
| 7821 | self.set_source_range(range); |
| 7822 | match op { |
| 7823 | ast::UnaryOp::UAdd => emit!( |
| 7824 | self, |
| 7825 | Instruction::CallIntrinsic1 { |
| 7826 | func: bytecode::IntrinsicFunction1::UnaryPositive |
| 7827 | } |
| 7828 | ), |
| 7829 | ast::UnaryOp::USub => emit!(self, Instruction::UnaryNegative), |
| 7830 | ast::UnaryOp::Not => { |
| 7831 | emit!(self, Instruction::ToBool); |
| 7832 | emit!(self, Instruction::UnaryNot); |
| 7833 | } |
| 7834 | ast::UnaryOp::Invert => emit!(self, Instruction::UnaryInvert), |
| 7835 | }; |
| 7836 | } |
| 7837 | ast::Expr::Attribute(ast::ExprAttribute { value, attr, .. }) => { |
| 7838 | // Check for super() attribute access optimization |
no test coverage detected