Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit759195a

Browse files
committed
compile_slice to returnBuildSliceArgCount
1 parent29ee656 commit759195a

File tree

1 file changed

+12
-21
lines changed

1 file changed

+12
-21
lines changed

‎crates/codegen/src/compile.rs‎

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ impl Compiler {
401401

402402
/// Compile a slice expression
403403
// = compiler_slice
404-
fncompile_slice(&mutself,s:&ExprSlice) ->CompileResult<u32>{
404+
fncompile_slice(&mutself,s:&ExprSlice) ->CompileResult<BuildSliceArgCount>{
405405
// Compile lower
406406
ifletSome(lower) =&s.lower{
407407
self.compile_expression(lower)?;
@@ -416,13 +416,14 @@ impl Compiler {
416416
self.emit_load_const(ConstantData::None);
417417
}
418418

419-
// Compile step if present
420-
ifletSome(step) =&s.step{
421-
self.compile_expression(step)?;
422-
Ok(3)// Three values on stack
423-
}else{
424-
Ok(2)// Two values on stack
425-
}
419+
Ok(match&s.step{
420+
Some(step) =>{
421+
// Compile step if present
422+
self.compile_expression(step)?;
423+
BuildSliceArgCount::Three
424+
}
425+
None =>BuildSliceArgCount::Two,
426+
})
426427
}
427428

428429
/// Compile a subscript expression
@@ -449,29 +450,19 @@ impl Compiler {
449450

450451
// Handle two-element slice (for Load/Store, not Del)
451452
ifSelf::is_two_element_slice(slice) && !matches!(ctx,ExprContext::Del){
452-
letn =match slice{
453+
letargc =match slice{
453454
Expr::Slice(s) =>self.compile_slice(s)?,
454455
_ =>unreachable!("is_two_element_slice should only return true for Expr::Slice"),
455456
};
456457
match ctx{
457458
ExprContext::Load =>{
458459
// CPython uses BINARY_SLICE
459-
emit!(
460-
self,
461-
Instruction::BuildSlice{
462-
argc:BuildSliceArgCount::from_op_arg(n).unwrap()
463-
}
464-
);
460+
emit!(self,Instruction::BuildSlice{ argc});
465461
emit!(self,Instruction::Subscript);
466462
}
467463
ExprContext::Store =>{
468464
// CPython uses STORE_SLICE
469-
emit!(
470-
self,
471-
Instruction::BuildSlice{
472-
argc:BuildSliceArgCount::from_op_arg(n).unwrap()
473-
}
474-
);
465+
emit!(self,Instruction::BuildSlice{ argc});
475466
emit!(self,Instruction::StoreSubscript);
476467
}
477468
_ =>unreachable!(),

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp