[pypy-svn] r32354 - pypy/branch/kill-keepalives/pypy/translator/c

arigo at codespeak.net arigo at codespeak.net
Fri Sep 15 14:17:41 CEST 2006


Author: arigo
Date: Fri Sep 15 14:17:38 2006
New Revision: 32354

Modified:
   pypy/branch/kill-keepalives/pypy/translator/c/funcgen.py
   pypy/branch/kill-keepalives/pypy/translator/c/node.py
Log:
Fix funcgen for the corner case of getinteriorfield when the top-level
container is a FixedSizeArray.



Modified: pypy/branch/kill-keepalives/pypy/translator/c/funcgen.py
==============================================================================
--- pypy/branch/kill-keepalives/pypy/translator/c/funcgen.py	(original)
+++ pypy/branch/kill-keepalives/pypy/translator/c/funcgen.py	Fri Sep 15 14:17:38 2006
@@ -476,18 +476,25 @@
 
     def interior_expr(self, args, rettype=False):
         TYPE = args[0].concretetype.TO
-        expr = '(*(' + self.expr(args[0]) + '))'
-        for arg in args[1:]:
+        expr = self.expr(args[0])
+        for i, arg in enumerate(args[1:]):
             defnode = self.db.gettypedefnode(TYPE)
             if arg.concretetype is Void:
                 fieldname = arg.value
-                expr = defnode.access_expr(expr, fieldname)
-                TYPE = getattr(TYPE, fieldname)
+                if i == 0:
+                    expr = defnode.ptr_access_expr(expr, fieldname)
+                else:
+                    expr = defnode.access_expr(expr, fieldname)
+                if isinstance(TYPE, lltype.FixedSizeArray):
+                    TYPE = TYPE.OF
+                else:
+                    TYPE = getattr(TYPE, fieldname)
             else:
-                if not isinstance(TYPE, FixedSizeArray):
-                    expr = '(%s).items[%s]'%(expr, self.expr(arg))
+                indexexpr = self.expr(arg)
+                if i == 0:
+                    expr = defnode.ptr_access_expr_varindex(expr, indexexpr)
                 else:
-                    expr = '(%s)[%s]'%(expr, self.expr(arg))
+                    expr = defnode.access_expr_varindex(expr, indexexpr)
                 TYPE = TYPE.OF
         if rettype:
             return expr, TYPE

Modified: pypy/branch/kill-keepalives/pypy/translator/c/node.py
==============================================================================
--- pypy/branch/kill-keepalives/pypy/translator/c/node.py	(original)
+++ pypy/branch/kill-keepalives/pypy/translator/c/node.py	Fri Sep 15 14:17:38 2006
@@ -237,10 +237,13 @@
         return 'struct %s @' % self.name
 
     def access_expr(self, baseexpr, index):
-        return '%s.items[%d]' % (baseexpr, index)
+        return '%s.items[%s]' % (baseexpr, index)
 
     def ptr_access_expr(self, baseexpr, index):
-        return '%s->items[%d]' % (baseexpr, index)
+        return '%s->items[%s]' % (baseexpr, index)
+
+    access_expr_varindex     = access_expr
+    ptr_access_expr_varindex = ptr_access_expr
 
     def definition(self):
         gcpolicy = self.db.gcpolicy
@@ -318,13 +321,19 @@
         return self.itemtypename.replace('@', '*@')
 
     def access_expr(self, baseexpr, index):
-        if not isinstance(index, int):
-            assert index.startswith('item')
-            index = int(index[4:])
+        if isinstance(index, int):
+            return self.access_expr_varindex(baseexpr, str(index))
+        assert index.startswith('item')
+        index = int(index[4:])
         return '%s[%d]' % (baseexpr, index)
 
     ptr_access_expr = access_expr
 
+    def access_expr_varindex(self, baseexpr, indexexpr):
+        return '%s[%s]' % (baseexpr, indexexpr)
+
+    ptr_access_expr_varindex = access_expr_varindex
+
     def definition(self):
         return []    # no declaration is needed
 



More information about the Pypy-commit mailing list