Author: Lars Wassermann <lars.wasserm...@gmail.com>
Branch: 
Changeset: r153:ff4a899fcfd9
Date: 2013-03-08 17:00 +0100
http://bitbucket.org/pypy/lang-smalltalk/changeset/ff4a899fcfd9/

Log:    renamed CachedArrayShadow, added test, changed version field from
        int to Version-object moved adding a CachedObjectShadow to special
        selectors array from now on, only objects of varsized classes
        without instance variables can be special selectors array (e.g.
        instances of Array)

diff --git a/spyvm/constants.py b/spyvm/constants.py
--- a/spyvm/constants.py
+++ b/spyvm/constants.py
@@ -150,7 +150,7 @@
                      'at:put:', 'size', 'next', 'nextPut:', 'atEnd', '==',
                      'class', 'blockCopy:', 'value', 'value:', 'do:', 'new',
                      'new:', 'x', 'y']
-@elidable
+
 def find_selectorindex(selector):
     return SPECIAL_SELECTORS.index(selector) * 2
 find_selectorindex._annspecialcase_ = "specialize:memo"
diff --git a/spyvm/model.py b/spyvm/model.py
--- a/spyvm/model.py
+++ b/spyvm/model.py
@@ -365,9 +365,9 @@
         from spyvm.shadow import MethodDictionaryShadow
         return self.as_special_get_shadow(space, MethodDictionaryShadow)
 
-    def as_cached_array_get_shadow(self, space):
-        from spyvm.shadow import CachedArrayShadow
-        return self.as_special_get_shadow(space, CachedArrayShadow)
+    def as_cached_object_get_shadow(self, space):
+        from spyvm.shadow import CachedObjectShadow
+        return self.as_special_get_shadow(space, CachedObjectShadow)
 
     def become(self, w_other):
         if not isinstance(w_other, W_PointersObject):
diff --git a/spyvm/objspace.py b/spyvm/objspace.py
--- a/spyvm/objspace.py
+++ b/spyvm/objspace.py
@@ -149,7 +149,6 @@
         self.w_two = model.W_SmallInteger(2)
         w_special_selectors = model.W_PointersObject(
             self.classtable['w_Array'], len(constants.SPECIAL_SELECTORS) * 2)
-        w_special_selectors.as_cached_array_get_shadow(self)
         self.w_special_selectors = w_special_selectors
 
         self.objtable = {}
@@ -163,7 +162,8 @@
     @specialize.arg(1)
     def get_special_selector(self, selector):
         i0 = constants.find_selectorindex(selector)
-        return self.w_special_selectors.at0(self, i0)
+        self.w_special_selectors.as_cached_object_get_shadow(self)
+        return self.w_special_selectors.fetch(self, i0)
 
     # methods for wrapping and unwrapping stuff
 
diff --git a/spyvm/shadow.py b/spyvm/shadow.py
--- a/spyvm/shadow.py
+++ b/spyvm/shadow.py
@@ -893,12 +893,15 @@
                 space, self, receiver, arguments, sender)
         return s_new
 
-class CachedArrayShadow(AbstractCachingShadow):
-    _attr_ = ['version']
+class Version:
+    pass
+
+class CachedObjectShadow(AbstractCachingShadow):
+    _immutable_fields_ = ['version?']
 
     def __init__(self, space, w_self):
         AbstractCachingShadow.__init__(self, space, w_self)
-        self.version = 0
+        self.version = Version()
 
     def fetch(self, n0):
         jit.promote(self)
@@ -912,8 +915,8 @@
         return self._w_self._fetch(n0)
 
     def store(self, n0, w_value):
-        self.version = self.version + 1
+        self.version = Version()
         return self._w_self._store(n0, w_value)
 
     def update_shadow(self):
-        self.version = self.version + 1
\ No newline at end of file
+        self.version = Version()
\ No newline at end of file
diff --git a/spyvm/squeakimage.py b/spyvm/squeakimage.py
--- a/spyvm/squeakimage.py
+++ b/spyvm/squeakimage.py
@@ -491,6 +491,9 @@
                 self.w_object = objectmodel.instantiate(model.W_CompiledMethod)
             else:
                 assert 0, "not reachable"
+        else:
+            #XXX invalidate shadow here
+            pass
         return self.w_object
 
     def fillin_w_object(self):
diff --git a/spyvm/test/test_shadow.py b/spyvm/test/test_shadow.py
--- a/spyvm/test/test_shadow.py
+++ b/spyvm/test/test_shadow.py
@@ -207,3 +207,13 @@
 
     shadow = w_compiledmethod.as_compiledmethod_get_shadow(space)
     assert shadow.bytecode == "abx"
+
+def test_cached_object_shadow():
+    w_o = space.wrap_list([0, 1, 2, 3, 4, 5, 6, 7])
+    s_o = w_o.as_cached_object_get_shadow(space)
+    version = s_o.version
+    for i in range(w_o.size()):
+        assert w_o.at0(space, i) == i
+    w_o.atput0(space, 0, 8)
+    assert version is not s_o.version
+    assert w_o.at0(space, 0) == 8
\ No newline at end of file
diff --git a/spyvm/todo.txt b/spyvm/todo.txt
--- a/spyvm/todo.txt
+++ b/spyvm/todo.txt
@@ -54,4 +54,8 @@
         except OverflowError:
             raise WrappingError("integer too large to fit into a tagged 
pointer")
 
-make classes
\ No newline at end of file
+make classes
+
+
+Unclarities:
+[ ] should image loading invalidate the shadows of the precreated objects?
\ No newline at end of file
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to