Commits

Antonio Cuni committed 07ebef3 Merge

hg merge default; this has been painful because it also merged the translation-cleanup branch (again). It's possible that I break something, although most interpreter/objspace tests pass

Comments (0)

Files changed (123)

lib_pypy/itertools.py

-# Note that PyPy contains also a built-in module 'itertools' which will
-# hide this one if compiled in.
-
-"""Functional tools for creating and using iterators.
-
-Infinite iterators:
-count([n]) --> n, n+1, n+2, ...
-cycle(p) --> p0, p1, ... plast, p0, p1, ...
-repeat(elem [,n]) --> elem, elem, elem, ... endlessly or up to n times
-
-Iterators terminating on the shortest input sequence:
-izip(p, q, ...) --> (p[0], q[0]), (p[1], q[1]), ... 
-ifilter(pred, seq) --> elements of seq where pred(elem) is True
-ifilterfalse(pred, seq) --> elements of seq where pred(elem) is False
-islice(seq, [start,] stop [, step]) --> elements from
-       seq[start:stop:step]
-imap(fun, p, q, ...) --> fun(p0, q0), fun(p1, q1), ...
-starmap(fun, seq) --> fun(*seq[0]), fun(*seq[1]), ...
-tee(it, n=2) --> (it1, it2 , ... itn) splits one iterator into n
-chain(p, q, ...) --> p0, p1, ... plast, q0, q1, ... 
-takewhile(pred, seq) --> seq[0], seq[1], until pred fails
-dropwhile(pred, seq) --> seq[n], seq[n+1], starting when pred fails
-groupby(iterable[, keyfunc]) --> sub-iterators grouped by value of keyfunc(v)
-"""
-
-__all__ = ['chain', 'count', 'cycle', 'dropwhile', 'groupby', 'ifilter',
-           'ifilterfalse', 'imap', 'islice', 'izip', 'repeat', 'starmap',
-           'takewhile', 'tee', 'compress', 'product']
-
-try: from __pypy__ import builtinify
-except ImportError: builtinify = lambda f: f
-
-
-class chain(object):
-    """Make an iterator that returns elements from the first iterable
-    until it is exhausted, then proceeds to the next iterable, until
-    all of the iterables are exhausted. Used for treating consecutive
-    sequences as a single sequence.
-
-    Equivalent to :
-
-    def chain(*iterables):
-        for it in iterables:
-            for element in it:
-                yield element
-    """
-    def __init__(self, *iterables):
-        self._iterables_iter = iter(map(iter, iterables))
-        # little trick for the first chain.__next__() call
-        self._cur_iterable_iter = iter([])
-
-    def __iter__(self):
-        return self
-    
-    def __next__(self):
-        while True:
-            try:
-                return next(self._cur_iterable_iter)
-            except StopIteration:
-                self._cur_iterable_iter = next(self._iterables_iter)
-
-
-class compress(object):
-    def __init__(self, data, selectors):
-        self.data = iter(data)
-        self.selectors = iter(selectors)
-
-    def __iter__(self):
-        return self
-
-    def __next__(self):
-        while True:
-            next_item = next(self.data)
-            next_selector = next(self.selectors)
-            if bool(next_selector):
-                return next_item
-
-
-class count(object):
-    """Make an iterator that returns consecutive integers starting
-    with n.  If not specified n defaults to zero. Does not currently
-    support python long integers. Often used as an argument to imap()
-    to generate consecutive data points.  Also, used with izip() to
-    add sequence numbers.
-
-    Equivalent to :
-
-    def count(n=0):
-        if not isinstance(n, int):
-            raise TypeError("%s is not a regular integer" % n)
-        while True:
-            yield n
-            n += 1
-    """
-    def __init__(self, n=0):
-        if not isinstance(n, int):
-            raise TypeError('%s is not a regular integer' % n)
-        self.times = n-1
-
-    def __iter__(self):
-        return self
-
-    def __next__(self):
-        self.times += 1
-        return self.times
-
-    def __repr__(self):
-        return 'count(%d)' % (self.times + 1)
-
-
-            
-class cycle(object):
-    """Make an iterator returning elements from the iterable and
-    saving a copy of each. When the iterable is exhausted, return
-    elements from the saved copy. Repeats indefinitely.
-
-    Equivalent to :
-
-    def cycle(iterable):
-        saved = []
-        for element in iterable:
-            yield element
-            saved.append(element)
-        while saved:
-            for element in saved:
-                yield element    
-    """
-    def __init__(self, iterable):
-        self._cur_iter = iter(iterable)
-        self._saved = []
-        self._must_save = True
-        
-    def __iter__(self):
-        return self
-
-    def __next__(self):
-        # XXX Could probably be improved
-        try:
-            next_elt = next(self._cur_iter)
-            if self._must_save:
-                self._saved.append(next_elt)
-        except StopIteration:
-            self._cur_iter = iter(self._saved)
-            next_elt = next(self._cur_iter)
-            self._must_save = False
-        return next_elt
-            
-        
-class dropwhile(object):
-    """Make an iterator that drops elements from the iterable as long
-    as the predicate is true; afterwards, returns every
-    element. Note, the iterator does not produce any output until the
-    predicate is true, so it may have a lengthy start-up time.
-
-    Equivalent to :
-
-    def dropwhile(predicate, iterable):
-        iterable = iter(iterable)
-        for x in iterable:
-            if not predicate(x):
-                yield x
-                break
-        for x in iterable:
-            yield x
-    """
-    def __init__(self, predicate, iterable):
-        self._predicate = predicate
-        self._iter = iter(iterable)
-        self._dropped = False
-
-    def __iter__(self):
-        return self
-
-    def __next__(self):
-        value = next(self._iter)
-        if self._dropped:
-            return value
-        while self._predicate(value):
-            value = next(self._iter)
-        self._dropped = True
-        return value
-
-class groupby(object):
-    """Make an iterator that returns consecutive keys and groups from the
-    iterable. The key is a function computing a key value for each
-    element. If not specified or is None, key defaults to an identity
-    function and returns the element unchanged. Generally, the
-    iterable needs to already be sorted on the same key function.
-
-    The returned group is itself an iterator that shares the
-    underlying iterable with groupby(). Because the source is shared,
-    when the groupby object is advanced, the previous group is no
-    longer visible. So, if that data is needed later, it should be
-    stored as a list:
-
-       groups = []
-       uniquekeys = []
-       for k, g in groupby(data, keyfunc):
-           groups.append(list(g))      # Store group iterator as a list
-           uniquekeys.append(k)
-    """    
-    def __init__(self, iterable, key=None):
-        if key is None:
-            key = lambda x: x
-        self.keyfunc = key
-        self.it = iter(iterable)
-        self.tgtkey = self.currkey = self.currvalue = range(0)
-
-    def __iter__(self):
-        return self
-
-    def __next__(self):
-        while self.currkey == self.tgtkey:
-            self.currvalue = next(self.it) # Exit on StopIteration
-            self.currkey = self.keyfunc(self.currvalue)
-        self.tgtkey = self.currkey
-        return (self.currkey, self._grouper(self.tgtkey))
-
-    def _grouper(self, tgtkey):
-        while self.currkey == tgtkey:
-            yield self.currvalue
-            self.currvalue = next(self.it) # Exit on StopIteration
-            self.currkey = self.keyfunc(self.currvalue)
-
-
-
-class _ifilter_base(object):
-    """base class for ifilter and ifilterflase"""
-    def __init__(self, predicate, iterable):
-        # Make sure iterable *IS* iterable
-        self._iter = iter(iterable)
-        if predicate is None:
-            self._predicate = bool
-        else:
-            self._predicate = predicate
-
-    def __iter__(self):
-        return self
-    
-class ifilter(_ifilter_base):
-    """Make an iterator that filters elements from iterable returning
-    only those for which the predicate is True.  If predicate is
-    None, return the items that are true.
-
-    Equivalent to :
-
-    def ifilter:
-        if predicate is None:
-            predicate = bool
-        for x in iterable:
-            if predicate(x):
-                yield x
-    """
-    def __next__(self):
-        next_elt = next(self._iter)
-        while True:
-            if self._predicate(next_elt):
-                return next_elt
-            next_elt = next(self._iter)
-
-class ifilterfalse(_ifilter_base):
-    """Make an iterator that filters elements from iterable returning
-    only those for which the predicate is False.  If predicate is
-    None, return the items that are false.
-
-    Equivalent to :
-    
-    def ifilterfalse(predicate, iterable):
-        if predicate is None:
-            predicate = bool
-        for x in iterable:
-            if not predicate(x):
-                yield x
-    """
-    def __next__(self):
-        next_elt = next(self._iter)
-        while True:
-            if not self._predicate(next_elt):
-                return next_elt
-            next_elt = next(self._iter)
-             
-
-
-
-class imap(object):
-    """Make an iterator that computes the function using arguments
-    from each of the iterables. If function is set to None, then
-    imap() returns the arguments as a tuple. Like map() but stops
-    when the shortest iterable is exhausted instead of filling in
-    None for shorter iterables. The reason for the difference is that
-    infinite iterator arguments are typically an error for map()
-    (because the output is fully evaluated) but represent a common
-    and useful way of supplying arguments to imap().
-
-    Equivalent to :
-
-    def imap(function, *iterables):
-        iterables = map(iter, iterables)
-        while True:
-            args = [next(i) for i in iterables]
-            if function is None:
-                yield tuple(args)
-            else:
-                yield function(*args)
-    
-    """
-    def __init__(self, function, iterable, *other_iterables):
-        self._func = function
-        self._iters = map(iter, (iterable, ) + other_iterables)
-
-    def __iter__(self):
-        return self
-
-    def __next__(self):
-        args = [next(it) for it in self._iters]
-        if self._func is None:
-            return tuple(args)
-        else:
-            return self._func(*args)
-
-
-
-class islice(object):
-    """Make an iterator that returns selected elements from the
-    iterable.  If start is non-zero, then elements from the iterable
-    are skipped until start is reached. Afterward, elements are
-    returned consecutively unless step is set higher than one which
-    results in items being skipped. If stop is None, then iteration
-    continues until the iterator is exhausted, if at all; otherwise,
-    it stops at the specified position. Unlike regular slicing,
-    islice() does not support negative values for start, stop, or
-    step. Can be used to extract related fields from data where the
-    internal structure has been flattened (for example, a multi-line
-    report may list a name field on every third line).
-    """ 
-    def __init__(self, iterable, *args):
-        s = slice(*args)
-        self.start, self.stop, self.step = s.start or 0, s.stop, s.step
-        if not isinstance(self.start, int):
-           raise ValueError("Start argument must be an integer")
-        if self.stop is not None and not isinstance(self.stop, int):
-           raise ValueError("Stop argument must be an integer or None")
-        if self.step is None:
-            self.step = 1
-        if self.start<0 or (self.stop is not None and self.stop<0
-           ) or self.step<=0:
-            raise ValueError("indices for islice() must be positive")
-        self.it = iter(iterable)
-        self.donext = None
-        self.cnt = 0
-
-    def __iter__(self):
-        return self
-
-    def __next__(self):
-        nextindex = self.start
-        if self.stop is not None and nextindex >= self.stop:
-            raise StopIteration
-        while self.cnt <= nextindex:
-            nextitem = next(self.it)
-            self.cnt += 1
-        self.start += self.step 
-        return nextitem
-
-class izip(object):
-    """Make an iterator that aggregates elements from each of the
-    iterables.  Like zip() except that it returns an iterator instead
-    of a list. Used for lock-step iteration over several iterables at
-    a time.
-
-    Equivalent to :
-
-    def izip(*iterables):
-        iterables = map(iter, iterables)
-        while iterables:
-            result = [next(i) for i in iterables]
-            yield tuple(result)
-    """
-    def __init__(self, *iterables):
-        self._iterators = map(iter, iterables)
-        self._result = [None] * len(self._iterators)
-
-    def __iter__(self):
-        return self
-
-    def __next__(self):
-        if not self._iterators:
-            raise StopIteration()
-        return tuple([next(i) for i in self._iterators])
-
-
-class product(object):
-
-    def __init__(self, *args, **kw):
-        if len(kw) > 1:
-            raise TypeError("product() takes at most 1 argument (%d given)" %
-                             len(kw))
-        self.repeat = kw.get('repeat', 1)
-        self.gears = [x for x in args] * self.repeat
-        self.num_gears = len(self.gears)
-        # initialization of indicies to loop over
-        self.indicies = [(0, len(self.gears[x]))
-                         for x in range(0, self.num_gears)]
-        self.cont = True
-
-    def roll_gears(self):
-        # Starting from the end of the gear indicies work to the front
-        # incrementing the gear until the limit is reached. When the limit
-        # is reached carry operation to the next gear
-        should_carry = True
-        for n in range(0, self.num_gears):
-            nth_gear = self.num_gears - n - 1
-            if should_carry:
-                count, lim = self.indicies[nth_gear]
-                count += 1
-                if count == lim and nth_gear == 0:
-                    self.cont = False
-                if count == lim:
-                    should_carry = True
-                    count = 0
-                else:
-                    should_carry = False
-                self.indicies[nth_gear] = (count, lim)
-            else:
-                break
-
-    def __iter__(self):
-        return self
-
-    def __next__(self):
-        if not self.cont:
-            raise StopIteration
-        l = []
-        for x in range(0, self.num_gears):
-            index, limit = self.indicies[x]
-            l.append(self.gears[x][index])
-        self.roll_gears()
-        return tuple(l)
-
-
-class repeat(object):
-    """Make an iterator that returns object over and over again.
-    Runs indefinitely unless the times argument is specified.  Used
-    as argument to imap() for invariant parameters to the called
-    function. Also used with izip() to create an invariant part of a
-    tuple record.
-
-    Equivalent to :
-
-    def repeat(object, times=None):
-        if times is None:
-            while True:
-                yield object
-        else:
-            for i in xrange(times):
-                yield object
-    """
-    def __init__(self, obj, times=None):
-        self._obj = obj
-        if times is not None:
-            range(times) # Raise a TypeError
-            if times < 0:
-                times = 0
-        self._times = times
-        
-    def __iter__(self):
-        return self
-
-    def __next__(self):
-        # __next__() *need* to decrement self._times when consumed
-        if self._times is not None:
-            if self._times <= 0: 
-                raise StopIteration()
-            self._times -= 1
-        return self._obj
-
-    def __repr__(self):
-        if self._times is not None:
-            return 'repeat(%r, %r)' % (self._obj, self._times)
-        else:
-            return 'repeat(%r)' % (self._obj,)
-
-    def __len__(self):
-        if self._times == -1 or self._times is None:
-            raise TypeError("len() of uniszed object")
-        return self._times
-    
-
-class starmap(object):
-    """Make an iterator that computes the function using arguments
-    tuples obtained from the iterable. Used instead of imap() when
-    argument parameters are already grouped in tuples from a single
-    iterable (the data has been ``pre-zipped''). The difference
-    between imap() and starmap() parallels the distinction between
-    function(a,b) and function(*c).
-
-    Equivalent to :
-
-    def starmap(function, iterable):
-        iterable = iter(iterable)
-        while True:
-            yield function(*next(iterable))
-    """
-    def __init__(self, function, iterable):
-        self._func = function
-        self._iter = iter(iterable)
-
-    def __iter__(self):
-        return self
-
-    def __next__(self):
-        # CPython raises a TypeError when the iterator doesn't return a tuple
-        t = next(self._iter)
-        if not isinstance(t, tuple):
-            raise TypeError("iterator must return a tuple")
-        return self._func(*t)
-
-
-
-class takewhile(object):
-    """Make an iterator that returns elements from the iterable as
-    long as the predicate is true.
-
-    Equivalent to :
-    
-    def takewhile(predicate, iterable):
-        for x in iterable:
-            if predicate(x):
-                yield x
-            else:
-                break
-    """
-    def __init__(self, predicate, iterable):
-        self._predicate = predicate
-        self._iter = iter(iterable)
-
-    def __iter__(self):
-        return self
-
-    def __next__(self):
-        value = next(self._iter)
-        if not self._predicate(value):
-            raise StopIteration()
-        return value
-
-    
-class TeeData(object):
-    """Holds cached values for TeeObjects"""
-    def __init__(self, iterator):
-        self.data = []
-        self._iter = iterator
-
-    def __getitem__(self, i):
-        # iterates until 'i' if not done yet
-        while i>= len(self.data):
-            self.data.append(next(self._iter))
-        return self.data[i]
-
-
-class TeeObject(object):
-    """Iterables / Iterators as returned by the tee() function"""
-    def __init__(self, iterable=None, tee_data=None):
-        if tee_data:
-            self.tee_data = tee_data
-            self.pos = 0
-        # <=> Copy constructor
-        elif isinstance(iterable, TeeObject):
-            self.tee_data = iterable.tee_data
-            self.pos = iterable.pos
-        else:
-            self.tee_data = TeeData(iter(iterable))
-            self.pos = 0
-            
-    def __next__(self):
-        data = self.tee_data[self.pos]
-        self.pos += 1
-        return data
-    
-    def __iter__(self):
-        return self
-
-
-@builtinify
-def tee(iterable, n=2):
-    """Return n independent iterators from a single iterable.
-    Note : once tee() has made a split, the original iterable
-    should not be used anywhere else; otherwise, the iterable could get
-    advanced without the tee objects being informed.
-    
-    Note : this member of the toolkit may require significant auxiliary
-    storage (depending on how much temporary data needs to be stored).
-    In general, if one iterator is going to use most or all of the
-    data before the other iterator, it is faster to use list() instead
-    of tee()
-    
-    Equivalent to :
-
-    def tee(iterable, n=2):
-        it = iter(iterable)
-        deques = [collections.deque() for i in range(n)]
-        def gen(mydeque):
-            while True:
-                if not mydeque:             # when the local deque is empty
-                    newval = next(it)       # fetch a new value and
-                    for d in deques:        # load it to all the deques
-                        d.append(newval)
-                yield mydeque.popleft()
-        return tuple(gen(d) for d in deques)
-    """
-    if isinstance(iterable, TeeObject):
-        # a,b = tee(range(10)) ; c,d = tee(a) ; self.assert_(a is c)
-        return tuple([iterable] +
-        [TeeObject(tee_data=iterable.tee_data) for i in range(n - 1)])
-    tee_data = TeeData(iter(iterable))
-    return tuple([TeeObject(tee_data=tee_data) for i in range(n)])

