Typed Python
A compiler for a typed subset of the Python 2.5 specification, developed with a group of 3 people in Spring 2018 for CS 164 (Programming Languages) at UC Berkeley. The compiler itself is written in C++, and compiles to C++ as well. The lexer and parser are written using Bison & FLEX.
Although the language features are somewhat limited (e.g. no augmented assignment, floating point literals, decorators, or lambda functions), there are some notable additions:
- Type denotations for target variables in assignments or formal parameters in functions are included, and enforced as compile-time checks. This differs from type-hinting in recent versions of Python3, which does not actually enforce types.
- Type arguments for classes, allowing for generic types
- Function overloading - multiple functions with the same name are disambiguated by the number and types of their parameters
- Native functions, allowing you to designate a C or C++ function to implement the Python function.
- Optimized integer operations, achieved by working with integers as “unboxed” values instead of objects.
Additionally, full garbage collection is implemented, as in standard Python.