[pypy-svn] r78364 - in pypy/branch/mapdict-without-jit/pypy/objspace/std: . test
arigo at codespeak.net
arigo at codespeak.net
Wed Oct 27 16:47:56 CEST 2010
Author: arigo
Date: Wed Oct 27 16:47:54 2010
New Revision: 78364
Modified:
pypy/branch/mapdict-without-jit/pypy/objspace/std/mapdict.py
pypy/branch/mapdict-without-jit/pypy/objspace/std/test/test_mapdict.py
Log:
(cfbolz, arigo)
By tiny steps that all make sense, in the end we reach something
completely ridiculous.
Modified: pypy/branch/mapdict-without-jit/pypy/objspace/std/mapdict.py
==============================================================================
--- pypy/branch/mapdict-without-jit/pypy/objspace/std/mapdict.py (original)
+++ pypy/branch/mapdict-without-jit/pypy/objspace/std/mapdict.py Wed Oct 27 16:47:54 2010
@@ -15,13 +15,14 @@
# we want to propagate knowledge that the result cannot be negative
class AbstractAttribute(object):
- _immutable_fields_ = ['w_cls']
+ _immutable_fields_ = ['terminator']
cache_attrs = None
_size_estimate = 0
- def __init__(self, space, w_cls):
+ def __init__(self, space, terminator):
self.space = space
- self.w_cls = w_cls
+ assert isinstance(terminator, Terminator)
+ self.terminator = terminator
def read(self, obj, selector):
raise NotImplementedError("abstract base class")
@@ -42,7 +43,7 @@
raise NotImplementedError("abstract base class")
def get_terminator(self):
- raise NotImplementedError("abstract base class")
+ return self.terminator
def set_terminator(self, obj, terminator):
raise NotImplementedError("abstract base class")
@@ -95,10 +96,15 @@
raise NotImplementedError("abstract base class")
def __repr__(self):
- return "<%s w_cls=%s>" % (self.__class__.__name__, self.w_cls)
+ return "<%s>" % (self.__class__.__name__,)
class Terminator(AbstractAttribute):
+ _immutable_fields_ = ['w_cls']
+
+ def __init__(self, space, w_cls):
+ AbstractAttribute.__init__(self, space, self)
+ self.w_cls = w_cls
def read(self, obj, selector):
return None
@@ -116,9 +122,6 @@
def length(self):
return 0
- def get_terminator(self):
- return self
-
def set_terminator(self, obj, terminator):
result = Object()
result.space = self.space
@@ -128,6 +131,9 @@
def remove_dict_entries(self, obj):
return self.copy(obj)
+ def __repr__(self):
+ return "<%s w_cls=%s>" % (self.__class__.__name__, self.w_cls)
+
class DictTerminator(Terminator):
_immutable_fields_ = ['devolved_dict_terminator']
def __init__(self, space, w_cls):
@@ -189,7 +195,7 @@
class PlainAttribute(AbstractAttribute):
_immutable_fields_ = ['selector', 'position', 'back']
def __init__(self, selector, back):
- AbstractAttribute.__init__(self, back.space, back.w_cls)
+ AbstractAttribute.__init__(self, back.space, back.terminator)
self.selector = selector
self.position = back.length()
self.back = back
@@ -232,9 +238,6 @@
def length(self):
return self.position + 1
- def get_terminator(self):
- return self.back.get_terminator()
-
def set_terminator(self, obj, terminator):
new_obj = self.back.set_terminator(obj, terminator)
self._copy_attr(obj, new_obj)
@@ -328,7 +331,7 @@
assert flag
def getclass(self, space):
- return self._get_mapdict_map().w_cls
+ return self._get_mapdict_map().terminator.w_cls
def setclass(self, space, w_cls):
new_obj = self._get_mapdict_map().set_terminator(self, w_cls.terminator)
@@ -609,7 +612,7 @@
INVALID_CACHE_ENTRY = CacheEntry()
INVALID_CACHE_ENTRY.map = objectmodel.instantiate(AbstractAttribute)
# different from any real map ^^^
-INVALID_CACHE_ENTRY.map.w_cls = None
+INVALID_CACHE_ENTRY.map.terminator = None
def init_mapdict_cache(pycode):
num_entries = len(pycode.co_names_w)
@@ -621,7 +624,7 @@
entry = pycode._mapdict_caches[nameindex]
map = w_obj._get_mapdict_map()
if map is entry.map:
- version_tag = map.w_cls.version_tag()
+ version_tag = map.terminator.w_cls.version_tag()
if version_tag is entry.version_tag:
# everything matches, it's incredibly fast
if pycode.space.config.objspace.std.withmethodcachecounter:
@@ -634,7 +637,7 @@
space = pycode.space
w_name = pycode.co_names_w[nameindex]
if map is not None:
- w_type = map.w_cls
+ w_type = map.terminator.w_cls
w_descr = w_type.getattribute_if_not_from_object()
if w_descr is not None:
return space._handle_getattribute(w_descr, w_obj, w_name)
Modified: pypy/branch/mapdict-without-jit/pypy/objspace/std/test/test_mapdict.py
==============================================================================
--- pypy/branch/mapdict-without-jit/pypy/objspace/std/test/test_mapdict.py (original)
+++ pypy/branch/mapdict-without-jit/pypy/objspace/std/test/test_mapdict.py Wed Oct 27 16:47:54 2010
@@ -30,7 +30,8 @@
PlainAttribute(("a", DICT),
Terminator(space, w_cls)))
assert aa.space is space
- assert aa.w_cls is w_cls
+ assert aa.terminator.w_cls is w_cls
+ assert aa.get_terminator() is aa.terminator
obj = Object()
obj.map, obj.storage = aa, [10, 20]
More information about the Pypy-commit
mailing list