Commits

Maciej Fijalkowski committed 3301be1

(fijal, antocuni) fix translation

Comments (0)

Files changed (2)

pypy/annotation/classdef.py

                 "the attribute here; the list of read locations is:\n" +
                 '\n'.join([str(loc[0]) for loc in self.read_locations]))
 
-
 class ClassDef(object):
     "Wraps a user class."
 

pypy/module/micronumpy/types.py

     _mixin_ = True
     
     def _read(self, storage, width, i, offset):
-        return byteswap(Primitive._read(self, storage, width, i, offset))
+        if we_are_translated():
+            res = libffi.array_getitem(clibffi.cast_type_to_ffitype(self.T),
+                                        width, storage, i, offset)
+        else:
+            res = libffi.array_getitem_T(self.T, width, storage, i, offset)
+        return byteswap(res)
 
     def _write(self, storage, width, i, offset, value):
-        Primitive._write(self, storage, width, i, offset, byteswap(value))
+        value = byteswap(value)
+        if we_are_translated():
+            libffi.array_setitem(clibffi.cast_type_to_ffitype(self.T),
+                                 width, storage, i, offset, value)
+        else:
+            libffi.array_setitem_T(self.T, width, storage, i, offset, value)
 
     def pack_str(self, box):
         return struct.pack(self.format_code, byteswap(self.unbox(box)))
 
 class Bool(BaseType, Primitive):
+    _attrs_ = ()
+
     T = lltype.Bool
     BoxType = interp_boxes.W_BoolBox
     format_code = "?"
     _mixin_ = True
 
 class Int8(BaseType, Integer):
+    _attrs_ = ()
+
     T = rffi.SIGNEDCHAR
     BoxType = interp_boxes.W_Int8Box
     format_code = "b"
 NonNativeInt8 = Int8
 
 class UInt8(BaseType, Integer):
+    _attrs_ = ()
+
     T = rffi.UCHAR
     BoxType = interp_boxes.W_UInt8Box
     format_code = "B"
 NonNativeUInt8 = UInt8
 
 class Int16(BaseType, Integer):
+    _attrs_ = ()
+
     T = rffi.SHORT
     BoxType = interp_boxes.W_Int16Box
     format_code = "h"
 
 class NonNativeInt16(BaseType, NonNativeInteger):
+    _attrs_ = ()
+
     T = rffi.SHORT
     BoxType = interp_boxes.W_Int16Box
     format_code = "h"
 
 class UInt16(BaseType, Integer):
+    _attrs_ = ()
+
     T = rffi.USHORT
     BoxType = interp_boxes.W_UInt16Box
     format_code = "H"
 
 class NonNativeUInt16(BaseType, NonNativeInteger):
+    _attrs_ = ()
+
     T = rffi.USHORT
     BoxType = interp_boxes.W_UInt16Box
     format_code = "H"
 
 class Int32(BaseType, Integer):
+    _attrs_ = ()
+
     T = rffi.INT
     BoxType = interp_boxes.W_Int32Box
     format_code = "i"
 
 class NonNativeInt32(BaseType, NonNativeInteger):
+    _attrs_ = ()
+
     T = rffi.INT
     BoxType = interp_boxes.W_Int32Box
     format_code = "i"
 
 class UInt32(BaseType, Integer):
+    _attrs_ = ()
+
     T = rffi.UINT
     BoxType = interp_boxes.W_UInt32Box
     format_code = "I"
 
 class NonNativeUInt32(BaseType, NonNativeInteger):
+    _attrs_ = ()
+
     T = rffi.UINT
     BoxType = interp_boxes.W_UInt32Box
     format_code = "I"
 
 class Long(BaseType, Integer):
+    _attrs_ = ()
+
     T = rffi.LONG
     BoxType = interp_boxes.W_LongBox
     format_code = "l"
 
 class NonNativeLong(BaseType, NonNativeInteger):
