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

arigo at codespeak.net arigo at codespeak.net
Thu Jun 25 22:40:02 CEST 2009


Author: arigo
Date: Thu Jun 25 22:40:00 2009
New Revision: 65970

Modified:
   pypy/branch/pyjitpl5/pypy/rpython/lltypesystem/rclass.py
   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:
Re-enable the production of 'promote_virtualizable'.


Modified: pypy/branch/pyjitpl5/pypy/rpython/lltypesystem/rclass.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/rpython/lltypesystem/rclass.py	(original)
+++ pypy/branch/pyjitpl5/pypy/rpython/lltypesystem/rclass.py	Thu Jun 25 22:40:00 2009
@@ -472,6 +472,7 @@
             cname = inputconst(Void, mangled_name)
             if force_cast:
                 vinst = llops.genop('cast_pointer', [vinst], resulttype=self)
+            self.hook_access_field(vinst, cname, llops, flags)
             return llops.genop('getfield', [vinst, cname], resulttype=r)
         else:
             if self.classdef is None:
@@ -487,6 +488,7 @@
             cname = inputconst(Void, mangled_name)
             if force_cast:
                 vinst = llops.genop('cast_pointer', [vinst], resulttype=self)
+            self.hook_access_field(vinst, cname, llops, flags)
             llops.genop('setfield', [vinst, cname, vvalue])
         else:
             if self.classdef is None:
@@ -494,6 +496,9 @@
             self.rbase.setfield(vinst, attr, vvalue, llops, force_cast=True,
                                 flags=flags)
 
+    def hook_access_field(self, vinst, cname, llops, flags):
+        pass        # for virtualizables; see rvirtualizable2.py
+
     def new_instance(self, llops, classcallhop=None):
         """Build a new instance, without calling __init__."""
         flavor = self.gcflavor

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	Thu Jun 25 22:40:00 2009
@@ -34,34 +34,23 @@
 class Virtualizable2InstanceRepr(AbstractVirtualizable2InstanceRepr, InstanceRepr):
 
     VirtualizableAccessor = VirtualizableAccessor
-##    op_getfield = 'getfield'
-##    op_setfield = 'setfield'
 
-##    def _setup_instance_repr(self):
-##        llfields = []
-##        if self.top_of_virtualizable_hierarchy:
-##            llfields.append(('vable_base', llmemory.Address))
-##            llfields.append(('vable_rti', VABLERTIPTR))
-##        InstanceRepr._setup_repr(self, llfields,
-##                                 hints = {'virtualizable2': True,
-##                                          'virtuals' : self.virtuals},
-##                                 adtmeths = {'access': self.accessor})
-
-##    def gencast(self, llops, vinst):
-##        return llops.genop('cast_pointer', [vinst], resulttype=self)
+    def _setup_repr_llfields(self):
+        llfields = []
+        if self.top_of_virtualizable_hierarchy:
+            llfields.append(('vable_base', llmemory.Address))
+            llfields.append(('vable_rti', VABLERTIPTR))
+        return llfields
 
     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:
-##                vinst = llops.genop('cast_pointer', [vinst], resulttype=self)
-##            cname = inputconst(lltype.Void, 'vable_rti')
-##            vvalue = inputconst(VABLERTIPTR, lltype.nullptr(VABLERTIPTR.TO))
-##            llops.genop('setfield', [vinst, cname, vvalue])
-##        else:
-##            self.rbase.set_vable(llops, vinst, force_cast=True)
+    def set_vable(self, llops, vinst, force_cast=False):
+        if self.top_of_virtualizable_hierarchy:
+            if force_cast:
+                vinst = llops.genop('cast_pointer', [vinst], resulttype=self)
+            cname = inputconst(lltype.Void, 'vable_rti')
+            vvalue = inputconst(VABLERTIPTR, lltype.nullptr(VABLERTIPTR.TO))
+            llops.genop('setfield', [vinst, cname, vvalue])
+        else:
+            self.rbase.set_vable(llops, vinst, force_cast=True)

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	Thu Jun 25 22:40:00 2009
@@ -465,14 +465,19 @@
         v_attr = inputconst(ootype.Void, mangled)
         r_value = self.allfields[mangled]
         self.lowleveltype._check_field(mangled)
+        self.hook_access_field(v_inst, v_attr, llops, {})    # XXX flags
         return llops.genop('oogetfield', [v_inst, v_attr],
                            resulttype = r_value)
 
     def setfield(self, vinst, attr, vvalue, llops):
         mangled_name = mangle(attr, self.rtyper.getconfig())
         cname = inputconst(ootype.Void, mangled_name)
+        self.hook_access_field(vinst, cname, llops, {})      # XXX flags
         llops.genop('oosetfield', [vinst, cname, vvalue])
 
+    def hook_access_field(self, vinst, cname, llops, flags):
+        pass        # for virtualizables; see rvirtualizable2.py
+
     def rtype_is_true(self, hop):
         vinst, = hop.inputargs(self)
         return hop.genop('oononnull', [vinst], resulttype=ootype.Bool)

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	Thu Jun 25 22:40:00 2009
@@ -18,23 +18,13 @@
 class Virtualizable2InstanceRepr(AbstractVirtualizable2InstanceRepr, InstanceRepr):
 
     VirtualizableAccessor = VirtualizableAccessor
