[pypy-svn] r14200 - in pypy/dist/pypy/translator/llvm2: . test

rxe at codespeak.net rxe at codespeak.net
Mon Jul 4 12:30:55 CEST 2005


Author: rxe
Date: Mon Jul  4 12:30:54 2005
New Revision: 14200

Modified:
   pypy/dist/pypy/translator/llvm2/arraynode.py
   pypy/dist/pypy/translator/llvm2/node.py
   pypy/dist/pypy/translator/llvm2/test/test_genllvm.py
Log:
Make arrays work with non primitive types.

Unfortunately to set ref we need to wait until the dependent nodes have been 
setup.  This is an intermediate checkin while it is decided how we should make
the framework more flexible.



Modified: pypy/dist/pypy/translator/llvm2/arraynode.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/arraynode.py	(original)
+++ pypy/dist/pypy/translator/llvm2/arraynode.py	Mon Jul  4 12:30:54 2005
@@ -13,16 +13,32 @@
         self.db = db
         assert isinstance(array, lltype.Array)
         self.array = array
-        ref_template = "%%array.%s." % array.OF
         c = count()
-        self.ref = ref_template + str(c)
+        self.ref_template = "%%array.%s." + str(c)
+        self.ref = self.getref()
         self.constructor_ref = "%%new.array.%s" % c 
-        self.constructor_decl = "%s * %s(int %%len)" % (
-                    self.ref, self.constructor_ref)
+
+    def __str__(self):
+        return "<ArrayTypeNode %r>" % self.ref
+
+    def getref(self):
+        try:
+            arrayname = self.db.repr_arg_type(self.array.OF)
+        except KeyError:
+            arrayname = str(self.array.OF)
+        arrayname = arrayname.replace("%", "")
+        arrayname = arrayname.replace("*", "PTR")
+        return self.ref_template % arrayname
         
+    def get_structure_decl(self):
+        if not hasattr(self, "constructor_decl"):
+            self.constructor_decl =  "%s * %s(int %%len)" % \
+                                    (self.ref, self.constructor_ref)    
+        return self.constructor_decl
+
     def writedecl(self, codewriter): 
         # declaration for constructor
-        codewriter.declare(self.constructor_decl)
+        codewriter.declare(self.get_structure_decl())
 
     def writeimpl(self, codewriter):
         """ this function generates a LLVM function like the following:
@@ -39,7 +55,7 @@
            ret %array* %result
         }"""
         log.writeimpl(self.ref)
-        codewriter.openfunc(self.constructor_decl)
+        codewriter.openfunc(self.get_structure_decl())
         indices = [("uint", 1), ("int", "%len")]
         codewriter.getelementptr("%size", self.ref + "*",
                                  "null", *indices)
@@ -52,9 +68,6 @@
         codewriter.ret(self.ref+"*", "%result")
         codewriter.closefunc()
 
-    def __str__(self):
-        return "<ArrayTypeNode %r>" % self.ref
-
     def setup(self):
         self.db.prepare_repr_arg_type(self.array.OF)
         self._issetup = True
@@ -113,5 +126,5 @@
         lenitems = len(self.value.items)
         lenstr = ".%s" % lenitems
         codewriter.globalinstance(self.ref,
-                                  self.db.repr_arg_type() + lenstr,
+                                  self.db.repr_arg_type(self.value._TYPE),
                                   self.get_values())

Modified: pypy/dist/pypy/translator/llvm2/node.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/node.py	(original)
+++ pypy/dist/pypy/translator/llvm2/node.py	Mon Jul  4 12:30:54 2005
@@ -1,6 +1,9 @@
 class LLVMNode(object):
     def _get_ref(self):
-        return self._ref
+        if callable(self._ref):
+            return self._ref()
+        else:
+            return self._ref
     def _set_ref(self, ref):
         if hasattr(self, "_ref"):
             raise TypeError, ("can only set ref once! currently: %s" %

Modified: pypy/dist/pypy/translator/llvm2/test/test_genllvm.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/test/test_genllvm.py	(original)
+++ pypy/dist/pypy/translator/llvm2/test/test_genllvm.py	Mon Jul  4 12:30:54 2005
@@ -258,12 +258,12 @@
     assert f(1) == 2
     assert f(2) == 3
 
-def Xtest_list_list_getitem(): 
+def test_list_list_getitem(): 
     def list_list_getitem(): 
         l = [[1]]
         return l[0][0]
     f = compile_function(list_list_getitem, [])
-    assert f() == 2
+    assert f() == 1
 
 def Xtest_list_getitem_pbc(): 
     l = [1,2]



More information about the Pypy-commit mailing list