User:Shabda/drafts/Shed Skin

Shed Skin is an experimental compiler that translates pure but implicitly statically typed Python programs into optimized C++. Programs often must be modified to satisfy the typing restriction, but remain valid Python after modification. Shed Skin is currently limited to small programs, that do not make heavy use of the Python standard library, although an increasing number of modules is supported. The largest program translated to date is 1,600 lines.

Variables can only ever have a single type. So e.g.  is not allowed. A single type, however, can be abstract or generic (as in C++), so that e.g.  is allowed where A and B have a common base class`.

Its author claims that the performance of code generated by Shed Skin is typically 2-40 times better than that obtained by using Psyco. Third-party profiles of Pscyo often show it matching C in speed, however. Shed Skin is, in some cases, much slower than manually optimized C++ code. Code generated by Shed Skin is completely independent of a Python run-time, which allows use of that code on hardware-constrained embedded systems. Shed Skin can be used for code obfuscation: it is much more difficult to reverse-engineer machine language generated by a C++ compiler) than Python bytecode.

To deduce type information in order to generate C++ type declarations, such as, Shed Skin uses type inference techniques. It combines Ole Agesen's Cartesian Product Algorithm with John Plevyak's Iterative Class Splitting technique. As of yet, it is unclear whether these techniques will allow Shed Skin to scale much further than the mentioned 1,600 lines. However, the author still plans to make significant improvements, which should improve scalability dramatically. Additionally, type profiling or remembering analysis results between compile sessions will make a huge difference.

Shed Skin currently consists of 6,500 lines of code, excluding the C++ implementation of the Python builtins (June 28, 2007). It supports only a subset of the features of Python. Shed Skin is similar to projects such as Pyrex, Boo, RPython, and Cinpy.

Current Limitations

 * Programs cannot freely use the Python standard library, but several common imports are supported (see lib/*.py).
 * The type analysis currently does not scale well beyond a few hundreds of lines of code.
 * There is currently no easy way to connect compiled code with arbitrary Python code, besides using files or standard in- and output.