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

Method load_args_for_super

crates/codegen/src/compile.rs:997–1041  ·  view source on GitHub ↗

Load arguments for super() optimization onto the stack Stack result: [global_super, class, self]

(&mut self, super_type: &SuperCallType<'_>)

Source from the content-addressed store, hash-verified

995 /// Load arguments for super() optimization onto the stack
996 /// Stack result: [global_super, class, self]
997 fn load_args_for_super(&mut self, super_type: &SuperCallType<'_>) -> CompileResult<()> {
998 // 1. Load global super
999 self.compile_name("super", NameUsage::Load)?;
1000
1001 match super_type {
1002 SuperCallType::TwoArg {
1003 class_arg,
1004 self_arg,
1005 } => {
1006 // 2-arg: load provided arguments
1007 self.compile_expression(class_arg)?;
1008 self.compile_expression(self_arg)?;
1009 }
1010 SuperCallType::ZeroArg => {
1011 // 0-arg: load __class__ cell and first parameter
1012 // Load __class__ from cell/free variable
1013 let scope = self.get_ref_type("__class__").map_err(|e| self.error(e))?;
1014 let idx = match scope {
1015 SymbolScope::Cell => self.get_cell_var_index("__class__")?,
1016 SymbolScope::Free => self.get_free_var_index("__class__")?,
1017 _ => {
1018 return Err(self.error(CodegenErrorType::SyntaxError(
1019 "super(): __class__ cell not found".to_owned(),
1020 )));
1021 }
1022 };
1023 emit!(self, Instruction::LoadDeref { i: idx });
1024
1025 // Load first parameter (typically 'self').
1026 // Safety: can_optimize_super_call() ensures argcount > 0, and
1027 // parameters are always added to varnames first (see symboltable.rs).
1028 let first_param = {
1029 let info = self.code_stack.last().unwrap();
1030 info.metadata.varnames.first().cloned()
1031 };
1032 let first_param = first_param.ok_or_else(|| {
1033 self.error(CodegenErrorType::SyntaxError(
1034 "super(): no arguments and no first parameter".to_owned(),
1035 ))
1036 })?;
1037 self.compile_name(&first_param, NameUsage::Load)?;
1038 }
1039 }
1040 Ok(())
1041 }
1042
1043 /// Check if this is an inlined comprehension context (PEP 709).
1044 /// PEP 709: Inline comprehensions in function-like scopes.

Callers 2

compile_expressionMethod · 0.80
compile_callMethod · 0.80

Calls 12

compile_nameMethod · 0.80
compile_expressionMethod · 0.80
get_ref_typeMethod · 0.80
get_cell_var_indexMethod · 0.80
get_free_var_indexMethod · 0.80
ok_or_elseMethod · 0.80
ErrClass · 0.50
errorMethod · 0.45
to_ownedMethod · 0.45
unwrapMethod · 0.45
lastMethod · 0.45
firstMethod · 0.45

Tested by

no test coverage detected