Shedskin
Encyclopedia
Shed Skin is a Python
Python (programming language)
Python is a general-purpose, high-level programming language whose design philosophy emphasizes code readability. Python claims to "[combine] remarkable power with very clear syntax", and its standard library is large and comprehensive...

 to C++
C++
C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as an intermediate-level language, as it comprises a combination of both high-level and low-level language features. It was developed by Bjarne Stroustrup starting in 1979 at Bell...

 programming language compiler
Compiler
A compiler is a computer program that transforms source code written in a programming language into another computer language...

. It is experimental, and can translate pure, but implicitly statically typed Python programs into optimized C++. It can generate stand-alone programs or extension modules that can be imported and used in larger Python programs.

Shed Skin is an open source project with contributions from many people, however the main author is Mark Dufour. Work has been going into Shed Skin since 2005.

Besides the typing restriction, programs cannot freely use the Python standard library, although about 20 common modules, such as random, itertools and re (regular expressions), are supported as of 2011. Also, not all Python features, such as nested function
Nested function
In computer programming, a nested function is a function which is lexically encapsulated within another function. It can only be called by the enclosing function or by functions directly or indirectly nested within the same enclosing function. In other words, the scope of the nested function is...

s and variable numbers of arguments, are supported. Many introspective dynamic parts of the language are unsupported. For example, functions like getattr, and hasattr are unsupported.

As of May 2011, Unicode is not supported.

For a set of 54 non-trivial test programs (at over 15,000 lines in total (sloccount)), measurements show a typical speedup of 2-20 times over Psyco, and 2-200 times over CPython. Shed Skin is still in an early stage of development, so many other programs will not compile unmodified.

Shed Skin can be used to generate standalone executables which need only the C++ runtime libraries. It can also be used to generate CPython modules. This allows compiling parts of larger programs with Shed Skin, while running the other parts using regular CPython.

Another use has been to wrap C++ classes using Shed Skin to allow C++ classes to be used as Python classes.

The license of the Shed Skin source code is under two parts. The main compiler code is under the GNU General Public License
GNU General Public License
The GNU General Public License is the most widely used free software license, originally written by Richard Stallman for the GNU Project....

 (GPL). The supporting code that it uses as a run time library is under a BSD license. This allows compiling programs which are considered under the GPL or are not considered under the GPL.

Type inference

Shed Skin combines Ole Agesen's Cartesian Product Algorithm (CPA) with the data-polymorphic part of John Plevyak's Iterative Flow Analysis (IFA). Version 0.6 introduced scalability improvements which repeatedly analyze larger versions of a program (in addition to the mentioned techniques), until it is fully analyzed. This allows Shed Skin to do type inference
Type inference
Type inference refers to the automatic deduction of the type of an expression in a programming language. If some, but not all, type annotations are already present it is referred to as type reconstruction....

on larger programs than previously. It starts with an empty callgraph, essentially, and slowly adds to it, until the whole call graph has been added. A graph has been published by the author, showing analysis times for 50 example programs, at a total of around 15,000 lines.

Modules

For version 0.9 the following 25 modules are largely supported. Several of these, such as os.path, were compiled to C++ using Shed Skin.
  • array
  • binascii
  • bisect
  • collections (defaultdict, deque)
  • ConfigParser (no SafeConfigParser)
  • copy
  • colorsys
  • csv (no Dialect, Sniffer)
  • datetime
  • fnmatch
  • getopt
  • glob
  • heapq
  • itertools (no starmap)
  • math
  • mmap
  • os
  • os.path
  • random
  • re
  • socket
  • string
  • struct (no Struct, pack_into, unpack_from)
  • sys
  • time


Note that any other module, such as pygame, pyqt or pickle, may be used in combination with a Shed Skin generated extension module. For examples of this, see the Shed Skin examples.

External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK