Commits

Maciej Fijalkowski committed ac346c2 Merge

merge

Comments (0)

Files changed (27)

 ^pypy/doc/config/.+\.rst$
 ^pypy/doc/basicblock\.asc$
 ^pypy/doc/.+\.svninfo$
-^pypy/translator/c/src/libffi_msvc/.+\.obj$
-^pypy/translator/c/src/libffi_msvc/.+\.dll$
-^pypy/translator/c/src/libffi_msvc/.+\.lib$
-^pypy/translator/c/src/libffi_msvc/.+\.exp$
-^pypy/translator/c/src/cjkcodecs/.+\.o$
-^pypy/translator/c/src/cjkcodecs/.+\.obj$
-^pypy/translator/jvm/\.project$
-^pypy/translator/jvm/\.classpath$
-^pypy/translator/jvm/eclipse-bin$
-^pypy/translator/jvm/src/pypy/.+\.class$
-^pypy/translator/benchmark/docutils$
-^pypy/translator/benchmark/templess$
-^pypy/translator/benchmark/gadfly$
-^pypy/translator/benchmark/mako$
-^pypy/translator/benchmark/bench-custom\.benchmark_result$
-^pypy/translator/benchmark/shootout_benchmarks$
-^pypy/translator/goal/pypy-translation-snapshot$
-^pypy/translator/goal/pypy-c
-^pypy/translator/goal/pypy-jvm
-^pypy/translator/goal/pypy-jvm.jar
-^pypy/translator/goal/.+\.exe$
-^pypy/translator/goal/.+\.dll$
-^pypy/translator/goal/target.+-c$
+^rpython/translator/c/src/libffi_msvc/.+\.obj$
+^rpython/translator/c/src/libffi_msvc/.+\.dll$
+^rpython/translator/c/src/libffi_msvc/.+\.lib$
+^rpython/translator/c/src/libffi_msvc/.+\.exp$
+^rpython/translator/c/src/cjkcodecs/.+\.o$
+^rpython/translator/c/src/cjkcodecs/.+\.obj$
+^rpython/translator/c/src/stacklet/.+\.o$
+^rpython/translator/c/src/.+\.o$
+^rpython/translator/jvm/\.project$
+^rpython/translator/jvm/\.classpath$
+^rpython/translator/jvm/eclipse-bin$
+^rpython/translator/jvm/src/pypy/.+\.class$
+^rpython/translator/benchmark/docutils$
+^rpython/translator/benchmark/templess$
+^rpython/translator/benchmark/gadfly$
+^rpython/translator/benchmark/mako$
+^rpython/translator/benchmark/bench-custom\.benchmark_result$
+^rpython/translator/benchmark/shootout_benchmarks$
+^rpython/translator/goal/target.+-c$
+^rpython/translator/goal/.+\.exe$
+^rpython/translator/goal/.+\.dll$
+^pypy/goal/pypy-translation-snapshot$
+^pypy/goal/pypy-c
+^pypy/goal/pypy-jvm
+^pypy/goal/pypy-jvm.jar
+^pypy/goal/.+\.exe$
+^pypy/goal/.+\.dll$
 ^pypy/_cache$
 ^pypy/doc/statistic/.+\.html$
 ^pypy/doc/statistic/.+\.eps$
 ^pypy/doc/statistic/.+\.pdf$
-^pypy/translator/cli/src/pypylib\.dll$
-^pypy/translator/cli/src/query\.exe$
-^pypy/translator/cli/src/main\.exe$
+^rpython/translator/cli/src/pypylib\.dll$
+^rpython/translator/cli/src/query\.exe$
+^rpython/translator/cli/src/main\.exe$
 ^lib_pypy/ctypes_config_cache/_.+_cache\.py$
 ^lib_pypy/ctypes_config_cache/_.+_.+_\.py$
-^pypy/translator/cli/query-descriptions$
+^rpython/translator/cli/query-descriptions$
 ^pypy/doc/discussion/.+\.html$
 ^include/.+\.h$
 ^include/.+\.inl$

lib_pypy/numpypy/core/__init__.py

 from fromnumeric import *
 import shape_base
 from shape_base import *
-import multiarray
 
 from fromnumeric import amax as max, amin as min
 from _numpypy import absolute as abs

lib_pypy/numpypy/core/arrayprint.py

             #else:
             format_function = formatdict['int']
         elif issubclass(dtypeobj, _nt.floating):
-            if issubclass(dtypeobj, _nt.longfloat):
+            if hasattr(_nt, 'longfloat') and issubclass(dtypeobj, _nt.longfloat):
                 format_function = formatdict['longfloat']
             else:
                 format_function = formatdict['float']
         elif issubclass(dtypeobj, _nt.complexfloating):
-            if issubclass(dtypeobj, _nt.clongfloat):
+            if hasattr(_nt, 'clongfloat') and issubclass(dtypeobj, _nt.clongfloat):
                 format_function = formatdict['longcomplexfloat']
             else:
                 format_function = formatdict['complexfloat']

lib_pypy/numpypy/core/numeric.py

-__all__ = ['asanyarray', 'base_repr',
+__all__ = [
+           'asanyarray', 'base_repr',
            'array_repr', 'array_str', 'set_string_function',
-           'array_equal', 'asarray', 'outer', 'identity']
+           'array_equal', 'asarray', 'outer', 'identity', 'little_endian',
+           'Inf', 'inf', 'infty', 'Infinity', 'nan', 'NaN', 'False_', 'True_',
+          ]
 
 from _numpypy import array, ndarray, int_, float_, bool_, flexible #, complex_# , longlong
 from _numpypy import concatenate
 from .fromnumeric import any
-import math
 import sys
 import multiarray
+import umath
+from umath import *
 from numpypy.core.arrayprint import array2string
 
+def extend_all(module):
+    adict = {}
+    for a in __all__:
+        adict[a] = 1
+    try:
+        mall = getattr(module, '__all__')
+    except AttributeError:
+        mall = [k for k in module.__dict__.keys() if not k.startswith('_')]
+    for a in mall:
+        if a not in adict:
+            __all__.append(a)
+
+extend_all(umath)
+
 newaxis = None
 
 # XXX this file to be reviewed
 
 little_endian = (sys.byteorder == 'little')
 
-Inf = inf = infty = Infinity = PINF = float('inf')
-NINF = float('-inf')
-PZERO = 0.0
-NZERO = -0.0
-nan = NaN = NAN = float('nan')
+Inf = inf = infty = Infinity = PINF
+nan = NaN = NAN
 False_ = bool_(False)
 True_ = bool_(True)
