[pypy-svn] r52226 - in pypy/branch/jit-refactoring/pypy/rpython: . lltypesystem ootypesystem
arigo at codespeak.net
arigo at codespeak.net
Thu Mar 6 19:03:30 CET 2008
Author: arigo
Date: Thu Mar 6 19:03:29 2008
New Revision: 52226
Modified:
pypy/branch/jit-refactoring/pypy/rpython/lltypesystem/rpbc.py
pypy/branch/jit-refactoring/pypy/rpython/ootypesystem/rpbc.py
pypy/branch/jit-refactoring/pypy/rpython/rpbc.py
Log:
Give these Structs a better name than just 'pbc' if possible.
Modified: pypy/branch/jit-refactoring/pypy/rpython/lltypesystem/rpbc.py
==============================================================================
--- pypy/branch/jit-refactoring/pypy/rpython/lltypesystem/rpbc.py (original)
+++ pypy/branch/jit-refactoring/pypy/rpython/lltypesystem/rpbc.py Thu Mar 6 19:03:29 2008
@@ -51,9 +51,12 @@
self.pbc_cache = {}
def _setup_repr(self):
+ # try to find a name for the Struct, arbitrarily using the longest
+ # common prefix or suffix of the classes of the objects
+ name = self.guess_type_name()
llfields = self._setup_repr_fields()
kwds = {'hints': {'immutable': True}}
- self.pbc_type.become(Struct('pbc', *llfields, **kwds))
+ self.pbc_type.become(Struct(name, *llfields, **kwds))
def create_instance(self):
return malloc(self.pbc_type, immortal=True)
Modified: pypy/branch/jit-refactoring/pypy/rpython/ootypesystem/rpbc.py
==============================================================================
--- pypy/branch/jit-refactoring/pypy/rpython/ootypesystem/rpbc.py (original)
+++ pypy/branch/jit-refactoring/pypy/rpython/ootypesystem/rpbc.py Thu Mar 6 19:03:29 2008
@@ -175,7 +175,7 @@
def __init__(self, rtyper, access_set):
self.rtyper = rtyper
self.access_set = access_set
- self.lowleveltype = ootype.Instance('pbc', PBCROOT)
+ self.lowleveltype = ootype.Instance(self.guess_type_name(), PBCROOT)
self.pbc_cache = {}
def _setup_repr(self):
Modified: pypy/branch/jit-refactoring/pypy/rpython/rpbc.py
==============================================================================
--- pypy/branch/jit-refactoring/pypy/rpython/rpbc.py (original)
+++ pypy/branch/jit-refactoring/pypy/rpython/rpbc.py Thu Mar 6 19:03:29 2008
@@ -466,6 +466,31 @@
self.fieldmap[attr] = mangled_name, r_value
return fields
+ def guess_type_name(self):
+ # try to find a name for the Struct, arbitrarily using the longest
+ # common prefix of the classes of the objects
+ names = []
+ if self.access_set is not None:
+ for desc in self.access_set.descs:
+ x = desc.pyobj
+ if x is not None:
+ names.append(x.__class__.__name__)
+ if not names:
+ name = ''
+ else:
+ s1 = min(names)
+ s2 = max(names)
+ n = min(len(s1), len(s2))
+ name = s1[:n]
+ for i in xrange(n):
+ if s1[i] != s2[i]:
+ name = s1[:i]
+ break
+ if name:
+ return 'pbc_' + name
+ else:
+ return 'pbc'
+
def convert_desc(self, frozendesc):
if (self.access_set is not None and
frozendesc not in self.access_set.descs):
More information about the pypy-svn
mailing list