[pypy-svn] r65098 - in pypy/branch/pyjitpl5/pypy/rpython: . lltypesystem ootypesystem
antocuni at codespeak.net
antocuni at codespeak.net
Wed May 6 16:12:05 CEST 2009
Author: antocuni
Date: Wed May 6 16:12:04 2009
New Revision: 65098
Added:
pypy/branch/pyjitpl5/pypy/rpython/lltypesystem/rvirtualizable2.py (contents, props changed)
pypy/branch/pyjitpl5/pypy/rpython/ootypesystem/rvirtualizable2.py (contents, props changed)
Modified:
pypy/branch/pyjitpl5/pypy/rpython/ootypesystem/rclass.py
pypy/branch/pyjitpl5/pypy/rpython/rclass.py
pypy/branch/pyjitpl5/pypy/rpython/rvirtualizable2.py
pypy/branch/pyjitpl5/pypy/rpython/typesystem.py
Log:
(in-progress) add lltype and ootype specific versions of rvirtualizable2.py. TestOOtype still fails
Added: pypy/branch/pyjitpl5/pypy/rpython/lltypesystem/rvirtualizable2.py
==============================================================================
--- (empty file)
+++ pypy/branch/pyjitpl5/pypy/rpython/lltypesystem/rvirtualizable2.py Wed May 6 16:12:04 2009
@@ -0,0 +1,60 @@
+from pypy.rpython.rmodel import inputconst
+from pypy.rpython.lltypesystem import lltype, llmemory
+from pypy.rpython.lltypesystem.rvirtualizable import VABLERTIPTR
+from pypy.rpython.lltypesystem.rclass import InstanceRepr
+from pypy.rpython.rvirtualizable2 import AbstractVirtualizableAccessor
+from pypy.rpython.rvirtualizable2 import AbstractVirtualizable2InstanceRepr
+
+
+class VirtualizableAccessor(AbstractVirtualizableAccessor):
+
+ def prepare_getsets(self):
+ self.getsets = {}
+ STRUCT = self.TYPE
+ for fieldname in self.redirected_fields:
+ FIELDTYPE = getattr(STRUCT, fieldname)
+ GETTER = lltype.FuncType([lltype.Ptr(STRUCT)], FIELDTYPE)
+ SETTER = lltype.FuncType([lltype.Ptr(STRUCT), FIELDTYPE],
+ lltype.Void)
+ VABLE_GETSET = lltype.Struct('vable_getset',
+ ('get', lltype.Ptr(GETTER)),
+ ('set', lltype.Ptr(SETTER)),
+ hints={'immutable': True})
+ getset = lltype.malloc(VABLE_GETSET, flavor='raw', zero=False)
+ # as long as no valid pointer has been put in the structure
+ # by the JIT, accessing the fields should raise, in order
+ # to prevent constant-folding
+ py.test.raises(lltype.UninitializedMemoryAccess, "getset.get")
+ py.test.raises(lltype.UninitializedMemoryAccess, "getset.set")
+ self.getsets[fieldname] = getset
+ setattr(self, 'getset_' + fieldname, getset)
+
+
+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 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 Wed May 6 16:12:04 2009
@@ -190,7 +190,7 @@
self.object_type = self.lowleveltype
self.gcflavor = gcflavor
- def _setup_repr(self):
+ def _setup_repr(self, hints=None):
if self.classdef is None:
self.allfields = {}
self.allmethods = {}
Added: pypy/branch/pyjitpl5/pypy/rpython/ootypesystem/rvirtualizable2.py
==============================================================================
--- (empty file)
+++ pypy/branch/pyjitpl5/pypy/rpython/ootypesystem/rvirtualizable2.py Wed May 6 16:12:04 2009
@@ -0,0 +1,29 @@
+from pypy.rpython.rmodel import inputconst
+from pypy.rpython.ootypesystem import ootype
+from pypy.rpython.ootypesystem.rclass import InstanceRepr
+from pypy.rpython.rvirtualizable2 import AbstractVirtualizableAccessor
+from pypy.rpython.rvirtualizable2 import AbstractVirtualizable2InstanceRepr
+
+
+class VirtualizableAccessor(AbstractVirtualizableAccessor):
+
+ def prepare_getsets(self):
+ self.getsets = {} # TODO
+
+
+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
+ #return llops.genop('cast_pointer', [vinst], resulttype=self)
+
+ def set_vable(self, llops, vinst, force_cast=False):
+ pass # TODO
Modified: pypy/branch/pyjitpl5/pypy/rpython/rclass.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/rpython/rclass.py (original)
+++ pypy/branch/pyjitpl5/pypy/rpython/rclass.py Wed May 6 16:12:04 2009
@@ -52,11 +52,9 @@
from pypy.rpython.lltypesystem import rvirtualizable
return rvirtualizable.VirtualizableInstanceRepr(rtyper, classdef)
elif virtualizable2:
- assert rtyper.type_system.name == 'lltypesystem'
assert len(unboxed) == 0
assert gcflavor == 'gc'
- from pypy.rpython import rvirtualizable2
- return rvirtualizable2.Virtualizable2InstanceRepr(rtyper, classdef)
+ return rtyper.type_system.rvirtualizable2.Virtualizable2InstanceRepr(rtyper, classdef)
elif len(unboxed) == 0:
return rtyper.type_system.rclass.InstanceRepr(rtyper, classdef, gcflavor)
else:
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 16:12:04 2009
@@ -1,14 +1,13 @@
import py
from pypy.rpython.rmodel import inputconst
-from pypy.rpython.lltypesystem import lltype, llmemory
-from pypy.rpython.lltypesystem.rclass import InstanceRepr
-from pypy.rpython.lltypesystem.rvirtualizable import VABLERTIPTR
+from pypy.rpython.lltypesystem import lltype
+from pypy.rpython.rclass import AbstractInstanceRepr
-class VirtualizableAccessor(object):
+class AbstractVirtualizableAccessor(object):
- def initialize(self, STRUCT, redirected_fields, PARENT=None):
- self.STRUCT = STRUCT
+ def initialize(self, TYPE, redirected_fields, PARENT=None):
+ self.TYPE = TYPE
self.redirected_fields = redirected_fields
self.subaccessors = []
if PARENT is None:
@@ -18,7 +17,7 @@
self.parent.subaccessors.append(self)
def __repr__(self):
- return '<VirtualizableAccessor for %s>' % getattr(self, 'STRUCT', '?')
+ return '<VirtualizableAccessor for %s>' % getattr(self, 'TYPE', '?')
def __getattr__(self, name):
if name.startswith('getset') and 'getsets' not in self.__dict__:
@@ -29,34 +28,23 @@
self.__class__.__name__, name))
def prepare_getsets(self):
- self.getsets = {}
- STRUCT = self.STRUCT
- for fieldname in self.redirected_fields:
- FIELDTYPE = getattr(STRUCT, fieldname)
- GETTER = lltype.FuncType([lltype.Ptr(STRUCT)], FIELDTYPE)
- SETTER = lltype.FuncType([lltype.Ptr(STRUCT), FIELDTYPE],
- lltype.Void)
- VABLE_GETSET = lltype.Struct('vable_getset',
- ('get', lltype.Ptr(GETTER)),
- ('set', lltype.Ptr(SETTER)),
- hints={'immutable': True})
- getset = lltype.malloc(VABLE_GETSET, flavor='raw', zero=False)
- # as long as no valid pointer has been put in the structure
- # by the JIT, accessing the fields should raise, in order
- # to prevent constant-folding
- py.test.raises(lltype.UninitializedMemoryAccess, "getset.get")
- py.test.raises(lltype.UninitializedMemoryAccess, "getset.set")
- self.getsets[fieldname] = getset
- setattr(self, 'getset_' + fieldname, getset)
+ raise NotImplementedError
def _freeze_(self):
return True
-class Virtualizable2InstanceRepr(InstanceRepr):
+class AbstractVirtualizable2InstanceRepr(AbstractInstanceRepr):
+
+ VirtualizableAccessor = AbstractVirtualizableAccessor
+ op_getfield = None
+ op_setfield = None
+
+ def _super(self):
+ return super(AbstractVirtualizable2InstanceRepr, self)
def __init__(self, rtyper, classdef):
- InstanceRepr.__init__(self, rtyper, classdef)
+ self._super().__init__(rtyper, classdef)
classdesc = classdef.classdesc
if '_virtualizable2_' in classdesc.classdict:
basedesc = classdesc.basedesc
@@ -68,17 +56,19 @@
self.virtuals = tuple(classdesc.classdict['_always_virtual_'].value)
except KeyError:
self.virtuals = ()
- self.accessor = VirtualizableAccessor()
+ self.accessor = self.VirtualizableAccessor()
+
+ def _setup_instance_repr(self):
+ raise NotImplementedError
+
+ def gencast(self, llops, vinst):
+ raise NotImplementedError
+
+ def set_vable(self, llops, vinst, force_cast=False):
+ raise NotImplementedError
def _setup_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})
+ self._setup_instance_repr()
my_redirected_fields = []
for _, (mangled_name, _) in self.fields.items():
my_redirected_fields.append(mangled_name)
@@ -89,18 +79,9 @@
self.accessor.initialize(self.object_type, my_redirected_fields,
self.rbase.lowleveltype.TO)
- 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 new_instance(self, llops, classcallhop=None):
- vptr = InstanceRepr.new_instance(self, llops, classcallhop)
+ vptr = self._super().new_instance(llops, classcallhop)
self.set_vable(llops, vptr)
return vptr
@@ -110,12 +91,12 @@
mangled_name, r = self.fields[attr]
if mangled_name in self.my_redirected_fields:
if force_cast:
- vinst = llops.genop('cast_pointer', [vinst],
- resulttype=self)
+ vinst = self.gencast(llops, vinst)
c_name = inputconst(lltype.Void, mangled_name)
llops.genop('promote_virtualizable', [vinst, c_name])
- return llops.genop('getfield', [vinst, c_name], resulttype=r)
- return InstanceRepr.getfield(self, vinst, attr, llops, force_cast)
+ 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={}):
@@ -124,10 +105,9 @@
mangled_name, r = self.fields[attr]
if mangled_name in self.my_redirected_fields:
if force_cast:
- vinst = llops.genop('cast_pointer', [vinst],
- resulttype=self)
+ vinst = self.gencast(llops, vinst)
c_name = inputconst(lltype.Void, mangled_name)
llops.genop('promote_virtualizable', [vinst, c_name])
- llops.genop('setfield', [vinst, c_name, vvalue])
+ llops.genop(self.op_setfield, [vinst, c_name, vvalue])
return
- InstanceRepr.setfield(self, vinst, attr, vvalue, llops, force_cast)
+ self._super().setfield(vinst, attr, vvalue, llops, force_cast)
Modified: pypy/branch/pyjitpl5/pypy/rpython/typesystem.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/rpython/typesystem.py (original)
+++ pypy/branch/pyjitpl5/pypy/rpython/typesystem.py Wed May 6 16:12:04 2009
@@ -22,7 +22,8 @@
return None
if name in ('rclass', 'rpbc', 'rbuiltin', 'rtuple', 'rlist',
'rslice', 'rdict', 'rrange', 'rstr', 'rgeneric',
- 'll_str', 'rbuilder', 'exceptiondata'):
+ 'll_str', 'rbuilder', 'rvirtualizable2',
+ 'exceptiondata'):
mod = load(name)
if mod is not None:
setattr(self, name, mod)
More information about the Pypy-commit
mailing list