[pypy-svn] r13218 - in pypy: branch/translator-without-old-genc/c dist/pypy/rpython

arigo at codespeak.net arigo at codespeak.net
Thu Jun 9 09:44:35 CEST 2005


Author: arigo
Date: Thu Jun  9 09:44:31 2005
New Revision: 13218

Modified:
   pypy/branch/translator-without-old-genc/c/funcgen.py
   pypy/dist/pypy/rpython/rbuiltin.py
   pypy/dist/pypy/rpython/rclass.py
Log:
Support for cast_parent in rtyper.

Sort local variable declarations in the generated C function in a futile
attempt to make them slightly more readable.



Modified: pypy/branch/translator-without-old-genc/c/funcgen.py
==============================================================================
--- pypy/branch/translator-without-old-genc/c/funcgen.py	(original)
+++ pypy/branch/translator-without-old-genc/c/funcgen.py	Thu Jun  9 09:44:31 2005
@@ -85,12 +85,15 @@
         for a in self.graph.getargs():
             inputargset[a] = True
 
+        result_by_name = []
         for v in self.allvariables():
             if v not in inputargset:
                 result = cdecl(self.typemap[v], v.name) + ';'
                 if self.lltypemap[v] == Void:
                     result = '/*%s*/' % result
-                yield result
+                result_by_name.append((v._name, result))
+        result_by_name.sort()
+        return [result for name, result in result_by_name]
 
     # ____________________________________________________________
 
@@ -415,6 +418,13 @@
                   ]
         return '\t'.join(result)
 
+    def OP_CAST_PARENT(self, op, err):
+        TYPE = self.lltypemap[op.result]
+        typename = self.db.gettype(TYPE)
+        return '%s = (%s)%s;' % (self.expr(op.result),
+                                 cdecl(typename, ''),
+                                 self.expr(op.args[0]))
+
     def OP_SAME_AS(self, op, err):
         result = []
         assert self.lltypemap[op.args[0]] == self.lltypemap[op.result]

Modified: pypy/dist/pypy/rpython/rbuiltin.py
==============================================================================
--- pypy/dist/pypy/rpython/rbuiltin.py	(original)
+++ pypy/dist/pypy/rpython/rbuiltin.py	Thu Jun  9 09:44:31 2005
@@ -6,6 +6,7 @@
 from pypy.rpython.rtyper import TyperError
 from pypy.rpython.rrange import rtype_builtin_range
 from pypy.rpython.rmodel import Repr, TyperError
+from pypy.rpython import rptr
 
 
 class __extend__(annmodel.SomeBuiltin):
@@ -119,8 +120,16 @@
 def rtype_const_result(hop):
     return hop.inputconst(Void, hop.s_result.const)
 
+def rtype_cast_parent(hop):
+    assert hop.args_s[0].is_constant()
+    assert isinstance(hop.args_r[1], rptr.PtrRepr)
+    v_type, v_input = hop.inputargs(Void, hop.args_r[1])
+    return hop.genop('cast_parent', [v_input],    # v_type implicit in r_result
+                     resulttype = hop.r_result.lowleveltype)
+
 
 BUILTIN_TYPER[lltype.malloc] = rtype_malloc
+BUILTIN_TYPER[lltype.cast_parent] = rtype_cast_parent
 BUILTIN_TYPER[lltype.typeOf] = rtype_const_result
 BUILTIN_TYPER[lltype.nullptr] = rtype_const_result
 BUILTIN_TYPER[rarithmetic.intmask] = rtype_intmask

Modified: pypy/dist/pypy/rpython/rclass.py
==============================================================================
--- pypy/dist/pypy/rpython/rclass.py	(original)
+++ pypy/dist/pypy/rpython/rclass.py	Thu Jun  9 09:44:31 2005
@@ -189,8 +189,7 @@
     def fromparentpart(self, v_vtableptr, llops):
         """Return the vtable pointer cast from the parent vtable's type
         to self's vtable type."""
-        ctype = inputconst(Void, self.lowleveltype)
-        return llops.genop('cast_parent', [ctype, v_vtableptr],
+        return llops.genop('cast_parent', [v_vtableptr],
                            resulttype=self.lowleveltype)
 
     def fromtypeptr(self, vcls, llops):
@@ -435,8 +434,7 @@
                 r_ins2 = r_ins2.rbase
             cast_chain.reverse()
             for r in cast_chain:
-                ctype = inputconst(Void, r.lowleveltype)
-                v = llops.genop('cast_parent', [ctype, v],
+                v = llops.genop('cast_parent', [v],
                                 resulttype = r.lowleveltype)
             return v
         else:



More information about the Pypy-commit mailing list