Commit 0adadf5c authored by Armin Rigo's avatar Armin Rigo

Merging release/0.7.x, step 1

parent 81a43fbb
PyPy: Python in Python implementation / Version 0.7.0
Welcome to PyPy! PyPy-0.7.0 marks the first public release
that allows to build a self-contained Python implementation
that does not depend or run on top of CPython anymore.
We invested a lot of time in improving the documentation and
website and thus invite you to head over to our getting-started
pypy/doc/getting-started.txt (local if you got a tarball)
which gives you many good starting and entry points into
playing with PyPy. It will also point you to our
documentation section which is generated from information
in the pypy/doc directory.
Our online release announcement has some more
information about the specific PyPy-0.7.0 release:
pypy/documentation/release-0.7.0.txt or
Please note that the last 9 months of PyPy development
have been funded by the European Union through its research
Enjoy and send us feedback!
the pypy-dev team <>
#!/usr/bin/env python
"""PyPy Translator Frontend
Glue script putting together the various pieces of the translator.
Can be used for interactive testing of the translator.
t = Translator(func)
t.view() # control flow graph
print t.source() # original source
print t.c() # C translation
print # common lisp translation
print t.llvm() # LLVM translation
t.simplify() # flow graph simplification
a = t.annotate([int]) # pass the list of args types
a.simplify() # simplification by annotator
t.view() # graph + annotations under the mouse # call original function
t.dis() # bytecode disassemble
t.specialize() # use low level operations (for C only)
f = t.ccompile() # C compilation
f = t.llvmcompile() # LLVM compilation
assert f(arg) == # sanity check
Some functions are provided for the benefit of interactive testing.
Try dir(test) for list of current snippets.
For extra features start this script with a -h option.
extra_help = """Extra options enable features for testing the various backend
translators. As a sideeffect the entry function of the compiled
code will be run.
-v(iew flow graph)
-b<org/c/cl/llvm> (set backend) [default=c]
-s(show source)
-C(ompilation disable)
-t(est compiled)
[python script] <entry function (default=main())>
import autopath, os, sys
from pypy.translator.translator import Translator
from pypy.rpython.rtyper import *
from pypy.rpython.rarithmetic import *
import py
class Options(object):
available_backends = {'org':'Original source', 'c':'C translation (default)', 'cl':'common lisp translation', 'llvm':'LLVM translation', 'pyrex':'pyrex translation'}
backend = 'c' #ugly !?!
python_script = ''
entry_function = 'main()'
view_flow_graph = False
show_source = False
compile = True
test_compiled = False
def __init__(self,argv=[]):
if not argv:
print extra_help
for arg in argv:
if arg[0] == '-':
option = arg[:2]
if option == '-b':
new_backend = arg[2:]
if new_backend in self.available_backends:
self.backend = new_backend
print 'error: unknown backend', new_backend, '. Avaialable backends are:', self.available_backends
elif option == '-v':
self.view_flow_graph = True
elif option == '-s':
self.show_source = True
elif option == '-C':
self.compile = False
elif option == '-t':
self.test_compiled = True
print extra_help
if not self.python_script:
self.python_script = arg
self.entry_function = arg
def main(argv=[]):
options = Options(argv)
modname = options.python_script.replace('/', '.')
if modname[-3:] == '.py':
modname = modname[:-3]
if modname[0] == '.': #absolute path #ah
path = py.path.local(options.python_script)
print path, path.get("basename"), path.get("dirname")
absmodname = path.get("purebasename")[0]
exec "import %(absmodname)s as testmodule" % locals()
else: #relative path
exec "import %(modname)s as testmodule" % locals()
if '(' in options.entry_function:
entry_function, arguments = options.entry_function.split('(',1)
entry_function, arguments = options.entry_function, ')'
#print 'entry_functionText=',entry_function
entry_function = getattr(testmodule, entry_function)
#print 'entry_function=',entry_function
if arguments != ')' and arguments.find(',') == -1:
arguments = arguments[:-1] + ',)'
arguments = [argument for argument in eval('('+arguments)]
#print 'arguments=',arguments
argumentTypes = [type(arg) for arg in arguments]
#print 'argumentTypes=',argumentTypes
t = Translator(entry_function)
a = t.annotate(argumentTypes)
if options.view_flow_graph:
rtyper = RPythonTyper(t.annotator)
t = Translator(entry_function)
a = t.annotate(argumentTypes)
if options.show_source:
if options.backend == 'org':
print t.source()
elif options.backend == 'c':
print t.c()
#note: this is a workaround until GenC can generate identical code multiple times
t = Translator(entry_function)
a = t.annotate(argumentTypes)
elif options.backend == 'cl':
elif options.backend == 'llvm':
print t.llvm()
#note: this is a workaround because genllvm calls the RPythonTyper which is not smart enough right now to leave already lltyped blocks alone
t = Translator(entry_function)
a = t.annotate(argumentTypes)
elif options.backend == 'pyrex':
print t.pyrex()
if options.compile:
if options.backend == 'c':
#a.specialize() # use low level operations (for C only)
f = t.ccompile()
elif options.backend == 'llvm':
f = t.llvmcompile()
elif options.backend == 'pyrex':
f = t.pyrexcompile()
print 'warning: backend', options.backend, 'has no compile phase'
assert f
print 'Backend', options.backend, 'compilation successful!'
backendReturn =*arguments)
if options.test_compiled:
pythonReturn = f(*arguments)
assert backendReturn == pythonReturn
print 'Backend', options.backend, 'compiled code returns same as python script (%s)' % backendReturn
print 'Backend', options.backend, 'compiled code returns (%s)' % backendReturn, '[use -t to perform a sanity check]'
def setup_readline():
import readline
import rlcompleter2
except ImportError:
import rlcompleter
readline.parse_and_bind("tab: complete")
import os
histfile = os.path.join(os.environ["HOME"], ".pypytrhist")
except IOError:
import atexit
atexit.register(readline.write_history_file, histfile)
if __name__ == '__main__':
except ImportError, err:
print "Disabling readline support (%s)" % err
from pypy.translator.test import snippet as test
#from pypy.translator.llvm.test import llvmsnippet as test2
from pypy.rpython.rtyper import RPythonTyper
except ImportError, err:
print "Disabling readline support (%s)" % err
if (os.getcwd() not in sys.path and
os.path.curdir not in sys.path):
sys.path.insert(0, os.getcwd())
if len(sys.argv) > 1:
print __doc__
# 2.3 specific -- sanxiyn
import os
os.putenv("PYTHONINSPECT", "1")
This diff is collapsed.
This diff is collapsed.
Frequently Asked Questions
How fast is PyPy?
As of August 2005, PyPy was succesfully translated to C.
The version of PyPy that still runs on top of CPython
is slower by a factor of 2000 compared to CPython. The translated
versions seems to be roughly 300 times slower than CPython.
On the other hand, the really interesting question is: Why is
PyPy so slow?
.. _whysoslow:
Why is PyPy so slow?
Our translation process does not try to optimize the produced code
very much. So far the project has been focused on getting a well
tested very compliant self-contained static Python implementation.
During end 2005 and 2006 we are targetting optimizations at various
levels. If you then still think that PyPy is slow then we will
have to find a better answer :-)
What is RPython?
RPython is the restricted subset of the Python language that
we are able to translate to machine level code. A major part of
PyPy's interpreter and type implementations is written
in this restricted style. For a more exhaustive definitions
please refer to `RPython`_.
Do I have to rewrite my programs in RPython?
No. PyPy always runs your code in its own interpreter, which is
a full and compliant Python 2.4 interpreter. RPython is only
the language in which parts of PyPy itself are written.
How do I compile PyPy?
See the `getting-started`_ guide. Note that at the moment this
produces an executable that contains a lot of things that are
hard-coded for your particular system (including paths), so it's
not really suitable for being installed or redistributed.
.. _`RPython`: coding-guide.html#rpython
.. _`getting-started`: getting-started.html
This diff is collapsed.
PyPy-0.7.0: first self-contained Python Implementation
The PyPy Development Team is happy to announce its first
public release of a fully translatable self contained Python
implementation. The 0.7 release is a preview release showcasing the
results of our efforts in the last few months:
- full program type inference with full translation
to two different machine-level targets: C and LLVM
- the ability to translate with thread support or without
- a translation choice of using a reference counting or Boehm
garbage collector
- very high compliancy with Python 2.4.1 (fully based on
new style classes)
What is PyPy (about)?
PyPy is an MIT-licensed reimplementation of Python written in Python
itself, flexible and easy to experiment with. It translates itself
to lower level languages. Our long-term goals are to target a large
variety of platforms, small and large, by providing a compiler toolsuite
that can produce custom Python versions. Platform, Memory and Threading
models are to become aspects of the translation process - as opposed to
encoding low level details into a language implementation itself.
Eventually, dynamic optimization techniques - implemented as another
translation aspect - should become robust against language changes.
Where to start?
Getting started:
PyPy Documentation:
PyPy Homepage:
The interpreter and object model implementations shipped with 0.7 can
run on their own and implement the core language features of
Python as of CPython 2.4. However, we do not recommend using
PyPy for anything else than for playing or research purposes.
Ongoing work and near term goals
PyPy has been a community effort from the start and it would
not have got that far without the coding and feedback support
from numerous people. Please feel free to give feedback and
raise questions.
contact points:
contributor list:
have fun,
the pypy-dev team ...
(insert names here)
PyPy development and activities happen as an open source project
and with the support of a consortium funded by a two year EU IST
research grant. Here is a list of partners of the EU project:
Heinrich-Heine University (Germany), AB Strakt (Sweden)
merlinux GmbH (Germany), tismerysoft GmbH(Germany)
Logilab Paris (France), DFKI GmbH (Germany)
ChangeMaker (Sweden)
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment