Shed Skin

From Wikipedia, the free encyclopedia

Shed Skin
OS Cross-platform
Genre Python compiler
License GNU General Public License (GPL)
Website http://sourceforge.net/projects/shedskin/

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. a=1; a='1' is not allowed. A single type, however, can be abstract or generic (as in C++), so that e.g. a=A(); a=B() is allowed where A and B have a common base class.

In a set of test cases developed by ShedSkin's author, code generated by Shed Skin ran 2-40 times faster than did the same code optimized using Psyco's psyco.full() method. However, ShedSkin can also be significantly slower than CPython for some programs compilable by ShedSkin (e.g. ones relying on the well-optimized behavior of CPython set and str types).[1].

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 int, Shed Skin uses type inference techniques. It combines Ole Agesen's Cartesian Product Algorithm with John Plevyak's Iterative Class Splitting technique. These techniques may limit scaling of program size significantly further than in existing test cases.

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.

Contents

[edit] 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.
  • As of version 0.0.22, it is possible to generate simple extension modules, but custom classes are not supported and arguments/return values are copied recursively.

[edit] See also

[edit] References

  1. ^ Flávio Codeço Coelho (Monday, 6 August 2007). Set implementation performance.

[edit] External links