Skip to content

Commit 64f439f

Browse files
committed
trivial edits
1 parent b176f9c commit 64f439f

File tree

4 files changed

+25
-21
lines changed

4 files changed

+25
-21
lines changed

compiler/codegen/src/compile.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
88
#![deny(clippy::cast_possible_truncation)]
99

10-
use crate::ir::BlockIdx;
1110
use crate::{
1211
error::{CodegenError, CodegenErrorType},
1312
ir,
@@ -18,13 +17,14 @@ use itertools::Itertools;
1817
use num_complex::Complex64;
1918
use num_traits::ToPrimitive;
2019
use rustpython_ast::located::{self as located_ast, Located};
21-
use rustpython_ast::{Pattern, PatternMatchAs, PatternMatchValue};
22-
use rustpython_compiler_core::bytecode::ComparisonOperator;
2320
use rustpython_compiler_core::{
24-
bytecode::{self, Arg as OpArgMarker, CodeObject, ConstantData, Instruction, OpArg, OpArgType},
21+
bytecode::{
22+
self, Arg as OpArgMarker, CodeObject, ComparisonOperator, ConstantData, Instruction, OpArg,
23+
OpArgType,
24+
},
2525
Mode,
2626
};
27-
use rustpython_parser_core::source_code::{LineNumber, SourceLocation, SourceRange};
27+
use rustpython_parser_core::source_code::{LineNumber, SourceLocation};
2828
use std::borrow::Cow;
2929

3030
type CompileResult<T> = Result<T, CodegenError>;
@@ -216,7 +216,7 @@ macro_rules! emit {
216216

217217
struct PatternContext {
218218
current_block: usize,
219-
blocks: Vec<BlockIdx>,
219+
blocks: Vec<ir::BlockIdx>,
220220
allow_irrefutable: bool,
221221
}
222222

@@ -1766,7 +1766,7 @@ impl Compiler {
17661766

17671767
fn compile_pattern_value(
17681768
&mut self,
1769-
value: &PatternMatchValue<SourceRange>,
1769+
value: &located_ast::PatternMatchValue,
17701770
_pattern_context: &mut PatternContext,
17711771
) -> CompileResult<()> {
17721772
self.compile_expression(&value.value)?;
@@ -1781,7 +1781,7 @@ impl Compiler {
17811781

17821782
fn compile_pattern_as(
17831783
&mut self,
1784-
as_pattern: &PatternMatchAs<SourceRange>,
1784+
as_pattern: &located_ast::PatternMatchAs,
17851785
pattern_context: &mut PatternContext,
17861786
) -> CompileResult<()> {
17871787
if as_pattern.pattern.is_none() && !pattern_context.allow_irrefutable {
@@ -1808,19 +1808,23 @@ impl Compiler {
18081808

18091809
fn compile_pattern_inner(
18101810
&mut self,
1811-
pattern_type: &Pattern<SourceRange>,
1811+
pattern_type: &located_ast::Pattern,
18121812
pattern_context: &mut PatternContext,
18131813
) -> CompileResult<()> {
18141814
match &pattern_type {
1815-
Pattern::MatchValue(value) => self.compile_pattern_value(value, pattern_context),
1816-
Pattern::MatchAs(as_pattern) => self.compile_pattern_as(as_pattern, pattern_context),
1815+
located_ast::Pattern::MatchValue(value) => {
1816+
self.compile_pattern_value(value, pattern_context)
1817+
}
1818+
located_ast::Pattern::MatchAs(as_pattern) => {
1819+
self.compile_pattern_as(as_pattern, pattern_context)
1820+
}
18171821
_ => Err(self.error(CodegenErrorType::NotImplementedYet)),
18181822
}
18191823
}
18201824

18211825
fn compile_pattern(
18221826
&mut self,
1823-
pattern_type: &Pattern<SourceRange>,
1827+
pattern_type: &located_ast::Pattern,
18241828
pattern_context: &mut PatternContext,
18251829
) -> CompileResult<()> {
18261830
self.compile_pattern_inner(pattern_type, pattern_context)?;
@@ -1873,7 +1877,7 @@ impl Compiler {
18731877
emit!(self, Instruction::Pop);
18741878
} else {
18751879
// Show line coverage for default case (it doesn't create bytecode)
1876-
emit!(self, Instruction::Noop);
1880+
emit!(self, Instruction::Nop);
18771881
}
18781882
self.compile_statements(&m.body)?;
18791883
}

compiler/codegen/src/error.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ pub enum CodegenErrorType {
3030
TooManyStarUnpack,
3131
EmptyWithItems,
3232
EmptyWithBody,
33-
NotImplementedYet, // RustPython marker for unimplemented features
3433
DuplicateStore(String),
3534
InvalidMatchCase,
35+
NotImplementedYet, // RustPython marker for unimplemented features
3636
}
3737

3838
impl std::error::Error for CodegenErrorType {}
@@ -77,15 +77,15 @@ impl fmt::Display for CodegenErrorType {
7777
EmptyWithBody => {
7878
write!(f, "empty body on With")
7979
}
80-
NotImplementedYet => {
81-
write!(f, "RustPython does not implement this feature yet")
82-
}
8380
DuplicateStore(s) => {
8481
write!(f, "duplicate store {s}")
8582
}
8683
InvalidMatchCase => {
8784
write!(f, "invalid match case")
8885
}
86+
NotImplementedYet => {
87+
write!(f, "RustPython does not implement this feature yet")
88+
}
8989
}
9090
}
9191
}

compiler/core/src/bytecode.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ pub enum Instruction {
373373
/// No-op, don't do anything at all
374374
///
375375
/// Equivalent to `NOP` in cpython bytecode
376-
Noop,
376+
Nop,
377377
/// Importing by name
378378
ImportName {
379379
idx: Arg<NameIdx>,
@@ -1184,7 +1184,7 @@ impl Instruction {
11841184
///
11851185
pub fn stack_effect(&self, arg: OpArg, jump: bool) -> i32 {
11861186
match self {
1187-
Noop => 0,
1187+
Nop => 0,
11881188
ImportName { .. } | ImportNameless => -1,
11891189
ImportStar => -1,
11901190
ImportFrom { .. } => 1,
@@ -1370,7 +1370,7 @@ impl Instruction {
13701370
};
13711371

13721372
match self {
1373-
Noop => w!(Noop),
1373+
Nop => w!(Nop),
13741374
ImportName { idx } => w!(ImportName, name = idx),
13751375
ImportNameless => w!(ImportNameless),
13761376
ImportStar => w!(ImportStar),

vm/src/frame.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ impl ExecutingFrame<'_> {
517517
}
518518

519519
match instruction {
520-
bytecode::Instruction::Noop => Ok(None),
520+
bytecode::Instruction::Nop => Ok(None),
521521
bytecode::Instruction::LoadConst { idx } => {
522522
self.push_value(self.code.constants[idx.get(arg) as usize].clone().into());
523523
Ok(None)

0 commit comments

Comments
 (0)