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

tverwaes at codespeak.net tverwaes at codespeak.net
Thu Mar 13 20:01:48 CET 2008


Author: tverwaes
Date: Thu Mar 13 20:01:45 2008
New Revision: 52453

Modified:
   pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/model.py
   pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/primitives.py
   pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/shadow.py
   pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/squeakimage.py
   pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_interpreter.py
   pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_shadow.py
Log:
(akuhn, tverwaes) comments and renamings

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	Thu Mar 13 20:01:45 2008
@@ -97,12 +97,15 @@
         pass
 
 class W_SmallInteger(W_Object):
+    """Boxed integer value"""
+    # TODO can we tell pypy that its never larger then 31-bit?
     __slots__ = ('value',)     # the only allowed slot here
 
     def __init__(self, value):
         self.value = value
 
     def getclass(self):
+        """Return SmallInteger from special objects array."""
         from pypy.lang.smalltalk.classtable import w_SmallInteger
         return w_SmallInteger
 
@@ -110,21 +113,24 @@
         return self.value
 
     def invariant(self):
-        return isinstance(self.value, int)
+        return isinstance(self.value, int) and self.value < 0x8000
 
     def __repr__(self):
         return "W_SmallInteger(%d)" % self.value
 
     def equals(self, other):
+        # TODO what is correct terminology to say that identity is by value?
         if not isinstance(other, W_SmallInteger):
             return False
         return self.value == other.value
 
 class W_Float(W_Object):
+    """Boxed float value."""
     def __init__(self, value):
         self.value = value
 
     def getclass(self):
+        """Return Float from special objects array."""
         from pypy.lang.smalltalk.classtable import w_Float
         return w_Float
 
@@ -140,9 +146,12 @@
     def equals(self, other):
         if not isinstance(other, W_Float):
             return False
+        # TODO is that correct in Squeak?
         return self.value == other.value
 
 class W_AbstractObjectWithIdentityHash(W_Object):
+    """Object with explicit hash (ie all except small
+    ints and floats)."""
     #XXX maybe this is too extreme, but it's very random
     hash_generator = rrandom.Random()
     UNASSIGNED_HASH = sys.maxint
@@ -159,7 +168,8 @@
         return isinstance(self.hash, int)
 
 class W_AbstractObjectWithClassReference(W_AbstractObjectWithIdentityHash):
-    """ The base class of objects that store 'w_class' explicitly. """
+    """Objects with arbitrary class (ie not CompiledMethod, SmallInteger or
+    Float)."""
 
     def __init__(self, w_class):
         if w_class is not None:     # it's None only for testing
@@ -184,17 +194,19 @@
                 isinstance(self.w_class, W_PointersObject))
 
     def become(self, w_old, w_new):
+        # TODO to be eventually replaced by PyPy's become
         if self.w_class == w_old:
             self.w_class = w_new
         elif self.w_class == w_new:
             self.w_class = w_old
 
 class W_PointersObject(W_AbstractObjectWithClassReference):
-    """ The normal object """
+    """Common object."""
     
     _shadow = None # Default value
 
     def __init__(self, w_class, size):
+        """Create new object with size = fixed + variable size."""
         W_AbstractObjectWithClassReference.__init__(self, w_class)
         self._vars = [w_nil] * size
 
@@ -208,20 +220,20 @@
 
     def fetch(self, n0):
         if self._shadow is not None:
-            self._shadow.check_for_w_updates()
+            self._shadow.sync_w_self()
         return self._vars[n0]
         
     def store(self, n0, w_value):    
         if self._shadow is not None:
-            self._shadow.check_for_w_updates()
-            self._shadow.invalidate()
+            self._shadow.sync_w_self()
+            self._shadow.invalidate_shadow()
         self._vars[n0] = w_value
 
-    def fetchvarpointer(self, idx):
-        return self._vars[idx+self.instsize()]
+    # def fetchvarpointer(self, idx):
+    #    return self._vars[idx+self.instsize()]
 
-    def storevarpointer(self, idx, value):
-        self._vars[idx+self.instsize()] = value
+    # def storevarpointer(self, idx, value):
+    #    self._vars[idx+self.instsize()] = value
 
     def varsize(self):
         return self.size() - self.instsize()
@@ -251,11 +263,11 @@
             shadow = TheClass(self, invalid)
             self._shadow = shadow
         elif not isinstance(shadow, TheClass):
-            shadow.check_for_w_updates()
-            shadow.invalidate()
+            shadow.sync_w_self()
+            shadow.invalidate_shadow()
             shadow = TheClass(self, invalid)
             self._shadow = shadow
-        shadow.check_for_updates()
+        shadow.sync_shadow()
         return shadow
 
     def get_shadow(self):

