Author: Tim Felgentreff <[email protected]>
Branch: bitblt
Changeset: r203:4e4cba5617f0
Date: 2013-03-18 13:12 +0100
http://bitbucket.org/pypy/lang-smalltalk/changeset/4e4cba5617f0/

Log:    add test for DNU

diff --git a/images/running-something-mini.image 
b/images/running-something-mini.image
index 
e87374dba659882613fccb6486bb1da78b5e7fde..c748b0833b7ac5f4885ffd1f49a1d5a37df6b00f
GIT binary patch

[cut]

diff --git a/spyvm/interpreter.py b/spyvm/interpreter.py
--- a/spyvm/interpreter.py
+++ b/spyvm/interpreter.py
@@ -1,5 +1,5 @@
 import py
-from spyvm.shadow import ContextPartShadow, MethodContextShadow, 
BlockContextShadow
+from spyvm.shadow import ContextPartShadow, MethodContextShadow, 
BlockContextShadow, MethodNotFound
 from spyvm import model, constants, primitives, conftest, wrapper
 from spyvm.tool.bitmanipulation import splitter
 
@@ -287,9 +287,23 @@
                 interp._last_indent, w_selector.as_string(), receiver,
                 [self.peek(argcount-1-i) for i in range(argcount)])
         assert argcount >= 0
-        s_method = receiverclassshadow.lookup(w_selector)
-        # XXX catch MethodNotFound here and send doesNotUnderstand:
-        # AK shouln't that be done in lookup itself, please check what spec 
says about DNU in case of super sends.
+        try:
+            s_method = receiverclassshadow.lookup(w_selector)
+        except MethodNotFound:
+            arguments = self.pop_and_return_n(argcount)
+            s_message_class = 
self.space.classtable["w_Message"].as_class_get_shadow(self.space)
+            w_message = s_message_class.new()
+            w_message.store(self.space, 0, w_selector)
+            w_message.store(self.space, 1, self.space.wrap_list(arguments))
+            try:
+                s_method = 
receiverclassshadow.lookup(self.space.objtable["w_doesNotUnderstand"])
+            except MethodNotFound:
+                print "Missing doesDoesNotUnderstand in hierarchy of %s" % 
receiverclassshadow.getname()
+                raise
+            s_frame = s_method.create_frame(self.space, receiver, [w_message], 
self)
+            self.pop()
+            return interp.stack_frame(s_frame)
+
         code = s_method.primitive()
         if code:
             # the primitive pushes the result (if any) onto the stack itself
diff --git a/spyvm/test/test_miniimage.py b/spyvm/test/test_miniimage.py
--- a/spyvm/test/test_miniimage.py
+++ b/spyvm/test/test_miniimage.py
@@ -356,6 +356,13 @@
     assert isinstance(w_dnu, model.W_BytesObject)
     assert w_dnu.as_string() == "doesNotUnderstand:"
 
+def test_run_doesNotUnderstand():
+    from spyvm.test import test_miniimage
+    setup_module(test_miniimage, filename='running-something-mini.image')
+    w_result = 
test_miniimage.interp.perform(test_miniimage.interp.space.wrap_int(0), 
"runningADNU")
+    assert isinstance(w_result, model.W_BytesObject)
+    assert w_result.as_string() == "foobarThis:doesNotExist:('pypy' 'heya' )"
+
 def test_Message():
     w_message_cls = interp.space.w_Message
     assert w_message_cls is interp.space.classtable["w_Message"]
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to