xpile 0.1.616

Polyglot transpile workbench (Python/C/C++/Rust/Ruchy/Lean ↔ Rust/Ruchy/PTX/WGSL/SPIR-V) with provable contracts at every layer.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# PMAT-1082: with a `finally`, the every-exit-path wrap (PMAT-1070) puts the
# `except` HANDLER inside the OUTER catch_unwind closure too — so `continue`
# there cannot reach the loop (rustc E0267). Refused at lowering; without the
# finally the handler runs at loop scope and handler-continue is supported
# (see try_handler_continue.py).
def f(n: int) -> int:
    total: int = 0
    cleanup: int = 0
    for i in range(n):
        try:
            if i == 1:
                raise ValueError("bad")
            total = total + i
        except ValueError:
            continue
        finally:
            cleanup = cleanup + 1
    return total + cleanup