[pypy-svn] r51794 - in pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk: . test

tverwaes at codespeak.net tverwaes at codespeak.net
Fri Feb 22 16:14:25 CET 2008


Author: tverwaes
Date: Fri Feb 22 16:14:24 2008
New Revision: 51794

Modified:
   pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/model.py
   pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/shadow.py
   pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_shadow.py
Log:
keeping shadows up to date


Modified: pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/model.py
==============================================================================
--- pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/model.py	(original)
+++ pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/model.py	Fri Feb 22 16:14:24 2008
@@ -183,17 +183,22 @@
 
     # XXX XXX
     # Need to find better way of handling overloading of shadows!!!
+    def setshadow(self, shadow):
+        self._shadow = shadow
+
     def as_special_get_shadow(self, TheClass):
         shadow = self._shadow
         if shadow is None:
-            self._shadow = shadow = TheClass(self)
-        assert isinstance(shadow, TheClass)
+            shadow = TheClass(self)
+        elif not isinstance(shadow, TheClass):
+            shadow.invalidate()
+            shadow = TheClass(self)
+        shadow.check_for_updates()
         return shadow
 
     def as_class_get_shadow(self):
         from pypy.lang.smalltalk.shadow import ClassShadow
         shadow = self.as_special_get_shadow(ClassShadow)
-        shadow.check_for_updates()
         return shadow
 
     def as_link_get_shadow(self):

Modified: pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/shadow.py
==============================================================================
--- pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/shadow.py	(original)
+++ pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/shadow.py	Fri Feb 22 16:14:24 2008
@@ -6,13 +6,28 @@
     """A shadow is an optional extra bit of information that
     can be attached at run-time to any Smalltalk object.
     """
+    def __init__(self, w_self):
+        self._w_self = w_self
+        self.invalidate()
+
     def invalidate(self):
         """XXX This should get called whenever the base Smalltalk
         object changes."""
+        self.invalid = True
 
     def w_self(self):
         return self._w_self
 
+    def check_for_updates(self):
+        if self.invalid:
+            self.w_self().setshadow(self)
+            self.update_shadow()
+
+    # XXX XXX Remove function when fixing superclass to AbstractShadow
+    def update_shadow(self):
+        pass
+
+
 # ____________________________________________________________ 
 
 POINTERS = 0
@@ -33,18 +48,13 @@
     (i.e. used as the class of another Smalltalk object).
     """
     def __init__(self, w_self):
-        self._w_self = w_self
-        self.invalidate()
+        AbstractShadow.__init__(self, w_self)
 
     def invalidate(self):
+        AbstractShadow.invalidate(self)
         self.methoddict = {}
         self.s_superclass = None     # the ClassShadow of the super class
         self.name = None
-        self.invalid = True
-
-    def check_for_updates(self):
-        if self.invalid:
-            self.update_shadow()
 
     def update_shadow(self):
         from pypy.lang.smalltalk import objtable
@@ -220,7 +230,7 @@
 
 class LinkedListShadow(AbstractShadow):
     def __init__(self, w_self):
-        self._w_self = w_self
+        AbstractShadow.__init__(self, w_self)
 
     def w_firstlink(self):
         return self.w_self().fetch(constants.FIRST_LINK_INDEX)
@@ -263,7 +273,7 @@
     """A shadow for Smalltalk objects that are semaphores
     """
     def __init__(self, w_self):
-        self._w_self = w_self
+        LinkedListShadow.__init__(self, w_self)
 
     def put_to_sleep(self, s_process):
         priority = s_process.priority()
@@ -311,7 +321,7 @@
 
 class LinkShadow(AbstractShadow):
     def __init__(self, w_self):
-        self._w_self = w_self
+        AbstractShadow.__init__(self, w_self)
 
     def next(self):
         return self.w_self().fetch(constants.NEXT_LINK_INDEX)
@@ -323,7 +333,7 @@
     """A shadow for Smalltalk objects that are processes
     """
     def __init__(self, w_self):
-        self._w_self = w_self
+        LinkShadow.__init__(self, w_self)
 
     def priority(self):
         return utility.unwrap_int(self.w_self().fetch(constants.PROCESS_PRIORITY_INDEX))
@@ -342,7 +352,7 @@
 
 class AssociationShadow(AbstractShadow):
     def __init__(self, w_self):
-        self._w_self = w_self
+        AbstractShadow.__init__(self, w_self)
 
     def key(self):
         return self.w_self().fetch(constants.ASSOCIATION_KEY_INDEX)
@@ -355,7 +365,7 @@
 
 class SchedulerShadow(AbstractShadow):
     def __init__(self, w_self):
-        self._w_self = w_self
+        AbstractShadow.__init__(self, w_self)
 
     def s_active_process(self):
         return self.w_self().fetch(constants.SCHEDULER_ACTIVE_PROCESS_INDEX).as_process_get_shadow()
@@ -376,6 +386,7 @@
     
     def __init__(self, w_self):
         self._w_self = w_self
+        self.invalidate()
 
     def s_home(self):
         raise NotImplementedError()
@@ -386,6 +397,16 @@
 
     # XXX XXX Remove function when fixing superclass to AbstractShadow
     def invalidate(self):
+        self.invalid = True
+
+    # XXX XXX Remove function when fixing superclass to AbstractShadow
+    def check_for_updates(self):
+        if self.invalid:
+            self.w_self().setshadow(self)
+            self.update_shadow()
+
+    # XXX XXX Remove function when fixing superclass to AbstractShadow
+    def update_shadow(self):
         pass
 
     def w_receiver(self):
@@ -484,7 +505,7 @@
 class BlockContextShadow(ContextPartShadow):
 
     def __init__(self, w_self):
-        self._w_self = w_self
+        ContextPartShadow.__init__(self, w_self)
 
     def expected_argument_count(self):
         return utility.unwrap_int(self.w_self().fetch(constants.BLKCTX_BLOCK_ARGUMENT_COUNT_INDEX))
@@ -504,7 +525,7 @@
 
 class MethodContextShadow(ContextPartShadow):
     def __init__(self, w_self):
-        self._w_self = w_self
+        ContextPartShadow.__init__(self, w_self)
 
     def w_method(self):
         return self.w_self().fetch(constants.MTHDCTX_METHOD)

Modified: pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_shadow.py
==============================================================================
--- pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_shadow.py	(original)
+++ pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_shadow.py	Fri Feb 22 16:14:24 2008
@@ -24,7 +24,6 @@
         w_selector = utility.wrap_string(selector)
         w_methoddict.store(constants.METHODDICT_NAMES_INDEX+pos, w_selector)
         w_array.store(pos, w_compiledmethod)
-    #print w_methoddict._vars
     return w_methoddict
 
 def build_smalltalk_class(name, format, w_superclass=w_Object,



More information about the Pypy-commit mailing list