+    _attrs_ = ()
+
     T = rffi.LONG
     BoxType = interp_boxes.W_LongBox
     format_code = "l"
 
 class ULong(BaseType, Integer):
+    _attrs_ = ()
+
     T = rffi.ULONG
     BoxType = interp_boxes.W_ULongBox
     format_code = "L"
 
 class NonNativeULong(BaseType, NonNativeInteger):
+    _attrs_ = ()
+
     T = rffi.ULONG
     BoxType = interp_boxes.W_ULongBox
     format_code = "L"
 
 class Int64(BaseType, Integer):
+    _attrs_ = ()
+
     T = rffi.LONGLONG
     BoxType = interp_boxes.W_Int64Box
     format_code = "q"
 
 class NonNativeInt64(BaseType, NonNativeInteger):
+    _attrs_ = ()
+
     T = rffi.LONGLONG
     BoxType = interp_boxes.W_Int64Box
     format_code = "q"    
     return self.box(value)
 
 class UInt64(BaseType, Integer):
+    _attrs_ = ()
+
     T = rffi.ULONGLONG
     BoxType = interp_boxes.W_UInt64Box
     format_code = "Q"
     _coerce = func_with_new_name(_uint64_coerce, '_coerce')
 
 class NonNativeUInt64(BaseType, NonNativeInteger):
+    _attrs_ = ()
+
     T = rffi.ULONGLONG
     BoxType = interp_boxes.W_UInt64Box
     format_code = "Q"
 class NonNativeFloat(NonNativePrimitive, Float):
     _mixin_ = True
 
+    def _read(self, storage, width, i, offset):
+        if we_are_translated():
+            res = libffi.array_getitem(clibffi.cast_type_to_ffitype(self.T),
+                                        width, storage, i, offset)
+        else:
+            res = libffi.array_getitem_T(self.T, width, storage, i, offset)
+        #return byteswap(res)
+        return res
+
+    def _write(self, storage, width, i, offset, value):
+        #value = byteswap(value) XXX
+        if we_are_translated():
+            libffi.array_setitem(clibffi.cast_type_to_ffitype(self.T),
+                                 width, storage, i, offset, value)
+        else:
+            libffi.array_setitem_T(self.T, width, storage, i, offset, value)
+
+    def pack_str(self, box):
+        # XXX byteswap
+        return struct.pack(self.format_code, self.unbox(box))
+
+
 class Float32(BaseType, Float):
+    _attrs_ = ()
+
     T = rffi.FLOAT
     BoxType = interp_boxes.W_Float32Box
     format_code = "f"
 
 class NonNativeFloat32(BaseType, NonNativeFloat):
+    _attrs_ = ()
+
     T = rffi.FLOAT
     BoxType = interp_boxes.W_Float32Box
     format_code = "f"    
 
 class Float64(BaseType, Float):
+    _attrs_ = ()
+
     T = rffi.DOUBLE
     BoxType = interp_boxes.W_Float64Box
     format_code = "d"
 
 class NonNativeFloat64(BaseType, NonNativeFloat):
+    _attrs_ = ()
+
     T = rffi.DOUBLE
     BoxType = interp_boxes.W_Float64Box
     format_code = "d"
 
-class CompositeType(BaseType):
-    def __init__(self, offsets_and_fields, size):
-        self.offsets_and_fields = offsets_and_fields
-        self.size = size
-
-    def get_element_size(self):
-        return self.size
-
 class BaseStringType(object):
     _mixin_ = True
     
 
 NonNativeUnicodeType = UnicodeType
 
-class RecordType(CompositeType):
+class RecordType(BaseType):
+
     T = lltype.Char
+
+    def __init__(self, offsets_and_fields, size):
+        self.offsets_and_fields = offsets_and_fields
+        self.size = size
+
+    def get_element_size(self):
+        return self.size
     
     def read(self, arr, width, i, offset, dtype=None):
         if dtype is None:
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.