Load arguments for super() optimization onto the stack Stack result: [global_super, class, self]
(&mut self, super_type: &SuperCallType<'_>)
| 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. |
no test coverage detected