xpile 0.1.615

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
# PMAT-1075 (file I/O, 2nd increment): `open(path, "w").write(content)` as a
# statement writes a whole str to a file (truncating), emitted inline as
# `std::fs::write(&(path), &(content))` (borrowed via AsRef so a variable
# path/content isn't moved) with a panic on error. Append mode "a" refuses
# precisely. Round-trips with `open(path).read()` (PMAT-1074). Verified vs
# CPython (write-then-read).
def write_then_read(p: str, s: str) -> int:
    open(p, "w").write(s)
    return len(open(p).read())


def overwrite(p: str) -> str:
    open(p, "w").write("first-longer")
    open(p, "w").write("second")
    return open(p).read()