[pypy-svn] r65106 - in pypy/branch/pyjitpl5/pypy/rpython: . lltypesystem ootypesystem test

antocuni at codespeak.net antocuni at codespeak.net
Wed May 6 17:12:58 CEST 2009


Author: antocuni
Date: Wed May  6 17:12:57 2009
New Revision: 65106

Modified:
   pypy/branch/pyjitpl5/pypy/rpython/lltypesystem/rvirtualizable2.py
   pypy/branch/pyjitpl5/pypy/rpython/ootypesystem/rclass.py
   pypy/branch/pyjitpl5/pypy/rpython/ootypesystem/rvirtualizable2.py
   pypy/branch/pyjitpl5/pypy/rpython/rvirtualizable2.py
   pypy/branch/pyjitpl5/pypy/rpython/test/test_rvirtualizable2.py
Log:
complete the implementation of rvirtualizable2 for ootype. test pass


Modified: pypy/branch/pyjitpl5/pypy/rpython/lltypesystem/rvirtualizable2.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/rpython/lltypesystem/rvirtualizable2.py	(original)
+++ pypy/branch/pyjitpl5/pypy/rpython/lltypesystem/rvirtualizable2.py	Wed May  6 17:12:57 2009
@@ -49,6 +49,15 @@
     def gencast(self, llops, vinst):
         return llops.genop('cast_pointer', [vinst], resulttype=self)
 
+    def get_mangled_fields(self):
+        return [mangled_name for _, (mangled_name, _) in self.fields.items()]
+
+    def get_field(self, attr):
+        return self.fields[attr]
+
+    def is_in_fields(self, attr):
+        return attr in self.fields
+
     def set_vable(self, llops, vinst, force_cast=False):
         if self.top_of_virtualizable_hierarchy:
             if force_cast:

Modified: pypy/branch/pyjitpl5/pypy/rpython/ootypesystem/rclass.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/rpython/ootypesystem/rclass.py	(original)
+++ pypy/branch/pyjitpl5/pypy/rpython/ootypesystem/rclass.py	Wed May  6 17:12:57 2009
@@ -191,6 +191,9 @@
         self.gcflavor = gcflavor
 
     def _setup_repr(self, hints=None):
+        if hints:
+            self.lowleveltype._hints.update(hints)
+
         if self.classdef is None:
             self.allfields = {}
             self.allmethods = {}
@@ -408,12 +411,9 @@
         s_inst = hop.args_s[0]
         attr = hop.args_s[1].const
         mangled = mangle(attr, self.rtyper.getconfig())
-        v_attr = hop.inputconst(ootype.Void, mangled)
         if mangled in self.allfields:
             # regular instance attributes
-            self.lowleveltype._check_field(mangled)
-            return hop.genop("oogetfield", [v_inst, v_attr],
-                             resulttype = hop.r_result.lowleveltype)
+            return self.getfield(v_inst, attr, hop.llops)
         elif mangled in self.allmethods:
             # special case for methods: represented as their 'self' only
             # (see MethodsPBCRepr)
@@ -452,13 +452,17 @@
         self.lowleveltype._check_field(mangled)
         r_value = self.allfields[mangled]
         v_inst, _, v_newval = hop.inputargs(self, ootype.Void, r_value)
-        v_attr = hop.inputconst(ootype.Void, mangled)
-        return hop.genop('oosetfield', [v_inst, v_attr, v_newval])
+        self.setfield(v_inst, attr, v_newval, hop.llops)
+
+    def getfield(self, v_inst, attr, llops):
+        mangled = mangle(attr, self.rtyper.getconfig())
+        v_attr = inputconst(ootype.Void, mangled)
+        r_value = self.allfields[mangled]
+        self.lowleveltype._check_field(mangled)
+        return llops.genop('oogetfield', [v_inst, v_attr],
+                           resulttype = r_value)
 
     def setfield(self, vinst, attr, vvalue, llops):
-        # this method emulates behaviour from the corresponding
-        # lltypesystem one. It is referenced in some obscure corners
-        # like rtyping of OSError.
         mangled_name = mangle(attr, self.rtyper.getconfig())
         cname = inputconst(ootype.Void, mangled_name)
         llops.genop('oosetfield', [vinst, cname, vvalue])

Modified: pypy/branch/pyjitpl5/pypy/rpython/ootypesystem/rvirtualizable2.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/rpython/ootypesystem/rvirtualizable2.py	(original)
+++ pypy/branch/pyjitpl5/pypy/rpython/ootypesystem/rvirtualizable2.py	Wed May  6 17:12:57 2009
@@ -1,6 +1,6 @@
 from pypy.rpython.rmodel import inputconst
 from pypy.rpython.ootypesystem import ootype
