Commits

Maciej Fijalkowski committed c1fe98c Draft Merge

merge

Comments (0)

Files changed (3)

pypy/rlib/rarithmetic.py

     # whatever size a long has, make it big enough for a pointer.
     return _get_bitsize(_long_typecode)
 
-# exported for now for testing array values. 
+# exported for now for testing array values.
 # might go into its own module.
 def get_long_pattern(x):
     """get the bit pattern for a long, adjusted to pointer size"""
 # used in tests for ctypes and for genc and friends
 # to handle the win64 special case:
 is_emulated_long = _long_typecode != 'l'
-    
+
 LONG_BIT = _get_long_bit()
 LONG_MASK = (2**LONG_BIT)-1
 LONG_TEST = 2**(LONG_BIT-1)
         y = long(other)
         return self._widen(other, x + y)
     __radd__ = __add__
-    
+
     def __sub__(self, other):
         x = long(self)
         y = long(other)
         y = long(self)
         x = long(other)
         return self._widen(other, x - y)
-    
+
     def __mul__(self, other):
         x = long(self)
         if not isinstance(other, (int, long)):
         res = pow(x, y, m)
         return self._widen(other, res)
 
+
 class signed_int(base_int):
     SIGNED = True
+
     def __new__(klass, val=0):
-        if type(val) is float:
+        if isinstance(val, (float, str)):
             val = long(val)
-        if val > klass.MASK>>1 or val < -(klass.MASK>>1)-1:
-            raise OverflowError("%s does not fit in signed %d-bit integer"%(val, klass.BITS))
+        if val > klass.MASK >> 1 or val < -(klass.MASK >> 1) - 1:
+            raise OverflowError("%s does not fit in signed %d-bit integer" % (val, klass.BITS))
         if val < 0:
             val = ~ ((~val) & klass.MASK)
         return super(signed_int, klass).__new__(klass, val)
     typemap = {}
 
+
 class unsigned_int(base_int):
     SIGNED = False
+
     def __new__(klass, val=0):
-        if isinstance(val, (float, long)):
+        if isinstance(val, (float, long, str)):
             val = long(val)
         return super(unsigned_int, klass).__new__(klass, val & klass.MASK)
     typemap = {}
         def compute_annotation(self):
             from pypy.annotation import model as annmodel
             return annmodel.SomeInteger(knowntype=int_type)
-            
+
     class ForTypeEntry(extregistry.ExtRegistryEntry):
         _about_ = int_type
 
             v_result, = hop.inputargs(hop.r_result.lowleveltype)
             hop.exception_cannot_occur()
             return v_result
-            
+
     return int_type
 
 class BaseIntValueEntry(extregistry.ExtRegistryEntry):
     def compute_annotation(self):
         from pypy.annotation import model as annmodel
         return annmodel.SomeInteger(knowntype=r_ulonglong)
-        
+
 class BaseIntTypeEntry(extregistry.ExtRegistryEntry):
     _about_ = base_int
 
     """ Convert little->big endian and the opposite
     """
     from pypy.rpython.lltypesystem import lltype, rffi
-    
+
     T = lltype.typeOf(arg)
     # XXX we cannot do arithmetics on small ints
     if isinstance(arg, base_int):

pypy/rpython/lltypesystem/rbuiltin.py

-from pypy.tool.pairtype import pairtype
 from pypy.annotation import model as annmodel
-from pypy.rpython.lltypesystem import lltype
-from pypy.rpython.lltypesystem import rclass
+from pypy.rlib import objectmodel
+from pypy.rpython.lltypesystem import lltype, rclass
 from pypy.rpython.lltypesystem.rdict import rtype_r_dict
-from pypy.rlib import objectmodel
-from pypy.rpython.rmodel import TyperError, Constant
-from pypy.rpython.rbool import bool_repr
+from pypy.rpython.rmodel import TyperError
+
 
 def rtype_builtin_isinstance(hop):
     hop.exception_cannot_occur()
 
 BUILTIN_TYPER[weakref.ref] = rtype_weakref_create
 BUILTIN_TYPER[llmemory.weakref_create] = rtype_weakref_create
