Shed Skin

Last updated
Shed Skin
Original author(s) Mark Dufour, others
Initial release2005
Stable release
0.9.6 / December 10, 2022;3 months ago (2022-12-10)
Repository
Written in Python, C++
Operating system Cross-platform: Linux, Mac OS X, Windows
Available inPython
Type Source-to-source compiler
License GPLv3, BSD, MIT
Website shedskin.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.

Contents

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

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

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

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.

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

Related Research Articles

<span class="mw-page-title-main">Python (programming language)</span> General-purpose programming language

Python is a high-level, general-purpose programming language. Its design philosophy emphasizes code readability with the use of significant indentation.

GNU Bison, commonly known as Bison, is a parser generator that is part of the GNU Project. Bison reads a specification in the BNF notation, warns about any parsing ambiguities, and generates a parser that reads sequences of tokens and decides whether the sequence conforms to the syntax specified by the grammar.

<span class="mw-page-title-main">NumPy</span> Python library for numerical programming

NumPy is a library for the Python programming language, adding support for large, multi-dimensional arrays and matrices, along with a large collection of high-level mathematical functions to operate on these arrays. The ancestor of NumPy, Numeric, was originally created by Jim Hugunin with contributions from several other developers. In 2005, Travis Oliphant created NumPy by incorporating features of the competing Numarray into Numeric, with extensive modifications. NumPy is open-source software and has many contributors. NumPy is a NumFOCUS fiscally sponsored project.

Jython is an implementation of the Python programming language designed to run on the Java platform. The implementation was formerly known as JPython until 1999.

<span class="mw-page-title-main">Doxygen</span> Free software for generating software documentation from source code

Doxygen is a documentation generator and static analysis tool for software source trees. When used as a documentation generator, Doxygen extracts information from specially-formatted comments within the code. When used for analysis, Doxygen uses its parse tree to generate diagrams and charts of the code structure. Doxygen can cross reference documentation and code, so that the reader of a document can easily refer to the actual code.

<span class="mw-page-title-main">PyQt</span>

PyQt is a Python binding of the cross-platform GUI toolkit Qt, implemented as a Python plug-in. PyQt is free software developed by the British firm Riverbank Computing. It is available under similar terms to Qt versions older than 4.5; this means a variety of licenses including GNU General Public License (GPL) and commercial license, but not the GNU Lesser General Public License (LGPL). PyQt supports Microsoft Windows as well as various flavours of UNIX, including Linux and MacOS.

IronPython is an implementation of the Python programming language targeting the .NET Framework and Mono. Jim Hugunin created the project and actively contributed to it up until Version 1.0 which was released on September 5, 2006. IronPython 2.0 was released on December 10, 2008. After version 1.0 it was maintained by a small team at Microsoft until the 2.7 Beta 1 release. Microsoft abandoned IronPython in late 2010, after which Hugunin left to work at Google. The project is currently maintained by a group of volunteers at GitHub. It is free and open-source software, and can be implemented with Python Tools for Visual Studio, which is a free and open-source extension for Microsoft's Visual Studio IDE.

Psyco is an unmaintained specializing just-in-time compiler for pre-2.7 Python originally developed by Armin Rigo and further maintained and developed by Christian Tismer. Development ceased in December, 2011.

CPython is the reference implementation of the Python programming language. Written in C and Python, CPython is the default and most widely used implementation of the Python language.

<span class="mw-page-title-main">PyPy</span> Alternative implementation of the Python programming language

PyPy is an implementation of the Python programming language. PyPy often runs faster than the standard implementation CPython because PyPy uses a just-in-time compiler. Most Python code runs well on PyPy except for code that depends on CPython extensions, which either does not work or incurs some overhead when run in PyPy. Internally, PyPy uses a technique known as meta-tracing, which transforms an interpreter into a tracing just-in-time compiler. Since interpreters are usually easier to write than compilers, but run slower, this technique can make it easier to produce efficient implementations of programming languages. PyPy's meta-tracing toolchain is called RPython.

In computer programming, a programming language implementation is a system for executing computer programs. There are two general approaches to programming language implementation:

libffi is a foreign function interface library. It provides a C programming language interface for calling natively compiled functions given information about the target function at run time instead of compile time. It also implements the opposite functionality: libffi can produce a pointer to a function that can accept and decode any combination of arguments defined at run time.

Web2py is an open-source web application framework written in the Python programming language. Web2py allows web developers to program dynamic web content using Python. Web2py is designed to help reduce tedious web development tasks, such as developing web forms from scratch, although a web developer may build a form from scratch if required.

<span class="mw-page-title-main">Cython</span> Programming language

Cython is a programming language, a superset of the Python programming language, designed to give C-like performance with code that is written mostly in Python with optional additional C-inspired syntax.

<span class="mw-page-title-main">Rust (programming language)</span> General-purpose programming language

Rust is a multi-paradigm, high-level, general-purpose programming language. Rust emphasizes performance, type safety, and concurrency. Rust enforces memory safety—that is, that all references point to valid memory—without requiring the use of a garbage collector or reference counting present in other memory-safe languages. To simultaneously enforce memory safety and prevent concurrent data races, Rust's "borrow checker" tracks the object lifetime of all references in a program during compilation. Rust is popular for systems programming but also offers high-level features including some functional programming constructs.

SIP is an open source software tool used to connect computer programs or libraries written in C or C++ with the scripting language Python. It is an alternative to SWIG.

<span class="mw-page-title-main">Meson (software)</span> Build automation system

Meson is a software tool for automating the building (compiling) of software. The overall goal for Meson is to promote programmer productivity. Meson is free and open-source software written in Python, under the Apache License 2.0.

MicroPython is a software implementation of a programming language largely compatible with Python 3, written in C, that is optimized to run on a microcontroller.

Nuitka is a source-to-source compiler which compiles Python code to C source code, applying some compile-time optimizations in the process such as constant folding and propagation, built-in call prediction, type inference, and conditional statement execution. Nuitka initially was designed to produce C++ code, but current versions produce C source code using only those features of C11 that are shared by C++03, enabling further compilation to a binary executable format by modern C and C++ compilers including gcc, clang, MinGW, or Microsoft Visual C++. It accepts Python code compatible with several different Python versions and optionally allows for the creation of standalone programs that do not require Python to be installed on the target computer.

References

  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