-e = math.e
-pi = math.pi
 
 def outer(a,b):
     """

lib_pypy/numpypy/core/umath.py

+import math
+e = math.e
+pi = math.pi
+del math
+
+PZERO = 0.0
+NZERO = -0.0
+PINF = float('inf')
+NINF = float('-inf')
+NAN = float('nan')

pypy/doc/whatsnew-head.rst

 
 .. branch: numpypy-longdouble
 Long double support for numpypy
+.. branch: numpypy-disable-longdouble
+Since r_longdouble support is missing, disable all longdouble and derivative
+dtypes using ENABLED_LONG_DOUBLE = False
 .. branch: numpypy-real-as-view
 Convert real, imag from ufuncs to views. This involves the beginning of
 view() functionality

pypy/module/micronumpy/__init__.py

 from pypy.interpreter.mixedmodule import MixedModule
-from pypy.module.micronumpy.interp_boxes import long_double_size
+from pypy.module.micronumpy.interp_boxes import long_double_size, ENABLED_LONG_DOUBLE
 
 
 class Module(MixedModule):
         'count_nonzero': 'interp_arrayops.count_nonzero',
 
         'set_string_function': 'appbridge.set_string_function',
-
-        'True_': 'types.Bool.True',
-        'False_': 'types.Bool.False',
-
         'typeinfo': 'interp_dtype.get_dtype_cache(space).w_typeinfo',
 
         'generic': 'interp_boxes.W_GenericBox',
         'float16': 'interp_boxes.W_Float16Box',
         'float32': 'interp_boxes.W_Float32Box',
         'float64': 'interp_boxes.W_Float64Box',
-        'longdouble': 'interp_boxes.W_LongDoubleBox',
-        'longfloat': 'interp_boxes.W_LongDoubleBox',
         'intp': 'types.IntP.BoxType',
         'uintp': 'types.UIntP.BoxType',
         'flexible': 'interp_boxes.W_FlexibleBox',
         'complex_': 'interp_boxes.W_Complex128Box',
         'complex128': 'interp_boxes.W_Complex128Box',
         'complex64': 'interp_boxes.W_Complex64Box',
-        'clongdouble': 'interp_boxes.W_CLongDoubleBox',
-        'clongfloat': 'interp_boxes.W_CLongDoubleBox',
     }
 
     # ufuncs
         w_all = space.wrap(all_list)
         space.setitem(self.w_dict, space.new_interned_str('__all__'), w_all)
 
-if long_double_size == 16:
-    Module.interpleveldefs['float128'] = 'interp_boxes.W_Float128Box'
-    Module.interpleveldefs['complex256'] = 'interp_boxes.W_Complex256Box'
-elif long_double_size == 12:
-    Module.interpleveldefs['float96'] = 'interp_boxes.W_Float96Box'
-    Module.interpleveldefs['complex192'] = 'interp_boxes.W_Complex192Box'
+if ENABLED_LONG_DOUBLE:
+    long_double_dtypes = [
+        ('longdouble', 'interp_boxes.W_LongDoubleBox'),
+        ('longfloat', 'interp_boxes.W_LongDoubleBox'),
+        ('clongdouble', 'interp_boxes.W_CLongDoubleBox'),
+        ('clongfloat', 'interp_boxes.W_CLongDoubleBox'),
+      ]
+    if long_double_size == 16:
+        long_double_dtypes += [
+            ('float128', 'interp_boxes.W_Float128Box'),
+            ('complex256', 'interp_boxes.W_Complex256Box'),
+            ]
+    elif long_double_size == 12:
+        long_double_dtypes += [
+            ('float96', 'interp_boxes.W_Float96Box'),
+            ('complex192', 'interp_boxes.W_Complex192Box'),
+            ]
+    for dt, box in long_double_dtypes:
+        Module.interpleveldefs[dt] = box

pypy/module/micronumpy/interp_arrayops.py

     args_w = [convert_to_array(space, w_arg) for w_arg in args_w]
     dtype = args_w[0].get_dtype()
     shape = args_w[0].get_shape()[:]
-    if len(shape) <= axis:
+    _axis = axis
+    if axis < 0:
+        _axis = len(shape) + axis
+    if _axis < 0 or len(shape) <= _axis:
         raise operationerrfmt(space.w_IndexError, "axis %d out of bounds [0, %d)", axis, len(shape))
     for arr in args_w[1:]:
         dtype = interp_ufuncs.find_binop_result_dtype(space, dtype,
                                                       arr.get_dtype())
-        if len(arr.get_shape()) <= axis:
+        if _axis < 0 or len(arr.get_shape()) <= _axis:
             raise operationerrfmt(space.w_IndexError, "axis %d out of bounds [0, %d)", axis, len(shape))
         for i, axis_size in enumerate(arr.get_shape()):
-            if len(arr.get_shape()) != len(shape) or (i != axis and axis_size != shape[i]):
+            if len(arr.get_shape()) != len(shape) or (i != _axis and axis_size != shape[i]):
                 raise OperationError(space.w_ValueError, space.wrap(
                     "all the input arrays must have same number of dimensions"))
-            elif i == axis:
+            elif i == _axis:
                 shape[i] += axis_size
     res = W_NDimArray.from_shape(shape, dtype, 'C')
     chunks = [Chunk(0, i, 1, i) for i in shape]
     axis_start = 0
     for arr in args_w:
-        if arr.get_shape()[axis] == 0:
+        if arr.get_shape()[_axis] == 0:
             continue
-        chunks[axis] = Chunk(axis_start, axis_start + arr.get_shape()[axis], 1,
-                             arr.get_shape()[axis])
+        chunks[_axis] = Chunk(axis_start, axis_start + arr.get_shape()[_axis], 1,
+                             arr.get_shape()[_axis])
         Chunks(chunks).apply(res).implementation.setslice(space, arr)
-        axis_start += arr.get_shape()[axis]
+        axis_start += arr.get_shape()[_axis]
     return res
 
 @unwrap_spec(repeats=int)

pypy/module/micronumpy/interp_boxes.py

 MIXIN_64 = (int_typedef,) if LONG_BIT == 64 else ()
 
 # Is this the proper place for this?
+ENABLED_LONG_DOUBLE = False
 long_double_size = rffi.sizeof_c_type('long double', ignore_errors=True)
+
 import os
 if long_double_size == 8 and os.name == 'nt':
-    # this is a lie, or maybe a wish
+    # this is a lie, or maybe a wish, MS fakes longdouble math with double
     long_double_size = 12
 
 
     descr__new__, _get_dtype = new_dtype_getter("complex128")
     _COMPONENTS_BOX = W_Float64Box
 
-if long_double_size == 12:
+if ENABLED_LONG_DOUBLE and long_double_size == 12:
     class W_Float96Box(W_FloatingBox, PrimitiveBox):
         descr__new__, _get_dtype = new_dtype_getter("float96")
 
 
     W_CLongDoubleBox = W_Complex192Box
 
-elif long_double_size == 16:
+elif ENABLED_LONG_DOUBLE and long_double_size == 16:
     class W_Float128Box(W_FloatingBox, PrimitiveBox):
         descr__new__, _get_dtype = new_dtype_getter("float128")
     W_LongDoubleBox = W_Float128Box
 
     W_CLongDoubleBox = W_Complex256Box
 
-else:
+elif ENABLED_LONG_DOUBLE:
     W_LongDoubleBox = W_Float64Box
     W_CLongDoubleBox = W_Complex64Box
 
     __new__ = interp2app(W_Float64Box.descr__new__.im_func),
 )
 
-if long_double_size == 12:
+if ENABLED_LONG_DOUBLE and long_double_size == 12:
     W_Float96Box.typedef = TypeDef("float96", (W_FloatingBox.typedef),
         __module__ = "numpypy",
 
         imag = GetSetProperty(W_ComplexFloatingBox.descr_get_imag),
     )
 
-elif long_double_size == 16:
+elif ENABLED_LONG_DOUBLE and long_double_size == 16:
     W_Float128Box.typedef = TypeDef("float128", (W_FloatingBox.typedef),
         __module__ = "numpypy",
 

pypy/module/micronumpy/interp_dtype.py

     def is_record_type(self):
         return self.fields is not None
 
+    def is_str_or_unicode(self):
+        return (self.num == 18 or self.num == 19)
+
     def is_flexible_type(self):
-        return (self.num == 18 or self.num == 19 or self.num == 20)
+        return (self.is_str_or_unicode() or self.is_record_type())
 
     def __repr__(self):
         if self.fields is not None:
             aliases=["complex"],
             float_type = self.w_float64dtype,
         )
-        if interp_boxes.long_double_size == 12:
+        if interp_boxes.ENABLED_LONG_DOUBLE and interp_boxes.long_double_size == 12:
             self.w_float96dtype = W_Dtype(
                 types.Float96(),
                 num=13,
             )
             self.w_longdouble = self.w_float96dtype
             self.w_clongdouble = self.w_complex192dtype
-        elif interp_boxes.long_double_size == 16:
+        elif interp_boxes.ENABLED_LONG_DOUBLE and interp_boxes.long_double_size == 16:
             self.w_float128dtype = W_Dtype(
                 types.Float128(),
                 num=13,
             )
             self.w_longdouble = self.w_float128dtype
             self.w_clongdouble = self.w_complex256dtype
-        else:
+        elif interp_boxes.ENABLED_LONG_DOUBLE:
             self.w_float64dtype.aliases += ["longdouble", "longfloat"]
             self.w_complex128dtype.aliases += ["clongdouble", "clongfloat"]
             self.w_longdouble = self.w_float64dtype
             self.w_clongdouble = self.w_complex128dtype
         self.w_stringdtype = W_Dtype(
-            types.StringType(1),
+            types.StringType(0),
             num=18,
             kind=STRINGLTR,
             name='string',
             char=UINTPLTR,
             w_box_type = space.gettypefor(uintp_box),
         )
+        float_dtypes = [self.w_float16dtype,
+                self.w_float32dtype, self.w_float64dtype,
+                ]
+        complex_dtypes =  [self.w_complex64dtype, self.w_complex128dtype]
+        if interp_boxes.ENABLED_LONG_DOUBLE:
+            float_dtypes.append(self.w_longdouble)
+            complex_dtypes.append(self.w_clongdouble)
         self.builtin_dtypes = [
             self.w_booldtype,
             self.w_int8dtype, self.w_uint8dtype,
             self.w_int16dtype, self.w_uint16dtype,
             self.w_longdtype, self.w_ulongdtype,
             self.w_int32dtype, self.w_uint32dtype,
-            self.w_int64dtype, self.w_uint64dtype,
-            self.w_float16dtype,
-            self.w_float32dtype, self.w_float64dtype, self.w_longdouble,
-            self.w_complex64dtype, self.w_complex128dtype, self.w_clongdouble,
+            self.w_int64dtype, self.w_uint64dtype] + \
+            float_dtypes + complex_dtypes + [
             self.w_stringdtype, self.w_unicodedtype, self.w_voiddtype,
             self.w_intpdtype, self.w_uintpdtype,
         ]
         self.float_dtypes_by_num_bytes = sorted(
             (dtype.itemtype.get_element_size(), dtype)
-            for dtype in [self.w_float16dtype, self.w_float32dtype,
-                          self.w_float64dtype, self.w_longdouble]
+            for dtype in float_dtypes
         )
         self.dtypes_by_num = {}
         self.dtypes_by_name = {}
             'LONGLONG': self.w_int64dtype,
             'SHORT': self.w_int16dtype,
             'VOID': self.w_voiddtype,
-            'LONGDOUBLE': self.w_longdouble,
             'UBYTE': self.w_uint8dtype,
             'UINTP': self.w_ulongdtype,
             'ULONG': self.w_ulongdtype,
             'USHORT': self.w_uint16dtype,
             'FLOAT': self.w_float32dtype,
             'BOOL': self.w_booldtype,
-            'CLONGDOUBLE': self.w_clongdouble,
         }
+        if interp_boxes.ENABLED_LONG_DOUBLE:
+            typeinfo_full['LONGDOUBLE'] = self.w_longdouble
+            typeinfo_full['CLONGDOUBLE'] = self.w_clongdouble
+
         typeinfo_partial = {
             'Generic': interp_boxes.W_GenericBox,
             'Character': interp_boxes.W_CharacterBox,

pypy/module/micronumpy/interp_numarray.py

         return w_object
 
     shape, elems_w = find_shape_and_elems(space, w_object, dtype)
-    if dtype is None:
+    if dtype is None or (
+                 dtype.is_str_or_unicode() and dtype.itemtype.get_size() < 1):
         for w_elem in elems_w:
             dtype = interp_ufuncs.find_dtype_for_scalar(space, w_elem,
                                                         dtype)
 
         if dtype is None:
             dtype = interp_dtype.get_dtype_cache(space).w_float64dtype
+    if dtype.is_str_or_unicode() and dtype.itemtype.get_size() < 1:
+        # promote S0 -> S1, U0 -> U1
+        dtype = interp_dtype.variable_dtype(space, dtype.char + '1')
     if ndmin > len(shape):
         shape = [1] * (ndmin - len(shape)) + shape
     arr = W_NDimArray.from_shape(shape, dtype, order=order)

pypy/module/micronumpy/interp_ufuncs.py

             return interp_dtype.get_dtype_cache(space).w_complex64dtype
         elif dt2.num == 15:
             return interp_dtype.get_dtype_cache(space).w_complex128dtype
-        elif dt2.num == 16:
+        elif interp_boxes.ENABLED_LONG_DOUBLE and dt2.num == 16:
             return interp_dtype.get_dtype_cache(space).w_clongdouble
         else:
             raise OperationError(space.w_TypeError, space.wrap("Unsupported types"))

pypy/module/micronumpy/test/test_complex.py

         raises(TypeError, signbit, complex(1,1))
 
     def test_reciprocal(self):
-        from _numpypy import array, reciprocal, complex64, complex128, clongdouble
-
+        from _numpypy import array, reciprocal, complex64, complex128
+        c_and_relerr = [(complex64, 2e-7), (complex128, 2e-15)]
+        try:
+            from _numpypy import clongdouble
+            c_and_relerr.append((clongdouble, 2e-30))
+        except:
+            pass # no longdouble yet
         inf = float('inf')
         nan = float('nan')
         #complex    
                     complex(-r, i), 
                     -0j, 0j, cnan, 
                     cnan, cnan, cnan]
-        for c, rel_err in ((complex64, 2e-7), (complex128, 2e-15), (clongdouble, 2e-15)):
+        for c, rel_err in c_and_relerr:
             actual = reciprocal(array([orig], dtype=c))
             for b, a, e in zip(orig, actual, expected):
                 assert (a[0].real - e.real) < rel_err
         raises(TypeError, copysign, a, b)
 
     def test_exp2(self):
-        from _numpypy import array, exp2, complex128, complex64, clongfloat
+        from _numpypy import array, exp2, complex128, complex64
+        c_and_relerr = [(complex64, 2e-7), (complex128, 2e-15)]
+        try:
+            from _numpypy import clongdouble
+            c_and_relerr.append((clongdouble, 2e-30))
+        except:
+            pass # no longdouble yet
         inf = float('inf')
         ninf = -float('inf')
         nan = float('nan')
         cmpl = complex
-        for c,rel_err in ((complex128, 2e-15), (complex64, 1e-7), (clongfloat, 2e-15)):
+        for c,rel_err in c_and_relerr:
             a = [cmpl(-5., 0), cmpl(-5., -5.), cmpl(-5., 5.),
                        cmpl(0., -5.), cmpl(0., 0.), cmpl(0., 5.),
                        cmpl(-0., -5.), cmpl(-0., 0.), cmpl(-0., 5.),
     def test_basic(self):
         from _numpypy import (complex128, complex64, add, array, dtype,
             subtract as sub, multiply, divide, negative, absolute as abs,
-            floor_divide, real, imag, sign, clongfloat)
+            floor_divide, real, imag, sign)
         from _numpypy import (equal, not_equal, greater, greater_equal, less,
                 less_equal, isnan)
+        complex_dtypes = [complex64, complex128]
+        try:
+            from _numpypy import clongfloat
+            complex_dtypes.append(clongfloat)
+        except:
+            pass
         assert real(4.0) == 4.0
         assert imag(0.0) == 0.0
         a = array([complex(3.0, 4.0)])
         b = a.real
         assert b.dtype == dtype(float)
-        for complex_ in complex64, complex128, clongfloat:
+        for complex_ in complex_dtypes:
 
             O = complex(0, 0)
             c0 = complex_(complex(2.5, 0))

pypy/module/micronumpy/test/test_dtypes.py

             from rpython.rtyper.lltypesystem import rffi
             ptr_size = rffi.sizeof(rffi.CCHARP)
         cls.w_ptr_size = cls.space.wrap(ptr_size)
-
+    
 class AppTestDtypes(BaseAppTestDtypes):
     def test_dtype(self):
         from _numpypy import dtype
         raises(TypeError, lambda: dtype("int8") == 3)
         assert dtype(bool) == bool
 
-    def test_dtype_aliases(self):
-        from _numpypy import dtype
-        assert dtype('longfloat').num in (12, 13)
-        assert dtype('longdouble').num in (12, 13)
-        assert dtype('clongfloat').num in (15, 16)
-        assert dtype('clongdouble').num in (15, 16)
-
     def test_dtype_with_types(self):
         from _numpypy import dtype
 
         assert str(d) == "bool"
 
     def test_bool_array(self):
-        from _numpypy import array, False_, True_
+        from _numpypy import array
+        from numpypy import False_, True_
 
         a = array([0, 1, 2, 2.5], dtype='?')
         assert a[0] is False_
             assert a[i] is True_
 
     def test_copy_array_with_dtype(self):
-        from _numpypy import array, False_, longlong
+        from _numpypy import array, longlong
+        from numpypy import False_
 
         a = array([0, 1, 2, 3], dtype=long)
         # int on 64-bit, long in 32-bit
         assert b[0] is False_
 
     def test_zeros_bool(self):
-        from _numpypy import zeros, False_
+        from _numpypy import zeros
+        from numpypy import False_
 
         a = zeros(10, dtype=bool)
         for i in range(10):
             assert a[i] is False_
 
     def test_ones_bool(self):
-        from _numpypy import ones, True_
+        from _numpypy import ones
+        from numpypy import True_
 
         a = ones(10, dtype=bool)
         for i in range(10):
             '?', 'b', 'B', 'h', 'H', 'i', 'I', 'l', 'L', 'q', 'Q', 'f', 'd', 
             'e'
         ]
-        if array([0], dtype='longdouble').itemsize > 8:
-            types += ['g', 'G']
         a = array([True], '?')
         for t in types:
             assert (a + array([0], t)).dtype is dtype(t)
             (numpy.float16, 10.),
             (numpy.float32, 2.0),
             (numpy.float64, 4.32),
-            (numpy.longdouble, 4.32),
         ]:
             assert hash(tp(value)) == hash(value)
 
         assert int_(4) ** 2 == 16
 
     def test_bool(self):
-        import _numpypy as numpy
+        import numpypy as numpy
 
         assert numpy.bool_.mro() == [numpy.bool_, numpy.generic, object]
         assert numpy.bool_(3) is numpy.True_
         from math import isnan
         assert isnan(numpy.float32(None))
         assert isnan(numpy.float64(None))
-        assert isnan(numpy.longdouble(None))
-
-    def test_longfloat(self):
-        import _numpypy as numpy
-        # it can be float96 or float128
-        if numpy.longfloat != numpy.float64:
-            assert numpy.longfloat.mro()[1:] == [numpy.floating,
-                                       numpy.inexact, numpy.number, 
-                                       numpy.generic, object]
-        a = numpy.array([1, 2, 3], numpy.longdouble)
-        assert type(a[1]) is numpy.longdouble
-        assert numpy.float64(12) == numpy.longdouble(12)
-        assert numpy.float64(12) == numpy.longfloat(12)
-        raises(ValueError, numpy.longfloat, '23.2df')
 
     def test_complex_floating(self):
         import _numpypy as numpy
 
     def test_operators(self):
         from operator import truediv
-        from _numpypy import float64, int_, True_, False_
+        from _numpypy import float64, int_
+        from numpypy import True_, False_
         assert 5 / int_(2) == int_(2)
         assert truediv(int_(3), int_(2)) == float64(1.5)
         assert truediv(3, int_(2)) == float64(1.5)
         a = array([1, 2, 3], dtype=self.non_native_prefix + 'f2')
         assert a[0] == 1
         assert (a + a)[1] == 4
-        a = array([1, 2, 3], dtype=self.non_native_prefix + 'g') # longdouble
-        assert a[0] == 1
-        assert (a + a)[1] == 4
-        a = array([1, 2, 3], dtype=self.non_native_prefix + 'G') # clongdouble
-        assert a[0] == 1
-        assert (a + a)[1] == 4
 
 class AppTestPyPyOnly(BaseNumpyAppTest):
     def setup_class(cls):
         assert typeinfo['LONGLONG'] == ('q', 9, 64, 8, 9223372036854775807L, -9223372036854775808L, int64)
         assert typeinfo['VOID'] == ('V', 20, 0, 1, void)
         assert typeinfo['BOOL'] == ('?', 0, 8, 1, 1, 0, bool_)
+
+class AppTestNoLongDoubleDtypes(BaseNumpyAppTest):
+    def setup_class(cls):
+        from pypy.module.micronumpy import Module
+        if Module.interpleveldefs.get('longfloat', None):
+            py.test.skip('longdouble exists, skip these tests')
+        if option.runappdirect and '__pypy__' not in sys.builtin_module_names:
+            py.test.skip("pypy only test for no longdouble support")
+        BaseNumpyAppTest.setup_class.im_func(cls)
+
+    def test_nolongfloat(self):
+        import _numpypy
+        from _numpypy import dtype
+        assert not getattr(_numpypy, 'longdouble', False)
+        assert not getattr(_numpypy, 'float128', False)
+        assert not getattr(_numpypy, 'float96', False)
+        raises(TypeError, dtype, 'longdouble')
+        raises(TypeError, dtype, 'clongdouble')
+        raises(TypeError, dtype, 'longfloat')
+        raises(TypeError, dtype, 'clongfloat')
+        raises(TypeError, dtype, 'float128')
+        raises(TypeError, dtype, 'float96')
+
+class AppTestLongDoubleDtypes(BaseNumpyAppTest):
+    def setup_class(cls):
+        from pypy.module.micronumpy import Module
+        print dir(Module.interpleveldefs)
+        if not Module.interpleveldefs.get('longfloat', None):
+            py.test.skip('no longdouble types yet')
+        BaseNumpyAppTest.setup_class.im_func(cls)
+
+    def test_longfloat(self):
+        import _numpypy as numpy
+        # it can be float96 or float128
+        if numpy.longfloat != numpy.float64:
+            assert numpy.longfloat.mro()[1:] == [numpy.floating,
+                                       numpy.inexact, numpy.number, 
+                                       numpy.generic, object]
+        a = numpy.array([1, 2, 3], numpy.longdouble)
+        assert type(a[1]) is numpy.longdouble
+        assert numpy.float64(12) == numpy.longdouble(12)
+        assert numpy.float64(12) == numpy.longfloat(12)
+        raises(ValueError, numpy.longfloat, '23.2df')
+
+    def test_dtype_aliases(self):
+        from _numpypy import dtype
+        assert dtype('longfloat').num in (12, 13)
+        assert dtype('longdouble').num in (12, 13)
+        assert dtype('clongfloat').num in (15, 16)
+        assert dtype('clongdouble').num in (15, 16)
+
+    def test_bool_binop_types(self):
+        from _numpypy import array, dtype
+        types = ['g', 'G']
+        a = array([True], '?')
+        for t in types:
+            assert (a + array([0], t)).dtype is dtype(t)
+
+    def test_hash(self):
+        import _numpypy as numpy
+        for tp, value in [
+            (numpy.longdouble, 4.32),
+        ]:
+            assert hash(tp(value)) == hash(value)
+
+    def test_float_None(self):
+        import _numpypy as numpy
+        from math import isnan
+        assert isnan(numpy.longdouble(None))
+
+    def test_non_native(self):
+        from _numpypy import array
+        a = array([1, 2, 3], dtype=self.non_native_prefix + 'g') # longdouble
+        assert a[0] == 1
+        assert (a + a)[1] == 4
+        a = array([1, 2, 3], dtype=self.non_native_prefix + 'G') # clongdouble
+        assert a[0] == 1
+        assert (a + a)[1] == 4

pypy/module/micronumpy/test/test_numarray.py

 
     def test_mul(self):
         import _numpypy
+        from numpypy import False_, True_
 
         a = _numpypy.array(range(5))
         b = a * a
         a = _numpypy.array(range(5), dtype=bool)
         b = a * a
         assert b.dtype is _numpypy.dtype(bool)
-        assert b[0] is _numpypy.False_
+        assert b[0] is False_
         for i in range(1, 5):
-            assert b[i] is _numpypy.True_
+            assert b[i] is True_
 
     def test_mul_constant(self):
         from _numpypy import array
         b = array([])
         raises(ValueError, "b.max()")
 
-        assert list(zeros((0, 2)).max(axis=1)) == []
+        if 0: # XXX too pedantic
+            assert list(zeros((0, 2)).max(axis=1)) == []
 
     def test_max_add(self):
         from _numpypy import array
         b = array([])
         raises(ValueError, "b.min()")
 
-        assert list(zeros((0, 2)).min(axis=1)) == []
+        if 0: # XXX too pedantic
+            assert list(zeros((0, 2)).min(axis=1)) == []
 
     def test_argmax(self):
         from _numpypy import array
         assert len(a) == 6
         assert (a == [0,1,2,3,4,5]).all()
         assert a.dtype is dtype(int)
-        a = concatenate((a1, a2), axis=1)
-        assert (a == [0,1,2,3,4,5]).all()
+        if 0: # XXX why does numpy allow this?
+            a = concatenate((a1, a2), axis=1)
+            assert (a == [0,1,2,3,4,5]).all()
         a = concatenate((a1, a2), axis=-1)
         assert (a == [0,1,2,3,4,5]).all()
 
         g2 = array([[3,4,5]])
         g = concatenate((g1, g2), axis=-2)
         assert (g == [[0,1,2],[3,4,5]]).all()
+        exc = raises(IndexError, concatenate, (g1, g2), axis=-3)
+        assert str(exc.value) == "axis -3 out of bounds [0, 2)"
         exc = raises(IndexError, concatenate, (g1, g2), axis=2)
         assert str(exc.value) == "axis 2 out of bounds [0, 2)"
-        exc = raises(IndexError, concatenate, (g1, g2), axis=-3)
-        assert str(exc.value) == "axis -3 out of bounds [0, 2)"
 
         exc = raises(ValueError, concatenate, ())
         assert str(exc.value) == \
         assert str(exc.value) == \
                 "all the input arrays must have same number of dimensions"
 
-        g1 = array([0,1,2])
-        g2 = array([[3,4,5]])
-        exc = raises(ValueError, concatenate, (g1, g2), axis=2)
-        assert str(exc.value) == \
-                "all the input arrays must have same number of dimensions"
+        if 0: # XXX too pedantic
+            g1 = array([0,1,2])
+            g2 = array([[3,4,5]])
+            exc = raises(ValueError, concatenate, (g1, g2), axis=2)
+            assert str(exc.value) == \
+                    "all the input arrays must have same number of dimensions"
 
         a = array([1, 2, 3, 4, 5, 6])
         a = (a + a)[::2]
             i2 = (i+1) * a.dtype.itemsize
             assert list(reversed(s1[i1:i2])) == s2[i1:i2]
 
-        a = array([1, -1, 10000], dtype='longfloat')
-        s1 = map(ord, a.tostring())
-        s2 = map(ord, a.byteswap().tostring())
-        assert a.dtype.itemsize >= 8
-        for i in range(a.size):
-            i1 = i * a.dtype.itemsize
-            i2 = (i+1) * a.dtype.itemsize
-            assert list(reversed(s1[i1:i2])) == s2[i1:i2]
-
     def test_clip(self):
         from _numpypy import array
         a = array([1, 2, 17, -3, 12])
 
     def test_fromstring_types(self):
         from _numpypy import (fromstring, int8, int16, int32, int64, uint8,
-            uint16, uint32, float16, float32, float64, longfloat, array)
+            uint16, uint32, float16, float32, float64, array)
         a = fromstring('\xFF', dtype=int8)
         assert a[0] == -1
         b = fromstring('\xFF', dtype=uint8)
         assert j[0] == 12
         k = fromstring(self.float16val, dtype=float16)
         assert k[0] == float16(5.)
-        dt =  array([5],dtype=longfloat).dtype
-        if dt.itemsize == 12:
-            from _numpypy import float96
-            m = fromstring('\x00\x00\x00\x00\x00\x00\x00\xa0\x01@\x00\x00', dtype=float96)
-        elif dt.itemsize==16:
-            from _numpypy import float128
-            m = fromstring('\x00\x00\x00\x00\x00\x00\x00\xa0\x01@\x00\x00\x00\x00\x00\x00', dtype=float128)
-        elif dt.itemsize == 8:
-            skip('longfloat is float64')
-        else:
-            skip('unknown itemsize for longfloat')
-        assert m[0] == longfloat(5.)
 
     def test_fromstring_invalid(self):
         from _numpypy import fromstring, uint16, uint8
         assert d.name == 'void32'
 
         a = array([('a', 2), ('cde', 1)], dtype=d)
-        assert a[0]['x'] == '\x02'
+        if 0: # XXX why does numpy allow this?
+            assert a[0]['x'] == '\x02'
         assert a[0]['y'] == 2
-        assert a[1]['x'] == '\x01'
+        if 0: # XXX why does numpy allow this?
+            assert a[1]['x'] == '\x01'
         assert a[1]['y'] == 1
 
         d = dtype([('x', 'S1'), ('y', 'int32')])
         assert x.__pypy_data__ is obj
         del x.__pypy_data__
         assert x.__pypy_data__ is None
+
+class AppTestLongDoubleDtypes(BaseNumpyAppTest):
+    def setup_class(cls):
+        from pypy.module.micronumpy import Module
+        print dir(Module.interpleveldefs)
+        if not Module.interpleveldefs.get('longfloat', None):
+            py.test.skip('no longdouble types yet')
+        BaseNumpyAppTest.setup_class.im_func(cls)
+
+    def test_byteswap(self):
+        from _numpypy import array
+
+        a = array([1, -1, 10000], dtype='longfloat')
+        s1 = map(ord, a.tostring())
+        s2 = map(ord, a.byteswap().tostring())
+        assert a.dtype.itemsize >= 8
+        for i in range(a.size):
+            i1 = i * a.dtype.itemsize
+            i2 = (i+1) * a.dtype.itemsize
+            assert list(reversed(s1[i1:i2])) == s2[i1:i2]
+
+    def test_fromstring_types(self):
+        from _numpypy import (fromstring, longfloat, array)
+        dt =  array([5],dtype=longfloat).dtype
+        if dt.itemsize == 12:
+            from _numpypy import float96
+            m = fromstring('\x00\x00\x00\x00\x00\x00\x00\xa0\x01@\x00\x00', dtype=float96)
+        elif dt.itemsize==16:
+            from _numpypy import float128
+            m = fromstring('\x00\x00\x00\x00\x00\x00\x00\xa0\x01@\x00\x00\x00\x00\x00\x00', dtype=float128)
+        elif dt.itemsize == 8:
+            skip('longfloat is float64')
+        else:
+            skip('unknown itemsize for longfloat')
+        assert m[0] == longfloat(5.)
+
+

pypy/module/micronumpy/types.py

 
 NonNativeComplex128 = Complex128
 
-if interp_boxes.long_double_size == 12:
+if interp_boxes.ENABLED_LONG_DOUBLE and interp_boxes.long_double_size == 12:
     class Float96(BaseType, Float):
         _attrs_ = ()
 
 
     NonNativeComplex192 = Complex192
 
-elif interp_boxes.long_double_size == 16:
+elif interp_boxes.ENABLED_LONG_DOUBLE and interp_boxes.long_double_size == 16:
     class Float128(BaseType, Float):
         _attrs_ = ()
 

pypy/module/test_lib_pypy/numpypy/test_numpy.py

         import numpypy
         assert numpypy.set_string_function is not \
                numpypy.core.multiarray.set_string_function
+
+    def test_constants(self):
+        import numpypy
+        assert numpypy.PZERO == numpypy.NZERO == 0.0
+        assert numpypy.inf is float('inf')
+        assert numpypy.nan is float('nan')

rpython/flowspace/argument.py

 Arguments objects.
 """
 
+
 class Signature(object):
     _immutable_ = True
     _immutable_fields_ = ["argnames[*]"]
             return NotImplemented
         return not self == other
 
-
     # make it look tuply for its use in the annotator
 
     def __len__(self):
             return self.kwargname
         raise IndexError
 
+
 class ArgumentsForTranslation(object):
     def __init__(self, space, args_w, keywords=None, keywords_w=None,
                  w_stararg=None, w_starstararg=None):
             self.keywords = self.keywords + keywords
             self.keywords_w = self.keywords_w + keywords_w
 
-
     def fixedunpack(self, argcount):
         """The simplest argument parsing: get the 'argcount' arguments,
         or raise a real ValueError if the length is wrong."""
         if self.keywords:
-            raise ValueError, "no keyword arguments expected"
+            raise ValueError("no keyword arguments expected")
         if len(self.arguments_w) > argcount:
-            raise ValueError, "too many arguments (%d expected)" % argcount
+            raise ValueError("too many arguments (%d expected)" % argcount)
         elif len(self.arguments_w) < argcount:
-            raise ValueError, "not enough arguments (%d expected)" % argcount
+            raise ValueError("not enough arguments (%d expected)" % argcount)
         return self.arguments_w
 
     def combine_if_necessary(self):
                 kwds_w[self.keywords[i]] = self.keywords_w[i]
         return self.arguments_w, kwds_w
 
