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

Method emit_resume_for_scope

crates/codegen/src/compile.rs:1270–1308  ·  view source on GitHub ↗

Emit RESUME instruction with proper handling for async preamble and module lineno. codegen_enter_scope equivalent for RESUME emission.

(&mut self, scope_type: CompilerScope, lineno: u32)

Source from the content-addressed store, hash-verified

1268 /// Emit RESUME instruction with proper handling for async preamble and module lineno.
1269 /// codegen_enter_scope equivalent for RESUME emission.
1270 fn emit_resume_for_scope(&mut self, scope_type: CompilerScope, lineno: u32) {
1271 // For generators and async functions, emit RETURN_GENERATOR + POP_TOP before RESUME
1272 let is_gen =
1273 scope_type == CompilerScope::AsyncFunction || self.current_symbol_table().is_generator;
1274 if is_gen {
1275 emit!(self, Instruction::ReturnGenerator);
1276 emit!(self, Instruction::PopTop);
1277 }
1278
1279 // CPython: LOCATION(lineno, lineno, 0, 0)
1280 // Module scope: loc.lineno = 0 (before the first line)
1281 let lineno_override = if scope_type == CompilerScope::Module {
1282 Some(0)
1283 } else {
1284 None
1285 };
1286
1287 // Use lineno for location (col = 0 as in CPython)
1288 let location = SourceLocation {
1289 line: OneIndexed::new(lineno as usize).unwrap_or(OneIndexed::MIN),
1290 character_offset: OneIndexed::MIN, // col = 0
1291 };
1292 let end_location = location; // end_lineno = lineno, end_col = 0
1293 let except_handler = None;
1294
1295 self.current_block().instructions.push(ir::InstructionInfo {
1296 instr: Instruction::Resume {
1297 context: OpArgMarker::marker(),
1298 }
1299 .into(),
1300 arg: OpArg::new(oparg::ResumeLocation::AtFuncStart.into()),
1301 target: BlockIdx::NULL,
1302 location,
1303 end_location,
1304 except_handler,
1305 lineno_override,
1306 cache_entries: 0,
1307 });
1308 }
1309
1310 fn push_output(
1311 &mut self,

Callers 5

enter_scopeMethod · 0.80
compile_programMethod · 0.80
compile_block_exprMethod · 0.80
compile_evalMethod · 0.80

Calls 5

newFunction · 0.85
current_symbol_tableMethod · 0.80
current_blockMethod · 0.80
SomeClass · 0.50
pushMethod · 0.45

Tested by

no test coverage detected