Commit 3a772ea0 authored by Armin Rigo's avatar Armin Rigo

Merging release/0.7.x, step 2: all files modified in the branch

are now copied into the trunk.
parent 0adadf5c
=======================================================
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
document
pypy/doc/getting-started.txt (local if you got a tarball)
http://codespeak.net/pypy/dist/pypy/doc/getting-started.html
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/doc/release-0.7.0.txt or
http://codespeak.net/pypy/dist/pypy/doc/release-0.7.0.html
Please note that the last 9 months of PyPy development
have been funded by the European Union through its research
programme.
Enjoy and send us feedback!
the pypy-dev team <pypy-dev@codespeak.net>
$Id$
$HeadURL$
#!/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.
Example:
t = Translator(func)
t.view() # control flow graph
print t.source() # original source
print t.c() # C translation
print t.cl() # 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
t.call(arg) # call original function
t.dis() # bytecode disassemble
t.specialize() # use low level operations
f = t.ccompile() # C compilation
mod = t.llvmcompile() # LLVM compilation
assert f(arg) == func(arg) # sanity check (for C)
assert mod.pypy_func_wrapper(arg) == func(arg) # sanity check (for LLVM)
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.
options:
-h(elp)
-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
sys.exit(0)
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
else:
print 'error: unknown backend', new_backend, '. Avaialable backends are:', self.available_backends
sys.exit(0)
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
else:
print extra_help
sys.exit(0)
else:
if not self.python_script:
self.python_script = arg
else:
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")
sys.path.append(path.get("dirname")[0])
absmodname = path.get("purebasename")[0]
exec "import %(absmodname)s as testmodule" % locals()
sys.path.pop()
else: #relative path
exec "import %(modname)s as testmodule" % locals()
if '(' in options.entry_function:
entry_function, arguments = options.entry_function.split('(',1)
else:
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)
t.simplify()
a = t.annotate(argumentTypes)
a.simplify()
if options.view_flow_graph:
rtyper = RPythonTyper(t.annotator)
rtyper.specialize()
t.view()
t = Translator(entry_function)
t.simplify()
a = t.annotate(argumentTypes)
a.simplify()
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)
t.simplify()
a = t.annotate(argumentTypes)
a.simplify()
elif options.backend == 'cl':
print t.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)
t.simplify()
a = t.annotate(argumentTypes)
a.simplify()
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()
else:
print 'warning: backend', options.backend, 'has no compile phase'
sys.exit(0)
assert f
print 'Backend', options.backend, 'compilation successful!'
backendReturn = t.call(*arguments)
if options.test_compiled:
pythonReturn = f(*arguments)
assert backendReturn == pythonReturn
print 'Backend', options.backend, 'compiled code returns same as python script (%s)' % backendReturn
else:
print 'Backend', options.backend, 'compiled code returns (%s)' % backendReturn, '[use -t to perform a sanity check]'
def setup_readline():
import readline
try:
import rlcompleter2
rlcompleter2.setup()
except ImportError:
import rlcompleter
readline.parse_and_bind("tab: complete")
import os
histfile = os.path.join(os.environ["HOME"], ".pypytrhist")
try:
readline.read_history_file(histfile)
except IOError:
pass
import atexit
atexit.register(readline.write_history_file, histfile)
if __name__ == '__main__':
try:
setup_readline()
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
try:
setup_readline()
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:
sys.exit(main(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.
I am getting strange errors while playing with PyPy, what should I do?
It seems that a lot of strange, unexplainable problems can be magically
solved by removing all the \*.pyc files from the PyPy source tree. Another
thing you can do is removing the pypy/_cache completely. If the error is
persistent and still annoys you after this treatment please send us a bug
report (or even better, a fix :-)
.. _`RPython`: coding-guide.html#rpython
.. _`getting-started`: getting-started.html
This diff is collapsed.
pypy-0.7.0: first PyPy-generated Python Implementations
==============================================================
What was once just an idea between a few people discussing
on some nested mailing list thread and in a pub became reality ...
the PyPy development team is happy to announce its first
public release of a fully translatable self contained Python
implementation. The 0.7 release showcases the results of our
efforts in the last few months since the 0.6 preview release
which have been partially funded by the European Union:
- whole program type inference on our Python Interpreter
implementation with full translation to two different
machine-level targets: C and LLVM
- a translation choice of using a refcounting or Boehm
garbage collectors
- the ability to translate with or without thread support
- very complete language-level compliancy with CPython 2.4.1
What is PyPy (about)?
------------------------------------------------
PyPy is a MIT-licensed research-oriented reimplementation of
Python written in Python itself, flexible and easy to
experiment with. It translates itself to lower level
languages. Our goals are to target a large variety of
platforms, small and large, by providing a compilation 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.
Note that PyPy is mainly a research and development project
and does not by itself focus on getting a production-ready
Python implementation although we do hope and expect it to
become a viable contender in that area sometime next year.
Where to start?
-----------------------------
Getting started: http://codespeak.net/pypy/dist/pypy/doc/getting-started.html
PyPy Documentation: http://codespeak.net/pypy/dist/pypy/doc/
PyPy Homepage: http://codespeak.net/pypy/
The interpreter and object model implementations shipped with
the 0.7 version can run on their own and implement the core
language features of Python as of CPython 2.4. However, we still
do not recommend using PyPy for anything else than for education,
playing or research purposes.
Ongoing work and near term goals
---------------------------------
PyPy has been developed during approximately 15 coding sprints
across Europe and the US. It continues to be a very
dynamically and incrementally evolving project with many
one-week meetings to follow. You are invited to consider coming to
the next such meeting in Paris mid October 2005 where we intend to
plan and head for an even more intense phase of the project
involving building a JIT-Compiler and enabling unique
features not found in other Python language implementations.
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: http://codespeak.net/pypy/dist/pypy/doc/contact.html
contributor list: http://codespeak.net/pypy/dist/pypy/doc/contributor.html
have fun,
the pypy team, of which here is a partial snapshot
of mainly involved persons:
Armin Rigo, Samuele Pedroni,
Holger Krekel, Christian Tismer,
Carl Friedrich Bolz, Michael Hudson,
Eric van Riet Paap, Richard Emslie,
Anders Chrigstroem, Anders Lehmann,
Ludovic Aubry, Adrien Di Mascio,
Niklaus Haldimann, Jacob Hallen,
Bea During, Laura Creighton,
and many contributors ...
PyPy development and activities happen as an open source project
and with the support of a consortium partially funded by a two
year European Union IST research grant. Here is a list of
the full partners of that consortium:
Heinrich-Heine University (Germany), AB Strakt (Sweden)
merlinux GmbH (Germany), tismerysoft GmbH(Germany)
Logilab Paris (France), DFKI GmbH (Germany)
ChangeMaker (Sweden), Impara (Germany)
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
"""Interp-level _sre tests."""
import autopath
import sys
from py.test import raises
import pypy.module._sre.interp_sre as isre
EM_SPACE = u"\u2001"
INDIAN_DIGIT = u"\u0966"
def create_context(space, string, string_position, end):
state = isre.W_State(space, space.wrap(string), space.wrap(0),
space.wrap(end), space.wrap(0))
state.string_position = string_position
return isre.MatchContext(space, state, [])
def test_is_uni_linebreak(space):
for char in ["\n", "\r"]:
assert isre.is_uni_linebreak(space, space.wrap(char))
assert isre.is_uni_linebreak(space, space.newunicode([ord(char)]))
for char in [" ", "b"]:
assert not isre.is_uni_linebreak(space, space.wrap(char))
assert not isre.is_uni_linebreak(space, space.newunicode([ord(char)]))
assert isre.is_uni_linebreak(space, space.newunicode([8232]))
def test_is_uni_word(space):
for char in ["a", "_", "\xe4"]:
assert isre.is_uni_word(space, space.wrap(char))
for char in ["a", "_", "\xe4", u"\u00e4", u"\u03a0"]:
assert isre.is_uni_word(space, space.newunicode([ord(char)]))
for char in [".", " "]:
assert not isre.is_uni_word(space, space.wrap(char))
for char in [".", " ", EM_SPACE]:
assert not isre.is_uni_word(space, space.newunicode([ord(char)]))
def test_is_loc_word(space):
# should also test chars actually affected by locale (between 128 and 256)
for char in ["1", "2"]:
assert isre.is_loc_word(space, space.wrap(char))
assert isre.is_loc_word(space, space.newunicode([ord(char)]))
for char in [" ", u".", u"\u03a0"]:
assert not isre.is_loc_word(space, space.newunicode([ord(char)]))
def test_is_uni_digit(space):
for char in ["0", "9"]:
assert isre.is_uni_digit(space, space.wrap(char))
for char in ["0", "9", INDIAN_DIGIT]:
assert isre.is_uni_digit(space, space.newunicode([ord(char)]))
for char in [" ", "s"]:
assert not isre.is_uni_digit(space, space.wrap(char))
def test_is_uni_space(space):
for char in [" ", "\t"]:
assert isre.is_uni_space(space, space.wrap(char))
for char in ["\v", "\n", EM_SPACE]:
assert isre.is_uni_space(space, space.newunicode([ord(char)]))
for char in ["a", "1"]:
assert not isre.is_uni_space(space, space.wrap(char))
def test_at_beginning(space):
assert isre.at_beginning(space, create_context(space, "", 0, 0))
assert not isre.at_beginning(space, create_context(space, "a", 1, 1))
def test_at_beginning_line(space):
assert isre.at_beginning_line(space, create_context(space, "", 0, 0))
assert isre.at_beginning_line(space, create_context(space, "\na", 1, 3))
assert not isre.at_beginning_line(space, create_context(space, "a", 1, 2))
def test_at_end(space):
for string, pos, end in [("", 0, 0), ("a", 1, 1), ("a\n", 1, 2)]:
assert isre.at_end(space, create_context(space, string, pos, end))
assert not isre.at_end(space, create_context(space, "a", 0, 1))
def test_at_boundary(space):
for string, pos, end in [("a.", 1, 2), (".a", 1, 2)]:
assert isre.at_boundary(space, create_context(space, string, pos, end))
for string, pos, end in [(".", 0, 1), (".", 1, 1), ("ab", 1, 2)]:
assert not isre.at_boundary(space, create_context(space, string, pos, end))
def test_getlower(space):
assert isre.getlower(space, ord("A"), 0) == ord("a")
def test_get_byte_array(space):
if sys.byteorder == "big":
if isre.CODESIZE == 2:
assert [0, 1] == isre.to_byte_array(1)
assert [1, 0] == isre.to_byte_array(256)
assert [1, 2] == isre.to_byte_array(258)
else:
assert [0, 0, 0, 1] == isre.to_byte_array(1)
assert [0, 0, 1, 0] == isre.to_byte_array(256)
assert [1, 2, 3, 4] == isre.to_byte_array(0x01020304)
else:
if isre.CODESIZE == 2:
assert [1, 0] == isre.to_byte_array(1)
assert [0, 1] == isre.to_byte_array(256)
assert [2, 1] == isre.to_byte_array(258)
else:
assert [1, 0, 0, 0] == isre.to_byte_array(1)
assert [0, 1, 0, 0] == isre.to_byte_array(256)
assert [4, 3, 2, 1] == isre.to_byte_array(0x01020304)
import py
log = py.log.Producer("log")
logexec = py.log.Producer("exec")
BASEURL = "file:///svn/pypy/release/0.7.x"
DDIR = py.path.local('/www/codespeak.net/htdocs/download/pypy')
def usage():
print "usage: %s versionbasename" %(py.std.argv[0])
raise SystemExit, 1
def cexec(cmd):
logexec(cmd)
return py.process.cmdexec(cmd)
def maketargz(target):
targz = target + ".tar.gz"
basename = target.basename
old = target.dirpath().chdir()
try:
out = cexec("tar zcvf %(targz)s %(basename)s" % locals())
finally:
old.chdir()
assert targz.check(file=1)
assert targz.size() > 0
return targz
def maketarbzip(target):
targz = target + ".tar.bz2"
basename = target.basename
old = target.dirpath().chdir()
try:
out = cexec("tar jcvf %(targz)s %(basename)s" % locals())
finally:
old.chdir()
assert targz.check(file=1)
assert targz.size() > 0
return targz
def makezip(target):
tzip = target + ".zip"
if tzip.check(file=1):
log("removing", tzip)
tzip.remove()
basename = target.basename
old = target.dirpath().chdir()
try:
out = cexec("zip -r9 %(tzip)s %(basename)s" % locals())
finally:
old.chdir()
assert tzip.check(file=1)
assert tzip.size() > 0
return tzip
def copydownload(fn):
log("copying to download location")
#fn.copy(dtarget)
ddir = DDIR
out = cexec("rsync %(fn)s code2.codespeak.net:%(ddir)s"
% locals())
def forced_export(BASEURL, target, lineend="LF"):
if target.check(dir=1):
log("removing", target)
target.remove()
out = cexec("svn export --native-eol %s %s %s"
%(lineend, BASEURL, target))
assert target.check(dir=1)
if __name__ == '__main__':
argc = len(py.std.sys.argv)
if argc < 1:
usage()
ver = py.std.sys.argv[1]
tmpdir = py.path.local("/tmp/pypy-release")
target = tmpdir.join(ver)
forced_export(BASEURL, target, lineend="LF")
target_targz = maketargz(target)
assert target_targz.check(file=1)
copydownload(target_targz)
target_tarbzip = maketarbzip(target)
assert target_tarbzip.check(file=1)
copydownload(target_tarbzip)
forced_export(BASEURL, target, lineend="CRLF")
target_zip = makezip(target)
assert target_zip.check(file=1)
copydownload(target_zip)
import autopath
import py
import sys
mydir = py.magic.autopath().dirpath().realpath()
from pypy.tool.pytest import htmlreport
from pypy.tool.pytest import confpath
if __name__ == '__main__':
testresultdir = confpath.testresultdir
assert testresultdir.check(dir=1)
try:
resultwc = py.path.svnwc(testresultdir)
print "updating", resultwc
resultwc.update()
except KeyboardInterrupt, RuntimeError:
raise
except Exception,e: #py.process.ExecutionFailed,e:
print >> sys.stderr, "Warning: ",e #Subversion update failed"
print "traversing", mydir
rep = htmlreport.HtmlReport()
rep.parselatest()
print "making html files"
rep.makeindex(testresultdir.join('index.html'))
#! /usr/bin/env python
"""
the html test reporter
"""
import sys, os, re
import py
from pypy.tool.pytest import result
from pypy.tool.pytest.overview import ResultCache
#
# various interesting path objects
#
html = py.xml.html
class HtmlReport(object):
def __init__(self):
self.resultcache = ResultCache()
def parselatest(self):
self.resultcache.parselatest()
#
# rendering
#
def render_latest_table(self, results):
table = html.table(
[html.th(x, align='left')
for x in ("failure", "filename", "revision",
"user", "platform", "elapsed",
"options", "last error line"
)],
)