-BUILTIN_TYPER[llmemory.weakref_deref ] = rtype_weakref_deref
+BUILTIN_TYPER[llmemory.weakref_deref] = rtype_weakref_deref
 BUILTIN_TYPER[llmemory.cast_ptr_to_weakrefptr] = rtype_cast_ptr_to_weakrefptr
 BUILTIN_TYPER[llmemory.cast_weakrefptr_to_ptr] = rtype_cast_weakrefptr_to_ptr

pypy/rpython/rbuiltin.py

-from pypy.tool.pairtype import pairtype
 from pypy.annotation import model as annmodel
 from pypy.objspace.flow.model import Constant
-from pypy.rpython.lltypesystem import lltype, rclass, llmemory
-from pypy.rpython import rint, raddress
 from pypy.rlib import rarithmetic, objectmodel
+from pypy.rpython import raddress, rptr, extregistry
 from pypy.rpython.error import TyperError
-from pypy.rpython.rmodel import Repr, IntegerRepr, inputconst
-from pypy.rpython.rrange import rtype_builtin_range, rtype_builtin_xrange
-from pypy.rpython.rrange import rtype_builtin_enumerate
-from pypy.rpython import rstr
-from pypy.rpython import rptr
-from pypy.tool import sourcetools
-from pypy.rpython import extregistry
+from pypy.rpython.lltypesystem import lltype, llmemory
+from pypy.rpython.rmodel import Repr
+from pypy.tool.pairtype import pairtype
+
 
 class __extend__(annmodel.SomeBuiltin):
     def rtyper_makerepr(self, rtyper):
     kwds_i = {}
     for i, key in enumerate(keywords):
         index = arguments.keywords_w[i]
-        kwds_i['i_'+key] = index
+        kwds_i['i_' + key] = index
 
     return hop, kwds_i
 
     r_func, nimplicitarg = r_callable.get_r_implfunc()
     s_callable = r_callable.get_s_callable()
 
-    nbargs = len(hop.args_s) - 1 + nimplicitarg 
+    nbargs = len(hop.args_s) - 1 + 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"
 
 
 # collect all functions
-import __builtin__, exceptions
+import __builtin__
 BUILTIN_TYPER = {}
 for name, value in globals().items():
     if name.startswith('rtype_builtin_'):
 
     hop.has_implicit_exception(MemoryError)   # record that we know about it
     hop.exception_is_here()
-    return hop.genop(opname, vlist, resulttype = hop.r_result.lowleveltype)
+    return hop.genop(opname, vlist, resulttype=hop.r_result.lowleveltype)
 
 def rtype_free(hop, i_flavor, i_track_allocation=None):
     vlist = [hop.inputarg(hop.args_r[0], arg=0)]
         elif ORIG == llmemory.Address:
             return llops.genop('cast_adr_to_ptr', [v_value], resulttype = TGT)
         elif isinstance(ORIG, lltype.Primitive):
-            v_value = gen_cast(llops, lltype.Signed, v_value)            
+            v_value = gen_cast(llops, lltype.Signed, v_value)
             return llops.genop('cast_int_to_ptr', [v_value], resulttype=TGT)
     elif TGT == llmemory.Address and isinstance(ORIG, lltype.Ptr):
         return llops.genop('cast_ptr_to_adr', [v_value], resulttype = TGT)
     flags = {'flavor': flavor}
     cflags = hop.inputconst(lltype.Void, flags)
     return hop.genop('free', [vinst, cflags])
-    
+
 BUILTIN_TYPER[objectmodel.free_non_gc_object] = rtype_free_non_gc_object
 
 # keepalive_until_here
 BUILTIN_TYPER[llmemory.cast_adr_to_ptr] = rtype_cast_adr_to_ptr
 BUILTIN_TYPER[llmemory.cast_adr_to_int] = rtype_cast_adr_to_int
 BUILTIN_TYPER[llmemory.cast_int_to_adr] = rtype_cast_int_to_adr
-