MCPcopy Index your code
hub / github.com/RustPython/RustPython / pattern_helper_sequence_subscr

Method pattern_helper_sequence_subscr

crates/codegen/src/compile.rs:6085–6136  ·  view source on GitHub ↗
(
        &mut self,
        patterns: &[ast::Pattern],
        star: usize,
        pc: &mut PatternContext,
    )

Source from the content-addressed store, hash-verified

6083 }
6084
6085 fn pattern_helper_sequence_subscr(
6086 &mut self,
6087 patterns: &[ast::Pattern],
6088 star: usize,
6089 pc: &mut PatternContext,
6090 ) -> CompileResult<()> {
6091 // Keep the subject around for extracting elements.
6092 pc.on_top += 1;
6093 for (i, pattern) in patterns.iter().enumerate() {
6094 // if pattern.is_wildcard() {
6095 // continue;
6096 // }
6097 if i == star {
6098 // This must be a starred wildcard.
6099 // assert!(pattern.is_star_wildcard());
6100 continue;
6101 }
6102 // Duplicate the subject.
6103 emit!(self, Instruction::Copy { i: 1 });
6104 if i < star {
6105 // For indices before the star, use a nonnegative index equal to i.
6106 self.emit_load_const(ConstantData::Integer { value: i.into() });
6107 } else {
6108 // For indices after the star, compute a nonnegative index:
6109 // index = len(subject) - (size - i)
6110 emit!(self, Instruction::GetLen);
6111 self.emit_load_const(ConstantData::Integer {
6112 value: (patterns.len() - i).into(),
6113 });
6114 // Subtract to compute the correct index.
6115 emit!(
6116 self,
6117 Instruction::BinaryOp {
6118 op: BinaryOperator::Subtract
6119 }
6120 );
6121 }
6122 // Use BINARY_OP/NB_SUBSCR to extract the element.
6123 emit!(
6124 self,
6125 Instruction::BinaryOp {
6126 op: BinaryOperator::Subscr
6127 }
6128 );
6129 // Compile the subpattern in irrefutable mode.
6130 self.compile_pattern_subpattern(pattern, pc)?;
6131 }
6132 // Pop the subject off the stack.
6133 pc.on_top -= 1;
6134 emit!(self, Instruction::PopTop);
6135 Ok(())
6136 }
6137
6138 fn compile_pattern_subpattern(
6139 &mut self,

Callers 1

Calls 4

emit_load_constMethod · 0.80
iterMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected