High performance implementation of Python for CLI/.NET with JIT compiler generation for dynamic languages. ========================================================================================================== Python is a highly flexible and open source scripting language which has significantly grown in popularity in the last few years. However, all the existing implementations prevent programmers from developing very efficient code. This thesis describes a new and more efficient implementation of the language, obtained by developing new techniques and adapting old ones which have not yet been applied to Python. Even though the specific implementation considered here targets the .NET framework, extreme care has been taken to develop a compiler easily portable to other platforms, and reusable for the implementation of other dynamic languages. As a language, Python is very hard to implement efficiently: the presence of highly dynamic constructs makes static analysis of programs extremely difficult, thus preventing ahead of time (AOT) compilers to generate efficient target code. CPython, the reference implementation of the language, is an interpreter and its performance is far from optimal. Jython and IronPython are two alternative implementations that target respectively the Java Virtual Machine and the .NET framework: differently from CPython, they are compilers which generate bytecode for the underling virtual machine, but often their performance is not better than CPython. An alternative solution to this problem, which has been already investigated for other object-oriented languages, is the implementation of a Just in Time (JIT) compiler. Unfortunately, writing a JIT compiler is far from being an easy task, and most of the times efficiency is gained at the cost of a dramatic loss of portability. To achieve this, the PyPy[1] project has been exploited. PyPy consists of both a mature, fully compatible Python interpreter and a framework to transform it in various way. In particular, it provides a JIT compiler generator, which automatically turns the interpreter into a JIT compiler. The contribution of this thesis includes both the work done in cooperation with the rest of the PyPy team for enhancing the PyPy JIT compiler generator, and for developing a back-end to target the .NET framework. In particular, implementing a JIT compiler for the .NET virtual machine rather than for a CPU has allowed the combination of two different JIT compilation layers: the PyPy one, which produces .NET bytecode, and the .NET one which produces executable machine code. This thesis demonstrates that this combination gives very good results in terms of performances. Finally, adopting the PyPy approach turned out to be successful for ensuring portability and reuse. Indeed, it is relatively simple to implement new dynamic languages in PyPy and get JIT compilers almost for free, but it is also possible to develop new back-ends for the JIT generator, in order to target new platforms, e.g. the JVM. [1] http://codespeak.net/pypy