-
     def match_signature(self, signature, defaults_w):
         """Parse args and kwargs according to the signature of a code object,
         or raise an ArgErr in case of failure.
         return ArgumentsForTranslation(self.space, args_w, keywords, keywords_w)
 
     @staticmethod
-    def fromshape(space, (shape_cnt,shape_keys,shape_star,shape_stst), data_w):
+    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:
 
     def _rawshape(self, nextra=0):
         assert not self.combine_has_happened
-        shape_cnt  = len(self.arguments_w)+nextra        # Number of positional args
+        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()
         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)
 
 #
 
 class ArgErr(Exception):
-
     def getmsg(self):
         raise NotImplementedError
 
+
 class ArgErrCount(ArgErr):
-
     def __init__(self, got_nargs, nkwds, signature,
                  defaults_w, missing_args):
         self.signature = signature
                 num_args)
         return msg
 
+
 class ArgErrMultipleValues(ArgErr):
-
     def __init__(self, argname):
         self.argname = argname
 
             self.argname)
         return msg
 
+
 class ArgErrUnknownKwds(ArgErr):
-
     def __init__(self, space, num_remainingkwds, keywords, kwds_mapping,
                  keyword_names_w):
         name = ''

rpython/flowspace/flowcontext.py

 from rpython.tool.stdlib_opcode import host_bytecode_spec
 from rpython.flowspace.argument import ArgumentsForTranslation
 from rpython.flowspace.model import (Constant, Variable, Block, Link,
-    UnwrapException, c_last_exception)
+    c_last_exception)
 from rpython.flowspace.framestate import (FrameState, recursively_unflatten,
-        recursively_flatten)
+    recursively_flatten)
 from rpython.flowspace.specialcase import (rpython_print_item,
-        rpython_print_newline)
+    rpython_print_newline)
+
 
 class FlowingError(Exception):
     """ Signals invalid RPython in the function being analysed"""
 
 # ____________________________________________________________
 
-class Recorder:
-
+class Recorder(object):
     def append(self, operation):
         raise NotImplementedError
 
     def guessbool(self, frame, w_condition, **kwds):
-        raise AssertionError, "cannot guessbool(%s)" % (w_condition,)
+        raise AssertionError("cannot guessbool(%s)" % (w_condition,))
 
 
 class BlockRecorder(Recorder):
 
 # ____________________________________________________________
 
-_unary_ops = [('UNARY_POSITIVE', "pos"),
+_unary_ops = [
+    ('UNARY_POSITIVE', "pos"),
     ('UNARY_NEGATIVE', "neg"),
     ('UNARY_NOT', "not_"),
     ('UNARY_CONVERT', "repr"),
-    ('UNARY_INVERT', "invert"),]
+    ('UNARY_INVERT', "invert"),
+]
 
 def unaryoperation(OPCODE, op):
     def UNARY_OP(self, *ignored):
             n -= 1
             if n < 0:
                 break
-            values_w[n] = self.locals_stack_w[base+n]
+            values_w[n] = self.locals_stack_w[base + n]
         return values_w
 
     def dropvalues(self, n):
     def replace_in_stack(self, oldvalue, newvalue):
         w_new = Constant(newvalue)
         stack_items_w = self.locals_stack_w
-        for i in range(self.valuestackdepth-1, self.pycode.co_nlocals-1, -1):
+        for i in range(self.valuestackdepth - 1, self.pycode.co_nlocals - 1, -1):
             w_v = stack_items_w[i]
             if isinstance(w_v, Constant):
                 if w_v.value is oldvalue:
                 raise FSException(space.w_TypeError,
                     space.wrap("raise: no active exception to re-raise"))
 
-        w_value = w_traceback = space.w_None
+        w_value = space.w_None
         if nbargs >= 3:
-            w_traceback = self.popvalue()
+            self.popvalue()
         if nbargs >= 2:
             w_value = self.popvalue()
         if 1:
 
     def call_function(self, oparg, w_star=None, w_starstar=None):
         n_arguments = oparg & 0xff
-        n_keywords = (oparg>>8) & 0xff
+        n_keywords = (oparg >> 8) & 0xff
         if n_keywords:
             keywords = [None] * n_keywords
             keywords_w = [None] * n_keywords
         arguments = self.popvalues(n_arguments)
         args = ArgumentsForTranslation(self.space, arguments, keywords,
                 keywords_w, w_star, w_starstar)
-        w_function  = self.popvalue()
+        w_function = self.popvalue()
         w_result = self.space.call_args(w_function, args)
         self.pushvalue(w_result)
 
     """Signals a 'return' statement.
     Argument is the wrapped object to return."""
     kind = 0x01
+
     def __init__(self, w_returnvalue):
         self.w_returnvalue = w_returnvalue
 
     """Signals an application-level exception
     (i.e. an OperationException)."""
     kind = 0x02
+
     def __init__(self, operr):
         self.operr = operr
 
     """Signals a 'continue' statement.
     Argument is the bytecode position of the beginning of the loop."""
     kind = 0x08
+
     def __init__(self, jump_to):
         self.jump_to = jump_to
 

rpython/flowspace/generator.py

 """Flow graph building for generators"""
 
-from rpython.flowspace.model import Block, Link, SpaceOperation, checkgraph
-from rpython.flowspace.model import Variable, Constant
-from rpython.translator.unsimplify import insert_empty_startblock
-from rpython.translator.unsimplify import split_block
+from rpython.flowspace.argument import Signature
+from rpython.flowspace.model import (Block, Link, SpaceOperation, Variable,
+    Constant, checkgraph)
+from rpython.translator.unsimplify import insert_empty_startblock, split_block
 from rpython.translator.simplify import eliminate_empty_blocks, simplify_graph
 from rpython.tool.sourcetools import func_with_new_name
-from rpython.flowspace.argument import Signature
 
 
 class AbstractPosition(object):
     mappings = [Entry]
     #
     stopblock = Block([])
-    v0 = Variable(); v1 = Variable()
+    v0 = Variable()
+    v1 = Variable()
     stopblock.operations = [
         SpaceOperation('simple_call', [Constant(StopIteration)], v0),
         SpaceOperation('type', [v0], v1),

rpython/flowspace/model.py

 # the below object/attribute model evolved from
 # a discussion in Berlin, 4th of october 2003
 import py
+
 from rpython.tool.uid import uid, Hashable
 from rpython.tool.sourcetools import PY_IDENTIFIER, nice_repr_for_func
 from rpython.rlib.rarithmetic import is_valid_int, r_longlong, r_ulonglong, r_uint
 class Block(object):
     __slots__ = """inputargs operations exitswitch
                 exits blockcolor""".split()
-    
+
     def __init__(self, inputargs):
-        self.inputargs = list(inputargs)  # mixed list of variable/const XXX 
+        self.inputargs = list(inputargs)  # mixed list of variable/const XXX
         self.operations = []              # list of SpaceOperation(s)
         self.exitswitch = None            # a variable or
                                           #  Constant(last_exception), see below
             else:
                 txt = "codeless block"
         return txt
-    
+
     def __repr__(self):
         txt = "%s with %d exits" % (str(self), len(self.exits))
         if self.exitswitch:
     def closeblock(self, *exits):
         assert self.exits == [], "block already closed"
         self.recloseblock(*exits)
-        
+
     def recloseblock(self, *exits):
         for exit in exits:
             exit.prevblock = self
     def renamed(self):
         return self._name is not self.dummyname
     renamed = property(renamed)
-    
+
     def __init__(self, name=None):
         self._name = self.dummyname
         self._nr = -1
         self.offset = offset      # offset in code string
 
     def __eq__(self, other):
-        return (self.__class__ is other.__class__ and 
+        return (self.__class__ is other.__class__ and
                 self.opname == other.opname and
                 self.args == other.args and
                 self.result == other.result)

rpython/flowspace/specialcase.py

         elif opname == 'getattr' and len(args_w) == 3:
             return space.do_operation('simple_call', Constant(getattr), *args_w)
         else:
-            raise Exception, "should call %r with exactly %d arguments" % (
-                fn, Arity[opname])
+            raise Exception("should call %r with exactly %d arguments" % (
+                fn, Arity[opname]))
     # completely replace the call with the underlying
     # operation and its limited implicit exceptions semantic
     return getattr(space, opname)(*args_w)
         locals: sc_locals}
 for fn in OperationName:
     SPECIAL_CASES[fn] = sc_operator
-

rpython/jit/metainterp/resume.py

-import sys, os
-from rpython.jit.metainterp.history import Box, Const, ConstInt, getkind
-from rpython.jit.metainterp.history import BoxInt, BoxPtr, BoxFloat
-from rpython.jit.metainterp.history import INT, REF, FLOAT, HOLE
-from rpython.jit.metainterp.history import AbstractDescr
+from rpython.jit.codewriter.effectinfo import EffectInfo
+from rpython.jit.metainterp import jitprof
+from rpython.jit.metainterp.history import (Box, Const, ConstInt, getkind,
+    BoxInt, BoxPtr, BoxFloat, INT, REF, FLOAT, AbstractDescr)
 from rpython.jit.metainterp.resoperation import rop
-from rpython.jit.metainterp import jitprof
-from rpython.jit.codewriter.effectinfo import EffectInfo
+from rpython.rlib import rarithmetic, rstack
+from rpython.rlib.objectmodel import we_are_translated, specialize, compute_unique_id
+from rpython.rlib.debug import (have_debug_prints, ll_assert, debug_start,
+    debug_stop, debug_print)
+from rpython.rtyper import annlowlevel
 from rpython.rtyper.lltypesystem import lltype, llmemory, rffi, rstr
-from rpython.rtyper import annlowlevel
-from rpython.rlib import rarithmetic, rstack
-from rpython.rlib.objectmodel import we_are_translated, specialize
-from rpython.rlib.objectmodel import compute_unique_id
-from rpython.rlib.debug import have_debug_prints, ll_assert
-from rpython.rlib.debug import debug_start, debug_stop, debug_print
-from rpython.jit.metainterp.optimize import InvalidLoop
+
 
 # Logic to encode the chain of frames and the state of the boxes at a
 # guard operation, and to decode it again.  This is a bit advanced,
     target = framestack[n]
     if n == 0:
         return
-    back = framestack[n-1]
+    back = framestack[n - 1]
     if target.parent_resumedata_frame_info_list is not None:
         assert target.parent_resumedata_frame_info_list.pc == back.pc
         return
-    _ensure_parent_resumedata(framestack, n-1)
+    _ensure_parent_resumedata(framestack, n - 1)
     target.parent_resumedata_frame_info_list = FrameInfo(
                                          back.parent_resumedata_frame_info_list,
                                          back.jitcode,
 
 def untag(value):
     value = rarithmetic.widen(value)
-    tagbits = value&TAGMASK
-    return value>>2, tagbits
+    tagbits = value & TAGMASK
+    return value >> 2, tagbits
 
 def tagged_eq(x, y):
     # please rpython :(
 TAGBOX      = 2
 TAGVIRTUAL  = 3
 
-UNASSIGNED = tag(-1<<13, TAGBOX)
-UNASSIGNEDVIRTUAL = tag(-1<<13, TAGVIRTUAL)
+UNASSIGNED = tag(-1 << 13, TAGBOX)
+UNASSIGNEDVIRTUAL = tag(-1 << 13, TAGVIRTUAL)
 NULLREF = tag(-1, TAGCONST)
 UNINITIALIZED = tag(-2, TAGCONST)   # used for uninitialized string characters
 
              return numb, liveboxes.copy(), v
 
         numb1, liveboxes, v = self.number(optimizer, snapshot.prev)
-        n = len(liveboxes)-v
+        n = len(liveboxes) - v
         boxes = snapshot.boxes
         length = len(boxes)
         numb = lltype.malloc(NUMBERING, length)
         # returns a negative number
         if box in self.cached_boxes:
             num = self.cached_boxes[box]
-            boxes[-num-1] = box
+            boxes[-num - 1] = box
         else:
             boxes.append(box)
             num = -len(boxes)
 
 _frame_info_placeholder = (None, 0, 0)
 
+
 class ResumeDataVirtualAdder(object):
-
     def __init__(self, storage, memo):
         self.storage = storage
         self.memo = memo
 
         # collect liveboxes and virtuals
         n = len(liveboxes_from_env) - v
-        liveboxes = [None]*n
+        liveboxes = [None] * n
         self.vfieldboxes = {}
         for box, tagged in liveboxes_from_env.iteritems():
             i, tagbits = untag(tagged)
         # xxx heuristic a bit out of thin air
         failargs_limit = memo.metainterp_sd.options.failargs_limit
         if nliveboxes > (failargs_limit // 2):
-            if nholes > nliveboxes//3:
+            if nholes > nliveboxes // 3:
                 return True
         return False
 
                     raise TagOverflow
                 itemindex = rffi.cast(rffi.INT, itemindex)
                 #
-                rd_pendingfields[i].lldescr  = lldescr
-                rd_pendingfields[i].num      = num
+                rd_pendingfields[i].lldescr = lldescr
+                rd_pendingfields[i].num = num
                 rd_pendingfields[i].fieldnum = fieldnum
-                rd_pendingfields[i].itemindex= itemindex
+                rd_pendingfields[i].itemindex = itemindex
         self.storage.rd_pendingfields = rd_pendingfields
 
     def _gettagged(self, box):
     def _prepare_pendingfields(self, pendingfields):
         if pendingfields:
             for i in range(len(pendingfields)):
-                lldescr  = pendingfields[i].lldescr
-                num      = pendingfields[i].num
+                lldescr = pendingfields[i].lldescr
+                num = pendingfields[i].num
                 fieldnum = pendingfields[i].fieldnum
-                itemindex= pendingfields[i].itemindex
+                itemindex = pendingfields[i].itemindex
                 descr = annlowlevel.cast_base_ptr_to_instance(AbstractDescr,
                                                               lldescr)
                 struct = self.decode_ref(num)
     metainterp.framestack.reverse()
     return resumereader.liveboxes, virtualizable_boxes, virtualref_boxes
 
+
 class ResumeDataBoxReader(AbstractResumeDataReader):
     unique_id = lambda: None
 
 
     def decode_int(self, tagged):
         return self.decode_box(tagged, INT)
+
     def decode_ref(self, tagged):
         return self.decode_box(tagged, REF)
+
     def decode_float(self, tagged):
         return self.decode_box(tagged, FLOAT)
 
         elif kind == REF:
             box = BoxPtr(self.cpu.get_latest_value_ref(self.deadframe, num))
         elif kind == FLOAT:
-            box = BoxFloat(self.cpu.get_latest_value_float(self.deadframe,num))
+            box = BoxFloat(self.cpu.get_latest_value_float(self.deadframe, num))
         else:
             assert 0, "bad kind: %d" % ord(kind)
         self.liveboxes[num] = box
 
     def decode_box_of_type(self, TYPE, tagged):
         kind = getkind(TYPE)
-        if kind == 'int':     kind = INT
-        elif kind == 'ref':   kind = REF
-        elif kind == 'float': kind = FLOAT
-        else: raise AssertionError(kind)
+        if kind == 'int':
+            kind = INT
+        elif kind == 'ref':
+            kind = REF
+        elif kind == 'float':
+            kind = FLOAT
+        else:
+            raise AssertionError(kind)
         return self.decode_box(tagged, kind)
     decode_box_of_type._annspecialcase_ = 'specialize:arg(1)'
 
     def write_an_int(self, index, box):
         self.boxes_i[index] = box
+
     def write_a_ref(self, index, box):
         self.boxes_r[index] = box
+
     def write_a_float(self, index, box):
         self.boxes_f[index] = box
 
     resumereader.consume_vref_and_vable(vrefinfo, vinfo, ginfo)
     return resumereader.force_all_virtuals()
 
+
 class ResumeDataDirectReader(AbstractResumeDataReader):
     unique_id = lambda: None
     virtual_default = lltype.nullptr(llmemory.GCREF.TO)
         assert (end & 1) == 0
         for i in range(0, end, 2):
             virtual = self.decode_ref(numb.nums[i])
-            vref = self.decode_ref(numb.nums[i+1])
+            vref = self.decode_ref(numb.nums[i + 1])
             # For each pair, we store the virtual inside the vref.
             vrefinfo.continue_tracing(vref, virtual)
 
         self.cur_numb = numb.prev
         if self.resume_after_guard_not_forced != 2:
             end_vref = self.consume_vable_info(vinfo, numb)
-            if ginfo is not None: end_vref -= 1
+            if ginfo is not None:
+                end_vref -= 1
             self.consume_virtualref_info(vrefinfo, numb, end_vref)
 
     def allocate_with_vtable(self, known_class):
         if storage.rd_pendingfields:
             debug_print('\tpending setfields')
             for i in range(len(storage.rd_pendingfields)):
-                lldescr  = storage.rd_pendingfields[i].lldescr
-                num      = storage.rd_pendingfields[i].num
+                lldescr = storage.rd_pendingfields[i].lldescr
+                num = storage.rd_pendingfields[i].num
                 fieldnum = storage.rd_pendingfields[i].fieldnum
-                itemindex= storage.rd_pendingfields[i].itemindex
+                itemindex = storage.rd_pendingfields[i].itemindex
                 debug_print("\t\t", str(lldescr), str(untag(num)), str(untag(fieldnum)), itemindex)
 
     debug_stop("jit-resume")

rpython/jit/metainterp/test/test_resume.py

 from __future__ import with_statement
 import py
+import sys
 from rpython.rtyper.lltypesystem import lltype, llmemory, rffi
 from rpython.jit.metainterp.optimizeopt.optimizer import OptValue
 from rpython.jit.metainterp.optimizeopt.virtualize import VirtualValue, VArrayValue

rpython/rlib/rarithmetic.py

 def is_valid_int(r):
     if objectmodel.we_are_translated():
         return isinstance(r, int)
-    return type(r) in (int, long, bool) and (
+    return isinstance(r, (base_int, int, long, bool)) and (
         -maxint - 1 <= r <= maxint)
 is_valid_int._annspecialcase_ = 'specialize:argtype(0)'
 

rpython/translator/c/test/test_genc.py

     assert hasattr(ctypes.CDLL(str(t.driver.c_entryp)), 'foobar')
 
 def test_exportstruct():
+    from rpython.translator.tool.cbuild import ExternalCompilationInfo
     from rpython.rlib.exports import export_struct
     def f():
         return 42
     FOO = Struct("FOO", ("field1", Signed))
     foo = malloc(FOO, flavor="raw")
     foo.field1 = 43
+    # maybe export_struct should add the struct name to eci automatically?
+    # https://bugs.pypy.org/issue1361
+    foo._obj._compilation_info = ExternalCompilationInfo(export_symbols=['BarStruct'])
     export_struct("BarStruct", foo._obj)
     t = Translation(f, [], backend="c")
     t.annotate()

rpython/translator/goal/old_queries.py

-# functions to query information out of the translator and annotator from the debug prompt of translate
-import types
-import re
-
-import rpython.annotator.model as annmodel
-import rpython.flowspace.model as flowmodel
-
-
-class typerep(object):
-    
-    def __init__(self, x):
-        self.typ = getattr(x, '__class__', type(x))
-        self.bound = None
-        if hasattr(x, 'im_self'):
-            self.bound = x.im_self is not None
-        elif hasattr(x, '__self__'):
-            self.bound = x.__self__ is not None
-
-    def __hash__(self):
-        return hash(self.typ)
-
-    def __cmp__(self, other):
-        return cmp((self.typ.__name__, self.bound, self.typ), (other.typ.__name__, other.bound, other.typ))
-
-    def __str__(self):
-        if self.bound is None:
-            s = self.typ.__name__
-        elif self.bound:
-            s = 'bound-%s' % self.typ.__name__
-        else:
-            s = 'unbound-%s' % self.typ.__name__
-
-        if self.typ.__module__ == '__builtin__':
-            s = "*%s*" % s
-
-        return s
-
-def typereps(bunch):
-    t = dict.fromkeys([typerep(x) for x in bunch]).keys()
-    t.sort()
-    return t
-
-def roots(classes):
-    # find independent hierarchy roots in classes,
-    # preserve None if it's part of classes
-    work = list(classes)
-    res = []
-
-    notbound = False
-    
-    while None in work:
-        work.remove(None)
-        notbound = True
-
-    if len(work) == 1:
-        return notbound, classes[0]
-
-    while work:
-        cand = work.pop()
-        for cls in work:
-            if issubclass(cls, cand):
-                continue
-            if issubclass(cand, cls):
-                cand = cls
-                continue
-        res.append(cand)
-        work = [cls for cls in work if not issubclass(cls, cand)]
-
-
-    for x in res:
-        for y in res:
-            if x != y:
-                assert not issubclass(x, y), "%s %s %s" % (classes, x,y)
-                assert not issubclass(y, x), "%s %s %s" % (classes, x,y)
-
-    return notbound, tuple(res)
-            
-def callablereps(bunch):
-    callables = [func for clsdef, func in bunch]
-    classes = [clsdef and clsdef.cls for clsdef, func in bunch]
-    return roots(classes), tuple(typereps(callables))
-
-def prettyfunc(func):
-    descr = "(%s:%s)" % (getattr(func, '__module__', None) or '?', func.func_code.co_firstlineno)
-    funcname = getattr(func, '__name__', None) or 'UNKNOWN'
-    cls = getattr(func, 'class_', None)
-    if cls:
-        funcname = "%s.%s" % (cls.__name__, funcname)
-    return descr+funcname
-
-def prettycallable((cls, obj)):
-    if cls is None or cls == (True, ()):
-        cls = None
-    else:
-        notbound = False
-        if isinstance(cls, tuple) and isinstance(cls[0], bool):
-            notbound, cls = cls
-        if isinstance(cls, tuple):
-            cls = "[%s]" % '|'.join([x.__name__ for x in cls])
-        else:
-            cls = cls.__name__
-        if notbound:
-            cls = "_|%s" % cls
-
-    if isinstance(obj, types.FunctionType):
-        obj = prettyfunc(obj) 
-    elif isinstance(obj, tuple):
-        obj = "[%s]" % '|'.join([str(x) for x in obj])
-    else:
-        obj = str(obj)
-        if obj.startswith('<'):
-            obj = obj[1:-1]
-
-    if cls is None:
-        return str(obj)
-    else:
-        return "%s::%s" % (cls, obj)
-
-
-def prettybunch(bunch):
-    if len(bunch) == 1:
-        parts = ["one", iter(bunch).next()]
-    else:
-        parts = ["of type(s)"] + typereps(bunch)
-    return ' '.join(map(str, parts))
-
-def pbcaccess(translator):
-    annotator = translator.annotator
-    for inf in annotator.getpbcaccesssets().root_info.itervalues():
-        objs = inf.objects
-        print len(objs), prettybunch(objs), inf.attrs.keys()
-
-# PBCs
-def pbcs(translator):
-    bk = translator.annotator.bookkeeper
-    xs = bk.pbccache.keys()
-    funcs = [x for x in xs if isinstance(x, types.FunctionType)]
-    staticmethods = [x for x in xs if isinstance(x, staticmethod)]
-    binstancemethods = [x for x in xs if isinstance(x, types.MethodType) and x.im_self]
-    ubinstancemethods = [x for x in xs if isinstance(x, types.MethodType) and not x.im_self]
-    typs = [x for x in xs if isinstance(x, (type, types.ClassType))]
-    rest = [x for x in xs if not isinstance(x, (types.FunctionType, staticmethod, types.MethodType, type, types.ClassType))]
-    for objs in (funcs, staticmethods, binstancemethods, ubinstancemethods, typs, rest):
-        print len(objs), prettybunch(objs)
-
-# mutable captured "constants")
-def mutables(translator):
-    bk = translator.annotator.bookkeeper
-    xs = bk.seen_mutable.keys()
-    print len(xs), prettybunch(xs)
-
-def prettypatt(patts):
-    accum = []
-    patts.sort()
-    for (sh_cnt, sh_ks, sh_st, sh_stst)  in patts:
-        arg = []
-        arg.append("+%d" % sh_cnt)
-        for kw in sh_ks:
-            arg.append("%s=" % kw)
-        if sh_st:
-           arg.append('*')
-        if sh_stst:
-           arg.append('**')
-        accum.append("(%s)" % ', '.join(arg))
-    return ' '.join(accum)
-        
-def pbccallsanity(translator):
-    callb = translator.annotator.getpbccallables()
-    bk = translator.annotator.bookkeeper
-    typs = [x for x in callb if isinstance(x, (type, types.ClassType))]
-    for t in typs:
-        assert len(callb[t]) == 1
-        assert callb[t] == {(None,t): True}
-    print len(typs), "of ",prettycallable(callablereps([(None, Exception), (None, object)]))
-    ubm = [x for x in callb if isinstance(x, types.MethodType) and x.im_self is None]
-    assert len(ubm) == 0
-    bm = [x for x in callb if isinstance(x, types.MethodType) and x.im_self is not None]
-    frompbc = 0
-    notfrompbc = []
-    for b in bm:
-        assert len(callb[b]) == 1
-        assert callb[b] == {(None,b): True}
-        if b.im_class in bk.pbctypes or (b.im_class is None and b.im_self in bk.pbccache):
-            frompbc += 1
-        else:
-            notfrompbc.append(b)
-    class A:
-        def m():
-            pass
-    print frompbc, "of", prettycallable(callablereps([(None, A().m)])), "from PBCs"
-    print len(bm)-frompbc, "of", prettycallable(callablereps([(None, A().m)])), "not from PBCs"
-    if len(notfrompbc) < 40:
-        for b in notfrompbc:
-            print " "*4, prettycallable((None, b))
-    fs = [x for x in callb if isinstance(x, types.FunctionType)]
-    assert len(fs) + len(typs) + frompbc + len(notfrompbc) == len(callb)
-    plain = []
-    r = []
-    for x in fs:
-        if len(callb[x]) == 1 and callb[x].keys()[0][0] == None:
-            r.extend(callb[x].keys())
-            plain.append(x)
-    print len(plain), "of", prettycallable(callablereps(r))
-    r = []
-    for x in fs:
-        if x not in plain and len(callb[x]) == 1:
-            r.extend(callb[x].keys())
-    print len(r), "of", prettycallable(callablereps(r))
-    r = []
-    b_nb = []
-    for x in fs:
-        if len(callb[x]) == 2 and [1 for clsdef, f in callb[x].keys() if clsdef is None]:
-            r.extend(callb[x].keys())
-            b_nb.append(x)
-    print len(r), "of", prettycallable(callablereps(r))
-    print "- other -"
-    for x in fs:
-        if len(callb[x]) >= 2 and x not in b_nb:
-            print ' '.join([prettycallable((classdef and classdef.cls, func)) for (classdef,func) in callb[x].keys()])
-
-def pretty_els(objs):
-    accum = []
-    for classdef, obj in objs:
-        cls = classdef and classdef.cls
-        accum.append(prettycallable((cls, obj)))
-        els = ' '.join(accum)
-    if len(accum) == 1:
-        return els
-    else:
-        return "{%s}" % els
-
-def pbccall(translator):
-    fams = translator.annotator.getpbccallfamilies().root_info.itervalues()
-    one_pattern_fams = {}
-    rest = []
-    for fam in fams:
-        shapes = fam.patterns
-
-        if len(shapes) != 1:
-            rest.append((len(fam.objects), fam.objects, shapes.keys()))
-        else:
-            kinds = callablereps(fam.objects)
-
-            flavor = tuple(kinds), shapes.keys()[0]
-                
-            cntrs = one_pattern_fams.setdefault(flavor, [0,0])
-            cntrs[0] += 1
-            cntrs[1] += len(fam.objects)
-
-    def pretty_nfam(nfam):
-        if nfam == 1:
-            return "1 family"
-        else:
-            return "%d families" % nfam
-
-    def pretty_nels(kinds, nels, nfam):
-        if nels == 1 or nels == nfam:
-            return "one %s" % prettycallable(kinds)
-        else:
-            return "in total %d %s" % (nels, prettycallable(kinds))
-
-    items = one_pattern_fams.items()
-
-    items.sort(lambda a,b: cmp((a[0][1],a[1][1]), (b[0][1],b[1][1]))) # sort by pattern and then by els
-
-    for (kinds, patt), (nfam, nels) in items:
-        print pretty_nfam(nfam), "with", pretty_nels(kinds, nels, nfam), "with one call-pattern:",  prettypatt([patt])
-
-    print "- many patterns  -"
-
-    manycallb = False
-    rest.sort(lambda a,b: cmp((a[0],a[2]), (b[0],b[2])))
-
-    for n, objs, patts in rest:
-        if len(objs) > 1 and not manycallb:
-            manycallb = True
-            print " - many callables, many patterns -"
-        print "family of", pretty_els(objs), "with call-patterns:", prettypatt(patts)
-
-def pbcbmsanity(translator):
-    callb = translator.annotator.getpbccallables()
-    bk = translator.annotator.bookkeeper
-    bmeths = [x for x in callb if isinstance(x, types.MethodType) and x.im_self is not None]
-    print "%d bound-methods" % len(bmeths)
-    fams = translator.annotator.getpbccallfamilies()
-    plural_bm_families = {}
-    one_el = 0
-    for bm in bmeths:
-        notpbc = bm.im_self not in bk.pbccache
-        freestanding = bm.im_func in callb
-        if notpbc or freestanding:
-            print "! %s," % bm,
-        if notpbc:
-            print "of non-PBC %s,",
-        if freestanding:
-            print "found freestanding too"
-        bm_fam = fams[(None, bm)]
-        if len(bm_fam.objects) == 1:
-            one_el += 1
-        else:
-            plural_bm_families[bm_fam] = True
-    print "%d families of one bound-method" % one_el
-    print "%d families with more than just one bound-method" % len(plural_bm_families)
-    for bm_fam in plural_bm_families:
-        print pretty_els(bm_fam.objects)
-    return plural_bm_families
-
-class Counters(dict):
-
-    def __getitem__(self, outcome):
-        if (isinstance(outcome, annmodel.SomeObject) or 
-            isinstance(outcome, tuple) and outcome and 
-            isinstance(outcome[0], annmodel.SomeObject)):
-            for k in self.iterkeys():
-                if k == outcome:
-                    outcome = k
-                    break
-            else:
-                raise KeyError
-        return dict.__getitem__(self, outcome)
-
-    def get(self, outcome, defl):
-        try:
-            return self[outcome]
-        except KeyError:
-            return defl
-
-    def __setitem__(self, outcome, c):
-        if (isinstance(outcome, annmodel.SomeObject) or 
-            isinstance(outcome, tuple) and outcome and 
-            isinstance(outcome[0], annmodel.SomeObject)):
-            for k in self.iterkeys():
-                if k == outcome:
-                    outcome = k
-                    break
-        return dict.__setitem__(self, outcome, c)