[pypy-svn] r47967 - in pypy/dist/pypy/lang/smalltalk: . test

arigo at codespeak.net arigo at codespeak.net
Thu Oct 25 19:04:56 CEST 2007


Author: arigo
Date: Thu Oct 25 19:04:55 2007
New Revision: 47967

Modified:
   pypy/dist/pypy/lang/smalltalk/interpreter.py
   pypy/dist/pypy/lang/smalltalk/model.py
   pypy/dist/pypy/lang/smalltalk/shadow.py
   pypy/dist/pypy/lang/smalltalk/test/test_miniimage.py
   pypy/dist/pypy/lang/smalltalk/test/test_model.py
Log:
(toon, arigo)
Move the testing version of lookup() out of W_PointerObject
into test_miniimage.  Raise MethodNotFound instead of
returning None when a method is not found.


Modified: pypy/dist/pypy/lang/smalltalk/interpreter.py
==============================================================================
--- pypy/dist/pypy/lang/smalltalk/interpreter.py	(original)
+++ pypy/dist/pypy/lang/smalltalk/interpreter.py	Thu Oct 25 19:04:55 2007
@@ -133,7 +133,7 @@
     def _sendSelector(self, selector, argcount, interp,
                       receiver, receiverclassshadow):
         method = receiverclassshadow.lookup(selector)
-        assert method
+        # XXX catch MethodNotFound here and send doesNotUnderstand:
         if method.primitive:
             func = primitives.prim_table[method.primitive]
             try:

Modified: pypy/dist/pypy/lang/smalltalk/model.py
==============================================================================
--- pypy/dist/pypy/lang/smalltalk/model.py	(original)
+++ pypy/dist/pypy/lang/smalltalk/model.py	Thu Oct 25 19:04:55 2007
@@ -3,9 +3,6 @@
 from pypy.rlib.rarithmetic import intmask
 from pypy.lang.smalltalk import constants
 
-class MethodNotFound(Exception):
-    pass
-
 class W_Object(object):
 
     def size(self):
@@ -131,36 +128,6 @@
         shadow.check_for_updates()
         return shadow
 
-    def compiledmethodnamed(self, methodname):
-        # XXX kill me.  Temporary, for testing
-        w_methoddict = self.fetch(constants.CLASS_METHODDICT_INDEX)._vars
-        names  = w_methoddict[constants.METHODDICT_NAMES_INDEX:]
-        values = w_methoddict[constants.METHODDICT_VALUES_INDEX]._vars
-        for var in names:
-            if isinstance(var, W_BytesObject):
-                if str(var) == str(methodname):
-                    return values[names.index(var)]
-        raise MethodNotFound
-
-    def lookup(self, methodname):
-        # XXX kill me.  Temporary, for testing
-        from pypy.lang.smalltalk import objtable
-        in_class = self
-        while in_class != None:
-            try:
-                return in_class.compiledmethodnamed(methodname)
-            except MethodNotFound:
-                # Current hack because we don't have a ref to the real
-                # nil yet... XXX XXX XXX
-                try:
-                    new_class = in_class._vars[constants.CLASS_SUPERCLASS_INDEX]
-                    if new_class is objtable.w_nil:
-                        raise IndexError
-                    else:
-                        in_class = new_class
-                except IndexError:
-                    return self.lookup("doesNotUnderstand:")
-
 class W_BytesObject(W_AbstractObjectWithClassReference):
     def __init__(self, w_class, size):
         W_AbstractObjectWithClassReference.__init__(self, w_class)

Modified: pypy/dist/pypy/lang/smalltalk/shadow.py
==============================================================================
--- pypy/dist/pypy/lang/smalltalk/shadow.py	(original)
+++ pypy/dist/pypy/lang/smalltalk/shadow.py	Thu Oct 25 19:04:55 2007
@@ -17,6 +17,9 @@
 WEAK_POINTERS = 3
 COMPILED_METHOD = 4
 
+class MethodNotFound(Exception):
+    pass
+
 class ClassShadowError(Exception):
     pass
 
@@ -168,7 +171,7 @@
         elif self.s_superclass != None:
             return self.s_superclass.lookup(selector)
         else:
-            return None
+            raise MethodNotFound
 
     def installmethod(self, selector, method):
         "NOT_RPYTHON"     # this is only for testing.

Modified: pypy/dist/pypy/lang/smalltalk/test/test_miniimage.py
==============================================================================
--- pypy/dist/pypy/lang/smalltalk/test/test_miniimage.py	(original)
+++ pypy/dist/pypy/lang/smalltalk/test/test_miniimage.py	Thu Oct 25 19:04:55 2007
@@ -33,7 +33,30 @@
 def get_float_class():
     image = get_image()
     return image.special(constants.SO_FLOAT_CLASS)
-     
+
+# ------ custom lookup implementations --------------------------------
+
+def compiledmethodnamed(w_class, methodname):
+    w_methoddict = w_class.fetch(constants.CLASS_METHODDICT_INDEX)._vars
+    names  = w_methoddict[constants.METHODDICT_NAMES_INDEX:]
+    values = w_methoddict[constants.METHODDICT_VALUES_INDEX]._vars
+    for var in names:
+        if isinstance(var, model.W_BytesObject):
+            if str(var) == str(methodname):
+                return values[names.index(var)]
+    raise shadow.MethodNotFound
+
+def lookup(w_class, methodname):
+    in_class = w_class
+    while in_class != None:
+        try:
+            return compiledmethodnamed(in_class, methodname)
+        except shadow.MethodNotFound:
+            pass
+        in_class = in_class._vars[constants.CLASS_SUPERCLASS_INDEX]
+        if in_class is objtable.w_nil:
+            raise shadow.MethodNotFound
+
 # ------ tests ------------------------------------------
         
 def test_miniimageexists():
@@ -195,7 +218,7 @@
 
     # Should get this from w_object
     w_smallint_class = image.special(constants.SO_SMALLINTEGER_CLASS)
-    w_method = w_smallint_class.lookup("abs")
+    w_method = lookup(w_smallint_class, "abs")
 
     # XXX
     # currently still using highlevel lookup directly pointing to

Modified: pypy/dist/pypy/lang/smalltalk/test/test_model.py
==============================================================================
--- pypy/dist/pypy/lang/smalltalk/test/test_model.py	(original)
+++ pypy/dist/pypy/lang/smalltalk/test/test_model.py	Thu Oct 25 19:04:55 2007
@@ -1,5 +1,6 @@
 import py
 from pypy.lang.smalltalk import model, shadow
+from pypy.lang.smalltalk.shadow import MethodNotFound
 import pypy.lang.smalltalk.classtable as ct
 
 mockclass = ct.bootstrap_class
@@ -56,10 +57,10 @@
     subshadow.methoddict["foo"] = 3
     assert shadow.lookup("foo") == 1
     assert shadow.lookup("bar") == 2
-    assert shadow.lookup("zork") == None
+    py.test.raises(MethodNotFound, shadow.lookup, "zork")
     assert subshadow.lookup("foo") == 3
     assert subshadow.lookup("bar") == 2
-    assert subshadow.lookup("zork") == None
+    py.test.raises(MethodNotFound, subshadow.lookup, "zork")
 
 def test_w_compiledin():
     w_super = mockclass(0)



More information about the Pypy-commit mailing list