Generalized try/finally handling that takes functions to gen the bodies. The point of this is to also be able to support with.
(
builder: IRBuilder, try_body: GenFunc, finally_body: GenFunc, line: int = -1
)
| 890 | |
| 891 | |
| 892 | def transform_try_finally_stmt( |
| 893 | builder: IRBuilder, try_body: GenFunc, finally_body: GenFunc, line: int = -1 |
| 894 | ) -> None: |
| 895 | """Generalized try/finally handling that takes functions to gen the bodies. |
| 896 | |
| 897 | The point of this is to also be able to support with.""" |
| 898 | # Finally is a big pain, because there are so many ways that |
| 899 | # exits can occur. We emit 10+ basic blocks for every finally! |
| 900 | |
| 901 | err_handler, main_entry, return_entry, finally_block = ( |
| 902 | BasicBlock(), |
| 903 | BasicBlock(), |
| 904 | BasicBlock(), |
| 905 | BasicBlock(), |
| 906 | ) |
| 907 | |
| 908 | # Compile the body of the try |
| 909 | ret_reg = try_finally_try(builder, err_handler, return_entry, main_entry, try_body) |
| 910 | |
| 911 | # Set up the entry blocks for the finally statement |
| 912 | old_exc = try_finally_entry_blocks( |
| 913 | builder, err_handler, return_entry, main_entry, finally_block, ret_reg |
| 914 | ) |
| 915 | |
| 916 | # Compile the body of the finally |
| 917 | cleanup_block, finally_control = try_finally_body( |
| 918 | builder, finally_block, finally_body, old_exc |
| 919 | ) |
| 920 | |
| 921 | # Resolve the control flow out of the finally block |
| 922 | out_block = try_finally_resolve_control( |
| 923 | builder, cleanup_block, finally_control, old_exc, ret_reg |
| 924 | ) |
| 925 | |
| 926 | builder.activate_block(out_block) |
| 927 | |
| 928 | |
| 929 | def transform_try_finally_stmt_async( |
no test coverage detected
searching dependent graphs…