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

Method compile_store

crates/codegen/src/compile.rs:7169–7236  ·  view source on GitHub ↗
(&mut self, target: &ast::Expr)

Source from the content-addressed store, hash-verified

7167 }
7168
7169 fn compile_store(&mut self, target: &ast::Expr) -> CompileResult<()> {
7170 match &target {
7171 ast::Expr::Name(ast::ExprName { id, .. }) => self.store_name(id.as_str())?,
7172 ast::Expr::Subscript(ast::ExprSubscript {
7173 value, slice, ctx, ..
7174 }) => {
7175 self.compile_subscript(value, slice, *ctx)?;
7176 }
7177 ast::Expr::Attribute(ast::ExprAttribute { value, attr, .. }) => {
7178 self.compile_expression(value)?;
7179 let namei = self.name(attr.as_str());
7180 emit!(self, Instruction::StoreAttr { namei });
7181 }
7182 ast::Expr::List(ast::ExprList { elts, .. })
7183 | ast::Expr::Tuple(ast::ExprTuple { elts, .. }) => {
7184 let mut seen_star = false;
7185
7186 // Scan for star args:
7187 for (i, element) in elts.iter().enumerate() {
7188 if let ast::Expr::Starred(_) = &element {
7189 if seen_star {
7190 return Err(self.error(CodegenErrorType::MultipleStarArgs));
7191 } else {
7192 seen_star = true;
7193 let before = i;
7194 let after = elts.len() - i - 1;
7195 let (before, after) = (|| Some((before.to_u8()?, after.to_u8()?)))()
7196 .ok_or_else(|| {
7197 self.error_ranged(
7198 CodegenErrorType::TooManyStarUnpack,
7199 target.range(),
7200 )
7201 })?;
7202 let counts = bytecode::UnpackExArgs { before, after };
7203 emit!(self, Instruction::UnpackEx { counts });
7204 }
7205 }
7206 }
7207
7208 if !seen_star {
7209 emit!(
7210 self,
7211 Instruction::UnpackSequence {
7212 count: elts.len().to_u32(),
7213 }
7214 );
7215 }
7216
7217 for element in elts {
7218 if let ast::Expr::Starred(ast::ExprStarred { value, .. }) = &element {
7219 self.compile_store(value)?;
7220 } else {
7221 self.compile_store(element)?;
7222 }
7223 }
7224 }
7225 _ => {
7226 return Err(self.error(match target {

Callers 7

compile_statementMethod · 0.80
compile_withMethod · 0.80
compile_forMethod · 0.80
compile_expressionMethod · 0.80
compile_comprehensionMethod · 0.80

Calls 14

store_nameMethod · 0.80
compile_subscriptMethod · 0.80
compile_expressionMethod · 0.80
ok_or_elseMethod · 0.80
error_rangedMethod · 0.80
python_nameMethod · 0.80
ErrClass · 0.50
SomeClass · 0.50
as_strMethod · 0.45
nameMethod · 0.45
iterMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected