(&mut self, expr: &ast::Expr)
| 9463 | } |
| 9464 | |
| 9465 | fn try_fold_constant_expr(&mut self, expr: &ast::Expr) -> CompileResult<Option<ConstantData>> { |
| 9466 | Ok(Some(match expr { |
| 9467 | ast::Expr::NumberLiteral(num) => match &num.value { |
| 9468 | ast::Number::Int(int) => ConstantData::Integer { |
| 9469 | value: ruff_int_to_bigint(int).map_err(|e| self.error(e))?, |
| 9470 | }, |
| 9471 | ast::Number::Float(f) => ConstantData::Float { value: *f }, |
| 9472 | ast::Number::Complex { real, imag } => ConstantData::Complex { |
| 9473 | value: Complex::new(*real, *imag), |
| 9474 | }, |
| 9475 | }, |
| 9476 | ast::Expr::StringLiteral(s) => ConstantData::Str { |
| 9477 | value: self.compile_string_value(s), |
| 9478 | }, |
| 9479 | ast::Expr::BytesLiteral(b) => ConstantData::Bytes { |
| 9480 | value: b.value.bytes().collect(), |
| 9481 | }, |
| 9482 | ast::Expr::BooleanLiteral(b) => ConstantData::Boolean { value: b.value }, |
| 9483 | ast::Expr::NoneLiteral(_) => ConstantData::None, |
| 9484 | ast::Expr::EllipsisLiteral(_) => ConstantData::Ellipsis, |
| 9485 | ast::Expr::Tuple(ast::ExprTuple { elts, .. }) => { |
| 9486 | let mut elements = Vec::with_capacity(elts.len()); |
| 9487 | for elt in elts { |
| 9488 | let Some(constant) = self.try_fold_constant_expr(elt)? else { |
| 9489 | return Ok(None); |
| 9490 | }; |
| 9491 | elements.push(constant); |
| 9492 | } |
| 9493 | ConstantData::Tuple { elements } |
| 9494 | } |
| 9495 | _ => return Ok(None), |
| 9496 | })) |
| 9497 | } |
| 9498 | |
| 9499 | fn emit_load_const(&mut self, constant: ConstantData) { |
| 9500 | let idx = self.arg_constant(constant); |
no test coverage detected