[pypy-commit] pypy numpy-dtype-refactor: progress, we now inherit from int

alex_gaynor noreply at buildbot.pypy.org
Thu Nov 10 19:13:26 CET 2011


Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: numpy-dtype-refactor
Changeset: r49286:ef2232d35126
Date: 2011-11-10 13:13 -0500
http://bitbucket.org/pypy/pypy/changeset/ef2232d35126/

Log:	progress, we now inherit from int

diff --git a/pypy/module/micronumpy/interp_boxes.py b/pypy/module/micronumpy/interp_boxes.py
--- a/pypy/module/micronumpy/interp_boxes.py
+++ b/pypy/module/micronumpy/interp_boxes.py
@@ -1,7 +1,11 @@
 from pypy.interpreter.baseobjspace import Wrappable
 from pypy.interpreter.typedef import TypeDef
+from pypy.objspace.std.inttype import int_typedef
+from pypy.rlib.rarithmetic import LONG_BIT
 
 
+MIXIN_64 = (int_typedef,) if LONG_BIT == 64 else ()
+
 class W_GenericBox(Wrappable):
     pass
 
@@ -22,6 +26,9 @@
 class W_SignedIntegerBox(W_IntegerBox):
     pass
 
+class W_LongBox(W_SignedIntegerBox):
+    pass
+
 class W_Int64Box(W_SignedIntegerBox):
     pass
 
@@ -42,4 +49,29 @@
 
 W_BoolBox.typedef = TypeDef("bool_", W_GenericBox.typedef,
     __module__ = "numpy",
+)
+
+W_NumberBox.typedef = TypeDef("number", W_GenericBox.typedef,
+    __module__ = "numpy",
+)
+
+W_IntegerBox.typedef = TypeDef("integer", W_NumberBox.typedef,
+    __module__ = "numpy",
+)
+
+W_SignedIntegerBox.typedef = TypeDef("signedinteger", W_IntegerBox.typedef,
+    __module__ = "numpy",
+)
+
+# XXX: fix for 32bit
+if LONG_BIT == 32:
+    long_name = "int32"
+elif LONG_BIT == 64:
+    long_name = "int64"
+W_LongBox.typedef = TypeDef(long_name, (W_SignedIntegerBox.typedef, int_typedef,),
+    __module__ = "numpy",
+)
+
+W_Int64Box.typedef = TypeDef("int64", (W_SignedIntegerBox.typedef,) + MIXIN_64,
+    __module__ = "numpy",
 )
\ No newline at end of file
diff --git a/pypy/module/micronumpy/interp_dtype.py b/pypy/module/micronumpy/interp_dtype.py
--- a/pypy/module/micronumpy/interp_dtype.py
+++ b/pypy/module/micronumpy/interp_dtype.py
@@ -135,15 +135,11 @@
             char="I",
         )
         if LONG_BIT == 32:
-            longtype = types.Int32()
-            unsigned_longtype = types.UInt32()
             name = "int32"
         elif LONG_BIT == 64:
-            longtype = types.Int64()
-            unsigned_longtype = types.UInt64()
             name = "int64"
         self.w_longdtype = W_Dtype(
-            longtype,
+            types.Long(),
             num=7,
             kind=SIGNEDLTR,
             name=name,
@@ -151,7 +147,7 @@
             alternate_constructors=[space.w_int],
         )
         self.w_ulongdtype = W_Dtype(
-            unsigned_longtype,
+            types.ULong(),
             num=8,
             kind=UNSIGNEDLTR,
             name="u" + name,
diff --git a/pypy/module/micronumpy/types.py b/pypy/module/micronumpy/types.py
--- a/pypy/module/micronumpy/types.py
+++ b/pypy/module/micronumpy/types.py
@@ -1,6 +1,7 @@
 from pypy.module.micronumpy import interp_boxes
 from pypy.objspace.std.floatobject import float2string
 from pypy.rlib import rfloat
+from pypy.rlib.rarithmetic import LONG_BIT
 from pypy.rpython.lltypesystem import lltype, rffi
 
 
@@ -85,6 +86,13 @@
 class UInt32(Primitive):
     T = rffi.UINT
 
+class Long(Primitive):
+    T = rffi.LONG
+    BoxType = interp_boxes.W_LongBox
+
+class ULong(Primitive):
+    T = rffi.ULONG
+
 class Int64(Integer):
     T = rffi.LONGLONG
     BoxType = interp_boxes.W_Int64Box


More information about the pypy-commit mailing list