[pypy-svn] r22832 - pypy/dist/pypy/jit
arigo at codespeak.net
arigo at codespeak.net
Sun Jan 29 13:37:06 CET 2006
Author: arigo
Date: Sun Jan 29 13:37:05 2006
New Revision: 22832
Modified:
pypy/dist/pypy/jit/hintcontainer.py
pypy/dist/pypy/jit/hintvlist.py
Log:
* Missing same_as()/union() in VirtualListDef.
* A nicer __repr__ showing unifications of virtual containers.
Modified: pypy/dist/pypy/jit/hintcontainer.py
==============================================================================
--- pypy/dist/pypy/jit/hintcontainer.py (original)
+++ pypy/dist/pypy/jit/hintcontainer.py Sun Jan 29 13:37:05 2006
@@ -1,3 +1,4 @@
+import weakref
from pypy.annotation.listdef import ListItem
from pypy.annotation import model as annmodel
from pypy.jit import hintmodel
@@ -5,10 +6,26 @@
class AbstractContainerDef(object):
+ __counter = 0
+ __cache = {}
def __init__(self, bookkeeper, TYPE):
self.T = TYPE
self.bookkeeper = bookkeeper
+ # hack to try to produce a repr that shows identifications
+ try:
+ weakdict = AbstractContainerDef.__cache[TYPE]
+ except KeyError:
+ weakdict = weakref.WeakValueDictionary()
+ AbstractContainerDef.__cache[self.__class__, TYPE] = weakdict
+ weakdict[AbstractContainerDef.__counter] = self
+ AbstractContainerDef.__counter += 1
+
+ def __repr__(self):
+ items = AbstractContainerDef.__cache[self.__class__, self.T].items()
+ keys = [key for key, containerdef in items if containerdef.same_as(self)]
+ tag = min(keys)
+ return "<%s #%d>" % (self.__class__.__name__, tag)
# ____________________________________________________________
@@ -93,9 +110,6 @@
def generalize_field(self, name, hs_value):
self.fields[name].generalize(hs_value)
- def __repr__(self):
- return "<VirtualStructDef '%s'>" % (self.T._name,)
-
# ____________________________________________________________
@@ -128,6 +142,3 @@
def generalize_item(self, hs_value):
self.arrayitem.generalize(hs_value)
-
- def __repr__(self):
- return "<VirtualArrayDef of %r>" % (self.T.OF,)
Modified: pypy/dist/pypy/jit/hintvlist.py
==============================================================================
--- pypy/dist/pypy/jit/hintvlist.py (original)
+++ pypy/dist/pypy/jit/hintvlist.py Sun Jan 29 13:37:05 2006
@@ -17,6 +17,14 @@
self.listitem.read_locations[self.bookkeeper.position_key] = True
return self.listitem.s_value
+ def same_as(self, other):
+ return self.listitem == other.listitem
+
+ def union(self, other):
+ assert self.T == other.T
+ self.listitem.merge(other.listitem)
+ return self
+
def generalize_item(self, hs_value):
assert hs_value.concretetype == self.T.ITEM
self.listitem.generalize(hs_value)
More information about the Pypy-commit
mailing list