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

arigo at codespeak.net arigo at codespeak.net
Sun Apr 9 19:16:09 CEST 2006


Author: arigo
Date: Sun Apr  9 19:16:07 2006
New Revision: 25635

Modified:
   pypy/dist/pypy/translator/c/database.py
   pypy/dist/pypy/translator/c/funcgen.py
   pypy/dist/pypy/translator/c/node.py
   pypy/dist/pypy/translator/c/test/test_lltyped.py
Log:
(arre, arigo)

Don't confuse C programmers and compilers so much about
pointers to arrays.



Modified: pypy/dist/pypy/translator/c/database.py
==============================================================================
--- pypy/dist/pypy/translator/c/database.py	(original)
+++ pypy/dist/pypy/translator/c/database.py	Sun Apr  9 19:16:07 2006
@@ -91,8 +91,13 @@
         if isinstance(T, Primitive):
             return PrimitiveType[T]
         elif isinstance(T, Ptr):
-            typename = self.gettype(T.TO)   # who_asks not propagated
-            return typename.replace('@', '*@')
+            if isinstance(T.TO, FixedSizeArray):
+                # /me blames C
+                node = self.gettypedefnode(T.TO)
+                return node.getptrtype()
+            else:
+                typename = self.gettype(T.TO)   # who_asks not propagated
+                return typename.replace('@', '*@')
         elif isinstance(T, (Struct, Array)):
             node = self.gettypedefnode(T, varlength=varlength)
             if who_asks is not None:

Modified: pypy/dist/pypy/translator/c/funcgen.py
==============================================================================
--- pypy/dist/pypy/translator/c/funcgen.py	(original)
+++ pypy/dist/pypy/translator/c/funcgen.py	Sun Apr  9 19:16:07 2006
@@ -428,7 +428,11 @@
     OP_BARE_SETFIELD = OP_SETFIELD
 
     def OP_GETSUBSTRUCT(self, op):
-        return self.OP_GETFIELD(op, ampersand='&')
+        RESULT = self.lltypemap(op.result).TO
+        if isinstance(RESULT, FixedSizeArray):
+            return self.OP_GETFIELD(op, ampersand='')
+        else:
+            return self.OP_GETFIELD(op, ampersand='&')
 
     def OP_GETARRAYSIZE(self, op):
         ARRAY = self.lltypemap(op.args[0]).TO
@@ -442,9 +446,7 @@
     def OP_GETARRAYITEM(self, op):
         ARRAY = self.lltypemap(op.args[0]).TO
         items = self.expr(op.args[0])
-        if isinstance(ARRAY, FixedSizeArray):
-            items = '(*%s)' % (items,)
-        else:
+        if not isinstance(ARRAY, FixedSizeArray):
             items += '->items'
         return self.generic_get(op, '%s[%s]' % (items,
                                                 self.expr(op.args[1])))
@@ -452,9 +454,7 @@
     def OP_SETARRAYITEM(self, op):
         ARRAY = self.lltypemap(op.args[0]).TO
         items = self.expr(op.args[0])
-        if isinstance(ARRAY, FixedSizeArray):
-            items = '(*%s)' % (items,)
-        else:
+        if not isinstance(ARRAY, FixedSizeArray):
             items += '->items'
         return self.generic_set(op, '%s[%s]' % (items,
                                                 self.expr(op.args[1])))
@@ -462,9 +462,7 @@
     def OP_GETARRAYSUBSTRUCT(self, op):
         ARRAY = self.lltypemap(op.args[0]).TO
         items = self.expr(op.args[0])
-        if isinstance(ARRAY, FixedSizeArray):
-            items = '*%s' % (items,)
-        else:
+        if not isinstance(ARRAY, FixedSizeArray):
             items += '->items'
         return '%s = %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	Sun Apr  9 19:16:07 2006
@@ -251,6 +251,9 @@
         FIXEDARRAY = self.FIXEDARRAY
         return self.itemtypename.replace('@', '(@)[%d]' % FIXEDARRAY.length)
 
+    def getptrtype(self):
+        return self.itemtypename.replace('@', '*@')
+
     def access_expr(self, baseexpr, index):
         if not isinstance(index, int):
             assert index.startswith('item')
@@ -454,6 +457,10 @@
     if USESLOTS:
         __slots__ = ()
 
+    def __init__(self, db, T, obj):
+        ContainerNode.__init__(self, db, T, obj)
+        self.ptrname = self.name
+
     def basename(self):
         return self.T._name
 

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	Sun Apr  9 19:16:07 2006
@@ -121,7 +121,10 @@
         a = malloc(A, immortal=True)
         a[3].n = 42
         def llf(n=int):
-            return bool(a[n].f)
+            if a[n].f:
+                return a[n].f(a)
+            else:
+                return -1
         fn = self.getcompiled(llf)
         res = fn(4)
-        assert res == 0
+        assert res == -1



More information about the Pypy-commit mailing list