[pypy-svn] r25731 - in pypy/dist/pypy/translator/c: . test

arigo at codespeak.net arigo at codespeak.net
Wed Apr 12 19:49:01 CEST 2006


Author: arigo
Date: Wed Apr 12 19:49:00 2006
New Revision: 25731

Modified:
   pypy/dist/pypy/translator/c/node.py
   pypy/dist/pypy/translator/c/test/test_lltyped.py
Log:
C back-end hacks for _subarray.


Modified: pypy/dist/pypy/translator/c/node.py
==============================================================================
--- pypy/dist/pypy/translator/c/node.py	(original)
+++ pypy/dist/pypy/translator/c/node.py	Wed Apr 12 19:49:00 2006
@@ -3,7 +3,7 @@
      Struct, Array, FixedSizeArray, FuncType, PyObjectType, typeOf, \
      GcStruct, GcArray, GC_CONTAINER, ContainerType, \
      parentlink, Ptr, PyObject, Void, OpaqueType, Float, \
-     RuntimeTypeInfo, getRuntimeTypeInfo, Char
+     RuntimeTypeInfo, getRuntimeTypeInfo, Char, _subarray
 from pypy.translator.c.funcgen import FunctionCodeGenerator
 from pypy.translator.c.external import CExternalFunctionCodeGenerator
 from pypy.translator.c.support import USESLOTS # set to False if necessary while refactoring
@@ -459,14 +459,15 @@
 
     def __init__(self, db, T, obj):
         ContainerNode.__init__(self, db, T, obj)
-        self.ptrname = self.name
+        if not isinstance(obj, _subarray):   # XXX hackish
+            self.ptrname = self.name
 
     def basename(self):
         return self.T._name
 
     def enum_dependencies(self):
-        for name in self.T._names:   # _names == ['item0', 'item1', ...]
-            yield getattr(self.obj, name)
+        for i in range(self.obj.getlength()):
+            yield self.obj.getitem(i)
 
     def getlength(self):
         return 1    # not variable-sized!

Modified: pypy/dist/pypy/translator/c/test/test_lltyped.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_lltyped.py	(original)
+++ pypy/dist/pypy/translator/c/test/test_lltyped.py	Wed Apr 12 19:49:00 2006
@@ -128,3 +128,35 @@
         fn = self.getcompiled(llf)
         res = fn(4)
         assert res == -1
+
+    def test_cast_subarray_pointer(self):
+        A = GcArray(Signed)
+        a = malloc(A, 5)
+        a[0] = 0
+        a[1] = 10
+        a[2] = 20
+        a[3] = 30
+        a[4] = 40
+        BOX = Ptr(FixedSizeArray(Signed, 2))
+        b01 = cast_subarray_pointer(BOX, a, 0)
+        b12 = cast_subarray_pointer(BOX, a, 1)
+        b23 = cast_subarray_pointer(BOX, a, 2)
+        b34 = cast_subarray_pointer(BOX, a, 3)
+        def llf(n=int):
+            saved = a[n]
+            a[n] = 1000
+            try:
+                return b01[0] + b12[0] + b23[1] + b34[1]
+            finally:
+                a[n] = saved
+        fn = self.getcompiled(llf)
+        res = fn(0)
+        assert res == 1000 + 10 + 30 + 40
+        res = fn(1)
+        assert res == 0 + 1000 + 30 + 40
+        res = fn(2)
+        assert res == 0 + 10 + 30 + 40
+        res = fn(3)
+        assert res == 0 + 10 + 1000 + 40
+        res = fn(4)
+        assert res == 0 + 10 + 30 + 1000



More information about the Pypy-commit mailing list