SPy: An interpreter and compiler for a fast statically typed variant of Python (antocuni.eu)

🤖 AI Summary
SPy is a new open‑source project that implements an interpreter and a compiler for a statically typed variant of Python aimed squarely at performance. It deliberately rejects the goal of "100% Python compatibility" — SPy programs live in .spy files and will not support some dynamic Python features (you shouldn't expect to compile Django/FastAPI). Key design choices: static type annotations are enforced and checked by both interpreter and compiler; the interpreter and compiler produce identical runtime semantics; metaprogramming is first‑class; dynamic features are opt‑in via a dynamic type; and common Python conveniences (decorators, descriptor protocol, **kwargs semantics) are targeted for zero‑cost abstraction where feasible. Integration with CPython is planned (embedding libpython.so when needed); today SPy can emit CFFI extensions and the dynamic type works in the interpreter only. The project is early stage (usable for demos — a raytracer demo ran ~200× faster than CPython). SPy’s motivation is practical: Python’s extreme dynamism and pointer‑heavy object model make high, predictable performance hard (cache-unfriendly layouts, complex runtime dispatch, mutable module/class state). Existing approaches either restrict Python to an un‑Pythonic subset (AOT/JIT subset compilers) or rely on JIT heuristics that can be unpredictable. SPy aims for C/Rust-like speed (10×–100× typical targets) while preserving Pythonic expressivity through language extensions and careful static constraints, trading full compatibility for predictable, analyzable performance and easier implementation.
Loading comments...
loading comments...