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

Method compile_try_except_no_finally

crates/codegen/src/compile.rs:3443–3610  ·  view source on GitHub ↗
(
        &mut self,
        body: &[ast::Stmt],
        handlers: &[ast::ExceptHandler],
        orelse: &[ast::Stmt],
    )

Source from the content-addressed store, hash-verified

3441 }
3442
3443 fn compile_try_except_no_finally(
3444 &mut self,
3445 body: &[ast::Stmt],
3446 handlers: &[ast::ExceptHandler],
3447 orelse: &[ast::Stmt],
3448 ) -> CompileResult<()> {
3449 let handler_block = self.new_block();
3450 let cleanup_block = self.new_block();
3451 let orelse_block = self.new_block();
3452 let end_block = self.new_block();
3453
3454 emit!(self, Instruction::Nop);
3455 emit!(
3456 self,
3457 PseudoInstruction::SetupFinally {
3458 delta: handler_block
3459 }
3460 );
3461
3462 self.push_fblock(FBlockType::TryExcept, handler_block, handler_block)?;
3463 self.compile_statements(body)?;
3464 self.pop_fblock(FBlockType::TryExcept);
3465 emit!(self, PseudoInstruction::PopBlock);
3466 self.set_no_location();
3467 emit!(
3468 self,
3469 PseudoInstruction::JumpNoInterrupt {
3470 delta: orelse_block
3471 }
3472 );
3473 self.set_no_location();
3474
3475 self.switch_to_block(handler_block);
3476 emit!(
3477 self,
3478 PseudoInstruction::SetupCleanup {
3479 delta: cleanup_block
3480 }
3481 );
3482 self.set_no_location();
3483 emit!(self, Instruction::PushExcInfo);
3484 self.set_no_location();
3485 self.push_fblock(FBlockType::ExceptionHandler, cleanup_block, cleanup_block)?;
3486
3487 for handler in handlers {
3488 let ast::ExceptHandler::ExceptHandler(ast::ExceptHandlerExceptHandler {
3489 type_,
3490 name,
3491 body,
3492 range: handler_range,
3493 ..
3494 }) = handler;
3495 self.set_source_range(*handler_range);
3496 let next_handler = self.new_block();
3497
3498 if let Some(exc_type) = type_ {
3499 self.compile_expression(exc_type)?;
3500 emit!(self, Instruction::CheckExcMatch);

Callers 1

compile_try_statementMethod · 0.80

Calls 14

new_blockMethod · 0.80
push_fblockMethod · 0.80
compile_statementsMethod · 0.80
pop_fblockMethod · 0.80
set_no_locationMethod · 0.80
switch_to_blockMethod · 0.80
set_source_rangeMethod · 0.80
compile_expressionMethod · 0.80
store_nameMethod · 0.80
push_fblock_fullMethod · 0.80
emit_load_constMethod · 0.80
compile_nameMethod · 0.80

Tested by

no test coverage detected