Commits

Amaury Forgeot d'Arc committed 9014bb4

Start a list of "predefined int types" used by compute_restype(left, right)

  • Participants
  • Parent commits 43d1532
  • Branches real-rffi.INT

Comments (0)

Files changed (1)

File pypy/rlib/rarithmetic.py

         return self_type
     if self_type in (bool, int, long):
         return other_type
-    return build_int(None, self_type.SIGNED and other_type.SIGNED, max(self_type.BITS, other_type.BITS))
+    return get_int(self_type.SIGNED and other_type.SIGNED, max(self_type.BITS, other_type.BITS))
 
 def signedtype(t):
     if t in (bool, int, long):
     if t is int:
         return int
     if t.BITS <= r_int.BITS:
-        return build_int(None, t.SIGNED, r_int.BITS)
+        return get_int(t.SIGNED, r_int.BITS)
     else:
         assert t.BITS <= r_longlong.BITS
-        return build_int(None, t.SIGNED, r_longlong.BITS)
+        return get_int(t.SIGNED, r_longlong.BITS)
 
 def most_neg_value_of_same_type(x):
     from pypy.rpython.lltypesystem import lltype
         return super(unsigned_int, klass).__new__(klass, val & klass.MASK)
     typemap = {}
 
+def get_int(sign, bits):
+    try:
+        return _predefined_ints[sign, bits]
+    except KeyError:
+        raise TypeError('No predefined %sint%d'%(['u', ''][sign], bits))
+
 def build_int(name, sign, bits):
     sign = bool(sign)
     if sign:
     else:
         base_int_type = unsigned_int
     mask = (2 ** bits) - 1
-    if name is None:
-        raise TypeError('No predefined %sint%d'%(['u', ''][sign], bits))
     int_type = type(name, (base_int_type,), {'MASK': mask,
                                              'BITS': bits,
                                              'SIGN': sign})
 else:
     r_int64 = int
 
+_predefined_ints = {
+    (True, 64): r_longlong,
+    (False, 64): r_ulonglong,
+    }
 
 def rstring_to_float(s):
     if USE_SHORT_FLOAT_REPR: