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

arigo at codespeak.net arigo at codespeak.net
Fri Sep 21 13:13:58 CEST 2007


Author: arigo
Date: Fri Sep 21 13:13:57 2007
New Revision: 46788

Modified:
   pypy/dist/pypy/translator/c/funcgen.py
   pypy/dist/pypy/translator/c/node.py
   pypy/dist/pypy/translator/c/test/test_lltyped.py
Log:
More fixes for barebone arrays.


Modified: pypy/dist/pypy/translator/c/funcgen.py
==============================================================================
--- pypy/dist/pypy/translator/c/funcgen.py	(original)
+++ pypy/dist/pypy/translator/c/funcgen.py	Fri Sep 21 13:13:57 2007
@@ -2,7 +2,7 @@
 from pypy.translator.c.support import USESLOTS # set to False if necessary while refactoring
 from pypy.translator.c.support import cdecl, ErrorValue
 from pypy.translator.c.support import llvalue_from_constant, gen_assignments
-from pypy.translator.c.support import c_string_constant
+from pypy.translator.c.support import c_string_constant, barebonearray
 from pypy.objspace.flow.model import Variable, Constant, Block
 from pypy.objspace.flow.model import c_last_exception, copygraph
 from pypy.rpython.lltypesystem.lltype import Ptr, PyObject, Void, Bool, Signed
@@ -546,7 +546,7 @@
     def OP_DIRECT_ARRAYITEMS(self, op):
         ARRAY = self.lltypemap(op.args[0]).TO
         items = self.expr(op.args[0])
-        if not isinstance(ARRAY, FixedSizeArray):
+        if not isinstance(ARRAY, FixedSizeArray) and not barebonearray(ARRAY):
             items += '->items'
         return '%s = %s;' % (self.expr(op.result), items)
 

Modified: pypy/dist/pypy/translator/c/node.py
==============================================================================
--- pypy/dist/pypy/translator/c/node.py	(original)
+++ pypy/dist/pypy/translator/c/node.py	Fri Sep 21 13:13:57 2007
@@ -253,7 +253,10 @@
             return '%s %s *@' % (self.typetag, self.name)
 
     def access_expr(self, baseexpr, index):
-        return '%s.items[%d]' % (baseexpr, index)
+        if self.barebone:
+            return '%s[%d]' % (baseexpr, index)
+        else:
+            return '%s.items[%d]' % (baseexpr, index)
 
     def ptr_access_expr(self, baseexpr, index):
         assert 0 <= index <= sys.maxint, "invalid constant index %r" % (index,)

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	Fri Sep 21 13:13:57 2007
@@ -130,7 +130,10 @@
 
     def test_direct_arrayitems(self):
         for a in [malloc(GcArray(Signed), 5),
-                  malloc(FixedSizeArray(Signed, 5), immortal=True)]:
+                  malloc(FixedSizeArray(Signed, 5), immortal=True),
+                  malloc(Array(Signed, hints={'nolength': True}), 5,
+                         immortal=True),
+                  ]:
             a[0] = 0
             a[1] = 10
             a[2] = 20
@@ -388,6 +391,31 @@
         res = fn(100)
         assert res == 3050
 
+    def test_structarray_nolength(self):
+        S = Struct('S', ('x', Signed))
+        A = Array(S, hints={'nolength': True})
+        a1 = malloc(A, 3, immortal=True)
+        a1[0].x = 30
+        a1[1].x = 300
+        a1[2].x = 3000
+        a1dummy = malloc(A, 2, immortal=True)
+
+        def f(n):
+            if n & 1:
+                src = a1dummy
+            else:
+                src = a1
+            a2 = malloc(A, n, flavor='raw')
+            for i in range(n):
+                a2[i].x = src[i % 3].x + i
+            res = a2[n // 2].x
+            free(a2, flavor='raw')
+            return res
+
+        fn = self.getcompiled(f, [int])
+        res = fn(100)
+        assert res == 3050
+
     def test_arithmetic_cornercases(self):
         import operator, sys
         from pypy.rlib.unroll import unrolling_iterable



More information about the Pypy-commit mailing list