hn.today

TurboPython – A Python-to-C++ Compiler

tpy-lang.org11 points2 comments
Screenshot of TurboPython – A Python-to-C++ Compiler

TurboPython is a statically typed language that keeps Python-like syntax while compiling through C++ to native binaries. It removes Python's runtime indirection - no garbage collector, no automatic reference counting, and no GIL - replacing them with an ownership-and-borrowing model that enforces memory safety and predictable performance at compile time. Tooling is distributed as a single Python package (tpy-lang) for Python 3.12+, uses a C++23 compiler (GCC 13+/Clang 19+) or a bundled compiler, and can produce standalone optimized binaries or CPython extensions. Most editors and type tools work out of-the-box because source looks like normal Python with required type annotations. CPython binary packages are not compatible: everything imported must be compiled or ported to TurboPython, and only a subset of the standard library is provided.

Ownership and static typing are the core differences. Function parameters, return types, and class fields require annotations; unannotated integer literals default to 32-bit. Every value has one owner (frame, field, or container); moving ownership uses Own types, fields are fixed typed slots set in __init__, and containers own their elements - appends either move, copy (explicit copy()), or warn. Primitive and view types are copied, classes and containers are reference types, and strings can be owned or borrowed depending on context. Dynamic Python features like eval, runtime dict mutation, and monkey-patching are disallowed. Core TurboPython types live in the tpy module, and tooling includes an assistant generator to help translate Python idioms into TurboPython correctly.

Read on tpy-lang.org2 comments on Hacker News

Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.

More in Programming

The daily digest

Today's best Hacker News stories, summarized and screenshotted, one email a day.