[pypy-svn] r18532 - in pypy/branch/hl-backend/pypy/rpython: . ootypesystem ootypesystem/test

ac at codespeak.net ac at codespeak.net
Fri Oct 14 11:58:06 CEST 2005


Author: ac
Date: Fri Oct 14 11:58:06 2005
New Revision: 18532

Added:
   pypy/branch/hl-backend/pypy/rpython/ootypesystem/rootype.py   (contents, props changed)
   pypy/branch/hl-backend/pypy/rpython/ootypesystem/test/test_oortype.py   (contents, props changed)
Modified:
   pypy/branch/hl-backend/pypy/rpython/ootypesystem/ootype.py
   pypy/branch/hl-backend/pypy/rpython/rbuiltin.py
   pypy/branch/hl-backend/pypy/rpython/rtyper.py
Log:
Initial work on rtyping code using explicit ootype.

Modified: pypy/branch/hl-backend/pypy/rpython/ootypesystem/ootype.py
==============================================================================
--- pypy/branch/hl-backend/pypy/rpython/ootypesystem/ootype.py	(original)
+++ pypy/branch/hl-backend/pypy/rpython/ootypesystem/ootype.py	Fri Oct 14 11:58:06 2005
@@ -37,7 +37,10 @@
         return new(self)
 
     def __repr__(self):
-        return '<%s %s>' % (self, self._name)
+        return '<%s>' % (self,)
+
+    def __str__(self):
+        return '%s(%s)' % (self.__class__.__name__, self._name)
 
     def _add_fields(self, fields):
         for name, defn in fields.iteritems():

Added: pypy/branch/hl-backend/pypy/rpython/ootypesystem/rootype.py
==============================================================================
--- (empty file)
+++ pypy/branch/hl-backend/pypy/rpython/ootypesystem/rootype.py	Fri Oct 14 11:58:06 2005
@@ -0,0 +1,21 @@
+from pypy.annotation import model as annmodel
+from pypy.rpython.rmodel import Repr
+
+class __extend__(annmodel.SomeOOInstance):
+    def rtyper_makerepr(self, rtyper):
+        return OOInstanceRepr(self.ootype)
+    def rtyper_makekey(self):
+        return self.__class__, self.ootype
+
+class OOInstanceRepr(Repr):
+    def __init__(self, ootype):
+        self.lowleveltype = ootype
+
+class __extend__(annmodel.SomeOOClass):
+    pass
+
+class __extend__(annmodel.SomeOOBoundMeth):
+    pass
+
+class __extend__(annmodel.SomeOOStaticMeth):
+    pass

Added: pypy/branch/hl-backend/pypy/rpython/ootypesystem/test/test_oortype.py
==============================================================================
--- (empty file)
+++ pypy/branch/hl-backend/pypy/rpython/ootypesystem/test/test_oortype.py	Fri Oct 14 11:58:06 2005
@@ -0,0 +1,25 @@
+
+from pypy.rpython.ootypesystem.ootype import *
+from pypy.annotation import model as annmodel
+from pypy.objspace.flow import FlowObjSpace
+from pypy.translator.translator import Translator
+
+def gengraph(f, *args):
+    t = Translator(f)
+    t.annotate(args)
+    #t.view()
+    t.specialize(type_system="ootype")
+    #t.view()
+    return t.flowgraphs[f]
+
+def test_simple_class():
+    C = Instance("test", None, {'a': Signed})
+    
+    def f():
+        c = new(C)
+        return c
+
+    g = gengraph(f)
+    rettype = g.getreturnvar().concretetype
+    assert rettype == C
+    

Modified: pypy/branch/hl-backend/pypy/rpython/rbuiltin.py
==============================================================================
--- pypy/branch/hl-backend/pypy/rpython/rbuiltin.py	(original)
+++ pypy/branch/hl-backend/pypy/rpython/rbuiltin.py	Fri Oct 14 11:58:06 2005
@@ -11,6 +11,7 @@
 from pypy.rpython.rbool import bool_repr
 from pypy.rpython.rdict import rtype_r_dict
 from pypy.tool import sourcetools
+from pypy.rpython.ootypesystem import ootype
 
 class __extend__(annmodel.SomeBuiltin):
     def rtyper_makerepr(self, rtyper):
@@ -263,6 +264,11 @@
     return hop.genop('runtime_type_info', vlist,
                  resulttype = rptr.PtrRepr(lltype.Ptr(lltype.RuntimeTypeInfo)))
 
+def rtype_new(hop):
+    assert hop.args_s[0].is_constant()
+    vlist = hop.inputargs(lltype.Void)
+    return hop.genop('new', vlist,
+                     resulttype = hop.r_result.lowleveltype)
 
 BUILTIN_TYPER[lltype.malloc] = rtype_malloc
 BUILTIN_TYPER[lltype.cast_pointer] = rtype_cast_pointer
@@ -277,6 +283,7 @@
 BUILTIN_TYPER[objectmodel.we_are_translated] = rtype_we_are_translated
 
 BUILTIN_TYPER[objectmodel.hlinvoke] = rtype_hlinvoke
+BUILTIN_TYPER[ootype.new] = rtype_new
 
 from pypy.rpython import extfunctable
 

Modified: pypy/branch/hl-backend/pypy/rpython/rtyper.py
==============================================================================
--- pypy/branch/hl-backend/pypy/rpython/rtyper.py	(original)
+++ pypy/branch/hl-backend/pypy/rpython/rtyper.py	Fri Oct 14 11:58:06 2005
@@ -149,8 +149,9 @@
         self.already_seen = {}
 
         self.specialize_more_blocks()
-        self.exceptiondata.make_helpers(self)
-        self.specialize_more_blocks()   # for the helpers just made
+        if self.exceptiondata is not None:
+            self.exceptiondata.make_helpers(self)
+            self.specialize_more_blocks()   # for the helpers just made
 
     def specialize_more_blocks(self):
         while True:
@@ -797,3 +798,4 @@
 from pypy.rpython import rexternalobj
 from pypy.rpython import rptr
 from pypy.rpython import raddress # memory addresses
+from pypy.rpython.ootypesystem import rootype



More information about the Pypy-commit mailing list