lib_pypy/numpypy/core/numeric.py

 
-from _numpypy import array, ndarray, int_, float_, bool_ #, complex_# , longlong
+from _numpypy import array, ndarray, int_, float_, bool_, flexible #, complex_# , longlong
 from _numpypy import concatenate
 from .fromnumeric import any
 import math
             typename = "'%s'" % typename
 
         lf = ''
-        if 0: # or issubclass(arr.dtype.type, flexible):
+        if issubclass(arr.dtype.type, flexible):
             if arr.dtype.names:
                 typename = "%s" % str(arr.dtype)
             else:

lib_pypy/pypy_test/test_itertools.py

-from py.test import raises
-from lib_pypy import itertools
-
-class TestItertools(object):
-
-    def test_compress(self):
-        it = itertools.compress(['a', 'b', 'c'], [0, 1, 0])
-
-        assert list(it) == ['b']
-
-    def test_compress_diff_len(self):
-        it = itertools.compress(['a'], [])
-        raises(StopIteration, next, it)
-
-    def test_product(self):
-        l = [1, 2]
-        m = ['a', 'b']
-
-        prodlist = itertools.product(l, m)
-        assert list(prodlist) == [(1, 'a'), (1, 'b'), (2, 'a'), (2, 'b')]
-
-    def test_product_repeat(self):
-        l = [1, 2]
-        m = ['a', 'b']
-
-        prodlist = itertools.product(l, m, repeat=2)
-        ans = [(1, 'a', 1, 'a'), (1, 'a', 1, 'b'), (1, 'a', 2, 'a'),
-               (1, 'a', 2, 'b'), (1, 'b', 1, 'a'), (1, 'b', 1, 'b'),
-               (1, 'b', 2, 'a'), (1, 'b', 2, 'b'), (2, 'a', 1, 'a'),
-               (2, 'a', 1, 'b'), (2, 'a', 2, 'a'), (2, 'a', 2, 'b'),
-               (2, 'b', 1, 'a'), (2, 'b', 1, 'b'), (2, 'b', 2, 'a'),
-               (2, 'b', 2, 'b')]
-        assert list(prodlist) == ans
-
-    def test_product_diff_sizes(self):
-        l = [1, 2]
-        m = ['a']
-
-        prodlist = itertools.product(l, m)
-        assert list(prodlist) == [(1, 'a'), (2, 'a')]
-
-        l = [1]
-        m = ['a', 'b']
-        prodlist = itertools.product(l, m)
-        assert list(prodlist) == [(1, 'a'), (1, 'b')]
-
-    def test_product_toomany_args(self):
-        l = [1, 2]
-        m = ['a']
-        raises(TypeError, itertools.product, l, m, repeat=1, foo=2)

