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

hpk at codespeak.net hpk at codespeak.net
Tue Jul 5 17:38:48 CEST 2005


Author: hpk
Date: Tue Jul  5 17:38:46 2005
New Revision: 14298

Modified:
   pypy/dist/pypy/translator/llvm2/codewriter.py
   pypy/dist/pypy/translator/llvm2/funcnode.py
   pypy/dist/pypy/translator/llvm2/structnode.py
   pypy/dist/pypy/translator/llvm2/test/test_genllvm.py
   pypy/dist/pypy/translator/llvm2/varsize.py
Log:
(rxe, hpk) 

made a first string test pass! 
it turned out that getsubstruct and getfield 
were doing wrong things. 



Modified: pypy/dist/pypy/translator/llvm2/codewriter.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/codewriter.py	(original)
+++ pypy/dist/pypy/translator/llvm2/codewriter.py	Tue Jul  5 17:38:46 2005
@@ -4,7 +4,7 @@
 from pypy.translator.llvm2.genllvm import use_boehm_gc
 
 log = log.codewriter 
-show_line_numbers = True
+show_line_numbers = False # True
 count = count().next
 
 class CodeWriter(object): 

Modified: pypy/dist/pypy/translator/llvm2/funcnode.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/funcnode.py	(original)
+++ pypy/dist/pypy/translator/llvm2/funcnode.py	Tue Jul  5 17:38:46 2005
@@ -129,6 +129,7 @@
     def write_block_operations(self, codewriter, block):
         opwriter = OpWriter(self.db, codewriter)
         for op in block.operations:
+            codewriter.comment(str(op))
             opwriter.write_operation(op)
     def write_startblock(self, codewriter, block):
         self.write_block_operations(codewriter, block)
@@ -286,14 +287,19 @@
         targetvar = self.db.repr_arg(op.result)
         targettype = self.db.repr_arg_type(op.result)
         assert targettype != "void"
-        if isinstance(op.result.concretetype, lltype.ContainerType):
-            # noop
-            self.codewriter.cast(targetvar, targettype, tmpvar, targettype)
-        else:
-            self.codewriter.load(targetvar, targettype, tmpvar)
-
-    getsubstruct = getfield
+        self.codewriter.load(targetvar, targettype, tmpvar)
 
+    def getsubstruct(self, op): 
+        typ = self.db.repr_arg_type(op.args[0]) 
+        typevar = self.db.repr_arg(op.args[0])
+        fieldnames = list(op.args[0].concretetype.TO._names)
+        index = fieldnames.index(op.args[1].value)
+        targetvar = self.db.repr_arg(op.result)
+        self.codewriter.getelementptr(targetvar, typ, 
+                                      typevar, ("uint", index))        
+        targettype = self.db.repr_arg_type(op.result)
+        assert targettype != "void"
+         
     def setfield(self, op): 
         tmpvar = self.db.repr_tmpvar()
         type = self.db.repr_arg_type(op.args[0]) 
@@ -316,11 +322,7 @@
                                       ("uint", 1), (indextype, index))
         targetvar = self.db.repr_arg(op.result)
         targettype = self.db.repr_arg_type(op.result)
-        if isinstance(op.result.concretetype, lltype.ContainerType):
-            # noop
-            self.codewriter.cast(targetvar, targettype, tmpvar, targettype)
-        else:
-            self.codewriter.load(targetvar, targettype, tmpvar)
+        self.codewriter.load(targetvar, targettype, tmpvar)
 
     def setarrayitem(self, op):
         array = self.db.repr_arg(op.args[0])

Modified: pypy/dist/pypy/translator/llvm2/structnode.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/structnode.py	(original)
+++ pypy/dist/pypy/translator/llvm2/structnode.py	Tue Jul  5 17:38:46 2005
@@ -60,13 +60,16 @@
 
         # build up a list of indices to get to the last 
         # var-sized struct (or rather the according array) 
-        indices_to_array = [("int", 0)]
-        s = self.struct
-        while isinstance(s, lltype.Struct):
-            last_pos = len(s._names_without_voids()) - 1
+        indices_to_array = [] 
+        current = self.struct
+        while isinstance(current, lltype.Struct):
+            last_pos = len(current._names_without_voids()) - 1
             indices_to_array.append(("uint", last_pos))
-            s = s._flds[s._names_without_voids()[-1]]
-        arraytype = self.db.repr_arg_type(s)
+            name = current._names_without_voids()[-1]
+            current = current._flds[name]
+        assert isinstance(current, lltype.Array)
+        arraytype = self.db.repr_arg_type(current.OF)
+        # XXX write type info as a comment 
         varsize.write_constructor(codewriter, 
             self.ref, self.constructor_decl, arraytype, 
             indices_to_array)

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	Tue Jul  5 17:38:46 2005
@@ -314,7 +314,7 @@
         for j in range(6): 
             assert f(i,j) == list_basic_ops(i,j)
 
-def xtest_string_simple(): 
+def test_string_simple(): 
     def string_simple(i): 
         return ord(str(i))
     f = compile_function(string_simple, [int], view=False)

Modified: pypy/dist/pypy/translator/llvm2/varsize.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/varsize.py	(original)
+++ pypy/dist/pypy/translator/llvm2/varsize.py	Tue Jul  5 17:38:46 2005
@@ -23,7 +23,7 @@
 
     # the following indices access the last element in the array 
     elemindices = list(indices_to_array) + [("uint", 1), ("int", "%len")]
-    
+   
     codewriter.openfunc(constructor_decl)
     codewriter.getelementptr("%size", ref + "*", "null", *elemindices) 
     codewriter.cast("%usize", elemtype + "*", "%size", "uint")



More information about the Pypy-commit mailing list