-##    op_getfield = 'oogetfield'
-##    op_setfield = 'oosetfield'
 
-##    def _setup_instance_repr(self):
-##        InstanceRepr._setup_repr(self, hints = {'virtualizable2': True,
-##                                                'virtuals' : self.virtuals})
-
-##    def gencast(self, llops, vinst):
-##        raise NotImplementedError
+    def _setup_repr_llfields(self):
+        return None      # TODO
 
     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
+    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	Thu Jun 25 22:40:00 2009
@@ -13,16 +13,19 @@
     def __repr__(self):
         return '<VirtualizableAccessor for %s>' % getattr(self, 'TYPE', '?')
 
-##    def __getattr__(self, name):
-##        if name.startswith('getset') and 'getsets' not in self.__dict__:
-##            self.prepare_getsets()
-##            return getattr(self, name)
-##        else:
-##            raise AttributeError("%s object has no attribute %r" % (
-##                self.__class__.__name__, name))
+    def __getattr__(self, name):
+        if name.startswith('getset') and 'getsets' not in self.__dict__:
+            try:
+                self.prepare_getsets()
+            except AttributeError, e:
+                raise Exception("AttributeError: %s" % e)
+            return getattr(self, name)
+        else:
+            raise AttributeError("%s object has no attribute %r" % (
+                self.__class__.__name__, name))
 
-##    def prepare_getsets(self):
-##        raise NotImplementedError
+    def prepare_getsets(self):
+        raise NotImplementedError
 
     def _freeze_(self):
         return True
@@ -31,8 +34,6 @@
 class AbstractVirtualizable2InstanceRepr(AbstractInstanceRepr):
 
     VirtualizableAccessor = AbstractVirtualizableAccessor
-##    op_getfield = None
-##    op_setfield = None
 
     def _super(self):
         return super(AbstractVirtualizable2InstanceRepr, self)
@@ -48,26 +49,25 @@
         else:
             self.top_of_virtualizable_hierarchy = False
 
-##    def _setup_instance_repr(self):
-##        raise NotImplementedError
-
-##    def gencast(self, llops, vinst):
-##        raise NotImplementedError
+    def _setup_repr_llfields(self):
+        raise NotImplementedError
 
-##    def set_vable(self, llops, vinst, force_cast=False):
-##        raise NotImplementedError
+    def set_vable(self, llops, vinst, force_cast=False):
+        raise NotImplementedError
 
     def get_field(self, attr):
         raise NotImplementedError
 
-##    def is_in_fields(self, attr):
-##        raise NotImplementedError
-
     def _setup_repr(self):
         if self.top_of_virtualizable_hierarchy:
             hints = {'virtualizable2_accessor': self.accessor}
-            self._super()._setup_repr(hints = hints)
+            llfields = self._setup_repr_llfields()
+            if llfields:
+                self._super()._setup_repr(llfields, hints = hints)
+            else:
+                self._super()._setup_repr(hints = hints)
             my_redirected_fields = []
+            self.my_redirected_fields = {}
             c_vfields = self.classdef.classdesc.classdict['_virtualizable2_']
             for name in c_vfields.value:
                 if name.endswith('[*]'):
@@ -77,38 +77,18 @@
                     suffix = ''
                 mangled_name, r = self.get_field(name)
                 my_redirected_fields.append(mangled_name + suffix)
+                self.my_redirected_fields[mangled_name] = True
             self.accessor.initialize(self.object_type, my_redirected_fields)
         else:
+            self.my_redirected_fields = {}
             self._super()._setup_repr()
 
-##    def new_instance(self, llops, classcallhop=None):
-##        vptr = self._super().new_instance(llops, classcallhop)
-##        self.set_vable(llops, vptr)
-##        return vptr
-
-##    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 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)
-##                c_name = inputconst(lltype.Void, mangled_name)
-##                llops.genop('promote_virtualizable', [vinst, c_name])
-##                return llops.genop(self.op_getfield, [vinst, c_name],
-##                                   resulttype=r)
-##        return self._super().getfield(vinst, attr, llops, force_cast)
-
-##    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 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)
-##                c_name = inputconst(lltype.Void, mangled_name)
-##                llops.genop('promote_virtualizable', [vinst, c_name])
-##                llops.genop(self.op_setfield, [vinst, c_name, vvalue])
-##                return
-##        self._super().setfield(vinst, attr, vvalue, llops, force_cast)
+    def new_instance(self, llops, classcallhop=None):
+        vptr = self._super().new_instance(llops, classcallhop)
+        self.set_vable(llops, vptr)
+        return vptr
+
+    def hook_access_field(self, vinst, cname, llops, flags):
+        if not flags.get('access_directly'):
+            if cname.value in self.my_redirected_fields:
+                llops.genop('promote_virtualizable', [vinst, cname])

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	Thu Jun 25 22:40:00 2009
@@ -11,7 +11,6 @@
 
 class BaseTest(BaseRtypingTest):
     def test_generate_promote_virtualizable(self):
-        py.test.skip("later")
         def fn(n):
             vinst = V(n)
             return vinst.v
@@ -23,8 +22,6 @@
         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'] == True
 
     def test_accessor(self):
         class Base(object):



More information about the Pypy-commit mailing list