Introduction
py4 is a transpiler that compiles a statically-typed, Python-like language to native binaries via C.
What py4 is
py4 gives you Python-style syntax — indentation blocks, class, enum, for, import, type annotations — and compiles it to a single C translation unit that is then compiled to a native binary with GCC or Clang.
The result is a program with no external runtime, no garbage collector, and no hidden object model.
What py4 is not
py4 is not a Python implementation. It does not aim for compatibility with CPython or any Python library. It deliberately omits dynamic features — Any, dynamic attributes, runtime module objects, exceptions — in exchange for a simpler, more predictable compilation model.
Design priorities
- Static typing throughout. Every variable, parameter, and return value has a concrete type at compile time.
- Compile-time resolution. Overload selection, enum variant lookup, and module scoping all happen before any C is generated.
- Readable output. The generated C is intended to be inspectable. Identifiers are meaningful, not mangled hashes.
- Narrow, complete features. A narrow feature that works end-to-end is worth more than a broad feature that half-works.
Compilation pipeline
source.p4 → lexer → parser → semantic analysis → C codegen → gcc/clang → binarypy4 compiles directly to a native binary by default. The intermediate C file is still available with --emit-c if you want to inspect or compile it yourself.
Project status
py4 is in active development. The language is intentionally ahead in compile-time structure and behind in dynamic/runtime features. The focus right now is on growing the self-hosting groundwork — the lexer prototype is already written in py4 itself.