-from pypy.rpython.ootypesystem.rclass import InstanceRepr
+from pypy.rpython.ootypesystem.rclass import InstanceRepr, mangle
 from pypy.rpython.rvirtualizable2 import AbstractVirtualizableAccessor
 from pypy.rpython.rvirtualizable2 import AbstractVirtualizable2InstanceRepr
 
@@ -23,7 +23,17 @@
 
     def gencast(self, llops, vinst):
         raise NotImplementedError
-        #return llops.genop('cast_pointer', [vinst], resulttype=self)
+
+    def get_mangled_fields(self):
+        return self.allfields.keys()
+
+    def get_field(self, attr):
+        mangled = mangle(attr, self.rtyper.getconfig())
+        return mangled, self.allfields[mangled]
+
+    def is_in_fields(self, attr):
+        mangled = mangle(attr, self.rtyper.getconfig())
+        return mangled in self.allfields
 
     def set_vable(self, llops, vinst, force_cast=False):
         pass # TODO

Modified: pypy/branch/pyjitpl5/pypy/rpython/rvirtualizable2.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/rpython/rvirtualizable2.py	(original)
+++ pypy/branch/pyjitpl5/pypy/rpython/rvirtualizable2.py	Wed May  6 17:12:57 2009
@@ -67,10 +67,19 @@
     def set_vable(self, llops, vinst, force_cast=False):
         raise NotImplementedError
 
+    def get_mangled_fields(self):
+        raise NotImplementedError
+
+    def get_field(self, attr):
+        raise NotImplementedError
+
+    def is_in_fields(self, attr):
+        raise NotImplementedError
+
     def _setup_repr(self):
         self._setup_instance_repr()
         my_redirected_fields = []
-        for _, (mangled_name, _) in self.fields.items():
+        for mangled_name in self.get_mangled_fields():
             my_redirected_fields.append(mangled_name)
         self.my_redirected_fields = dict.fromkeys(my_redirected_fields)    
         if self.top_of_virtualizable_hierarchy:
@@ -87,8 +96,8 @@
 
     def getfield(self, vinst, attr, llops, force_cast=False, flags={}):
         """Read the given attribute (or __class__ for the type) of 'vinst'."""
-        if not flags.get('access_directly') and attr in self.fields:
-            mangled_name, r = self.fields[attr]
+        if not flags.get('access_directly') and self.is_in_fields(attr):
+            mangled_name, r = self.get_field(attr)
             if mangled_name in self.my_redirected_fields:
                 if force_cast:
                     vinst = self.gencast(llops, vinst)
@@ -101,8 +110,8 @@
     def setfield(self, vinst, attr, vvalue, llops, force_cast=False,
                  flags={}):
         """Write the given attribute (or __class__ for the type) of 'vinst'."""
-        if not flags.get('access_directly') and attr in self.fields:
-            mangled_name, r = self.fields[attr]
+        if not flags.get('access_directly') and self.is_in_fields(attr):
+            mangled_name, r = self.get_field(attr)
             if mangled_name in self.my_redirected_fields:
                 if force_cast:
                     vinst = self.gencast(llops, vinst)

Modified: pypy/branch/pyjitpl5/pypy/rpython/test/test_rvirtualizable2.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/rpython/test/test_rvirtualizable2.py	(original)
+++ pypy/branch/pyjitpl5/pypy/rpython/test/test_rvirtualizable2.py	Wed May  6 17:12:57 2009
@@ -22,9 +22,15 @@
         v_inst = op_getfield.args[0]
         assert op_promote.opname == 'promote_virtualizable'
         assert op_promote.args[0] is v_inst
+        TYPE = self.gettype(v_inst)
+        assert TYPE._hints['virtualizable2']
+
 
 class TestLLtype(LLRtypeMixin, BaseTest):
 
+    def gettype(self, v):
+        return v.concretetype.TO
+
     def test_simple(self):
         def f(v):
             vinst = V(v)
@@ -35,5 +41,8 @@
         assert res.inst_v == 42
         assert not res.vable_rti
 
-## class TestOOtype(OORtypeMixin, BaseTest):
-##     pass
+class TestOOtype(OORtypeMixin, BaseTest):
+
+    def gettype(self, v):
+        return v.concretetype
+



More information about the Pypy-commit mailing list