lib_pypy/pyrepl/readline.py

         try:
             return unicode(line, ENCODING)
         except UnicodeDecodeError:   # bah, silently fall back...
-            return unicode(line, 'utf-8')
+            return unicode(line, 'utf-8', 'replace')
 
     def get_history_length(self):
         return self.saved_history_length

lib_pypy/pyrepl/unix_console.py

             if iscode:
                 self.__tputs(text)
             else:
-                os.write(self.output_fd, text.encode(self.encoding))
+                os.write(self.output_fd, text.encode(self.encoding, 'replace'))
         del self.__buffer[:]
 
     def __tputs(self, fmt, prog=delayprog):

py/_code/source.py

File contents unchanged.

pypy/annotation/annrpython.py

                         if cell.is_constant():
                             newcell.const = cell.const
                         cell = newcell
-                        cell.knowntypedata = renamed_knowntypedata
+                        cell.set_knowntypedata(renamed_knowntypedata)
 
                     cells.append(cell)
 

pypy/annotation/binaryop.py

 
 # XXX unify this with ObjSpace.MethodTable
 BINARY_OPERATIONS = set(['add', 'sub', 'mul', 'div', 'mod',
-                         'truediv', 'floordiv', 'divmod', 'pow',
+                         'truediv', 'floordiv', 'divmod',
                          'and_', 'or_', 'xor',
                          'lshift', 'rshift',
                          'getitem', 'setitem', 'delitem',
                          'getitem_idx', 'getitem_key', 'getitem_idx_key',
                          'inplace_add', 'inplace_sub', 'inplace_mul',
                          'inplace_truediv', 'inplace_floordiv', 'inplace_div',
-                         'inplace_mod', 'inplace_pow',
+                         'inplace_mod',
                          'inplace_lshift', 'inplace_rshift',
                          'inplace_and', 'inplace_or', 'inplace_xor',
                          'lt', 'le', 'eq', 'ne', 'gt', 'ge', 'is_', 'cmp',
                          'coerce',
                          ]
                         +[opname+'_ovf' for opname in
-                          """add sub mul floordiv div mod pow lshift
+                          """add sub mul floordiv div mod lshift
                            """.split()
                           ])
 
     def inplace_floordiv((obj1, obj2)): return pair(obj1, obj2).floordiv()
     def inplace_div((obj1, obj2)):      return pair(obj1, obj2).div()
     def inplace_mod((obj1, obj2)):      return pair(obj1, obj2).mod()
-    def inplace_pow((obj1, obj2)):      return pair(obj1, obj2).pow(s_None)
     def inplace_lshift((obj1, obj2)):   return pair(obj1, obj2).lshift()
     def inplace_rshift((obj1, obj2)):   return pair(obj1, obj2).rshift()
     def inplace_and((obj1, obj2)):      return pair(obj1, obj2).and_()
         # XXX HACK HACK HACK
         bk = getbookkeeper()
         if bk is not None: # for testing
-            knowntypedata = r.knowntypedata = {}
+            knowntypedata = {}
             fn, block, i = bk.position_key
 
             annotator = bk.annotator
 
             bind(obj2, obj1, 0)
             bind(obj1, obj2, 1)
+            r.set_knowntypedata(knowntypedata)
 
         return r
 
             return SomeInteger(nonneg=int1.nonneg, knowntype=int1.knowntype)
     rshift.can_only_throw = []
 
-    def pow((int1, int2), obj3):
-        knowntype = rarithmetic.compute_restype(int1.knowntype, int2.knowntype)
-        return SomeInteger(nonneg = int1.nonneg,
-                           knowntype=knowntype)
-    pow.can_only_throw = [ZeroDivisionError]
-    pow_ovf = _clone(pow, [ZeroDivisionError, OverflowError])
-
-    def inplace_pow((int1, int2)):
-        knowntype = rarithmetic.compute_restype(int1.knowntype, int2.knowntype)
-        return SomeInteger(nonneg = int1.nonneg,
-                           knowntype=knowntype)
-    inplace_pow.can_only_throw = [ZeroDivisionError]
-
     def _compare_helper((int1, int2), opname, operation):
         r = SomeBool()
         if int1.is_immutable_constant() and int2.is_immutable_constant():
             case = opname in ('gt', 'ge', 'eq')
             add_knowntypedata(knowntypedata, case, [op.args[0]],
                               SomeInteger(nonneg=True, knowntype=tointtype(int1)))
-        if knowntypedata:
-            r.knowntypedata = knowntypedata
+        r.set_knowntypedata(knowntypedata)
         # a special case for 'x < 0' or 'x >= 0',
         # where 0 is a flow graph Constant
         # (in this case we are sure that it cannot become a r_uint later)
         if hasattr(boo1, 'knowntypedata') and \
            hasattr(boo2, 'knowntypedata'):
             ktd = merge_knowntypedata(boo1.knowntypedata, boo2.knowntypedata)
-            if ktd:
-                s.knowntypedata = ktd
+            s.set_knowntypedata(ktd)
         return s 
 
     def and_((boo1, boo2)):
     div.can_only_throw = []
     truediv = div
 
-    def pow((flt1, flt2), obj3):
-        raise NotImplementedError("float power not supported, use math.pow")
-
     # repeat these in order to copy the 'can_only_throw' attribute
     inplace_div = div
     inplace_truediv = truediv

pypy/annotation/bookkeeper.py

 from pypy.annotation.dictdef import DictDef
 from pypy.annotation import description
 from pypy.annotation.signature import annotationoftype
-from pypy.interpreter.argument import ArgumentsForTranslation
+from pypy.objspace.flow.argument import ArgumentsForTranslation
 from pypy.rlib.objectmodel import r_dict, Symbolic
 from pypy.tool.algo.unionfind import UnionFind
 from pypy.rpython.lltypesystem import lltype, llmemory
 
     def consider_list_delitem(self, idx):
         return self.indexrepr(idx)
-    
+
     def consider_str_join(self, s):
         if s.is_constant():
             return repr(s.const)
                 check_no_flags(s_value_or_def.listdef.listitem)
             elif isinstance(s_value_or_def, SomeDict):
                 check_no_flags(s_value_or_def.dictdef.dictkey)
-                check_no_flags(s_value_or_def.dictdef.dictvalue)                
+                check_no_flags(s_value_or_def.dictdef.dictvalue)
             elif isinstance(s_value_or_def, SomeTuple):
                 for s_item in s_value_or_def.items:
                     check_no_flags(s_item)
             elif isinstance(s_value_or_def, ListItem):
                 if s_value_or_def in seen:
                     return
-                seen.add(s_value_or_def)                
+                seen.add(s_value_or_def)
                 check_no_flags(s_value_or_def.s_value)
-            
+
         for clsdef in self.classdefs:
             check_no_flags(clsdef)
 
                 listdef = ListDef(self, s_ImpossibleValue)
                 for e in x:
                     listdef.generalize(self.immutablevalue(e, False))
-                result = SomeList(listdef)    
+                result = SomeList(listdef)
         elif tp is dict or tp is r_dict:
             if need_const:
                 key = Constant(x)
                 try:
                     return self.immutable_cache[key]
                 except KeyError:
-                    result = SomeDict(DictDef(self, 
+                    result = SomeDict(DictDef(self,
                                               s_ImpossibleValue,
                                               s_ImpossibleValue,
                                               is_r_dict = tp is r_dict))
                     result.const_box = key
                     return result
             else:
-                dictdef = DictDef(self, 
+                dictdef = DictDef(self,
                 s_ImpossibleValue,
                 s_ImpossibleValue,
                 is_r_dict = tp is r_dict)
             return True
         else:
             return False
-        
+
     def getfrozen(self, pyobj):
         return description.FrozenDesc(self, pyobj)
 
         key = (x.__class__, x)
         if key in self.seen_mutable:
             return
-        clsdef = self.getuniqueclassdef(x.__class__)        
+        clsdef = self.getuniqueclassdef(x.__class__)
         self.seen_mutable[key] = True
         self.event('mutable', x)
         source = InstanceSource(self, x)
         except KeyError:
             access_sets = map[attrname] = UnionFind(description.ClassAttrFamily)
         return access_sets
-    
+
     def pbc_getattr(self, pbc, s_attr):
         assert s_attr.is_constant()
         attr = s_attr.const
         first = descs[0]
         if len(descs) == 1:
             return first.s_read_attribute(attr)
-        
+
         change = first.mergeattrfamilies(descs[1:], attr)
         attrfamily = first.getattrfamily(attr)
 
     def ondegenerated(self, what, s_value, where=None, called_from_graph=None):
         self.annotator.ondegenerated(what, s_value, where=where,
                                      called_from_graph=called_from_graph)
-        
+
     def whereami(self):
         return self.annotator.whereami(self.position_key)
 

pypy/annotation/builtin.py

             variables = [op.args[1]]
         for variable in variables:
             assert bk.annotator.binding(variable) == s_obj
-        r.knowntypedata = {}
-        
+        knowntypedata = {}
         if not hasattr(typ, '_freeze_') and isinstance(s_type, SomePBC):
-            add_knowntypedata(r.knowntypedata, True, variables, bk.valueoftype(typ))
+            add_knowntypedata(knowntypedata, True, variables, bk.valueoftype(typ))
+        r.set_knowntypedata(knowntypedata)
     return r
 
 # note that this one either needs to be constant, or we will create SomeObject
 
 def robjmodel_hlinvoke(s_repr, s_llcallable, *args_s):
     from pypy.rpython import rmodel
-    assert s_repr.is_constant() and isinstance(s_repr.const, rmodel.Repr),"hlinvoke expects a constant repr as first argument"
-    r_func, nimplicitarg  = s_repr.const.get_r_implfunc()
+    from pypy.rpython.error import TyperError
 
-    nbargs = len(args_s) + nimplicitarg 
+    assert s_repr.is_constant() and isinstance(s_repr.const, rmodel.Repr), "hlinvoke expects a constant repr as first argument"
+    r_func, nimplicitarg = s_repr.const.get_r_implfunc()
+
+    nbargs = len(args_s) + nimplicitarg
     s_sigs = r_func.get_s_signatures((nbargs, (), False, False))
     if len(s_sigs) != 1:
         raise TyperError("cannot hlinvoke callable %r with not uniform"
 
     return lltype_to_annotation(rresult.lowleveltype)
 
+
 def robjmodel_keepalive_until_here(*args_s):
     return immutablevalue(None)
 
     BUILTIN_ANALYZERS[unicodedata.decimal] = unicodedata_decimal # xxx
 
 # object - just ignore object.__init__
-BUILTIN_ANALYZERS[object.__init__] = object_init
+if hasattr(object.__init__, 'im_func'):
+    BUILTIN_ANALYZERS[object.__init__.im_func] = object_init
+else:
+    BUILTIN_ANALYZERS[object.__init__] = object_init    
 
 # import
 BUILTIN_ANALYZERS[__import__] = import_func

pypy/annotation/description.py

 import types, py
 from pypy.objspace.flow.model import Constant, FunctionGraph
-from pypy.interpreter.pycode import cpython_code_signature
-from pypy.interpreter.argument import rawshape
-from pypy.interpreter.argument import ArgErr
+from pypy.objspace.flow.bytecode import cpython_code_signature
+from pypy.objspace.flow.argument import rawshape, ArgErr
 from pypy.tool.sourcetools import valid_identifier
 from pypy.tool.pairtype import extendabletype
 
             name = pyobj.func_name
         if signature is None:
             if hasattr(pyobj, '_generator_next_method_of_'):
-                from pypy.interpreter.argument import Signature
+                from pypy.objspace.flow.argument import Signature
                 signature = Signature(['entry'])     # haaaaaack
                 defaults = ()
             else:
         try:
             inputcells = args.match_signature(signature, defs_s)
         except ArgErr, e:
-            raise TypeError("signature mismatch: %s() %s" % 
+            raise TypeError("signature mismatch: %s() %s" %
                             (self.name, e.getmsg()))
         return inputcells
 

pypy/annotation/model.py

     unsigned = False
     def __init__(self):
         pass
+    def set_knowntypedata(self, knowntypedata):
+        assert not hasattr(self, 'knowntypedata')
+        if knowntypedata:
+            self.knowntypedata = knowntypedata
 
 class SomeStringOrUnicode(SomeObject):
     immutable = True
     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:

pypy/annotation/specialize.py

 from pypy.objspace.flow.model import Block, Link, Variable, SpaceOperation
 from pypy.objspace.flow.model import Constant, checkgraph
 from pypy.annotation import model as annmodel
-from pypy.interpreter.argument import Signature
+from pypy.objspace.flow.argument import Signature
 
 def flatten_star_args(funcdesc, args_s):
     argnames, vararg, kwarg = funcdesc.signature

pypy/annotation/test/test_annrpython.py

 from pypy.rlib.rarithmetic import r_uint, base_int, r_longlong, r_ulonglong
 from pypy.rlib.rarithmetic import r_singlefloat
 from pypy.rlib import objectmodel
-from pypy.objspace.flow.objspace import FlowObjSpace
+from pypy.objspace.flow.objspace import FlowObjSpace, FlowingError
 
 from pypy.translator.test import snippet
 
         assert a.binding(et) == t
         assert isinstance(a.binding(ev), annmodel.SomeInstance) and a.binding(ev).classdef == a.bookkeeper.getuniqueclassdef(Exception)
 
-    def test_pow(self):
-        def f(n):
-            n **= 2
-            return 2 ** n
-        a = self.RPythonAnnotator()
-        s = a.build_types(f, [int])
-        # result should be an integer
-        assert s.knowntype == int
-
     def test_inplace_div(self):
         def f(n):
             n /= 2
             x **= y
             return x ** y
         a = self.RPythonAnnotator()
-        s = a.build_types(f, [int, int])
-        assert isinstance(s, annmodel.SomeInteger)
-        a = self.RPythonAnnotator()
-        py.test.raises(NotImplementedError, a.build_types, f, [float, float])
+        py.test.raises(FlowingError, a.build_types, f, [int, int])
+        a = self.RPythonAnnotator()
+        py.test.raises(FlowingError, a.build_types, f, [float, float])
 
     def test_intcmp_bug(self):
         def g(x, y):
         s = a.build_types(f, [annmodel.SomeInteger()])
         assert isinstance(s, annmodel.SomeBool)
 
+    def test_object_init(self):
+        class A(object):
+            pass
+
+        class B(A):
+            def __init__(self):
+                A.__init__(self)
+
+        def f():
+            B()
+
+        a = self.RPythonAnnotator()
+        a.build_types(f, []) # assert did not explode
+
 def g(n):
     return [0,1,2,n]
 

pypy/annotation/unaryop.py

         s_obj.is_true_behavior(r)
 
         bk = getbookkeeper()
-        knowntypedata = r.knowntypedata = {}
+        knowntypedata = {}
         fn, block, i = bk.position_key
         op = block.operations[i]
         assert op.opname == "is_true" or op.opname == "nonzero"
         if s_obj.can_be_none():
             s_nonnone_obj = s_obj.nonnoneify()
         add_knowntypedata(knowntypedata, True, [arg], s_nonnone_obj)
+        r.set_knowntypedata(knowntypedata)
         return r
-        
 
     def nonzero(obj):
         return obj.is_true()
     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

pypy/config/pypyoption.py

         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:

pypy/config/translationoption.py

                          ("translation.gcrootfinder", DEFL_ROOTFINDER_WITHJIT),
                          ("translation.list_comprehension_operations", True)]),
     ChoiceOption("jit_backend", "choose the backend for the JIT",
-                 ["auto", "x86", "x86-without-sse2", "llvm", 'arm'],
+                 ["auto", "x86", "x86-without-sse2", 'arm'],
                  default="auto", cmdline="--jit-backend"),
     ChoiceOption("jit_profiler", "integrate profiler support into the JIT",
                  ["off", "oprofile"],

pypy/doc/cpython_differences.rst

 Miscellaneous
 -------------
 
-* Hash randomization is not supported in PyPy.  Passing ``-R`` to the
-  command line, or setting the ``PYTHONHASHSEED`` environment variable
-  will display a warning message.
+* Hash randomization (``-R``) is ignored in PyPy.  As documented in
+  http://bugs.python.org/issue14621 , some of us believe it has no
+  purpose in CPython either.
 
-* ``sys.setrecursionlimit()`` is ignored (and not needed) on
-  PyPy.  On CPython it would set the maximum number of nested
-  calls that can occur before a RuntimeError is raised; on PyPy
-  overflowing the stack also causes RuntimeErrors, but the limit
-  is checked at a lower level.  (The limit is currently hard-coded
-  at 768 KB, corresponding to roughly 1480 Python calls on
-  Linux.)
+* ``sys.setrecursionlimit(n)`` sets the limit only approximately,
+  by setting the usable stack space to ``n * 768`` bytes.  On Linux,
+  depending on the compiler settings, the default of 768KB is enough
+  for about 1400 calls.
 
 * assignment to ``__class__`` is limited to the cases where it
   works on CPython 2.5.  On CPython 2.6 and 2.7 it works in a bit

pypy/doc/getting-started-dev.rst

 To translate and run for the CLI you must have the SDK installed: Windows
 users need the `.NET Framework SDK`_, while Linux and Mac users
 can use Mono_.  To translate and run for the JVM you must have a JDK 
-installed (at least version 5) and ``java``/``javac`` on your path.
+installed (at least version 6) and ``java``/``javac`` on your path.
 
 A slightly larger example
 +++++++++++++++++++++++++

pypy/doc/whatsnew-head.rst

 
 .. branch: numpypy-complex2
 Complex dtype support for numpy
+.. branch: numpypy-problems
+Improve dtypes intp, uintp, void, string and record
 .. branch: kill-someobject
 major cleanups including killing some object support
+.. branch: cpyext-PyThreadState_New
+implement threadstate-related functions in cpyext
 
 
 .. "uninteresting" branches that we should just ignore for the whatsnew:

pypy/interpreter/argument.py

                 w_key = keyword_names_w[i - limit]
             space.setitem(w_kwds, w_key, keywords_w[i])
 
-class ArgumentsForTranslation(Arguments):
-    def __init__(self, space, args_w, keywords=None, keywords_w=None,
-                 w_stararg=None, w_starstararg=None):
-        self.w_stararg = w_stararg
-        self.w_starstararg = w_starstararg
-        self.combine_has_happened = False
-        Arguments.__init__(self, space, args_w, keywords, keywords_w)
-
-    def combine_if_necessary(self):
-        if self.combine_has_happened:
-            return
-        self._combine_wrapped(self.w_stararg, self.w_starstararg)
-        self.combine_has_happened = True
-
-    def prepend(self, w_firstarg): # used often
-        "Return a new Arguments with a new argument inserted first."
-        return ArgumentsForTranslation(self.space, [w_firstarg] + self.arguments_w,
-                                       self.keywords, self.keywords_w, self.w_stararg,
-                                       self.w_starstararg)
-
-    def copy(self):
-        return ArgumentsForTranslation(self.space, self.arguments_w,
-                                       self.keywords, self.keywords_w, self.w_stararg,
-                                       self.w_starstararg)
-
-
-
-    def _match_signature(self, w_firstarg, scope_w, signature, defaults_w=None,
-                         w_kw_defs=None, blindargs=0):
-        self.combine_if_necessary()
-        # _match_signature is destructive
-        return Arguments._match_signature(
-               self, w_firstarg, scope_w, signature,
-               defaults_w, w_kw_defs, blindargs)
-
-    def unpack(self):
-        self.combine_if_necessary()
-        return Arguments.unpack(self)
-
-    def match_signature(self, signature, defaults_w, w_kw_defs=None):
-        """Parse args and kwargs according to the signature of a code object,
-        or raise an ArgErr in case of failure.
-        """
-        return self._parse(None, signature, defaults_w, w_kw_defs)
-
-    def unmatch_signature(self, signature, data_w):
-        """kind of inverse of match_signature"""
-        args_w, kwds_w = self.unpack()
-        need_cnt = len(args_w)
-        need_kwds = kwds_w.keys()
-        space = self.space
-        argnames, varargname, kwargname = signature
-        cnt = len(argnames)
-        data_args_w = data_w[:cnt]
-        if varargname:
-            data_w_stararg = data_w[cnt]
-            cnt += 1
-        else:
-            data_w_stararg = space.newtuple([])
-
-        unfiltered_kwds_w = {}
-        if kwargname:
-            data_w_starargarg = data_w[cnt]
-            for w_key in space.unpackiterable(data_w_starargarg):
-                key = space.str_w(w_key)
-                w_value = space.getitem(data_w_starargarg, w_key)
-                unfiltered_kwds_w[key] = w_value
-            cnt += 1
-        assert len(data_w) == cnt
-
-        ndata_args_w = len(data_args_w)
-        if ndata_args_w >= need_cnt:
-            args_w = data_args_w[:need_cnt]
-            for argname, w_arg in zip(argnames[need_cnt:], data_args_w[need_cnt:]):
-                unfiltered_kwds_w[argname] = w_arg
-            assert not space.is_true(data_w_stararg)
-        else:
-            stararg_w = space.unpackiterable(data_w_stararg)
-            datalen = len(data_args_w)
-            args_w = [None] * (datalen + len(stararg_w))
-            for i in range(0, datalen):
-                args_w[i] = data_args_w[i]
-            for i in range(0, len(stararg_w)):
-                args_w[i + datalen] = stararg_w[i]
-            assert len(args_w) == need_cnt
-
-        keywords = []
-        keywords_w = []
-        for key in need_kwds:
-            keywords.append(key)
-            keywords_w.append(unfiltered_kwds_w[key])
-
-        return ArgumentsForTranslation(self.space, args_w, keywords, keywords_w)
-
-    @staticmethod
-    def frompacked(space, w_args=None, w_kwds=None):
-        raise NotImplementedError("go away")
-
-    @staticmethod
-    def fromshape(space, (shape_cnt,shape_keys,shape_star,shape_stst), data_w):
-        args_w = data_w[:shape_cnt]
-        p = end_keys = shape_cnt + len(shape_keys)
-        if shape_star:
-            w_star = data_w[p]
-            p += 1
-        else:
-            w_star = None
-        if shape_stst:
-            w_starstar = data_w[p]
-            p += 1
-        else:
-            w_starstar = None
-        return ArgumentsForTranslation(space, args_w, list(shape_keys),
-                                       data_w[shape_cnt:end_keys], w_star,
-                                       w_starstar)
-
-    def flatten(self):
-        """ Argument <-> list of w_objects together with "shape" information """
-        shape_cnt, shape_keys, shape_star, shape_stst = self._rawshape()
-        data_w = self.arguments_w + [self.keywords_w[self.keywords.index(key)]
-                                         for key in shape_keys]
-        if shape_star:
-            data_w.append(self.w_stararg)
-        if shape_stst:
-            data_w.append(self.w_starstararg)
-        return (shape_cnt, shape_keys, shape_star, shape_stst), data_w
-
-    def _rawshape(self, nextra=0):
-        assert not self.combine_has_happened
-        shape_cnt  = len(self.arguments_w)+nextra        # Number of positional args
-        if self.keywords:
-            shape_keys = self.keywords[:]                # List of keywords (strings)
-            shape_keys.sort()
-        else:
-            shape_keys = []
-        shape_star = self.w_stararg is not None   # Flag: presence of *arg
-        shape_stst = self.w_starstararg is not None # Flag: presence of **kwds
-        return shape_cnt, tuple(shape_keys), shape_star, shape_stst # shape_keys are sorted
-
-def rawshape(args, nextra=0):
-    return args._rawshape(nextra)
-
-
 #
 # ArgErr family of exceptions raised in case of argument mismatch.
 # We try to give error messages following CPython's, which are very informative.

pypy/interpreter/buffer.py

         if not isinstance(self, RWBuffer):
             raise OperationError(space.w_TypeError,
                                  space.wrap("buffer is read-only"))
-        start, stop, step = space.decode_index(w_index, self.getlength())
+        start, stop, step, size = space.decode_index4(w_index, self.getlength())
         if step == 0:  # index only
             if len(newstring) != 1:
                 msg = 'buffer[index]=x: x must be a single character'
             char = newstring[0]   # annotator hint
             self.setitem(start, char)
         elif step == 1:
-            length = stop - start
-            if length != len(newstring):
-                msg = "buffer slice assignment is wrong size"
+            if len(newstring) != size:
+                msg = "right operand length must match slice length"
                 raise OperationError(space.w_ValueError, space.wrap(msg))
             self.setslice(start, newstring)
         else:

pypy/interpreter/test/test_argument.py

 # -*- coding: utf-8 -*-
 import py
-from pypy.interpreter.argument import (Arguments, ArgumentsForTranslation,
-    ArgErr, ArgErrUnknownKwds, ArgErrMultipleValues, ArgErrCount, rawshape,
-    Signature)
+from pypy.interpreter.argument import (Arguments, ArgErr, ArgErrUnknownKwds,
+        ArgErrMultipleValues, ArgErrCount, Signature)
 from pypy.interpreter.error import OperationError
 
 
         assert e.value.args[0] == "f() got an unexpected keyword argument 'ü'"
         """
 
-def make_arguments_for_translation(space, args_w, keywords_w={},
-                                   w_stararg=None, w_starstararg=None):
-    return ArgumentsForTranslation(space, args_w, keywords_w.keys(),
-                                   keywords_w.values(), w_stararg,
-                                   w_starstararg)
-
-class TestArgumentsForTranslation(object):
-
-    def test_prepend(self):
-        space = DummySpace()
-        args = ArgumentsForTranslation(space, ["0"])
-        args1 = args.prepend("thingy")
-        assert args1 is not args
-        assert args1.arguments_w == ["thingy", "0"]
-        assert args1.keywords is args.keywords
-        assert args1.keywords_w is args.keywords_w
-
-    def test_unmatch_signature(self):
-        space = DummySpace()
-        args = make_arguments_for_translation(space, [1,2,3])
-        sig = Signature(['a', 'b', 'c'], None, None)
-        data = args.match_signature(sig, [])
-        new_args = args.unmatch_signature(sig, data)
-        assert args.unpack() == new_args.unpack()
-
-        args = make_arguments_for_translation(space, [1])
-        sig = Signature(['a', 'b', 'c'], None, None)
-        data = args.match_signature(sig, [2, 3])
-        new_args = args.unmatch_signature(sig, data)
-        assert args.unpack() == new_args.unpack()
-
-        args = make_arguments_for_translation(space, [1,2,3,4,5])
-        sig = Signature(['a', 'b', 'c'], 'r', None)
-        data = args.match_signature(sig, [])
-        new_args = args.unmatch_signature(sig, data)
-        assert args.unpack() == new_args.unpack()
-
-        args = make_arguments_for_translation(space, [1], {'c': 3, 'b': 2})
-        sig = Signature(['a', 'b', 'c'], None, None)
-        data = args.match_signature(sig, [])
-        new_args = args.unmatch_signature(sig, data)
-        assert args.unpack() == new_args.unpack()
-
-        args = make_arguments_for_translation(space, [1], {'c': 5})
-        sig = Signature(['a', 'b', 'c'], None, None)
-        data = args.match_signature(sig, [2, 3])
-        new_args = args.unmatch_signature(sig, data)
-        assert args.unpack() == new_args.unpack()
-
-        args = make_arguments_for_translation(space, [1], {'c': 5, 'd': 7})
-        sig = Signature(['a', 'b', 'c'], None, 'kw')
-        data = args.match_signature(sig, [2, 3])
-        new_args = args.unmatch_signature(sig, data)
-        assert args.unpack() == new_args.unpack()
-
-        args = make_arguments_for_translation(space, [1,2,3,4,5], {'e': 5, 'd': 7})
-        sig = Signature(['a', 'b', 'c'], 'r', 'kw')
-        data = args.match_signature(sig, [2, 3])
-        new_args = args.unmatch_signature(sig, data)
-        assert args.unpack() == new_args.unpack()
-
-        args = make_arguments_for_translation(space, [], {},
-                                       w_stararg=[1],
-                                       w_starstararg={'c': 5, 'd': 7})
-        sig = Signature(['a', 'b', 'c'], None, 'kw')
-        data = args.match_signature(sig, [2, 3])
-        new_args = args.unmatch_signature(sig, data)
-        assert args.unpack() == new_args.unpack()
-
-        args = make_arguments_for_translation(space, [1,2], {'g': 9},
-                                       w_stararg=[3,4,5],
-                                       w_starstararg={'e': 5, 'd': 7})
-        sig = Signature(['a', 'b', 'c'], 'r', 'kw')
-        data = args.match_signature(sig, [2, 3])
-        new_args = args.unmatch_signature(sig, data)
-        assert args.unpack() == new_args.unpack()
-
-    def test_rawshape(self):
-        space = DummySpace()
-        args = make_arguments_for_translation(space, [1,2,3])
-        assert rawshape(args) == (3, (), False, False)
-
-        args = make_arguments_for_translation(space, [1])
-        assert rawshape(args, 2) == (3, (), False, False)
-
-        args = make_arguments_for_translation(space, [1,2,3,4,5])
-        assert rawshape(args) == (5, (), False, False)
-
-        args = make_arguments_for_translation(space, [1], {'c': 3, 'b': 2})
-        assert rawshape(args) == (1, ('b', 'c'), False, False)
-
-        args = make_arguments_for_translation(space, [1], {'c': 5})
-        assert rawshape(args) == (1, ('c', ), False, False)
-
-        args = make_arguments_for_translation(space, [1], {'c': 5, 'd': 7})
-        assert rawshape(args) == (1, ('c', 'd'), False, False)
-
-        args = make_arguments_for_translation(space, [1,2,3,4,5], {'e': 5, 'd': 7})
-        assert rawshape(args) == (5, ('d', 'e'), False, False)
-
-        args = make_arguments_for_translation(space, [], {},
-                                       w_stararg=[1],
-                                       w_starstararg={'c': 5, 'd': 7})
-        assert rawshape(args) == (0, (), True, True)
-
-        args = make_arguments_for_translation(space, [1,2], {'g': 9},
-                                       w_stararg=[3,4,5],
-                                       w_starstararg={'e': 5, 'd': 7})
-        assert rawshape(args) == (2, ('g', ), True, True)
-
-    def test_copy_and_shape(self):
-        space = DummySpace()
-        args = ArgumentsForTranslation(space, ['a'], ['x'], [1],
-                                       ['w1'], {'y': 'w2'})
-        args1 = args.copy()
-        args.combine_if_necessary()
-        assert rawshape(args1) == (1, ('x',), True, True)
-
-
-    def test_flatten(self):
-        space = DummySpace()
-        args = make_arguments_for_translation(space, [1,2,3])
-        assert args.flatten() == ((3, (), False, False), [1, 2, 3])
-
-        args = make_arguments_for_translation(space, [1])
-        assert args.flatten() == ((1, (), False, False), [1])
-
-        args = make_arguments_for_translation(space, [1,2,3,4,5])
-        assert args.flatten() == ((5, (), False, False), [1,2,3,4,5])
-
-        args = make_arguments_for_translation(space, [1], {'c': 3, 'b': 2})
-        assert args.flatten() == ((1, ('b', 'c'), False, False), [1, 2, 3])
-
-        args = make_arguments_for_translation(space, [1], {'c': 5})
-        assert args.flatten() == ((1, ('c', ), False, False), [1, 5])
-
-        args = make_arguments_for_translation(space, [1], {'c': 5, 'd': 7})
-        assert args.flatten() == ((1, ('c', 'd'), False, False), [1, 5, 7])
-
-        args = make_arguments_for_translation(space, [1,2,3,4,5], {'e': 5, 'd': 7})
-        assert args.flatten() == ((5, ('d', 'e'), False, False), [1, 2, 3, 4, 5, 7, 5])
-
-        args = make_arguments_for_translation(space, [], {},
-                                       w_stararg=[1],
-                                       w_starstararg={'c': 5, 'd': 7})
-        assert args.flatten() == ((0, (), True, True), [[1], {'c': 5, 'd': 7}])
-
-        args = make_arguments_for_translation(space, [1,2], {'g': 9},
-                                       w_stararg=[3,4,5],
-                                       w_starstararg={'e': 5, 'd': 7})
-        assert args.flatten() == ((2, ('g', ), True, True), [1, 2, 9, [3, 4, 5], {'e': 5, 'd': 7}])
-
-    def test_stararg_flowspace_variable(self):
-        space = DummySpace()
-        var = object()
-        shape = ((2, ('g', ), True, False), [1, 2, 9, var])
-        args = make_arguments_for_translation(space, [1,2], {'g': 9},
-                                       w_stararg=var)
-        assert args.flatten() == shape
-
-        args = ArgumentsForTranslation.fromshape(space, *shape)
-        assert args.flatten() == shape
-
-
-    def test_fromshape(self):
-        space = DummySpace()
-        shape = ((3, (), False, False), [1, 2, 3])
-        args = ArgumentsForTranslation.fromshape(space, *shape)
-        assert args.flatten() == shape
-
-        shape = ((1, (), False, False), [1])
-        args = ArgumentsForTranslation.fromshape(space, *shape)
-        assert args.flatten() == shape
-
-        shape = ((5, (), False, False), [1,2,3,4,5])
-        args = ArgumentsForTranslation.fromshape(space, *shape)
-        assert args.flatten() == shape
-
-        shape = ((1, ('b', 'c'), False, False), [1, 2, 3])
-        args = ArgumentsForTranslation.fromshape(space, *shape)
-        assert args.flatten() == shape
-
-        shape = ((1, ('c', ), False, False), [1, 5])
-        args = ArgumentsForTranslation.fromshape(space, *shape)
-        assert args.flatten() == shape
-
-        shape = ((1, ('c', 'd'), False, False), [1, 5, 7])
-        args = ArgumentsForTranslation.fromshape(space, *shape)
-        assert args.flatten() == shape
-
-        shape = ((5, ('d', 'e'), False, False), [1, 2, 3, 4, 5, 7, 5])
-        args = ArgumentsForTranslation.fromshape(space, *shape)
-        assert args.flatten() == shape
-
-        shape = ((0, (), True, True), [[1], {'c': 5, 'd': 7}])
-        args = ArgumentsForTranslation.fromshape(space, *shape)
-        assert args.flatten() == shape
-
-        shape = ((2, ('g', ), True, True), [1, 2, 9, [3, 4, 5], {'e': 5, 'd': 7}])
-        args = ArgumentsForTranslation.fromshape(space, *shape)
-        assert args.flatten() == shape
-

pypy/interpreter/test/test_compiler.py

 from pypy.conftest import gettestobjspace
 
 class TestPythonAstCompiler:
+    def setup_class(cls):
+        # itertools is required because it is imported indirectly by test_globals_warnings
+        cls.space = gettestobjspace(usemodules=['itertools'])
+
     def setup_method(self, method):
         self.compiler = self.space.createcompiler()
 

pypy/interpreter/test/test_zzpickle_and_slow.py

 
 class AppTestSlow:    
     def setup_class(cls):
-        space = gettestobjspace()
+        space = gettestobjspace(usemodules=['itertools'])
         cls.space = space
         if py.test.config.option.runappdirect:
             filename = __file__
 class AppTestInterpObjectPickling:
     pytestmark = py.test.mark.skipif("config.option.runappdirect")
     def setup_class(cls):
-        cls.space = gettestobjspace(usemodules=['struct'])
+        cls.space = gettestobjspace(usemodules=['struct', 'itertools'])
         _attach_helpers(cls.space)
 
     def teardown_class(cls):

pypy/jit/backend/detect_cpu.py

         return "pypy.jit.backend.x86.runner", "CPU_X86_64"
     elif backend_name == 'cli':
         return "pypy.jit.backend.cli.runner", "CliCPU"
-    elif backend_name == 'llvm':
-        return "pypy.jit.backend.llvm.runner", "LLVMCPU"
     elif backend_name == 'arm':
         return "pypy.jit.backend.arm.runner", "CPU_ARM"
     elif backend_name == 'armhf':

pypy/jit/metainterp/optimizeopt/optimizer.py

 from pypy.jit.metainterp import jitprof, resume, compile
 from pypy.jit.metainterp.executor import execute_nonspec
-from pypy.jit.metainterp.history import BoxInt, BoxFloat, Const, ConstInt, REF, INT
+from pypy.jit.metainterp.history import BoxInt, BoxFloat, Const, ConstInt, REF
 from pypy.jit.metainterp.optimizeopt.intutils import IntBound, IntUnbounded, \
                                                      ImmutableIntUnbounded, \
                                                      IntLowerBound, MININT, MAXINT
-from pypy.jit.metainterp.optimizeopt.util import (make_dispatcher_method,
-    args_dict)
+from pypy.jit.metainterp.optimizeopt.util import make_dispatcher_method
 from pypy.jit.metainterp.resoperation import rop, ResOperation, AbstractResOp
 from pypy.jit.metainterp.typesystem import llhelper, oohelper
 from pypy.tool.pairtype import extendabletype
-from pypy.rlib.debug import debug_start, debug_stop, debug_print
+from pypy.rlib.debug import debug_print
 from pypy.rlib.objectmodel import specialize
 
+
 LEVEL_UNKNOWN    = '\x00'
 LEVEL_NONNULL    = '\x01'
 LEVEL_KNOWNCLASS = '\x02'     # might also mean KNOWNARRAYDESCR, for arrays
 MODE_ARRAY   = '\x00'
 MODE_STR     = '\x01'
 MODE_UNICODE = '\x02'
+
+
 class LenBound(object):
     def __init__(self, mode, descr, bound):
         self.mode = mode

pypy/jit/metainterp/optimizeopt/rewrite.py

 from pypy.jit.codewriter.effectinfo import EffectInfo
-from pypy.jit.metainterp.history import ConstInt, make_hashable_int
+from pypy.jit.metainterp import compile
+from pypy.jit.metainterp.history import (Const, ConstInt, BoxInt, BoxFloat,
+    BoxPtr, make_hashable_int)
 from pypy.jit.metainterp.optimize import InvalidLoop
 from pypy.jit.metainterp.optimizeopt.intutils import IntBound
-from pypy.jit.metainterp.optimizeopt.optimizer import *
+from pypy.jit.metainterp.optimizeopt.optimizer import (Optimization, REMOVED,
+    CONST_0, CONST_1)
 from pypy.jit.metainterp.optimizeopt.util import _findall, make_dispatcher_method
 from pypy.jit.metainterp.resoperation import (opboolinvers, opboolreflex, rop,
     ResOperation)
         source_start_box = self.get_constant_box(op.getarg(3))
         dest_start_box = self.get_constant_box(op.getarg(4))
         length = self.get_constant_box(op.getarg(5))
-        if (source_value.is_virtual() and source_start_box and dest_start_box
-            and length and (dest_value.is_virtual() or length.getint() <= 8)):
+        extrainfo = op.getdescr().get_extra_info()
+        if (source_start_box and dest_start_box
+            and length and (dest_value.is_virtual() or length.getint() <= 8) and
+            (source_value.is_virtual() or length.getint() <= 8) and
+            len(extrainfo.write_descrs_arrays) == 1):   # <-sanity check
             from pypy.jit.metainterp.optimizeopt.virtualize import VArrayValue
-            assert isinstance(source_value, VArrayValue)
             source_start = source_start_box.getint()
             dest_start = dest_start_box.getint()
+            # XXX fish fish fish
+            arraydescr = extrainfo.write_descrs_arrays[0]
             for index in range(length.getint()):
-                val = source_value.getitem(index + source_start)
+                if source_value.is_virtual():
+                    assert isinstance(source_value, VArrayValue)
+                    val = source_value.getitem(index + source_start)
+                else:
+                    if arraydescr.is_array_of_pointers():
+                        resbox = BoxPtr()
+                    elif arraydescr.is_array_of_floats():
+                        resbox = BoxFloat()
+                    else:
+                        resbox = BoxInt()
+                    newop = ResOperation(rop.GETARRAYITEM_GC,
+                                      [op.getarg(1),
+                                       ConstInt(index + source_start)], resbox,
+                                       descr=arraydescr)
+                    self.optimizer.propagate_forward(newop)
+                    val = self.getvalue(resbox)
                 if dest_value.is_virtual():
                     dest_value.setitem(index + dest_start, val)
                 else:
                                          [op.getarg(2),
                                           ConstInt(index + dest_start),
                                           val.get_key_box()], None,
-                                         descr=source_value.arraydescr)
+                                         descr=arraydescr)
                     self.emit_operation(newop)
             return True
         if length and length.getint() == 0:

pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py

         '''
         self.optimize_loop(ops, expected)
 
+    def test_arraycopy_not_virtual_2(self):
+        ops = '''
+        [p0]
+        p1 = new_array(3, descr=arraydescr)
+        call(0, p0, p1, 0, 0, 3, descr=arraycopydescr)
+        i0 = getarrayitem_gc(p1, 0, descr=arraydescr)
+        jump(i0)
+        '''
+        expected = '''
+        [p0]
+        i0 = getarrayitem_gc(p0, 0, descr=arraydescr)
+        i1 = getarrayitem_gc(p0, 1, descr=arraydescr) # removed by the backend
+        i2 = getarrayitem_gc(p0, 2, descr=arraydescr) # removed by the backend
+        jump(i0)
+        '''
+        self.optimize_loop(ops, expected)
+
+    def test_arraycopy_not_virtual_3(self):
+        ops = '''
+        [p0, p1]
+        call(0, p0, p1, 0, 0, 3, descr=arraycopydescr)
+        i0 = getarrayitem_gc(p1, 0, descr=arraydescr)
+        jump(i0)
+        '''
+        expected = '''
+        [p0, p1]
+        i0 = getarrayitem_gc(p0, 0, descr=arraydescr)
+        i1 = getarrayitem_gc(p0, 1, descr=arraydescr)
+        i2 = getarrayitem_gc(p0, 2, descr=arraydescr)
+        setarrayitem_gc(p1, 0, i0, descr=arraydescr)
+        setarrayitem_gc(p1, 1, i1, descr=arraydescr)
+        setarrayitem_gc(p1, 2, i2, descr=arraydescr)
+        jump(i0)
+        '''
+        self.optimize_loop(ops, expected)
+
     def test_arraycopy_no_elem(self):
         """ this was actually observed in the wild
         """
         """
         expected = """
         []
-        p0 = newstr(11)
-        copystrcontent(s"hello world", p0, 0, 0, 11)
-        # Eventually this should just return s"hello", but ATM this test is
-        # just verifying that it doesn't return "\0\0\0\0\0", so being
-        # slightly underoptimized is ok.
-        p1 = newstr(5)
-        copystrcontent(p0, p1, 0, 0, 5)
-        finish(p1)
+        finish(s"hello")
         """
         self.optimize_strunicode_loop(ops, expected)
 
         """
         expected = """
         [i1]
-        p0 = newstr(6)
-        copystrcontent(s"hello!", p0, 0, 0, 6)
-        p1 = newstr(12)
-        copystrcontent(p0, p1, 0, 0, 6)
-        copystrcontent(s"abc123", p1, 0, 6, 6)
-        i0 = strgetitem(p1, i1)
+        i0 = strgetitem(s"hello!abc123", i1)
         finish(i0)
         """
         self.optimize_strunicode_loop(ops, expected)
         """
         expected = """
         []
-        p0 = newstr(6)
-        copystrcontent(s"hello!", p0, 0, 0, 6)
-        i0 = strgetitem(p0, 0)
-        finish(i0)
+        finish(104)
         """
         self.optimize_strunicode_loop(ops, expected)
 
         """
         self.optimize_strunicode_loop(ops, expected)
 
+    def test_str_copy_constant_virtual(self):
+        ops = """
+        []
+        p0 = newstr(10)
+        copystrcontent(s"abcd", p0, 0, 0, 4)
+        strsetitem(p0, 4, 101)
+        copystrcontent(s"fghij", p0, 0, 5, 5)
+        finish(p0)
+        """
+        expected = """
+        []
+        finish(s"abcde