[pypy-svn] r55008 - pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk

tverwaes at codespeak.net tverwaes at codespeak.net
Tue May 20 16:34:25 CEST 2008


Author: tverwaes
Date: Tue May 20 16:34:16 2008
New Revision: 55008

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/wrapper.py
Log:
(cfbolz, tverwaes) go over usages of _vars and replace by nicer usage if
necessary. Also fix size() for shadowed pointersobjects


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	Tue May 20 16:34:16 2008
@@ -254,6 +254,11 @@
         return self.varsize()
 
     def size(self):
+        if self._shadow is not None:
+            return self._shadow.size()
+        return self._size()
+
+    def _size(self):
         return len(self._vars)
 
     def invariant(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	Tue May 20 16:34:16 2008
@@ -12,6 +12,8 @@
         return self.w_self()._fetch(n0)
     def store(self, n0, w_value):
         return self.w_self()._store(n0, w_value)
+    def size(self):
+        return self.w_self()._size()
     def w_self(self):
         return self._w_self
     def getname(self):
@@ -81,7 +83,7 @@
         w_self = self.w_self()
         # read and painfully decode the format
         classformat = utility.unwrap_int(
-            w_self._vars[constants.CLASS_FORMAT_INDEX])
+            w_self._fetch(constants.CLASS_FORMAT_INDEX))
         # The classformat in Squeak, as an integer value, is:
         #    <2 bits=instSize//64><5 bits=cClass><4 bits=instSpec>
         #                                    <6 bits=instSize\\64><1 bit=0>
@@ -118,10 +120,10 @@
         self.guess_class_name()
 
         # read the methoddict
-        self.w_methoddict = w_self._vars[constants.CLASS_METHODDICT_INDEX]
+        self.w_methoddict = w_self._fetch(constants.CLASS_METHODDICT_INDEX)
         assert isinstance(self.w_methoddict, model.W_PointersObject)
 
-        w_superclass = w_self._vars[constants.CLASS_SUPERCLASS_INDEX]
+        w_superclass = w_self._fetch(constants.CLASS_SUPERCLASS_INDEX)
         if w_superclass.is_same_object(w_nil):
             self.w_superclass = None
         else:
@@ -133,7 +135,7 @@
 
         # read the name
         if w_self.size() > constants.CLASS_NAME_INDEX:
-            w_name = w_self._vars[constants.CLASS_NAME_INDEX]
+            w_name = w_self._fetch(constants.CLASS_NAME_INDEX)
         else:
             # Some heuristic to find the classname
             # Only used for debugging
@@ -142,10 +144,10 @@
             # we are probably holding a metaclass instead of a class.
             # metaclasses hold a pointer to the real class in the last
             # slot. This is pos 6 in mini.image and higher in squeak3.9
-            w_realclass = w_self._vars[w_self.size() - 1]
+            w_realclass = w_self._fetch(w_self.size() - 1)
             assert isinstance(w_realclass, model.W_PointersObject)
             if w_realclass.size() > constants.CLASS_NAME_INDEX:
-                w_name = w_realclass._vars[constants.CLASS_NAME_INDEX]
+                w_name = w_realclass.__fetch(onstants.CLASS_NAME_INDEX)
 
         if isinstance(w_name, model.W_BytesObject):
             self.name = w_name.as_string()
@@ -230,7 +232,7 @@
         "NOT_RPYTHON"     # this is only for testing.
         if self.w_methoddict is None:
             self.w_methoddict = model.W_PointersObject(None, 2)
-            self.w_methoddict._vars[1] = model.W_PointersObject(None, 0)
+            self.w_methoddict._store(1, model.W_PointersObject(None, 0))
             self.s_methoddict().invalid = False
 
     def installmethod(self, selector, method):
@@ -248,7 +250,7 @@
 
     def sync_cache(self):
         from pypy.lang.smalltalk import objtable
-        w_values = self.w_self()._vars[constants.METHODDICT_VALUES_INDEX]
+        w_values = self.w_self()._fetch(constants.METHODDICT_VALUES_INDEX)
         assert isinstance(w_values, model.W_PointersObject)
         s_values = w_values.get_shadow()
         # XXX Should add!
@@ -256,12 +258,12 @@
         size = self.w_self().size() - constants.METHODDICT_NAMES_INDEX
         self.methoddict = {}
         for i in range(size):
-            w_selector = self.w_self()._vars[constants.METHODDICT_NAMES_INDEX+i]
+            w_selector = self.w_self()._fetch(constants.METHODDICT_NAMES_INDEX+i)
             if not w_selector.is_same_object(objtable.w_nil):
                 if not isinstance(w_selector, model.W_BytesObject):
                     raise ClassShadowError("bogus selector in method dict")
                 selector = w_selector.as_string()
-                w_compiledmethod = w_values._vars[i]
+                w_compiledmethod = w_values._fetch(i)
                 if not isinstance(w_compiledmethod, model.W_CompiledMethod):
                     raise ClassShadowError("the methoddict must contain "
                                            "CompiledMethods only for now")
@@ -271,11 +273,13 @@
 class AbstractRedirectingShadow(AbstractShadow):
     def __init__(self, w_self):
         AbstractShadow.__init__(self, w_self)
-        self._w_self_size = len(self.w_self()._vars)
+        self._w_self_size = self.w_self().size()
     def fetch(self, n0):
         raise NotImplementedError()
     def store(self, n0, w_value):
         raise NotImplementedError()
+    def size(self):
+        return self._w_self_size
 
     def attach_shadow(self):
         AbstractShadow.attach_shadow(self)

Modified: pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/wrapper.py
==============================================================================
--- pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/wrapper.py	(original)
+++ pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/wrapper.py	Tue May 20 16:34:16 2008
@@ -10,13 +10,13 @@
 
     def read(self, index0):
         try:
-            return self.w_self._vars[index0]
+            return self.w_self.fetch(index0)
         except IndexError:
             raise WrapperException("Unexpected instance layout. Too small")
 
     def write(self, index0, w_new):
         try:
-            self.w_self._vars[index0] = w_new
+            self.w_self.store(index0, w_new)
         except IndexError:
             raise WrapperException("Unexpected instance layout. Too small")
 
@@ -154,7 +154,7 @@
         # Asserts as W_PointersObject
         lists = Wrapper(w_lists)
         
-        for i in range(len(w_lists._vars) -1, -1, -1):
+        for i in range(w_lists.size() - 1, -1, -1):
             process_list = ProcessListWrapper(lists.read(i))
             if not process_list.is_empty_list():
                 return process_list.remove_first_link_of_list()



More information about the Pypy-commit mailing list