Skip to content

Commit bcdf37b

Browse files
authored
Align opcode names in dis (#6526)
* opcodes dis repr like cpython. POP-> POP_TOP * Adjust frame.rs * Fix codegen * snapshots * Add doc for `PopTop` * fix jit
1 parent 61ddd98 commit bcdf37b

File tree

8 files changed

+234
-230
lines changed

8 files changed

+234
-230
lines changed

crates/codegen/src/compile.rs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,7 +1063,7 @@ impl Compiler {
10631063
}
10641064
);
10651065

1066-
emit!(self, Instruction::Pop);
1066+
emit!(self, Instruction::PopTop);
10671067
} else {
10681068
self.compile_statement(statement)?;
10691069
}
@@ -1079,7 +1079,7 @@ impl Compiler {
10791079
}
10801080
);
10811081

1082-
emit!(self, Instruction::Pop);
1082+
emit!(self, Instruction::PopTop);
10831083
} else {
10841084
self.compile_statement(last)?;
10851085
self.emit_load_const(ConstantData::None);
@@ -1104,7 +1104,7 @@ impl Compiler {
11041104
if let Some(last_statement) = body.last() {
11051105
match last_statement {
11061106
Stmt::Expr(_) => {
1107-
self.current_block().instructions.pop(); // pop Instruction::Pop
1107+
self.current_block().instructions.pop(); // pop Instruction::PopTop
11081108
}
11091109
Stmt::FunctionDef(_) | Stmt::ClassDef(_) => {
11101110
let pop_instructions = self.current_block().instructions.pop();
@@ -1401,14 +1401,14 @@ impl Compiler {
14011401
}
14021402

14031403
// Pop module from stack:
1404-
emit!(self, Instruction::Pop);
1404+
emit!(self, Instruction::PopTop);
14051405
}
14061406
}
14071407
Stmt::Expr(StmtExpr { value, .. }) => {
14081408
self.compile_expression(value)?;
14091409

14101410
// Pop result of stack, since we not use it:
1411-
emit!(self, Instruction::Pop);
1411+
emit!(self, Instruction::PopTop);
14121412
}
14131413
Stmt::Global(_) | Stmt::Nonlocal(_) => {
14141414
// Handled during symbol table construction.
@@ -2051,12 +2051,12 @@ impl Compiler {
20512051
self.store_name(alias.as_str())?
20522052
} else {
20532053
// Drop exception from top of stack:
2054-
emit!(self, Instruction::Pop);
2054+
emit!(self, Instruction::PopTop);
20552055
}
20562056
} else {
20572057
// Catch all!
20582058
// Drop exception from top of stack:
2059-
emit!(self, Instruction::Pop);
2059+
emit!(self, Instruction::PopTop);
20602060
}
20612061

20622062
// Handler code:
@@ -2950,7 +2950,7 @@ impl Compiler {
29502950
self.compile_store(var)?;
29512951
}
29522952
None => {
2953-
emit!(self, Instruction::Pop);
2953+
emit!(self, Instruction::PopTop);
29542954
}
29552955
}
29562956
final_block
@@ -3143,7 +3143,7 @@ impl Compiler {
31433143
for &label in pc.fail_pop.iter().skip(1).rev() {
31443144
self.switch_to_block(label);
31453145
// Emit the POP instruction.
3146-
emit!(self, Instruction::Pop);
3146+
emit!(self, Instruction::PopTop);
31473147
}
31483148
// Finally, use the first label.
31493149
self.switch_to_block(pc.fail_pop[0]);
@@ -3187,7 +3187,7 @@ impl Compiler {
31873187
match n {
31883188
// If no name is provided, simply pop the top of the stack.
31893189
None => {
3190-
emit!(self, Instruction::Pop);
3190+
emit!(self, Instruction::PopTop);
31913191
Ok(())
31923192
}
31933193
Some(name) => {
@@ -3313,7 +3313,7 @@ impl Compiler {
33133313
}
33143314
// Pop the subject off the stack.
33153315
pc.on_top -= 1;
3316-
emit!(self, Instruction::Pop);
3316+
emit!(self, Instruction::PopTop);
33173317
Ok(())
33183318
}
33193319

@@ -3497,7 +3497,7 @@ impl Compiler {
34973497
pc.on_top -= 1;
34983498

34993499
if is_true_wildcard {
3500-
emit!(self, Instruction::Pop);
3500+
emit!(self, Instruction::PopTop);
35013501
continue; // Don't compile wildcard patterns
35023502
}
35033503

@@ -3548,7 +3548,7 @@ impl Compiler {
35483548
if size == 0 && star_target.is_none() {
35493549
// If the pattern is just "{}", we're done! Pop the subject
35503550
pc.on_top -= 1;
3551-
emit!(self, Instruction::Pop);
3551+
emit!(self, Instruction::PopTop);
35523552
return Ok(());
35533553
}
35543554

@@ -3703,8 +3703,8 @@ impl Compiler {
37033703
// Non-rest pattern: just clean up the stack
37043704

37053705
// Pop them as we're not using them
3706-
emit!(self, Instruction::Pop); // Pop keys_tuple
3707-
emit!(self, Instruction::Pop); // Pop subject
3706+
emit!(self, Instruction::PopTop); // Pop keys_tuple
3707+
emit!(self, Instruction::PopTop); // Pop subject
37083708
}
37093709

37103710
Ok(())
@@ -3792,7 +3792,7 @@ impl Compiler {
37923792
// In Rust, old_pc is a local clone, so we need not worry about that.
37933793

37943794
// No alternative matched: pop the subject and fail.
3795-
emit!(self, Instruction::Pop);
3795+
emit!(self, Instruction::PopTop);
37963796
self.jump_to_fail_pop(pc, JumpOp::Jump)?;
37973797

37983798
// Use the label "end".
@@ -3814,7 +3814,7 @@ impl Compiler {
38143814

38153815
// Old context and control will be dropped automatically.
38163816
// Finally, pop the copy of the subject.
3817-
emit!(self, Instruction::Pop);
3817+
emit!(self, Instruction::PopTop);
38183818
Ok(())
38193819
}
38203820

@@ -3888,7 +3888,7 @@ impl Compiler {
38883888
pc.on_top -= 1;
38893889
if only_wildcard {
38903890
// Patterns like: [] / [_] / [_, _] / [*_] / [_, *_] / [_, _, *_] / etc.
3891-
emit!(self, Instruction::Pop);
3891+
emit!(self, Instruction::PopTop);
38923892
} else if star_wildcard {
38933893
self.pattern_helper_sequence_subscr(patterns, star.unwrap(), pc)?;
38943894
} else {
@@ -4012,7 +4012,7 @@ impl Compiler {
40124012
}
40134013

40144014
if i != case_count - 1 {
4015-
emit!(self, Instruction::Pop);
4015+
emit!(self, Instruction::PopTop);
40164016
}
40174017

40184018
self.compile_statements(&m.body)?;
@@ -4023,7 +4023,7 @@ impl Compiler {
40234023
if has_default {
40244024
let m = &cases[num_cases - 1];
40254025
if num_cases == 1 {
4026-
emit!(self, Instruction::Pop);
4026+
emit!(self, Instruction::PopTop);
40274027
} else {
40284028
emit!(self, Instruction::Nop);
40294029
}
@@ -4125,7 +4125,7 @@ impl Compiler {
41254125
// early exit left us with stack: `rhs, comparison_result`. We need to clean up rhs.
41264126
self.switch_to_block(break_block);
41274127
emit!(self, Instruction::Swap { index: 2 });
4128-
emit!(self, Instruction::Pop);
4128+
emit!(self, Instruction::PopTop);
41294129

41304130
self.switch_to_block(after_block);
41314131
}
@@ -4192,7 +4192,7 @@ impl Compiler {
41924192
emit!(self, Instruction::StoreSubscript);
41934193
} else {
41944194
// Drop annotation if not assigned to simple identifier.
4195-
emit!(self, Instruction::Pop);
4195+
emit!(self, Instruction::PopTop);
41964196
}
41974197

41984198
Ok(())
@@ -4823,7 +4823,7 @@ impl Compiler {
48234823
arg: bytecode::ResumeType::AfterYield as u32
48244824
}
48254825
);
4826-
emit!(compiler, Instruction::Pop);
4826+
emit!(compiler, Instruction::PopTop);
48274827

48284828
Ok(())
48294829
},

crates/codegen/src/snapshots/rustpython_codegen__compile__tests__if_ands.snap

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/codegen/src/snapshots/rustpython_codegen__compile__tests__if_mixed.snap

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/codegen/src/snapshots/rustpython_codegen__compile__tests__if_ors.snap

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)