Modified: pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/primitives.py
==============================================================================
--- pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/primitives.py	(original)
+++ pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/primitives.py	Thu Mar 13 20:01:45 2008
@@ -700,7 +700,7 @@
     assert isinstance(w_args, model.W_PointersObject)
     # Push all the items from the array
     for i in range(exp_arg_cnt):
-        s_block_ctx.push(w_args.fetchvarpointer(i))
+        s_block_ctx.push(w_args.at0(i))
 
     # XXX Check original logic. Image does not test this anyway
     # because falls back to value + internal implementation

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	Thu Mar 13 20:01:45 2008
@@ -3,7 +3,7 @@
 from pypy.tool.pairtype import extendabletype
 
 class Invalidateable(object):
-    def invalidate(self):
+    def invalidate_shadow(self):
         pass
 
 class AbstractShadow(Invalidateable):
@@ -17,7 +17,7 @@
         self.invalid = invalid
         self.w_invalid = False
         if invalid:
-            self.invalidate()
+            self.invalidate_shadow()
 
     def notifyinvalid(self, other):
         self._notifyinvalid += [other]
@@ -29,13 +29,13 @@
     def getname(self):
         return repr(self)
 
-    def invalidate(self):
+    def invalidate_shadow(self):
         """XXX This should get called whenever the base Smalltalk
         object changes."""
         if not self.invalid:
             self.invalid = True
             for listener in self._notifyinvalid:
-                listener.invalidate()
+                listener.invalidate_shadow()
             self._notifyinvalid = []
 
     def invalidate_w_self(self):
@@ -47,11 +47,11 @@
     def w_self(self):
         return self._w_self
 
-    def check_for_w_updates(self):
+    def sync_w_self(self):
         if self.w_invalid:
             self.update_w_self()
 
-    def check_for_updates(self):
+    def sync_shadow(self):
         if self.invalid:
             self.update_shadow()
 
@@ -84,8 +84,8 @@
     def __init__(self, w_self, invalid):
         AbstractShadow.__init__(self, w_self, invalid)
 
-    def invalidate(self):
-        AbstractShadow.invalidate(self)
+    def invalidate_shadow(self):
+        AbstractShadow.invalidate_shadow(self)
         self.methoddict = {}
         self.s_superclass = None     # the ClassShadow of the super class
         self.name = None
@@ -259,7 +259,7 @@
     def __init__(self, w_self, invalid):
         AbstractShadow.__init__(self, w_self, invalid)
 
-    def invalidate(self):
+    def invalidate_shadow(self):
         self.methoddict = {}
 
     def update_shadow(self):
@@ -581,11 +581,11 @@
         self._s_home = None
         ContextPartShadow.__init__(self, w_self, invalid)
 
-    def invalidate(self):
+    def invalidate_shadow(self):
         if self._s_home is not None:
             self._s_home.unnotify(self)
             self._s_home = None
-        AbstractShadow.invalidate(self)
+        AbstractShadow.invalidate_shadow(self)
 
     def update_shadow(self):
         self.store_w_home(self.w_self()._vars[constants.BLKCTX_HOME_INDEX])

Modified: pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/squeakimage.py
==============================================================================
--- pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/squeakimage.py	(original)
+++ pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/squeakimage.py	Thu Mar 13 20:01:45 2008
@@ -332,7 +332,7 @@
         w_pointersobject.w_class = self.g_class.w_object
         w_pointersobject.hash = self.chunk.hash12
         if w_pointersobject._shadow is not None:
-            w_pointersobject._shadow.invalidate()
+            w_pointersobject._shadow.invalidate_shadow()
 
     def fillin_wordsobject(self, w_wordsobject):
         w_wordsobject.words = self.chunk.data

Modified: pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_interpreter.py
==============================================================================
--- pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_interpreter.py	(original)
+++ pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_interpreter.py	Thu Mar 13 20:01:45 2008
@@ -61,7 +61,7 @@
             lstlen = len(lit)
             res = classtable.w_Array.as_class_get_shadow().new(lstlen)
             for i in range(lstlen):
-                res.storevarpointer(i, fakeliteral(lit[i]))
+                res.atput0(i, fakeliteral(lit[i]))
             return res
         return lit
     return [fakeliteral(lit) for lit in literals]

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	Thu Mar 13 20:01:45 2008
@@ -229,7 +229,7 @@
     assert s_object2.key() == w_o1
     assert s_object2.value() == w_o2
     assert w_object._shadow == s_object2
-    s_object.check_for_updates()
+    s_object.sync_shadow()
     assert s_object.w_firstlink() == w_o1
     assert s_object.w_lastlink() == w_o2
     assert w_object._shadow == s_object



More information about the Pypy-commit mailing list