Jump to content

Shed Skin

From Wikipedia, the free encyclopedia
Shed Skin
Original author(s)Mark Dufour, others
Initial release2005
Stable release
0.9.9 / June 22, 2024; 4 months ago (2024-06-22)
Repository
Written inPython, C++
Operating systemCross-platform: Linux, macOS, Windows
Available inPython
TypeSource-to-source compiler
LicenseGPLv3, BSD, MIT
Websiteshedskin.github.io

Shed Skin is an experimental restricted-Python (3.8+) to C++ programming language compiler. It 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.[1]

Features

[edit]

Besides the typing restriction,[2] 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 functions 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.[3]

As of June 2016 for a set of 75 non-trivial test programs (at over 25,000 lines of code in total),[4] measurements show a typical speedup of 2-20 times over Psyco, and 2-200 times over CPython.[5][6][7][8] Shed Skin is still in an early stage of development, so many other programs will not compile unmodified.[9]

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.[10]

The license of the Shed Skin source code is under two parts. The main compiler code is under the GNU General Public License (GPL). The supporting code that it uses as a run time library is under a BSD or MIT license depending on the module. This allows compiling both GPL and non-GPL programs.

Type inference

[edit]

Shed Skin combines Ole Agesen's Cartesian Product Algorithm (CPA) with the data-polymorphic part of John Plevyak's Iterative Flow Analysis (IFA).[11] 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 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.[12]

Modules

[edit]

For version 0.9 the following 25 modules are largely supported.[13] 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.

See also

[edit]

References

[edit]
  1. ^ first Shed Skin release
  2. ^ Learning Python Book section on Shed Skin
  3. ^ Shed Skin tutorial ("Python Subset Restrictions" section)
  4. ^ "Shedskin/Shedskin". GitHub. 17 May 2022.
  5. ^ Speed up your Python: Unladen vs. Shed Skin vs. PyPy vs. Cython vs. C
  6. ^ Taking on Shed-Skin
  7. ^ Speeding up Python code with Shed Skin
  8. ^ MiniLight, minimal global illumination renderer benchmark
  9. ^ Shed Skin webpage
  10. ^ Wrapping C++ classes using Shed Skin
  11. ^ Master Thesis Mark Dufour, "Shed Skin. An Optimizing Python-to-C++ Compiler", April 19, 2006
  12. ^ Type inference scalability, 2010-12
  13. ^ Shedskin 0.9 release notes
[edit]