[pypy-svn] r54919 - in pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk: . test
tverwaes at codespeak.net
tverwaes at codespeak.net
Mon May 19 11:23:00 CEST 2008
Author: tverwaes
Date: Mon May 19 11:22:58 2008
New Revision: 54919
Modified:
pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/classtable.py
pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/interpreter.py
pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/shadow.py
pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_miniimage.py
pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_model.py
pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_shadow.py
Log:
(cfbolz, tverwaes) cleaned up superclass link in classshadow
Modified: pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/classtable.py
==============================================================================
--- pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/classtable.py (original)
+++ pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/classtable.py Mon May 19 11:22:58 2008
@@ -9,7 +9,7 @@
s = shadow.ClassShadow(w_class, True)
s.methoddict = {}
if w_superclass is not None:
- s.s_superclass = w_superclass.as_class_get_shadow()
+ s.w_superclass = w_superclass
s.name = name
s.instance_size = instsize
s.instance_kind = format
@@ -65,8 +65,8 @@
define_core_cls(cls_nm, classtable[super_cls_nm], w_metacls)
w_Class = classtable["w_Class"]
w_Metaclass = classtable["w_Metaclass"]
- w_ProtoObjectClass.as_class_get_shadow().s_superclass = \
- w_Class.as_class_get_shadow()
+ w_ProtoObjectClass.as_class_get_shadow().w_superclass = \
+ w_Class
# at this point, all classes that still lack a w_class are themselves
# metaclasses
for nm, w_cls_obj in classtable.items():
Modified: pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/interpreter.py
==============================================================================
--- pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/interpreter.py (original)
+++ pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/interpreter.py Mon May 19 11:22:58 2008
@@ -197,7 +197,7 @@
assert isinstance(w_compiledin, model.W_PointersObject)
s_compiledin = w_compiledin.as_class_get_shadow()
self._sendSelector(selector, argcount, interp, self.w_receiver(),
- s_compiledin.s_superclass)
+ s_compiledin.s_superclass())
def _sendSelector(self, selector, argcount, interp,
receiver, receiverclassshadow):
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 Mon May 19 11:22:58 2008
@@ -87,7 +87,7 @@
def invalidate_shadow(self):
AbstractShadow.invalidate_shadow(self)
self.w_methoddict = None
- self.s_superclass = None # the ClassShadow of the super class
+ self.w_superclass = None
self.name = None
def getname(self):
@@ -141,6 +141,8 @@
else:
w_name = None
+ # Some heuristic to find the classname
+ # Only used for debugging
# XXX This is highly experimental XXX
# if the name-pos of class is not bytesobject,
# we are probably holding a metaclass instead of a class.
@@ -156,16 +158,11 @@
# read the methoddict
self.w_methoddict = w_self._vars[constants.CLASS_METHODDICT_INDEX]
assert isinstance(self.w_methoddict, model.W_PointersObject)
-
- # for the rest, we need to reset invalid to False already so
- # that cycles in the superclass and/or metaclass chains don't
- # cause infinite recursion
- # read s_superclass
w_superclass = w_self._vars[constants.CLASS_SUPERCLASS_INDEX]
- if w_superclass is not objtable.w_nil:
- assert isinstance(w_superclass, model.W_PointersObject)
- self.s_superclass = w_superclass.as_class_get_shadow()
- self.s_superclass.notifyinvalid(self)
+ if w_superclass is objtable.w_nil:
+ self.w_superclass = None
+ else:
+ self.w_superclass = w_superclass
AbstractShadow.update_shadow(self)
# XXX check better way to store objects
@@ -190,6 +187,14 @@
objtable.objects.extend([w_new])
return w_new
+ def s_methoddict(self):
+ return self.w_methoddict.as_methoddict_get_shadow()
+
+ def s_superclass(self):
+ if self.w_superclass is None:
+ return None
+ return self.w_superclass.as_class_get_shadow()
+
# _______________________________________________________________
# Methods for querying the format word, taken from the blue book:
#
@@ -223,7 +228,7 @@
while classshadow is not None:
if classshadow is s_superclass:
return True
- classshadow = classshadow.s_superclass
+ classshadow = classshadow.s_superclass()
else:
return False
@@ -238,17 +243,11 @@
while look_in_shadow is not None:
try:
w_method = look_in_shadow.s_methoddict().methoddict[selector]
- # We locally cache the method we found.
- #if look_in_shadow is not self:
- # self.methoddict[selector] = w_method
return w_method
except KeyError, e:
- look_in_shadow = look_in_shadow.s_superclass
+ look_in_shadow = look_in_shadow.s_superclass()
raise MethodNotFound(self, selector)
- def s_methoddict(self):
- return self.w_methoddict.as_methoddict_get_shadow()
-
def initialize_methoddict(self):
"NOT_RPYTHON" # this is only for testing.
if self.w_methoddict is None:
Modified: pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_miniimage.py
==============================================================================
--- pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_miniimage.py (original)
+++ pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_miniimage.py Mon May 19 11:22:58 2008
@@ -285,8 +285,3 @@
#print interp.s_active_context.stack
except interpreter.ReturnFromTopLevel, e:
return e.object
-
-#def test_eval():
-# w_smalltalk = objtable.objtable["w_smalltalkdict"]
-# w_utilities_class = perform(w_smalltalk, "classNamed:", w("Utilities"))
-# perform(w_utilities_class, "eval:", w("Transcript show: 1+2"))
Modified: pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_model.py
==============================================================================
--- pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_model.py (original)
+++ pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_model.py Mon May 19 11:22:58 2008
@@ -60,7 +60,7 @@
shadow.installmethod("bar", 2)
w_subclass = mockclass(0, w_superclass=w_class)
subshadow = w_subclass.as_class_get_shadow()
- assert subshadow.s_superclass is shadow
+ assert subshadow.s_superclass() is shadow
subshadow.installmethod("foo", 3)
shadow.initialize_methoddict()
subshadow.initialize_methoddict()
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 Mon May 19 11:22:58 2008
@@ -49,7 +49,7 @@
assert classshadow.isvariable() == varsized
assert classshadow.instsize() == instsize
assert classshadow.name == name
- assert classshadow.s_superclass is w_Object.as_class_get_shadow()
+ assert classshadow.s_superclass() is w_Object.as_class_get_shadow()
def test_basic_shape():
yield basicshape, "Empty", 0x02, shadow.POINTERS, False, 0
More information about the Pypy-commit
mailing list