Commit 9cb9a05c authored by Armin Rigo's avatar Armin Rigo

Finish the merge of trunk into pyjitpl5.

parent 4f7e5ab1
......@@ -36,64 +36,78 @@ copyrighted by one or more of the following people and organizations:
Armin Rigo
Samuele Pedroni
Michael Hudson
Carl Friedrich Bolz
Maciek Fijalkowski
Michael Hudson
Antonio Cuni
Christian Tismer
Holger Krekel
Eric van Riet Paap
Antonio Cuni
Anders Chrigstrom
Maciek Fijalkowski
Richard Emslie
Anders Chrigstrom
Aurelien Campeas
Amaury Forgeot d Arc
Anders Lehmann
Niklaus Haldimann
Seo Sanghyeon
Leonardo Santagada
Lawrence Oluyede
Alex Martelli
Jakub Gustak
Guido Wesdorp
Niko Matsakis
Toon Verwaest
Alexander Schremmer
Ludovic Aubry
Adrien Di Mascio
Alex Martelli
Stephan Diehl
Guido Wesdorp
Adrien Di Mascio
Stefan Schwarzer
Tomek Meka
Patrick Maupin
Leonardo Santagada
Bob Ippolito
Laura Creighton
Jacob Hallen
Laura Creighton
Camillo Bruni
Bob Ippolito
Simon Burton
Bruno Gola
Alexandre Fayolle
Marius Gedminas
Niko Matsakis
Amaury Forgeot d Arc
Guido van Rossum
Valentino Volonghi
Alexander Schremmer
Alexandre Fayolle
Wanja Saatkamp
Adrian Kuhn
Anders Hammarquist
Paul deGrandis
Gerald Klix
Wanja Saatkamp
Oscar Nierstrasz
Eugene Oden
Dinu Gherman
Lukas Renggli
Bartosz SKOWRON
Guenter Jantzen
Dinu Gherman
Georg Brandl
Ben Young
Nicolas Chauvat
Michael Twomey
Jean-Paul Calderone
Rocco Moretti
Simon Burton
Michael Twomey
Boris Feigin
Jared Grubb
Olivier Dormond
Gintautas Miliauskas
Stuart Williams
Jens-Uwe Mager
Justas Sadzevicius
Brian Dorsey
Jonathan David Riehl
Anders Qvist
Beatrice During
Elmo Mäntynen
Andreas Friedge
Anders Qvist
Alan McIntyre
Bert Freudenberg
Heinrich-Heine University, Germany
Open End AB (formerly AB Strakt), Sweden
Open End AB (formerly AB Strakt), Sweden
merlinux GmbH, Germany
tismerysoft GmbH, Germany
Logilab Paris, France
......@@ -118,3 +132,20 @@ License for 'pypy/translator/jvm/src/jna.jar'
The file 'pypy/translator/jvm/src/jna.jar' is licensed under the GNU
Lesser General Public License of which you can find a copy here:
http://www.gnu.org/licenses/lgpl.html
License for 'pypy/translator/jvm/src/jasmin.jar'
=============================================
The file 'pypy/translator/jvm/src/jasmin.jar' is copyright (c) 1996-2004 Jon Meyer
and distributed with permission. The use of Jasmin by PyPy does not imply
that PyPy is endorsed by Jon Meyer nor any of Jasmin's contributors. Furthermore,
the following disclaimer applies to Jasmin:
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
......@@ -21,21 +21,9 @@ 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.
For information in what's new in this release and about PyPy current
status, please read the release announcement:
pypy/doc/release-1.0.0.txt or
pypy/doc/release-1.0.0.html
http://codespeak.net/pypy/dist/pypy/doc/release-1.0.0.html
Enjoy and send us feedback!
the pypy-dev team <pypy-dev@codespeak.net>
For the period December 2004 - March 2007, the development of PyPy has
been co-funded by the European Union's research programme. For more
information on this aspect of the project please visit
http://pypy.org/.
$Id$
$HeadURL$
......@@ -151,7 +151,7 @@ class _CWriter(object):
return try_compile([self.path], eci)
def configure(CConfig):
def configure(CConfig, noerr=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
......@@ -179,7 +179,7 @@ def configure(CConfig):
writer.close()
eci = CConfig._compilation_info_
infolist = list(run_example_code(writer.path, eci))
infolist = list(run_example_code(writer.path, eci, noerr=noerr))
assert len(infolist) == len(entries)
resultinfo = {}
......@@ -569,8 +569,8 @@ void dump(char* key, int value) {
}
"""
def run_example_code(filepath, eci):
executable = build_executable([filepath], eci)
def run_example_code(filepath, eci, noerr=False):
executable = build_executable([filepath], eci, noerr=noerr)
output = py.process.cmdexec(executable)
section = None
for line in output.splitlines():
......
......@@ -11,8 +11,6 @@
Insert '--help' before 'bpnn.py' for a list of translation options,
or see the Overview of Command Line Options for translation at
http://codespeak.net/pypy/dist/pypy/doc/config/commandline.html
Use '--text' before 'bpnn.py' if you don't have Pygame installed.
"""
# Back-Propagation Neural Networks
#
......@@ -32,7 +30,7 @@ import time
import autopath
from pypy.rlib import rrandom
PRINT_IT = False
PRINT_IT = True
random = rrandom.Random(1)
......@@ -207,5 +205,5 @@ def target(*args):
return entry_point, None
if __name__ == '__main__':
#demo()
demo()
print __doc__
class Stack:
"""A very simple stack interface
(not very useful in Python)
"""
def __init__(self, max_size = 10):
self.max_size = max_size
self.elements = []
def _pre_pop(self):
return not self.is_empty()
def _post_pop(self, old, ret):
return ret == old.top() and \
self.size() == old.size() - 1
def pop(self):
return self.elements.pop()
def _pre_push(self, obj):
return obj is not None and not self.is_full()
def _post_push(self, old, ret, obj):
return not self.is_empty() and (self.top() == obj)
def push(self, obj):
self.elements.append(obj)
def top(self):
"""Returns the top element of the stack
"""
return self.elements[-1]
def is_empty(self):
"""Tells whether or not the stack is empty
"""
return not bool(self.elements)
def is_full(self):
"""Tells whether or not the stack is full
"""
return len(self.elements) == self.max_size
def size(self):
"""Returns the current size of the stack
"""
return len(self.elements)
def __str__(self):
return "elements = %s, max_size = %s" % (self.elements, self.max_size)
from dbc import ContractAspect, ContractError
ContractAspect()
from contract_stack import Stack
def run():
"""This is an example of how contracts work
"""
print "*"*30
print "Creating an empty stack (max_size = 3)"
stack = Stack(3)
try:
print "Empty stack, pop() should fail"
stack.pop()
except ContractError, excpt:
print "\t failed with %s, (OK)" % excpt
else:
print "\t did not failed, (XXX)"
print "\n\n\n"
stack.push(1)
print "push 1 done"
stack.push(2)
print "push 2 done"
stack.push(3)
print "push 3 done"
try:
print "The stack is full, push() should fail"
stack.push(4)
except ContractError, excpt:
print "\t failed with %s, (OK)" % excpt
else:
print "\t did not failed, (XXX)"
print "\n\n\n"
if __name__ == '__main__':
run()
"""
Standard Library usage demo.
Uses urllib and htmllib to download and parse a web page.
The purpose of this demo is to remind and show that almost all
pure-Python modules of the Standard Library work just fine.
"""
url = 'http://www.python.org/'
html = 'python.html'
import urllib
content = urllib.urlopen(url).read()
file(html, 'w').write(content)
import htmllib
htmllib.test([html])
import os
os.remove(html)
import time
ZERO = 0
def f1(n):
"Arbitrary test function."
i = 0
x = 1
while i<n:
j = 0 #ZERO
while j<=i:
j = j + 1
x = x + (i&j)
i = i + 1
return x
try:
import pypyjit
except ImportError:
print "No jit"
else:
pypyjit.enable(f1.func_code)
res = f1(2117)
print res
N = 5
start = time.time()
for i in range(N):
assert f1(2117) == res
end = time.time()
print '%d iterations, time per iteration: %s' % (N, (end-start)/N)
import time
def f(n):
r = 1
while n > 1:
r *= n
n -= 1
return r
import pypyjit
pypyjit.enable(f.func_code)
print f(7)
import time
def f(n):
if n > 1:
return n * f(n-1)
else:
return 1
import pypyjit
pypyjit.enable(f.func_code)
print f(7)
"""This is an example that uses the (prototype) Logic Object Space. To run,
you have to set USE_GREENLETS in pypy.objspace.logic to True and do:
$ py.py -o logic producerconsumer.py
newvar creates a new unbound logical variable. If you try to access an unbound
variable, the current uthread is blocked, until the variable is bound.
"""
def generate(n, limit):
print "generate", n, limit
if n < limit:
return (n, generate(n + 1, limit))
return None
def sum(L, a):
print "sum", a
Head, Tail = newvar(), newvar()
unify(L, (Head, Tail))
if Tail != None:
return sum(Tail, Head + a)
return a + Head
print "eager producer consummer"
print "before"
X = newvar()
S = newvar()
bind(S, uthread(sum, X, 0))
unify(X, uthread(generate, 0, 10))
print "after"
assert S == 45
print S # needs a special treatment
......@@ -177,4 +177,8 @@ if __name__ == '__main__':
chan = server(port)
channels.append(chan)
mainloop(channels)
try:
mainloop(channels)
finally:
for channel in channels:
channel.s.close()
# Populate the database for the SQL injection demo,
# it creates a DBS directory in the current working dir.
# Requires Gadfly on the python path, and a --allworkingmodules --oldstyle
# pypy-c.
# Passwords for the demo are just the reverse of user names.
import md5
import sys, os
import random
os.mkdir("DBS")
import gadfly
conn = gadfly.gadfly()
conn.startup("db0", "DBS")
names = ['bob', 'jamie', 'david', 'monica', 'rose', 'anna']
def make_pwd(name):
rname = list(name)
rname.reverse()
rname = ''.join(rname)
return md5.new(rname).hexdigest()
pwds = [make_pwd(name) for name in names]
products = [('superglue', 10.0, 5),
('pink wallpaper', 25.0, 20),
('red wallpaper', 20.0, 20),
('gray wallpaper', 15.0, 20),
('white wallpaper', 15.0, 20),
('green wallpaper', 20.0, 20) ]
cursor = conn.cursor()
cursor.execute("""create table purchases (pwd varchar, user varchar,
month integer, year integer,
product varchar,
qty integer,
amount float)
""")
ins = "insert into purchases values (?,?,?,2007,?,?,?)"
for i in range(15):
uid = random.randrange(0, len(names))
pwd = pwds[uid]
name = names[uid]
month = random.randrange(1, 13)
product, unitprice, maxqty = random.choice(products)
qty = random.randrange(1, maxqty)
data = (pwd, name, month, product, qty, qty*unitprice)
cursor.execute(ins, data)
conn.commit()
print "Done"
"""SQL injection example
Needs gadfly (sf.net/projects/gadfly) to be on the python path.
Use populate.py to create the example db.
Passwords are the reverse of user names :).
Query is the number of a calendar month, purchases
for the user with the password since including that month
are shown.
Works with an --allworkingmodules --oldstyle pypy-c .
"""
import sys
import gadfly
import BaseHTTPServer
import cgi
import md5
page="""
<html>
<head>
<title>DEMO</title>
</head>
<body>
<form method="get" action="/">
<label for="pwd">Passwd</label>
<input name="pwd" type="text" size="10"></input><br />
<label for="query">Query</label>
<input name="query" type="text" size="20"></input><br />
<input type="submit">
</form>
<div>
%s
</div>
</body>
</html>
"""
table = """
<table>
<th>customer</th>