[pypy-commit] pypy missing-ndarray-attributes: merge default into branch
mattip
noreply at buildbot.pypy.org
Thu Dec 27 22:58:11 CET 2012
Author: mattip <matti.picus at gmail.com>
Branch: missing-ndarray-attributes
Changeset: r59591:ff0c695757d5
Date: 2012-12-27 21:41 +0200
http://bitbucket.org/pypy/pypy/changeset/ff0c695757d5/
Log: merge default into branch
diff too long, truncating to 2000 out of 42990 lines
diff --git a/.hgtags b/.hgtags
--- a/.hgtags
+++ b/.hgtags
@@ -2,3 +2,4 @@
b48df0bf4e75b81d98f19ce89d4a7dc3e1dab5e5 benchmarked
d8ac7d23d3ec5f9a0fa1264972f74a010dbfd07f release-1.6
ff4af8f318821f7f5ca998613a60fca09aa137da release-1.7
+07e08e9c885ca67d89bcc304e45a32346daea2fa release-2.0-beta-1
diff --git a/LICENSE b/LICENSE
--- a/LICENSE
+++ b/LICENSE
@@ -1,9 +1,10 @@
-License for files in the pypy/ directory
-==================================================
+License
+=======
Except when otherwise stated (look for LICENSE files in directories or
information at the beginning of each file) all software and
-documentation in the 'pypy' directories is licensed as follows:
+documentation in the 'pypy', 'ctype_configure', 'dotviewer', 'demo',
+and 'lib_pypy' directories is licensed as follows:
The MIT License
diff --git a/README b/README
deleted file mode 100644
--- a/README
+++ /dev/null
@@ -1,24 +0,0 @@
-=====================================
-PyPy: Python in Python Implementation
-=====================================
-
-Welcome to PyPy!
-
-PyPy is both an implementation of the Python programming language, and
-an extensive compiler framework for dynamic language implementations.
-You can build self-contained Python implementations which execute
-independently from CPython.
-
-The home page is:
-
- http://pypy.org/
-
-The getting-started document will help guide you:
-
- http://doc.pypy.org/en/latest/getting-started.html
-
-It will also point you to the rest of the documentation which is generated
-from files in the pypy/doc directory within the source repositories. Enjoy
-and send us feedback!
-
- the pypy-dev team <pypy-dev at python.org>
diff --git a/README.rst b/README.rst
new file mode 100644
--- /dev/null
+++ b/README.rst
@@ -0,0 +1,24 @@
+=====================================
+PyPy: Python in Python Implementation
+=====================================
+
+Welcome to PyPy!
+
+PyPy is both an implementation of the Python programming language, and
+an extensive compiler framework for dynamic language implementations.
+You can build self-contained Python implementations which execute
+independently from CPython.
+
+The home page is:
+
+ http://pypy.org/
+
+The getting-started document will help guide you:
+
+ http://doc.pypy.org/en/latest/getting-started.html
+
+It will also point you to the rest of the documentation which is generated
+from files in the pypy/doc directory within the source repositories. Enjoy
+and send us feedback!
+
+ the pypy-dev team <pypy-dev at python.org>
diff --git a/demo/autopath.py b/demo/autopath.py
deleted file mode 100644
--- a/demo/autopath.py
+++ /dev/null
@@ -1,2 +0,0 @@
-import sys, os
-sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
diff --git a/demo/bpnn.py b/demo/bpnn.py
deleted file mode 100755
--- a/demo/bpnn.py
+++ /dev/null
@@ -1,214 +0,0 @@
-#!/usr/bin/env python
-"""
- Translator Demo
-
- To analyse and type-annotate the functions and class defined in
- this module, starting from the entry point function demo(),
- use the following command line:
-
- ../pypy/translator/goal/translate.py bpnn.py
-
- 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
-"""
-# Back-Propagation Neural Networks
-#
-# Written in Python. See http://www.python.org/
-#
-# Neil Schemenauer <nascheme at enme.ucalgary.ca>
-#
-# Modifications to the original (Armin Rigo):
-# * import random from PyPy's lib, which is Python 2.2's plain
-# Python implementation
-# * print a doc about how to start the Translator
-
-import sys
-import math
-import time
-
-import autopath
-from pypy.rlib import rrandom
-
-PRINT_IT = True
-
-random = rrandom.Random(1)
-
-# calculate a random number where: a <= rand < b
-def rand(a, b):
- return (b-a)*random.random() + a
-
-# Make a matrix (we could use NumPy to speed this up)
-def makeMatrix(I, J, fill=0.0):
- m = []
- for i in range(I):
- m.append([fill]*J)
- return m
-
-class NN:
-
- def __init__(self, ni, nh, no):
- # number of input, hidden, and output nodes
- self.ni = ni + 1 # +1 for bias node
- self.nh = nh
- self.no = no
-
- # activations for nodes
- self.ai = [1.0]*self.ni
- self.ah = [1.0]*self.nh
- self.ao = [1.0]*self.no
-
- # create weights
- self.wi = makeMatrix(self.ni, self.nh)
- self.wo = makeMatrix(self.nh, self.no)
- # set them to random vaules
- for i in range(self.ni):
- for j in range(self.nh):
- self.wi[i][j] = rand(-2.0, 2.0)
- for j in range(self.nh):
- for k in range(self.no):
- self.wo[j][k] = rand(-2.0, 2.0)
-
- # last change in weights for momentum
- self.ci = makeMatrix(self.ni, self.nh)
- self.co = makeMatrix(self.nh, self.no)
-
- def update(self, inputs):
- if len(inputs) != self.ni-1:
- raise ValueError, 'wrong number of inputs'
-
- # input activations
- for i in range(self.ni-1):
- #self.ai[i] = 1.0/(1.0+math.exp(-inputs[i]))
- self.ai[i] = inputs[i]
-
- # hidden activations
- for j in range(self.nh):
- sum = 0.0
- for i in range(self.ni):
- sum = sum + self.ai[i] * self.wi[i][j]
- self.ah[j] = 1.0/(1.0+math.exp(-sum))
-
- # output activations
- for k in range(self.no):
- sum = 0.0
- for j in range(self.nh):
- sum = sum + self.ah[j] * self.wo[j][k]
- self.ao[k] = 1.0/(1.0+math.exp(-sum))
-
- return self.ao[:]
-
-
- def backPropagate(self, targets, N, M):
- if len(targets) != self.no:
- raise ValueError, 'wrong number of target values'
-
- # calculate error terms for output
- output_deltas = [0.0] * self.no
- for k in range(self.no):
- ao = self.ao[k]
- output_deltas[k] = ao*(1-ao)*(targets[k]-ao)
-
- # calculate error terms for hidden
- hidden_deltas = [0.0] * self.nh
- for j in range(self.nh):
- sum = 0.0
- for k in range(self.no):
- sum = sum + output_deltas[k]*self.wo[j][k]
- hidden_deltas[j] = self.ah[j]*(1-self.ah[j])*sum
-
- # update output weights
- for j in range(self.nh):
- for k in range(self.no):
- change = output_deltas[k]*self.ah[j]
- self.wo[j][k] = self.wo[j][k] + N*change + M*self.co[j][k]
- self.co[j][k] = change
- #print N*change, M*self.co[j][k]
-
- # update input weights
- for i in range(self.ni):
- for j in range(self.nh):
- change = hidden_deltas[j]*self.ai[i]
- self.wi[i][j] = self.wi[i][j] + N*change + M*self.ci[i][j]
- self.ci[i][j] = change
-
- # calculate error
- error = 0.0
- for k in range(len(targets)):
- delta = targets[k]-self.ao[k]
- error = error + 0.5*delta*delta
- return error
-
-
- def test(self, patterns):
- for p in patterns:
- if PRINT_IT:
- print p[0], '->', self.update(p[0])
-
- def weights(self):
- if PRINT_IT:
- print 'Input weights:'
- for i in range(self.ni):
- print self.wi[i]
- print
- print 'Output weights:'
- for j in range(self.nh):
- print self.wo[j]
-
- def train(self, patterns, iterations=2000, N=0.5, M=0.1):
- # N: learning rate
- # M: momentum factor
- for i in xrange(iterations):
- error = 0.0
- for p in patterns:
- inputs = p[0]
- targets = p[1]
- self.update(inputs)
- error = error + self.backPropagate(targets, N, M)
- if PRINT_IT and i % 100 == 0:
- print 'error', error
-
-
-def demo():
- # Teach network XOR function
- pat = [
- [[0,0], [0]],
- [[0,1], [1]],
- [[1,0], [1]],
- [[1,1], [0]]
- ]
-
- # create a network with two input, two hidden, and two output nodes
- n = NN(2, 3, 1)
- # train it with some patterns
- n.train(pat, 2000)
- # test it
- n.test(pat)
-
-
-# __________ Entry point for stand-alone builds __________
-
-import time
-
-def entry_point(argv):
- if len(argv) > 1:
- N = int(argv[1])
- else:
- N = 200
- T = time.time()
- for i in range(N):
- demo()
- t1 = time.time() - T
- print "%d iterations, %s milliseconds per iteration" % (N, 1000.0*t1/N)
- return 0
-
-# _____ Define and setup target ___
-
-def target(*args):
- return entry_point, None
-
-if __name__ == '__main__':
- if len(sys.argv) == 1:
- sys.argv.append('1')
- entry_point(sys.argv)
- print __doc__
diff --git a/demo/dis-goal.py b/demo/dis-goal.py
deleted file mode 100644
--- a/demo/dis-goal.py
+++ /dev/null
@@ -1,7 +0,0 @@
-"""
-An old-time classical example, and one of our first goals.
-To run on top of PyPy.
-"""
-
-import dis
-dis.dis(dis.dis)
diff --git a/demo/distribution/client.py b/demo/distribution/client.py
deleted file mode 100644
--- a/demo/distribution/client.py
+++ /dev/null
@@ -1,35 +0,0 @@
-""" This a sample client, suitable for use with server.py from this
-directory
-
-run by:
-pypy-c client.py
-"""
-
-HOST = '127.0.0.1'
-PORT = 12222
-
-from distributed.socklayer import connect
-remote_handle = connect((HOST, PORT))
-
-import code
-code.interact(local=locals())
-
-""" Things that can be done: 1. remote object access
-
-x = remote_handle.x
-assert type(x) is remote_handle.X # typecheck
-x.meth(lambda x: x + 10, 6) # remote call, with callback localy
-x.meth(remote_handle.f, 3) # remote call, remote callback
-remote_handle.sys._getframe(2).f_locals['x'] # remote frame access
-# XXX should be 'is x' and shouldn't need (2) argument
-
-# XXX next one does not work, while it should. Too much mangling with remote
-# traceback frames probably
-try:
- x.meth(1, 2) # non-callable argument, AssertionError
-except:
- import sys
- e, c, tb = sys.exc_info()
- import pdb
- pdb.post_mortem(tb)
-"""
diff --git a/demo/distribution/fileclient.py b/demo/distribution/fileclient.py
deleted file mode 100644
--- a/demo/distribution/fileclient.py
+++ /dev/null
@@ -1,25 +0,0 @@
-
-""" This is sample client for a server based in fileserver.py, not counting
-initialization, code.interact and __doc__ has just 2 lines! Usage:
-
-pypy-c fileclient.py
-
-The file_opener is a proxy for remote file object. Which means you can
-perform same operations as locally, like file_opener('/etc/passwd').read()
-or file_opener('/tmp/x', 'w').write('x')
-
-pypy-c needs to be compiled with --allworkingmodules in order to have socket
-working.
-"""
-
-HOST = '127.0.0.1'
-PORT = 12221
-
-from distributed.socklayer import connect
-file_opener = connect((HOST, PORT)).open
-
-import code
-code.interact(local=locals())
-# The file_opener is a proxy for remote file object. Which means you can
-# perform same operations as locally, like file_opener('/etc/passwd').read()
-# or file_opener('/tmp/x', 'w').write('x')
diff --git a/demo/distribution/fileserver.py b/demo/distribution/fileserver.py
deleted file mode 100644
--- a/demo/distribution/fileserver.py
+++ /dev/null
@@ -1,19 +0,0 @@
-""" This is a sample demo showcasing file server, done by the pypy
-distribution library.
-
-Not counting __doc__ and initialization this is 2 line,
-fully operational file server,
-sample client which is in fileclient.py is included as well.
-
-run by:
-pypy-c fileserver.py
-
-pypy-c needs to be compiled with --allworkingmodules in order to have socket
-working.
-"""
-
-HOST = '127.0.0.1' # defaults to localhost, not to export your files
-PORT = 12221
-
-from distributed.socklayer import socket_loop
-socket_loop((HOST, PORT), {'open':open})
diff --git a/demo/distribution/server.py b/demo/distribution/server.py
deleted file mode 100644
--- a/demo/distribution/server.py
+++ /dev/null
@@ -1,38 +0,0 @@
-""" This is a demo exposing all globals from the current process over
-socket, to be accessible remotely.
-
-run by:
-pypy-c server.py
-
-pypy-c needs to be compiled with --allworkingmodules in order to have socket
-working.
-"""
-
-# things to export
-# function
-def f(x):
- return x + 3
-
-# class
-class X:
- def __init__(self):
- self.slot = 3
-
- def meth(self, f, arg):
- """ Method eating callable and calling it with an argument
- """
- assert callable(f)
- return f(arg)
-
-# object
-x = X()
-
-# module
-import sys
-
-# constants
-HOST = '127.0.0.1'
-PORT = 12222
-
-from distributed.socklayer import socket_loop
-socket_loop((HOST, PORT), globals())
diff --git a/demo/fibonacci.py b/demo/fibonacci.py
deleted file mode 100644
--- a/demo/fibonacci.py
+++ /dev/null
@@ -1,43 +0,0 @@
-"""
-Thunk (a.k.a. lazy objects) in PyPy.
-To run on top of the thunk object space with the following command-line:
-
- py.py -o thunk fibonacci.py
-
-This is a typical Functional Programming Languages demo, computing the
-Fibonacci sequence by using an infinite lazy linked list.
-"""
-
-try:
- from __pypy__ import thunk # only available in 'py.py -o thunk'
-except ImportError:
- print __doc__
- raise SystemExit(2)
-
-# ____________________________________________________________
-
-
-class ListNode:
- def __init__(self, head, tail):
- self.head = head # the first element of the list
- self.tail = tail # the sublist of all remaining elements
-
-
-def add_lists(list1, list2):
- """Compute the linked-list equivalent of the Python expression
- [a+b for (a,b) in zip(list1,list2)]
- """
- return ListNode(list1.head + list2.head,
- thunk(add_lists, list1.tail, list2.tail))
-
-
-# 1, 1, 2, 3, 5, 8, 13, 21, 34, ...
-Fibonacci = ListNode(1, ListNode(1, None))
-Fibonacci.tail.tail = thunk(add_lists, Fibonacci, Fibonacci.tail)
-
-
-if __name__ == '__main__':
- node = Fibonacci
- while True:
- print node.head
- node = node.tail
diff --git a/demo/fibonacci2.py b/demo/fibonacci2.py
deleted file mode 100644
--- a/demo/fibonacci2.py
+++ /dev/null
@@ -1,27 +0,0 @@
-"""
-Lazy functions in PyPy.
-To run on top of the thunk object space with the following command-line:
-
- py.py -o thunk fibonacci2.py
-
-This is a typical Functional Programming Languages demo, computing the
-Fibonacci sequence as nested 2-tuples.
-"""
-
-import pprint
-
-try:
- from __pypy__ import lazy
-except ImportError:
- print __doc__
- raise SystemExit(2)
-
-
- at lazy
-def fibo(a, b):
- return (a, fibo(b, a + b))
-
-
-fibonacci = fibo(1, 1)
-
-pprint.pprint(fibonacci, depth=10)
diff --git a/demo/foodbill.py b/demo/foodbill.py
deleted file mode 100644
--- a/demo/foodbill.py
+++ /dev/null
@@ -1,59 +0,0 @@
-"""
-Of historical interest: we computed the food bill of our first Gothenburg
-sprint with PyPy :-)
-"""
-
-slips=[(1, 'Kals MatMarkn', 6150, 'Chutney for Curry', 'dinner Saturday'),
- (2, 'Kals MatMarkn', 32000, 'Spaghetti, Beer', 'dinner Monday'),
- (2, 'Kals MatMarkn', -810, 'Deposit on Beer Bottles', 'various'),
- (3, 'Fram', 7700, 'Rice and Curry Spice', 'dinner Saturday'),
- (4, 'Kals MatMarkn', 25000, 'Alcohol-Free Beer, sundries', 'various'),
- (4, 'Kals MatMarkn', -1570, "Michael's toothpaste", 'none'),
- (4, 'Kals MatMarkn', -1690, "Laura's toothpaste", 'none'),
- (4, 'Kals MatMarkn', -720, 'Deposit on Beer Bottles', 'various'),
- (4, 'Kals MatMarkn', -60, 'Deposit on another Beer Bottle', 'various'),
- (5, 'Kals MatMarkn', 26750, 'lunch bread meat cheese', 'lunch Monday'),
- (6, 'Kals MatMarkn', 15950, 'various', 'dinner Tuesday and Thursday'),
- (7, 'Kals MatMarkn', 3650, 'Drottningsylt, etc.', 'dinner Thursday'),
- (8, 'Kals MatMarkn', 26150, 'Chicken and Mushroom Sauce', 'dinner Wed'),
- (8, 'Kals MatMarkn', -2490, 'Jacob and Laura -- juice', 'dinner Wed'),
- (8, 'Kals MatMarkn', -2990, "Chicken we didn't cook", 'dinner Wednesday'),
- (9, 'Kals MatMarkn', 1380, 'fruit for Curry', 'dinner Saturday'),
- (9, 'Kals MatMarkn', 1380, 'fruit for Curry', 'dinner Saturday'),
- (10, 'Kals MatMarkn', 26900, 'Jansons Frestelse', 'dinner Sunday'),
- (10, 'Kals MatMarkn', -540, 'Deposit on Beer Bottles', 'dinner Sunday'),
- (11, 'Kals MatMarkn', 22650, 'lunch bread meat cheese', 'lunch Thursday'),
- (11, 'Kals MatMarkn', -2190, 'Jacob and Laura -- juice', 'lunch Thursday'),
- (11, 'Kals MatMarkn', -2790, 'Jacob and Laura -- cereal', 'lunch Thurs'),
- (11, 'Kals MatMarkn', -760, 'Jacob and Laura -- milk', 'lunch Thursday'),
- (12, 'Kals MatMarkn', 18850, 'lunch bread meat cheese', 'lunch Friday'),
- (13, 'Kals MatMarkn', 18850, 'lunch bread meat cheese', 'guestimate Sun'),
- (14, 'Kals MatMarkn', 18850, 'lunch bread meat cheese', 'guestimate Tues'),
- (15, 'Kals MatMarkn', 20000, 'lunch bread meat cheese', 'guestimate Wed'),
- (16, 'Kals MatMarkn', 42050, 'grillfest', 'dinner Friday'),
- (16, 'Kals MatMarkn', -1350, 'Deposit on Beer Bottles', 'dinner Friday'),
- (17, 'System Bolaget', 15500, 'Cederlunds Caloric', 'dinner Thursday'),
- (17, 'System Bolaget', 22400, '4 x Farnese Sangiovese 56SEK', 'various'),
- (17, 'System Bolaget', 22400, '4 x Farnese Sangiovese 56SEK', 'various'),
- (17, 'System Bolaget', 13800, '2 x Jacobs Creek 69SEK', 'various'),
- (18, 'J and Ls winecabinet', 10800, '2 x Parrotes 54SEK', 'various'),
- (18, 'J and Ls winecabinet', 14700, '3 x Saint Paulin 49SEK', 'various'),
- (18, 'J and Ls winecabinet', 10400, '2 x Farnese Sangioves 52SEK',
- 'cheaper when we bought it'),
- (18, 'J and Ls winecabinet', 17800, '2 x Le Poiane 89SEK', 'various'),
- (18, 'J and Ls winecabinet', 9800, '2 x Something Else 49SEK', 'various'),
- (19, 'Konsum', 26000, 'Saturday Bread and Fruit', 'Slip MISSING'),
- (20, 'Konsum', 15245, 'Mooseburgers', 'found slip'),
- (21, 'Kals MatMarkn', 20650, 'Grilling', 'Friday dinner'),
- (22, 'J and Ls freezer', 21000, 'Meat for Curry, grilling', ''),
- (22, 'J and Ls cupboard', 3000, 'Rice', ''),
- (22, 'J and Ls cupboard', 4000, 'Charcoal', ''),
- (23, 'Fram', 2975, 'Potatoes', '3.5 kg @ 8.50SEK'),
- (23, 'Fram', 1421, 'Peas', 'Thursday dinner'),
- (24, 'Kals MatMarkn', 20650, 'Grilling', 'Friday dinner'),
- (24, 'Kals MatMarkn', -2990, 'TP', 'None'),
- (24, 'Kals MatMarkn', -2320, 'T-Gul', 'None')
- ]
-
-print [t[2] for t in slips]
-print (reduce(lambda x, y: x+y, [t[2] for t in slips], 0))/900
diff --git a/demo/pickle_coroutine.py b/demo/pickle_coroutine.py
deleted file mode 100644
--- a/demo/pickle_coroutine.py
+++ /dev/null
@@ -1,86 +0,0 @@
-"""
-Stackless demo.
-
-This example only works on top of a pypy-c compiled with stackless features
-and the signal module:
-
- translate.py --stackless targetpypystandalone --withmod-signal
-
-Usage:
-
- pypy-c pickle_coroutine.py --start demo.pickle
-
- Start the computation. You can interrupt it at any time by
- pressing Ctrl-C; at this point, the state of the computing
- coroutine is saved in demo.pickle.
-
- pypy-c pickle_coroutine.py --resume demo.pickle
-
- Reload the coroutine from demo.pickle and continue running it.
- (It can be interrupted again with Ctrl-C.)
-
-This demo is documented in detail in pypy/doc/stackless.txt.
-"""
-
-try:
- import sys, pickle, signal
- from stackless import coroutine
-except ImportError:
- print __doc__
- sys.exit(2)
-
-
-def ackermann(x, y):
- check()
- if x == 0:
- return y + 1
- if y == 0:
- return ackermann(x - 1, 1)
- return ackermann(x - 1, ackermann(x, y - 1))
-
-# ____________________________________________________________
-
-main = coroutine.getcurrent()
-sys.setrecursionlimit(100000)
-
-interrupt_flag = False
-
-def interrupt_handler(*args):
- global interrupt_flag
- interrupt_flag = True
-
-def check():
- if interrupt_flag:
- main.switch()
-
-
-def execute(coro):
- signal.signal(signal.SIGINT, interrupt_handler)
- res = coro.switch()
- if res is None and coro.is_alive: # interrupted!
- print "interrupted! writing %s..." % (filename,)
- f = open(filename, 'w')
- pickle.dump(coro, f)
- f.close()
- print "done"
- else:
- print "result:", res
-
-try:
- operation, filename = sys.argv[1:]
-except ValueError:
- print __doc__
- sys.exit(2)
-
-if operation == '--start':
- coro = coroutine()
- coro.bind(ackermann, 3, 7)
- print "running from the start..."
- execute(coro)
-elif operation == '--resume':
- print "reloading %s..." % (filename,)
- f = open(filename)
- coro = pickle.load(f)
- f.close()
- print "done, running now..."
- execute(coro)
diff --git a/demo/sharedref.py b/demo/sharedref.py
deleted file mode 100644
--- a/demo/sharedref.py
+++ /dev/null
@@ -1,184 +0,0 @@
-"""
- This is an example usage of the 'thunk' object space of PyPy.
- It implements transparent distributed object manipulation.
-
- Start a server on a local port, say port 8888, with:
-
- $ py.py -o thunk sharedref.py 8888
- Waiting for connection on port 8888
-
- Then start and connect a client from the same or another machine:
-
- $ py.py -o thunk sharedref.py ip_or_name:8888
- Connecting to ('...', 8888)
- Ok
- >>> l = [1,2,3]
- >>> chan.send(l) # send the list to the server over the connexion
-
- On the server-side:
-
- Connected from ('...', 1046)
- >>> l = chan.recv() # receive the list sent above
- >>> l
- [1, 2, 3]
- >>> l.append(4)
-
- Back on the client-side:
-
- >>> l
- [1, 2, 3, 4]
-
- The list behaves like a single distributed object, which both sides can
- modify and access without needing further explicit synchronization.
- There is no difference between who was the original sender or receiver of
- the object, nor between which side was originally 'server' or 'client'.
-"""
-
-import sys, marshal
-from __pypy__ import thunk, become
-from socket import *
-from select import select
-
-
-class Channel:
-
- def __init__(self, s, serverside):
- # invariants: a shared object 'obj' is
- # - either remote, and a thunk, and not a value in self.cache
- # - or local (or at least on "our" side of this Channel), and
- # then it has a corresponding key in self.cache
- self.s = s
- self.cache = {}
- self.inputfifo = []
- self.count = int(not serverside)
-
-## def _check(self, obj):
-## print '%s: cache=%r' % (self, self.cache.keys()),
-## if is_thunk(obj):
-## print 'THUNK'
-## else:
-## print obj
-
- def sendraw(self, obj):
- data = marshal.dumps(obj)
- hdr = str(len(data))
- hdr = '0'*(10-len(hdr)) + hdr
- self.s.sendall(hdr + data)
-
- def _readbytes(self, count):
- data = ''
- while len(data) < count:
- t = self.s.recv(count - len(data))
- if not t:
- raise EOFError
- data += t
- return data
-
- def recvraw(self):
- datasize = int(self._readbytes(10))
- data = self._readbytes(datasize)
- return marshal.loads(data)
-
- def send(self, obj, n=None):
- #print 'send', n,; self._check(obj)
- if n is None:
- n = self.count
- self.count += 2
- data = (n, obj, None)
- else:
- data = (n, obj)
- self.sendraw(data)
- become(obj, thunk(self._resume, n))
- #print 'done', n,; self._check(obj)
-
- def recv(self):
- obj = self.inputfifo.pop(0)
- #print 'recv',; self._check(obj)
- return obj
-
- def _resume(self, n):
- #print 'resume', n,; sys.stdout.flush()
- assert n not in self.cache
- self.sendraw((n,))
- while n not in self.cache:
- self.handle_once()
- obj = self.cache[n]
- #self._check(obj)
- return obj
-
- def handle_once(self):
- input = self.recvraw()
- if len(input) > 1:
- obj = input[1]
- self.cache[input[0]] = obj
- if len(input) > 2:
- self.inputfifo.append(obj)
- else:
- n = input[0]
- obj = self.cache[n]
- self.send(obj, n)
- del self.cache[n]
-
-
-def mainloop(channels):
- stdin = sys.stdin.fileno()
- sockfd = [chan.s.fileno() for chan in channels]
- while True:
- sys.stdout.write('>>> ')
- sys.stdout.flush()
- while True:
- iwtd, owtd, ewtd = select([stdin] + sockfd, [], [stdin])
- if stdin in iwtd or stdin in ewtd: break
- for chan in channels:
- if chan.s.fileno() in iwtd:
- chan.handle_once()
- code = raw_input()
- if not code: break
- try:
- co = compile(code, '<input>', 'single')
- exec co in globals()
- except Exception, e:
- print e.__class__.__name__, str(e)
-
-
-def server(port):
- s = socket(AF_INET, SOCK_STREAM)
- s.bind(('', port))
- s.listen(1)
- print 'Waiting for connection on port', port
- s, addr = s.accept()
- print 'Connected from', addr
- return Channel(s, True)
-
-def client(addr):
- s = socket(AF_INET, SOCK_STREAM)
- print 'Connecting to', addr
- s.connect(addr)
- print 'Ok'
- return Channel(s, False)
-
-
-if __name__ == '__main__':
- try:
- thunk, become # only available in 'py.py -o thunk'
- except NameError:
- print __doc__
- raise SystemExit(2)
-
- channels = []
- for a in sys.argv[1:]:
- try:
- port = int(a)
- except ValueError:
- host, port = a.split(':')
- port = int(port)
- chan = client((host, port))
- else:
- chan = server(port)
- channels.append(chan)
-
- try:
- mainloop(channels)
- finally:
- for channel in channels:
- channel.s.close()
diff --git a/demo/tproxy/persistence.py b/demo/tproxy/persistence.py
deleted file mode 100644
--- a/demo/tproxy/persistence.py
+++ /dev/null
@@ -1,62 +0,0 @@
-"""
-
-This small example implements a basic orthogonal persistence
-mechanism on top of PyPy's transparent proxies.
-
-"""
-from tputil import make_proxy
-
-list_changeops = set('__iadd__ __imul__ __delitem__ __setitem__ __setattr__'
- '__delslice__ __setslice__ '
- 'append extend insert pop remove reverse sort'.split())
-
-dict_changeops = set('__delitem__ __setitem__ __setattr__'
- 'clear pop popitem setdefault update'.split())
-
-def ischangeop(operation):
- """ return True if this operation is a changing operation
- on known builtins (dicts, lists).
- """
- if isinstance(operation.obj, list):
- changeops = list_changeops
- elif isinstance(operation.obj, dict):
- changeops = dict_changeops
- else:
- return False
- return operation.opname in changeops
-
-def make_persistent_proxy(instance, storage):
- def perform(operation):
- res = operation.delegate()
- if ischangeop(operation):
- print "persisting after:", operation
- storage.dump(instance)
- if res is not operation.proxyobj and isinstance(res, (dict, list)):
- res = make_proxy(perform, obj=res)
- return res
- return make_proxy(perform, obj=instance)
-
-def load(storage):
- obj = storage.load()
- return make_persistent_proxy(obj, storage)
-
-if __name__ == '__main__':
- import py
- storage = py.path.local("/tmp/dictpickle")
- pdict = make_persistent_proxy({}, storage)
-
- # the code below is not aware of pdict being a proxy
- assert type(pdict) is dict
- pdict['hello'] = 'world'
- pdict['somelist'] = []
- del pdict
-
- newdict = load(storage)
- assert newdict == {'hello': 'world', 'somelist': []}
- l = newdict['somelist']
- l.append(1) # this triggers persisting the whole dict
- l.extend([2,3]) # this triggers persisting the whole dict
- del newdict, l
-
- newdict = load(storage)
- print newdict['somelist'] # will show [1,2,3]
diff --git a/demo/tproxy/print_operations.py b/demo/tproxy/print_operations.py
deleted file mode 100644
--- a/demo/tproxy/print_operations.py
+++ /dev/null
@@ -1,26 +0,0 @@
-"""
-
-This example transparently intercepts and shows operations on
-builtin objects. Requires the "--objspace-std-withtproxy" option.
-
-"""
-
-from tputil import make_proxy
-
-def make_show_proxy(instance):
- def controller(operation):
- print "proxy sees:", operation
- res = operation.delegate()
- return res
- tproxy = make_proxy(controller, obj=instance)
- return tproxy
-
-if __name__ == '__main__':
- mydict = make_show_proxy({})
- assert type(mydict) is dict # this looks exactly like a dict
- mydict['hello'] = 'world' # will print __setitem__
- mydict[42] = 23 # will print __setitem__
- assert mydict.pop('hello') == 'world' # will print pop
- assert mydict.popitem() == (42,23) # will print popitem
-
-
diff --git a/lib-python/2.7/ctypes/test/test_internals.py b/lib-python/2.7/ctypes/test/test_internals.py
--- a/lib-python/2.7/ctypes/test/test_internals.py
+++ b/lib-python/2.7/ctypes/test/test_internals.py
@@ -1,7 +1,10 @@
# This tests the internal _objects attribute
import unittest
from ctypes import *
-from sys import getrefcount as grc
+try:
+ from sys import getrefcount as grc
+except ImportError:
+ grc = None # e.g. PyPy
# XXX This test must be reviewed for correctness!!!
@@ -22,6 +25,8 @@
self.assertEqual(id(a), id(b))
def test_ints(self):
+ if grc is None:
+ return unittest.skip("no sys.getrefcount()")
i = 42000123
refcnt = grc(i)
ci = c_int(i)
@@ -29,6 +34,8 @@
self.assertEqual(ci._objects, None)
def test_c_char_p(self):
+ if grc is None:
+ return unittest.skip("no sys.getrefcount()")
s = "Hello, World"
refcnt = grc(s)
cs = c_char_p(s)
diff --git a/lib-python/2.7/ctypes/test/test_memfunctions.py b/lib-python/2.7/ctypes/test/test_memfunctions.py
--- a/lib-python/2.7/ctypes/test/test_memfunctions.py
+++ b/lib-python/2.7/ctypes/test/test_memfunctions.py
@@ -53,7 +53,8 @@
s = string_at("foo bar")
# XXX The following may be wrong, depending on how Python
# manages string instances
- self.assertEqual(2, sys.getrefcount(s))
+ if hasattr(sys, 'getrefcount'):
+ self.assertEqual(2, sys.getrefcount(s))
self.assertTrue(s, "foo bar")
self.assertEqual(string_at("foo bar", 8), "foo bar\0")
diff --git a/lib-python/2.7/ctypes/test/test_python_api.py b/lib-python/2.7/ctypes/test/test_python_api.py
--- a/lib-python/2.7/ctypes/test/test_python_api.py
+++ b/lib-python/2.7/ctypes/test/test_python_api.py
@@ -9,7 +9,10 @@
################################################################
-from sys import getrefcount as grc
+try:
+ from sys import getrefcount as grc
+except ImportError:
+ grc = None # e.g. PyPy
if sys.version_info > (2, 4):
c_py_ssize_t = c_size_t
else:
diff --git a/lib-python/2.7/ctypes/test/test_refcounts.py b/lib-python/2.7/ctypes/test/test_refcounts.py
--- a/lib-python/2.7/ctypes/test/test_refcounts.py
+++ b/lib-python/2.7/ctypes/test/test_refcounts.py
@@ -11,7 +11,10 @@
class RefcountTestCase(unittest.TestCase):
def test_1(self):
- from sys import getrefcount as grc
+ try:
+ from sys import getrefcount as grc
+ except ImportError:
+ return unittest.skip("no sys.getrefcount()")
f = dll._testfunc_callback_i_if
f.restype = ctypes.c_int
@@ -35,7 +38,10 @@
def test_refcount(self):
- from sys import getrefcount as grc
+ try:
+ from sys import getrefcount as grc
+ except ImportError:
+ return unittest.skip("no sys.getrefcount()")
def func(*args):
pass
# this is the standard refcount for func
@@ -84,6 +90,10 @@
class AnotherLeak(unittest.TestCase):
def test_callback(self):
import sys
+ try:
+ from sys import getrefcount
+ except ImportError:
+ return unittest.skip("no sys.getrefcount()")
proto = ctypes.CFUNCTYPE(ctypes.c_int, ctypes.c_int, ctypes.c_int)
def func(a, b):
diff --git a/lib-python/2.7/distutils/command/build_ext.py b/lib-python/2.7/distutils/command/build_ext.py
--- a/lib-python/2.7/distutils/command/build_ext.py
+++ b/lib-python/2.7/distutils/command/build_ext.py
@@ -699,6 +699,9 @@
shared extension. On most platforms, this is just 'ext.libraries';
on Windows and OS/2, we add the Python library (eg. python20.dll).
"""
+ # For PyPy, we must not add any such Python library, on any platform
+ if "__pypy__" in sys.builtin_module_names:
+ return ext.libraries
# The python library is always needed on Windows.
if sys.platform == "win32":
template = "python%d%d"
diff --git a/lib-python/2.7/json/decoder.py b/lib-python/2.7/json/decoder.py
--- a/lib-python/2.7/json/decoder.py
+++ b/lib-python/2.7/json/decoder.py
@@ -62,8 +62,7 @@
DEFAULT_ENCODING = "utf-8"
-def py_scanstring(s, end, encoding=None, strict=True,
- _b=BACKSLASH, _m=STRINGCHUNK.match):
+def py_scanstring(s, end, encoding=None, strict=True):
"""Scan the string s for a JSON string. End is the index of the
character in s after the quote that started the JSON string.
Unescapes all valid JSON string escape sequences and raises ValueError
@@ -78,7 +77,7 @@
_append = chunks.append
begin = end - 1
while 1:
- chunk = _m(s, end)
+ chunk = STRINGCHUNK.match(s, end)
if chunk is None:
raise ValueError(
errmsg("Unterminated string starting at", s, begin))
@@ -109,7 +108,7 @@
# If not a unicode escape sequence, must be in the lookup table
if esc != 'u':
try:
- char = _b[esc]
+ char = BACKSLASH[esc]
except KeyError:
msg = "Invalid \\escape: " + repr(esc)
raise ValueError(errmsg(msg, s, end))
@@ -147,7 +146,7 @@
WHITESPACE_STR = ' \t\n\r'
def JSONObject(s_and_end, encoding, strict, scan_once, object_hook,
- object_pairs_hook, _w=WHITESPACE.match, _ws=WHITESPACE_STR):
+ object_pairs_hook):
s, end = s_and_end
pairs = []
pairs_append = pairs.append
@@ -156,8 +155,8 @@
nextchar = s[end:end + 1]
# Normally we expect nextchar == '"'
if nextchar != '"':
- if nextchar in _ws:
- end = _w(s, end).end()
+ if nextchar in WHITESPACE_STR:
+ end = WHITESPACE.match(s, end).end()
nextchar = s[end:end + 1]
# Trivial empty object
if nextchar == '}':
@@ -177,17 +176,17 @@
# To skip some function call overhead we optimize the fast paths where
# the JSON key separator is ": " or just ":".
if s[end:end + 1] != ':':
- end = _w(s, end).end()
+ end = WHITESPACE.match(s, end).end()
if s[end:end + 1] != ':':
raise ValueError(errmsg("Expecting : delimiter", s, end))
end += 1
try:
- if s[end] in _ws:
+ if s[end] in WHITESPACE_STR:
end += 1
- if s[end] in _ws:
- end = _w(s, end + 1).end()
+ if s[end] in WHITESPACE_STR:
+ end = WHITESPACE.match(s, end + 1).end()
except IndexError:
pass
@@ -199,8 +198,8 @@
try:
nextchar = s[end]
- if nextchar in _ws:
- end = _w(s, end + 1).end()
+ if nextchar in WHITESPACE_STR:
+ end = WHITESPACE.match(s, end + 1).end()
nextchar = s[end]
except IndexError:
nextchar = ''
@@ -213,11 +212,11 @@
try:
nextchar = s[end]
- if nextchar in _ws:
+ if nextchar in WHITESPACE_STR:
end += 1
nextchar = s[end]
- if nextchar in _ws:
- end = _w(s, end + 1).end()
+ if nextchar in WHITESPACE_STR:
+ end = WHITESPACE.match(s, end + 1).end()
nextchar = s[end]
except IndexError:
nextchar = ''
@@ -234,12 +233,12 @@
pairs = object_hook(pairs)
return pairs, end
-def JSONArray(s_and_end, scan_once, _w=WHITESPACE.match, _ws=WHITESPACE_STR):
+def JSONArray(s_and_end, scan_once):
s, end = s_and_end
values = []
nextchar = s[end:end + 1]
- if nextchar in _ws:
- end = _w(s, end + 1).end()
+ if nextchar in WHITESPACE_STR:
+ end = WHITESPACE.match(s, end + 1).end()
nextchar = s[end:end + 1]
# Look-ahead for trivial empty array
if nextchar == ']':
@@ -252,8 +251,8 @@
raise ValueError(errmsg("Expecting object", s, end))
_append(value)
nextchar = s[end:end + 1]
- if nextchar in _ws:
- end = _w(s, end + 1).end()
+ if nextchar in WHITESPACE_STR:
+ end = WHITESPACE.match(s, end + 1).end()
nextchar = s[end:end + 1]
end += 1
if nextchar == ']':
@@ -262,10 +261,10 @@
raise ValueError(errmsg("Expecting , delimiter", s, end))
try:
- if s[end] in _ws:
+ if s[end] in WHITESPACE_STR:
end += 1
- if s[end] in _ws:
- end = _w(s, end + 1).end()
+ if s[end] in WHITESPACE_STR:
+ end = WHITESPACE.match(s, end + 1).end()
except IndexError:
pass
@@ -358,13 +357,13 @@
self.parse_string = scanstring
self.scan_once = scanner.make_scanner(self)
- def decode(self, s, _w=WHITESPACE.match):
+ def decode(self, s):
"""Return the Python representation of ``s`` (a ``str`` or ``unicode``
instance containing a JSON document)
"""
- obj, end = self.raw_decode(s, idx=_w(s, 0).end())
- end = _w(s, end).end()
+ obj, end = self.raw_decode(s, idx=WHITESPACE.match(s, 0).end())
+ end = WHITESPACE.match(s, end).end()
if end != len(s):
raise ValueError(errmsg("Extra data", s, end, len(s)))
return obj
diff --git a/lib-python/2.7/timeit.py b/lib-python/2.7/timeit.py
--- a/lib-python/2.7/timeit.py
+++ b/lib-python/2.7/timeit.py
@@ -190,7 +190,8 @@
else:
it = [None] * number
gcold = gc.isenabled()
- gc.disable()
+ if '__pypy__' not in sys.builtin_module_names:
+ gc.disable() # only do that on CPython
try:
timing = self.inner(it, self.timer)
finally:
diff --git a/lib-python/conftest.py b/lib-python/conftest.py
--- a/lib-python/conftest.py
+++ b/lib-python/conftest.py
@@ -14,7 +14,7 @@
from pypy.interpreter.main import run_string, run_file
# the following adds command line options as a side effect!
-from pypy.conftest import gettestobjspace, option as pypy_option
+from pypy.conftest import option as pypy_option
from pypy.tool.pytest import appsupport
from pypy.tool.pytest.confpath import pypydir, testdir, testresultdir
diff --git a/lib_pypy/_ctypes_test.py b/lib_pypy/_ctypes_test.py
--- a/lib_pypy/_ctypes_test.py
+++ b/lib_pypy/_ctypes_test.py
@@ -2,10 +2,6 @@
import tempfile
import gc
-# Monkeypatch & hacks to let ctypes.tests import.
-# This should be removed at some point.
-sys.getrefcount = lambda x: len(gc.get_referrers(x)) - 1
-
def compile_shared():
"""Compile '_ctypes_test.c' into an extension module, and import it
"""
diff --git a/lib_pypy/_sqlite3.py b/lib_pypy/_sqlite3.py
--- a/lib_pypy/_sqlite3.py
+++ b/lib_pypy/_sqlite3.py
@@ -784,6 +784,9 @@
self.statement.reset()
raise self.connection._get_exception(ret)
+ if self.statement.kind == DML:
+ self.statement.reset()
+
if self.statement.kind == DQL and ret == SQLITE_ROW:
self.statement._build_row_cast_map()
self.statement._readahead(self)
@@ -791,9 +794,6 @@
self.statement.item = None
self.statement.exhausted = True
- if self.statement.kind == DML:
- self.statement.reset()
-
self.rowcount = -1
if self.statement.kind == DML:
self.rowcount = sqlite.sqlite3_changes(self.connection.db)
diff --git a/lib_pypy/stackless.py b/lib_pypy/stackless.py
--- a/lib_pypy/stackless.py
+++ b/lib_pypy/stackless.py
@@ -434,8 +434,8 @@
def insert(self):
if self.blocked:
raise RuntimeError, "You cannot run a blocked tasklet"
- if not self.alive:
- raise RuntimeError, "You cannot run an unbound(dead) tasklet"
+ if not self.alive:
+ raise RuntimeError, "You cannot run an unbound(dead) tasklet"
_scheduler_append(self)
def remove(self):
diff --git a/pypy/annotation/annrpython.py b/pypy/annotation/annrpython.py
--- a/pypy/annotation/annrpython.py
+++ b/pypy/annotation/annrpython.py
@@ -1,3 +1,5 @@
+from __future__ import absolute_import
+
import types
from pypy.tool.ansi_print import ansi_log
from pypy.tool.pairtype import pair
@@ -6,7 +8,7 @@
from pypy.objspace.flow.model import (Variable, Constant, FunctionGraph,
c_last_exception, checkgraph)
from pypy.translator import simplify, transform
-from pypy.annotation import model as annmodel, signature
+from pypy.annotation import model as annmodel, signature, unaryop, binaryop
from pypy.annotation.bookkeeper import Bookkeeper
import py
log = py.log.Producer("annrpython")
@@ -373,7 +375,12 @@
# Merge the new 'cells' with each of the block's existing input
# variables.
oldcells = [self.binding(a) for a in block.inputargs]
- unions = [annmodel.unionof(c1,c2) for c1, c2 in zip(oldcells,inputcells)]
+ try:
+ unions = [annmodel.unionof(c1,c2) for c1, c2 in zip(oldcells,inputcells)]
+ except annmodel.UnionError, e:
+ e.args = e.args + (
+ ErrorWrapper(gather_error(self, graph, block, None)),)
+ raise
# if the merged cells changed, we must redo the analysis
if unions != oldcells:
self.bindinputargs(graph, block, unions)
@@ -446,12 +453,12 @@
# occour for this specific, typed operation.
if block.exitswitch == c_last_exception:
op = block.operations[-1]
- if op.opname in annmodel.BINARY_OPERATIONS:
+ if op.opname in binaryop.BINARY_OPERATIONS:
arg1 = self.binding(op.args[0])
arg2 = self.binding(op.args[1])
binop = getattr(pair(arg1, arg2), op.opname, None)
can_only_throw = annmodel.read_can_only_throw(binop, arg1, arg2)
- elif op.opname in annmodel.UNARY_OPERATIONS:
+ elif op.opname in unaryop.UNARY_OPERATIONS:
arg1 = self.binding(op.args[0])
opname = op.opname
if opname == 'contains': opname = 'op_contains'
@@ -622,10 +629,10 @@
return self.bookkeeper.newdict()
- def _registeroperations(cls, model):
+ def _registeroperations(cls, unary_ops, binary_ops):
# All unary operations
d = {}
- for opname in model.UNARY_OPERATIONS:
+ for opname in unary_ops:
fnname = 'consider_op_' + opname
exec py.code.Source("""
def consider_op_%s(self, arg, *args):
@@ -633,7 +640,7 @@
""" % (opname, opname)).compile() in globals(), d
setattr(cls, fnname, d[fnname])
# All binary operations
- for opname in model.BINARY_OPERATIONS:
+ for opname in binary_ops:
fnname = 'consider_op_' + opname
exec py.code.Source("""
def consider_op_%s(self, arg1, arg2, *args):
@@ -643,7 +650,7 @@
_registeroperations = classmethod(_registeroperations)
# register simple operations handling
-RPythonAnnotator._registeroperations(annmodel)
+RPythonAnnotator._registeroperations(unaryop.UNARY_OPERATIONS, binaryop.BINARY_OPERATIONS)
class BlockedInference(Exception):
diff --git a/pypy/annotation/binaryop.py b/pypy/annotation/binaryop.py
--- a/pypy/annotation/binaryop.py
+++ b/pypy/annotation/binaryop.py
@@ -7,10 +7,10 @@
from pypy.tool.pairtype import pair, pairtype
from pypy.annotation.model import SomeObject, SomeInteger, SomeBool, s_Bool
from pypy.annotation.model import SomeString, SomeChar, SomeList, SomeDict
-from pypy.annotation.model import SomeUnicodeCodePoint, SomeStringOrUnicode
+from pypy.annotation.model import SomeUnicodeCodePoint, SomeUnicodeString
from pypy.annotation.model import SomeTuple, SomeImpossibleValue, s_ImpossibleValue
from pypy.annotation.model import SomeInstance, SomeBuiltin, SomeIterator
-from pypy.annotation.model import SomePBC, SomeFloat, s_None
+from pypy.annotation.model import SomePBC, SomeFloat, s_None, SomeByteArray
from pypy.annotation.model import SomeExternalObject, SomeWeakRef
from pypy.annotation.model import SomeAddress, SomeTypedAddressAccess
from pypy.annotation.model import SomeSingleFloat, SomeLongFloat, SomeType
@@ -19,7 +19,6 @@
from pypy.annotation.model import read_can_only_throw
from pypy.annotation.model import add_knowntypedata, merge_knowntypedata
from pypy.annotation.model import SomeGenericCallable
-from pypy.annotation.model import SomeUnicodeString
from pypy.annotation.bookkeeper import getbookkeeper
from pypy.objspace.flow.model import Variable, Constant
from pypy.rlib import rarithmetic
@@ -416,6 +415,34 @@
result.const = str1.const + str2.const
return result
+class __extend__(pairtype(SomeByteArray, SomeByteArray)):
+ def union((b1, b2)):
+ can_be_None = b1.can_be_None or b2.can_be_None
+ return SomeByteArray(can_be_None=can_be_None)
+
+ def add((b1, b2)):
+ result = SomeByteArray()
+ if b1.is_immutable_constant() and b2.is_immutable_constant():
+ result.const = b1.const + b2.const
+ return result
+
+class __extend__(pairtype(SomeByteArray, SomeInteger)):
+ def getitem((s_b, s_i)):
+ return SomeInteger()
+
+ def setitem((s_b, s_i), s_i2):
+ assert isinstance(s_i2, SomeInteger)
+
+class __extend__(pairtype(SomeString, SomeByteArray),
+ pairtype(SomeByteArray, SomeString),
+ pairtype(SomeChar, SomeByteArray),
+ pairtype(SomeByteArray, SomeChar)):
+ def add((b1, b2)):
+ result = SomeByteArray()
+ if b1.is_immutable_constant() and b2.is_immutable_constant():
+ result.const = b1.const + b2.const
+ return result
+
class __extend__(pairtype(SomeChar, SomeChar)):
def union((chr1, chr2)):
@@ -458,7 +485,8 @@
for s_item in s_tuple.items:
if isinstance(s_item, SomeFloat):
pass # or s_item is a subclass, like SomeInteger
- elif isinstance(s_item, SomeStringOrUnicode) and s_item.no_nul:
+ elif (isinstance(s_item, SomeString) or
+ isinstance(s_item, SomeUnicodeString)) and s_item.no_nul:
pass
else:
no_nul = False
diff --git a/pypy/annotation/bookkeeper.py b/pypy/annotation/bookkeeper.py
--- a/pypy/annotation/bookkeeper.py
+++ b/pypy/annotation/bookkeeper.py
@@ -1,6 +1,9 @@
"""
The Bookkeeper class.
"""
+
+from __future__ import absolute_import
+
import sys, types, inspect, weakref
from pypy.objspace.flow.model import Constant
@@ -10,7 +13,7 @@
SomeUnicodeCodePoint, SomeOOStaticMeth, s_None, s_ImpossibleValue, \
SomeLLADTMeth, SomeBool, SomeTuple, SomeOOClass, SomeImpossibleValue, \
SomeUnicodeString, SomeList, SomeObject, HarmlesslyBlocked, \
- SomeWeakRef, lltype_to_annotation, SomeType
+ SomeWeakRef, lltype_to_annotation, SomeType, SomeByteArray
from pypy.annotation.classdef import InstanceSource, ClassDef
from pypy.annotation.listdef import ListDef, ListItem
from pypy.annotation.dictdef import DictDef
@@ -346,6 +349,8 @@
result = SomeUnicodeCodePoint()
else:
result = SomeUnicodeString()
+ elif tp is bytearray:
+ result = SomeByteArray()
elif tp is tuple:
result = SomeTuple(items = [self.immutablevalue(e, need_const) for e in x])
elif tp is float:
diff --git a/pypy/annotation/builtin.py b/pypy/annotation/builtin.py
--- a/pypy/annotation/builtin.py
+++ b/pypy/annotation/builtin.py
@@ -9,7 +9,7 @@
from pypy.annotation.model import SomeFloat, unionof, SomeUnicodeString
from pypy.annotation.model import SomePBC, SomeInstance, SomeDict, SomeList
from pypy.annotation.model import SomeWeakRef, SomeIterator
-from pypy.annotation.model import SomeOOObject
+from pypy.annotation.model import SomeOOObject, SomeByteArray
from pypy.annotation.model import annotation_to_lltype, lltype_to_annotation, ll_to_annotation
from pypy.annotation.model import add_knowntypedata
from pypy.annotation.model import s_ImpossibleValue
@@ -119,6 +119,9 @@
def builtin_unicode(s_unicode):
return constpropagate(unicode, [s_unicode], SomeUnicodeString())
+def builtin_bytearray(s_str):
+ return constpropagate(bytearray, [s_str], SomeByteArray())
+
def our_issubclass(cls1, cls2):
""" we're going to try to be less silly in the face of old-style classes"""
from pypy.annotation.classdef import ClassDef
@@ -253,24 +256,6 @@
s = SomeInteger(nonneg=True, knowntype=s.knowntype)
return s
-def builtin_apply(*stuff):
- getbookkeeper().warning("ignoring apply%r" % (stuff,))
- return SomeObject()
-
-##def builtin_slice(*args):
-## bk = getbookkeeper()
-## if len(args) == 1:
-## return SomeSlice(
-## bk.immutablevalue(None), args[0], bk.immutablevalue(None))
-## elif len(args) == 2:
-## return SomeSlice(
-## args[0], args[1], bk.immutablevalue(None))
-## elif len(args) == 3:
-## return SomeSlice(
-## args[0], args[1], args[2])
-## else:
-## raise Exception, "bogus call to slice()"
-
def OSError_init(s_self, *args):
pass
diff --git a/pypy/annotation/description.py b/pypy/annotation/description.py
--- a/pypy/annotation/description.py
+++ b/pypy/annotation/description.py
@@ -1,4 +1,6 @@
+from __future__ import absolute_import
import types, py
+from pypy.annotation.signature import enforce_signature_args, enforce_signature_return
from pypy.objspace.flow.model import Constant, FunctionGraph
from pypy.objspace.flow.bytecode import cpython_code_signature
from pypy.objspace.flow.argument import rawshape, ArgErr
@@ -275,12 +277,17 @@
policy = self.bookkeeper.annotator.policy
self.specializer = policy.get_specializer(tag)
enforceargs = getattr(self.pyobj, '_annenforceargs_', None)
+ signature = getattr(self.pyobj, '_signature_', None)
+ if enforceargs and signature:
+ raise Exception("%r: signature and enforceargs cannot both be used" % (self,))
if enforceargs:
if not callable(enforceargs):
from pypy.annotation.policy import Sig
enforceargs = Sig(*enforceargs)
self.pyobj._annenforceargs_ = enforceargs
enforceargs(self, inputcells) # can modify inputcells in-place
+ if signature:
+ enforce_signature_args(self, signature[0], inputcells) # mutates inputcells
if getattr(self.pyobj, '_annspecialcase_', '').endswith("call_location"):
return self.specializer(self, inputcells, op)
else:
@@ -297,6 +304,10 @@
new_args = args.unmatch_signature(self.signature, inputcells)
inputcells = self.parse_arguments(new_args, graph)
result = schedule(graph, inputcells)
+ signature = getattr(self.pyobj, '_signature_', None)
+ if signature:
+ result = enforce_signature_return(self, signature[1], result)
+ self.bookkeeper.annotator.addpendingblock(graph, graph.returnblock, [result])
# Some specializations may break the invariant of returning
# annotations that are always more general than the previous time.
# We restore it here:
diff --git a/pypy/annotation/model.py b/pypy/annotation/model.py
--- a/pypy/annotation/model.py
+++ b/pypy/annotation/model.py
@@ -27,6 +27,7 @@
# \_____________________________________________________/
#
+from __future__ import absolute_import
from types import BuiltinFunctionType, MethodType, FunctionType
import pypy
@@ -201,11 +202,16 @@
self.knowntypedata = knowntypedata
class SomeStringOrUnicode(SomeObject):
+ """Base class for shared implementation of SomeString and SomeUnicodeString.
+
+ Cannot be an annotation."""
+
immutable = True
can_be_None=False
no_nul = False # No NUL character in the string.
def __init__(self, can_be_None=False, no_nul=False):
+ assert type(self) is not SomeStringOrUnicode
if can_be_None:
self.can_be_None = True
if no_nul:
@@ -224,19 +230,19 @@
d2 = d2.copy(); d2['no_nul'] = 0 # ignored
return d1 == d2
+ def nonnoneify(self):
+ return self.__class__(can_be_None=False, no_nul=self.no_nul)
+
class SomeString(SomeStringOrUnicode):
"Stands for an object which is known to be a string."
knowntype = str
- def nonnoneify(self):
- return SomeString(can_be_None=False, no_nul=self.no_nul)
-
class SomeUnicodeString(SomeStringOrUnicode):
"Stands for an object which is known to be an unicode string"
knowntype = unicode
- def nonnoneify(self):
- return SomeUnicodeString(can_be_None=False, no_nul=self.no_nul)
+class SomeByteArray(SomeStringOrUnicode):
+ knowntype = bytearray
class SomeChar(SomeString):
"Stands for an object known to be a string of length 1."
@@ -384,6 +390,14 @@
desc, = descriptions
if desc.pyobj is not None:
self.const = desc.pyobj
+ elif len(descriptions) > 1:
+ from pypy.annotation.description import ClassDesc
+ if self.getKind() is ClassDesc:
+ # a PBC of several classes: enforce them all to be
+ # built, without support for specialization. See
+ # rpython/test/test_rpbc.test_pbc_of_classes_not_all_used
+ for desc in descriptions:
+ desc.getuniqueclassdef()
def any_description(self):
return iter(self.descriptions).next()
@@ -700,7 +714,7 @@
return r
def not_const(s_obj):
- if s_obj.is_constant():
+ if s_obj.is_constant() and not isinstance(s_obj, SomePBC):
new_s_obj = SomeObject.__new__(s_obj.__class__)
dic = new_s_obj.__dict__ = s_obj.__dict__.copy()
if 'const' in dic:
@@ -764,7 +778,3 @@
else:
raise RuntimeError("The annotator relies on 'assert' statements from the\n"
"\tannotated program: you cannot run it with 'python -O'.")
-
-# this has the side-effect of registering the unary and binary operations
-from pypy.annotation.unaryop import UNARY_OPERATIONS
-from pypy.annotation.binaryop import BINARY_OPERATIONS
diff --git a/pypy/annotation/signature.py b/pypy/annotation/signature.py
--- a/pypy/annotation/signature.py
+++ b/pypy/annotation/signature.py
@@ -1,3 +1,5 @@
+
+from __future__ import absolute_import
import types
from pypy.annotation.model import SomeBool, SomeInteger, SomeString,\
@@ -128,3 +130,30 @@
s_arg,
s_input))
inputcells[:] = args_s
+
+def finish_type(paramtype, bookkeeper, func):
+ from pypy.rlib.types import SelfTypeMarker
+ if isinstance(paramtype, SomeObject):
+ return paramtype
+ elif isinstance(paramtype, SelfTypeMarker):
+ raise Exception("%r argument declared as annotation.types.self(); class needs decorator rlib.signature.finishsigs()" % (func,))
+ else:
+ return paramtype(bookkeeper)
+
+def enforce_signature_args(funcdesc, paramtypes, actualtypes):
+ assert len(paramtypes) == len(actualtypes)
+ params_s = [finish_type(paramtype, funcdesc.bookkeeper, funcdesc.pyobj) for paramtype in paramtypes]
+ for i, (s_param, s_actual) in enumerate(zip(params_s, actualtypes)):
+ if not s_param.contains(s_actual):
+ raise Exception("%r argument %d:\n"
+ "expected %s,\n"
+ " got %s" % (funcdesc, i+1, s_param, s_actual))
+ actualtypes[:] = params_s
+
+def enforce_signature_return(funcdesc, sigtype, inferredtype):
+ s_sigret = finish_type(sigtype, funcdesc.bookkeeper, funcdesc.pyobj)
+ if not s_sigret.contains(inferredtype):
+ raise Exception("%r return value:\n"
+ "expected %s,\n"
+ " got %s" % (funcdesc, s_sigret, inferredtype))
+ return s_sigret
diff --git a/pypy/annotation/test/test_annrpython.py b/pypy/annotation/test/test_annrpython.py
--- a/pypy/annotation/test/test_annrpython.py
+++ b/pypy/annotation/test/test_annrpython.py
@@ -255,13 +255,6 @@
assert getcdef(snippet.H).about_attribute('attr') == (
a.bookkeeper.immutablevalue(1))
- def DISABLED_test_knownkeysdict(self):
- # disabled, SomeDict() is now a general {s_key: s_value} dict
- a = self.RPythonAnnotator()
- s = a.build_types(snippet.knownkeysdict, [int])
- # result should be an integer
- assert s.knowntype == int
-
def test_generaldict(self):
a = self.RPythonAnnotator()
s = a.build_types(snippet.generaldict, [str, int, str, int])
@@ -483,6 +476,13 @@
s = a.build_types(f, [str])
assert isinstance(s, annmodel.SomeString)
+ def test_str_isalpha(self):
+ def f(s):
+ return s.isalpha()
+ a = self.RPythonAnnotator()
+ s = a.build_types(f, [str])
+ assert isinstance(s, annmodel.SomeBool)
+
def test_simple_slicing(self):
a = self.RPythonAnnotator()
s = a.build_types(snippet.simple_slice, [somelist(annmodel.s_Int)])
@@ -3819,6 +3819,37 @@
a = self.RPythonAnnotator()
a.build_types(f, []) # assert did not explode
+ def test_bytearray(self):
+ def f():
+ return bytearray("xyz")
+
+ a = self.RPythonAnnotator()
+ assert isinstance(a.build_types(f, []), annmodel.SomeByteArray)
+
+ def test_bytearray_add(self):
+ def f(a):
+ return a + bytearray("xyz")
+
+ a = self.RPythonAnnotator()
+ assert isinstance(a.build_types(f, [annmodel.SomeByteArray()]),
+ annmodel.SomeByteArray)
+ a = self.RPythonAnnotator()
+ assert isinstance(a.build_types(f, [str]),
+ annmodel.SomeByteArray)
+ a = self.RPythonAnnotator()
+ assert isinstance(a.build_types(f, [annmodel.SomeChar()]),
+ annmodel.SomeByteArray)
+
+ def test_bytearray_setitem_getitem(self):
+ def f(b, i, c):
+ b[i] = c
+ return b[i + 1]
+
+ a = self.RPythonAnnotator()
+ assert isinstance(a.build_types(f, [annmodel.SomeByteArray(),
+ int, int]),
+ annmodel.SomeInteger)
+
def g(n):
return [0,1,2,n]
diff --git a/pypy/annotation/unaryop.py b/pypy/annotation/unaryop.py
--- a/pypy/annotation/unaryop.py
+++ b/pypy/annotation/unaryop.py
@@ -2,6 +2,8 @@
Unary operations on SomeValues.
"""
+from __future__ import absolute_import
+
from types import MethodType
from pypy.annotation.model import \
SomeObject, SomeInteger, SomeBool, SomeString, SomeChar, SomeList, \
@@ -524,7 +526,14 @@
return SomeString()
method_encode.can_only_throw = [UnicodeEncodeError]
+
class __extend__(SomeString):
+ def method_isdigit(chr):
+ return s_Bool
+
+ def method_isalpha(chr):
+ return s_Bool
+
def method_upper(str):
return SomeString()
@@ -560,12 +569,6 @@
def method_isspace(chr):
return s_Bool
- def method_isdigit(chr):
- return s_Bool
-
- def method_isalpha(chr):
- return s_Bool
-
def method_isalnum(chr):
return s_Bool
diff --git a/pypy/bin/py.py b/pypy/bin/py.py
--- a/pypy/bin/py.py
+++ b/pypy/bin/py.py
@@ -65,10 +65,17 @@
config, parser = option.get_standard_options()
interactiveconfig = Config(cmdline_optiondescr)
to_optparse(interactiveconfig, parser=parser)
+ def set_family_of_options(option, opt, value, parser):
+ from pypy.config.pypyoption import set_pypy_opt_level
+ set_pypy_opt_level(config, value)
parser.add_option(
'--cc', type=str, action="callback",
callback=set_compiler,
help="Compiler to use for compiling generated C")
+ parser.add_option(
+ '--opt', type=str, action="callback",
+ callback=set_family_of_options,
+ help="Set the family of options based on -opt=0,1,2,jit...")
args = option.process_options(parser, argv[1:])
if interactiveconfig.verbose:
error.RECORD_INTERPLEVEL_TRACEBACK = True
diff --git a/pypy/config/pypyoption.py b/pypy/config/pypyoption.py
--- a/pypy/config/pypyoption.py
+++ b/pypy/config/pypyoption.py
@@ -1,11 +1,12 @@
-import autopath
-import py, os
import sys
-from pypy.config.config import OptionDescription, BoolOption, IntOption, ArbitraryOption
-from pypy.config.config import ChoiceOption, StrOption, to_optparse, Config
-from pypy.config.config import ConflictConfigError
+
+import py
+
+from pypy.config.config import (OptionDescription, BoolOption, IntOption,
+ ChoiceOption, StrOption, to_optparse, ConflictConfigError)
from pypy.config.translationoption import IS_64_BITS
+
modulepath = py.path.local(__file__).dirpath().dirpath().join("module")
all_modules = [p.basename for p in modulepath.listdir()
if p.check(dir=True, dotfile=False)
@@ -128,24 +129,11 @@
pypy_optiondescription = OptionDescription("objspace", "Object Space Options", [
- ChoiceOption("name", "Object Space name",
- ["std", "flow", "thunk", "dump"],
- "std",
- cmdline='--objspace -o'),
-
OptionDescription("opcodes", "opcodes to enable in the interpreter", [
BoolOption("CALL_METHOD", "emit a special bytecode for expr.name()",
default=False),
]),
- BoolOption("nofaking", "disallow faking in the object space",
- default=False,
- requires=[
- ("objspace.usemodules.posix", True),
- ("objspace.usemodules.time", True),
- ("objspace.usemodules.errno", True)],
- cmdline='--nofaking'),
-
OptionDescription("usemodules", "Which Modules should be used", [
BoolOption(modname, "use module %s" % (modname, ),
default=modname in default_modules,
@@ -177,10 +165,6 @@
cmdline="--translationmodules",
suggests=[("objspace.allworkingmodules", False)]),
- BoolOption("logbytecodes",
- "keep track of bytecode usage",
- default=False),
-
BoolOption("usepycfiles", "Write and read pyc files when importing",
default=True),
@@ -201,10 +185,6 @@
"make sure that all calls go through space.call_args",
default=False),
- BoolOption("timing",
- "timing of various parts of the interpreter (simple profiling)",
- default=False),
-
OptionDescription("std", "Standard Object Space Options", [
BoolOption("withtproxy", "support transparent proxies",
default=True),
@@ -228,12 +208,6 @@
requires=[("objspace.std.withsmallint", False)]),
# ^^^ because of missing delegate_xx2yy
- BoolOption("withstrjoin", "use strings optimized for addition",
- default=False),
-
- BoolOption("withstrslice", "use strings optimized for slicing",
- default=False),
-
BoolOption("withstrbuf", "use strings optimized for addition (ver 2)",
default=False),
@@ -254,18 +228,6 @@
"use specialised tuples",
default=False),
- BoolOption("withrope", "use ropes as the string implementation",
- default=False,
- requires=[("objspace.std.withstrslice", False),
- ("objspace.std.withstrjoin", False),
- ("objspace.std.withstrbuf", False)],
- suggests=[("objspace.std.withprebuiltchar", True),
- ("objspace.std.sharesmallstr", True)]),
-
- BoolOption("withropeunicode", "use ropes for the unicode implementation",
- default=False,
- requires=[("objspace.std.withrope", True)]),
-
BoolOption("withcelldict",
"use dictionaries that are optimized for being used as module dicts",
default=False,
@@ -330,16 +292,9 @@
# weakrefs needed, because of get_subclasses()
requires=[("translation.rweakref", True)]),
- BoolOption("logspaceoptypes",
- "a instrumentation option: before exit, print the types seen by "
- "certain simpler bytecodes",
- default=False),
ChoiceOption("multimethods", "the multimethod implementation to use",
["doubledispatch", "mrd"],
default="mrd"),
- BoolOption("mutable_builtintypes",
- "Allow the changing of builtin types", default=False,
- requires=[("objspace.std.builtinshortcut", True)]),
BoolOption("withidentitydict",
"track types that override __hash__, __eq__ or __cmp__ and use a special dict strategy for those which do not",
default=False,
@@ -372,7 +327,7 @@
config.objspace.std.suggest(builtinshortcut=True)
config.objspace.std.suggest(optimized_list_getitem=True)
config.objspace.std.suggest(getattributeshortcut=True)
- config.objspace.std.suggest(newshortcut=True)
+ #config.objspace.std.suggest(newshortcut=True)
config.objspace.std.suggest(withspecialisedtuple=True)
config.objspace.std.suggest(withidentitydict=True)
#if not IS_64_BITS:
@@ -390,11 +345,8 @@
config.objspace.std.suggest(withrangelist=True)
config.objspace.std.suggest(withprebuiltchar=True)
config.objspace.std.suggest(withmapdict=True)
- config.objspace.std.suggest(withstrslice=True)
- config.objspace.std.suggest(withstrjoin=True)
if not IS_64_BITS:
config.objspace.std.suggest(withsmalllong=True)
- # xxx other options? ropes maybe?
# some optimizations have different effects depending on the typesystem
if type_system == 'ootype':
diff --git a/pypy/config/test/test_config.py b/pypy/config/test/test_config.py
--- a/pypy/config/test/test_config.py
+++ b/pypy/config/test/test_config.py
@@ -4,8 +4,6 @@
def make_description():
gcoption = ChoiceOption('name', 'GC name', ['ref', 'framework'], 'ref')
gcdummy = BoolOption('dummy', 'dummy', default=False)
- objspaceoption = ChoiceOption('objspace', 'Object space',
- ['std', 'thunk'], 'std')
booloption = BoolOption('bool', 'Test boolean option', default=True)
intoption = IntOption('int', 'Test int option', default=0)
floatoption = FloatOption('float', 'Test float option', default=2.3)
@@ -18,7 +16,7 @@
requires=[('gc.name', 'framework')])
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
- descr = OptionDescription('pypy', '', [gcgroup, booloption, objspaceoption,
+ descr = OptionDescription('pypy', '', [gcgroup, booloption,
More information about the pypy-commit
mailing list