[pypy-commit] pypy numpy-dtype-refactor: more translation fixes

alex_gaynor noreply at buildbot.pypy.org
Fri Nov 11 20:23:13 CET 2011


Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: numpy-dtype-refactor
Changeset: r49340:fb125d8a0233
Date: 2011-11-11 14:22 -0500
http://bitbucket.org/pypy/pypy/changeset/fb125d8a0233/

Log:	more translation fixes

diff --git a/pypy/module/micronumpy/compile.py b/pypy/module/micronumpy/compile.py
--- a/pypy/module/micronumpy/compile.py
+++ b/pypy/module/micronumpy/compile.py
@@ -72,8 +72,8 @@
     def float(self, w_obj):
         if isinstance(w_obj, FloatObject):
             return w_obj
-        assert isinstance(w_obj, interp_boxes.W_FloatingBox)
-        return FloatObject(w_obj.value)
+        assert isinstance(w_obj, interp_boxes.W_GenericBox)
+        return self.float(w_obj.descr_float(self))
 
     def float_w(self, w_obj):
         assert isinstance(w_obj, FloatObject)
@@ -90,7 +90,7 @@
         if isinstance(w_obj, IntObject):
             return w_obj
         assert isinstance(w_obj, interp_boxes.W_GenericBox)
-        return IntObject(int(w_obj.value))
+        return self.int(w_obj.descr_int(self))
 
     def is_true(self, w_obj):
         assert isinstance(w_obj, BoolObject)
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
@@ -15,7 +15,18 @@
         return getattr(get_dtype_cache(space), "w_%sdtype" % name)
     return get_dtype
 
+class PrimitiveBox(object):
+    _mixin_ = True
+
+    def __init__(self, value):
+        self.value = value
+
+    def convert_to(self, dtype):
+        return dtype.box(self.value)
+
 class W_GenericBox(Wrappable):
+    _attrs_ = ()
+
     def descr_repr(self, space):
         return space.wrap(self.get_dtype(space).itemtype.str_format(self))
 
@@ -56,19 +67,11 @@
     descr_abs = _unaryop_impl("absolute")
 
 
-class W_BoolBox(W_GenericBox):
-    def __init__(self, value):
-        self.value = value
-
-    def convert_to(self, dtype):
-        return dtype.box(self.value)
+class W_BoolBox(W_GenericBox, PrimitiveBox):
+    pass
 
 class W_NumberBox(W_GenericBox):
-    def __init__(self, value):
-        self.value = value
-
-    def convert_to(self, dtype):
-        return dtype.box(self.value)
+    pass
 
 class W_IntegerBox(W_NumberBox):
     pass
@@ -79,34 +82,34 @@
 class W_UnsignedIntgerBox(W_IntegerBox):
     pass
 
-class W_Int8Box(W_SignedIntegerBox):
+class W_Int8Box(W_SignedIntegerBox, PrimitiveBox):
     pass
 
-class W_UInt8Box(W_UnsignedIntgerBox):
+class W_UInt8Box(W_UnsignedIntgerBox, PrimitiveBox):
     pass
 
-class W_Int16Box(W_SignedIntegerBox):
+class W_Int16Box(W_SignedIntegerBox, PrimitiveBox):
     pass
 
-class W_UInt16Box(W_UnsignedIntgerBox):
+class W_UInt16Box(W_UnsignedIntgerBox, PrimitiveBox):
     pass
 
-class W_Int32Box(W_SignedIntegerBox):
+class W_Int32Box(W_SignedIntegerBox, PrimitiveBox):
     pass
 
-class W_UInt32Box(W_UnsignedIntgerBox):
+class W_UInt32Box(W_UnsignedIntgerBox, PrimitiveBox):
     pass
 
-class W_LongBox(W_SignedIntegerBox):
+class W_LongBox(W_SignedIntegerBox, PrimitiveBox):
     get_dtype = dtype_getter("long")
 
-class W_ULongBox(W_UnsignedIntgerBox):
+class W_ULongBox(W_UnsignedIntgerBox, PrimitiveBox):
     pass
 
-class W_Int64Box(W_SignedIntegerBox):
+class W_Int64Box(W_SignedIntegerBox, PrimitiveBox):
     get_dtype = dtype_getter("int64")
 
-class W_UInt64Box(W_UnsignedIntgerBox):
+class W_UInt64Box(W_UnsignedIntgerBox, PrimitiveBox):
     pass
 
 class W_InexactBox(W_NumberBox):
@@ -115,10 +118,10 @@
 class W_FloatingBox(W_InexactBox):
     pass
 
-class W_Float32Box(W_FloatingBox):
+class W_Float32Box(W_FloatingBox, PrimitiveBox):
     get_dtype = dtype_getter("float32")
 
-class W_Float64Box(W_FloatingBox):
+class W_Float64Box(W_FloatingBox, PrimitiveBox):
     get_dtype = dtype_getter("float64")
 
 


More information about the pypy-commit mailing list