Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
flamescope = { version = "0.1.2", optional = true }

rustls = { workspace = true, optional = true }
rustls-graviola = { workspace = true, optional = true }

Check warning on line 52 in Cargo.toml

View workflow job for this annotation

GitHub Actions / cargo shear

shear/misplaced_optional_dependency

misplaced optional dependency `rustls-graviola` (remove the `optional` flag and move to `[dev-dependencies]`)

[target.'cfg(windows)'.dependencies]
libc = { workspace = true }
Expand Down Expand Up @@ -387,6 +387,7 @@
collapsible_else_if = "warn"
comparison_chain = "warn"
duration_suboptimal_units = "warn"
enum_glob_use = "warn"
explicit_deref_methods = "warn"
explicit_into_iter_loop = "warn"
explicit_iter_loop = "warn"
Expand Down
33 changes: 26 additions & 7 deletions crates/codegen/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7005,23 +7005,42 @@ impl Compiler {

/// [CPython `compiler_addcompare`](https://github.com/python/cpython/blob/627894459a84be3488a1789919679c997056a03c/Python/compile.c#L2880-L2924)
fn compile_addcompare(&mut self, op: &ast::CmpOp) {
use bytecode::ComparisonOperator::*;
match op {
ast::CmpOp::Eq => emit!(self, Instruction::CompareOp { opname: Equal }),
ast::CmpOp::NotEq => emit!(self, Instruction::CompareOp { opname: NotEqual }),
ast::CmpOp::Lt => emit!(self, Instruction::CompareOp { opname: Less }),
ast::CmpOp::Eq => emit!(
self,
Instruction::CompareOp {
opname: ComparisonOperator::Equal
}
),
ast::CmpOp::NotEq => emit!(
self,
Instruction::CompareOp {
opname: ComparisonOperator::NotEqual
}
),
ast::CmpOp::Lt => emit!(
self,
Instruction::CompareOp {
opname: ComparisonOperator::Less
}
),
ast::CmpOp::LtE => emit!(
self,
Instruction::CompareOp {
opname: LessOrEqual
opname: ComparisonOperator::LessOrEqual
}
),
ast::CmpOp::Gt => emit!(
self,
Instruction::CompareOp {
opname: ComparisonOperator::Greater
}
),
ast::CmpOp::Gt => emit!(self, Instruction::CompareOp { opname: Greater }),
ast::CmpOp::GtE => {
emit!(
self,
Instruction::CompareOp {
opname: GreaterOrEqual
opname: ComparisonOperator::GreaterOrEqual
}
)
}
Expand Down
19 changes: 10 additions & 9 deletions crates/codegen/src/symboltable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2568,16 +2568,15 @@ impl SymbolTableBuilder {
}

fn scan_pattern(&mut self, pattern: &ast::Pattern) -> SymbolTableResult {
use ast::Pattern::*;
match pattern {
MatchValue(ast::PatternMatchValue { value, .. }) => {
ast::Pattern::MatchValue(ast::PatternMatchValue { value, .. }) => {
self.scan_expression(value, ExpressionContext::Load)?
}
MatchSingleton(_) => {}
MatchSequence(ast::PatternMatchSequence { patterns, .. }) => {
ast::Pattern::MatchSingleton(_) => {}
ast::Pattern::MatchSequence(ast::PatternMatchSequence { patterns, .. }) => {
self.scan_patterns(patterns)?
}
MatchMapping(ast::PatternMatchMapping {
ast::Pattern::MatchMapping(ast::PatternMatchMapping {
keys,
patterns,
rest,
Expand All @@ -2589,27 +2588,29 @@ impl SymbolTableBuilder {
self.register_ident(rest, SymbolUsage::Assigned)?;
}
}
MatchClass(ast::PatternMatchClass { cls, arguments, .. }) => {
ast::Pattern::MatchClass(ast::PatternMatchClass { cls, arguments, .. }) => {
self.scan_expression(cls, ExpressionContext::Load)?;
self.scan_patterns(&arguments.patterns)?;
for kw in &arguments.keywords {
self.scan_pattern(&kw.pattern)?;
}
}
MatchStar(ast::PatternMatchStar { name, .. }) => {
ast::Pattern::MatchStar(ast::PatternMatchStar { name, .. }) => {
if let Some(name) = name {
self.register_ident(name, SymbolUsage::Assigned)?;
}
}
MatchAs(ast::PatternMatchAs { pattern, name, .. }) => {
ast::Pattern::MatchAs(ast::PatternMatchAs { pattern, name, .. }) => {
if let Some(pattern) = pattern {
self.scan_pattern(pattern)?;
}
if let Some(name) = name {
self.register_ident(name, SymbolUsage::Assigned)?;
}
}
MatchOr(ast::PatternMatchOr { patterns, .. }) => self.scan_patterns(patterns)?,
ast::Pattern::MatchOr(ast::PatternMatchOr { patterns, .. }) => {
self.scan_patterns(patterns)?
}
}
Ok(())
}
Expand Down
65 changes: 31 additions & 34 deletions crates/common/src/cformat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,17 @@ pub struct CFormatError {

impl fmt::Display for CFormatError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
use CFormatErrorType::*;
match self.typ {
UnmatchedKeyParentheses => write!(f, "incomplete format key"),
IncompleteFormat => write!(f, "incomplete format"),
UnsupportedFormatChar(c) => write!(
CFormatErrorType::UnmatchedKeyParentheses => write!(f, "incomplete format key"),
CFormatErrorType::IncompleteFormat => write!(f, "incomplete format"),
CFormatErrorType::UnsupportedFormatChar(c) => write!(
f,
"unsupported format character '{}' ({:#x}) at index {}",
c,
c.to_u32(),
self.index
),
IntTooBig => write!(f, "width/precision too big"),
CFormatErrorType::IntTooBig => write!(f, "width/precision too big"),
_ => write!(f, "unexpected error parsing format string"),
}
}
Expand Down Expand Up @@ -78,11 +77,9 @@ pub enum CFloatType {

impl CFloatType {
const fn case(self) -> Case {
use CFloatType::*;

match self {
ExponentLower | PointDecimalLower | GeneralLower => Case::Lower,
ExponentUpper | PointDecimalUpper | GeneralUpper => Case::Upper,
Self::ExponentLower | Self::PointDecimalLower | Self::GeneralLower => Case::Lower,
Self::ExponentUpper | Self::PointDecimalUpper | Self::GeneralUpper => Case::Upper,
}
}
}
Expand Down Expand Up @@ -443,27 +440,29 @@ impl CFormatSpec {

#[must_use]
pub fn format_number(&self, num: &BigInt) -> String {
use CNumberType::*;
let CFormatType::Number(format_type) = self.format_type else {
unreachable!()
};

let magnitude = num.abs();
let prefix = if self.flags.contains(CConversionFlags::ALTERNATE_FORM) {
match format_type {
Octal => "0o",
HexLower => "0x",
HexUpper => "0X",
CNumberType::Octal => "0o",
CNumberType::HexLower => "0x",
CNumberType::HexUpper => "0X",
_ => "",
}
} else {
""
};

let magnitude_string: String = match format_type {
DecimalD | DecimalI | DecimalU => magnitude.to_str_radix(10),
Octal => magnitude.to_str_radix(8),
HexLower => magnitude.to_str_radix(16),
HexUpper => {
CNumberType::DecimalD | CNumberType::DecimalI | CNumberType::DecimalU => {
magnitude.to_str_radix(10)
}
CNumberType::Octal => magnitude.to_str_radix(8),
CNumberType::HexLower => magnitude.to_str_radix(16),
CNumberType::HexUpper => {
let mut result = magnitude.to_str_radix(16);
result.make_ascii_uppercase();
result
Expand Down Expand Up @@ -621,35 +620,33 @@ where
C: FormatChar,
I: Iterator<Item = C>,
{
use CFloatType::*;
use CNumberType::*;
let (index, c) = iter.next().ok_or_else(|| {
(
CFormatErrorType::IncompleteFormat,
iter.peek().map_or(0, |x| x.0),
)
})?;
let format_type = match c.to_char_lossy() {
'd' => CFormatType::Number(DecimalD),
'i' => CFormatType::Number(DecimalI),
'u' => CFormatType::Number(DecimalU),
'o' => CFormatType::Number(Octal),
'x' => CFormatType::Number(HexLower),
'X' => CFormatType::Number(HexUpper),
'e' => CFormatType::Float(ExponentLower),
'E' => CFormatType::Float(ExponentUpper),
'f' => CFormatType::Float(PointDecimalLower),
'F' => CFormatType::Float(PointDecimalUpper),
'g' => CFormatType::Float(GeneralLower),
'G' => CFormatType::Float(GeneralUpper),

Ok(match c.to_char_lossy() {
'd' => CFormatType::Number(CNumberType::DecimalD),
'i' => CFormatType::Number(CNumberType::DecimalI),
'u' => CFormatType::Number(CNumberType::DecimalU),
'o' => CFormatType::Number(CNumberType::Octal),
'x' => CFormatType::Number(CNumberType::HexLower),
'X' => CFormatType::Number(CNumberType::HexUpper),
'e' => CFormatType::Float(CFloatType::ExponentLower),
'E' => CFormatType::Float(CFloatType::ExponentUpper),
'f' => CFormatType::Float(CFloatType::PointDecimalLower),
'F' => CFormatType::Float(CFloatType::PointDecimalUpper),
'g' => CFormatType::Float(CFloatType::GeneralLower),
'G' => CFormatType::Float(CFloatType::GeneralUpper),
'c' => CFormatType::Character(CCharacterType::Character),
'r' => CFormatType::String(CFormatConversion::Repr),
's' => CFormatType::String(CFormatConversion::Str),
'b' => CFormatType::String(CFormatConversion::Bytes),
'a' => CFormatType::String(CFormatConversion::Ascii),
_ => return Err((CFormatErrorType::UnsupportedFormatChar(c.into()), index)),
};
Ok(format_type)
})
}

fn parse_quantity<C, I>(iter: &mut ParseIter<I>) -> Result<Option<CFormatQuantity>, ParsingError>
Expand Down
7 changes: 3 additions & 4 deletions crates/common/src/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@ impl core::ops::BitOr for StrKind {
type Output = Self;

fn bitor(self, other: Self) -> Self {
use StrKind::*;
match (self, other) {
(Wtf8, _) | (_, Wtf8) => Wtf8,
(Utf8, _) | (_, Utf8) => Utf8,
(Ascii, Ascii) => Ascii,
(Self::Wtf8, _) | (_, Self::Wtf8) => Self::Wtf8,
(Self::Utf8, _) | (_, Self::Utf8) => Self::Utf8,
(Self::Ascii, Self::Ascii) => Self::Ascii,
}
}
}
Expand Down
Loading
Loading