[pypy-commit] lang-smalltalk default: fixed a problem with nonlockal returns due to the new context-handling

lwassermann noreply at buildbot.pypy.org
Thu Feb 28 18:37:05 CET 2013


Author: Lars Wassermann <lars.wassermann at gmail.com>
Branch: 
Changeset: r107:43d730a9efde
Date: 2013-02-28 18:36 +0100
http://bitbucket.org/pypy/lang-smalltalk/changeset/43d730a9efde/

Log:	fixed a problem with nonlockal returns due to the new context-
	handling moved the tests around, because for an unknown reason, they
	will not work in the other order... factored out
	MethodContextShadow>>is_closure_context added some printing help
	refactored kronos tracing code (Interpreter>>loop)

diff --git a/spyvm/interpreter.py b/spyvm/interpreter.py
--- a/spyvm/interpreter.py
+++ b/spyvm/interpreter.py
@@ -90,11 +90,8 @@
             w_new_context = self.step(s_active_context)
             if w_new_context is not None:
                 s_active_context = w_new_context.as_context_get_shadow(self.space)
-                # m = s_active_context.w_method()
-                # try:
-                #     print m.literals[-1]._vars[-1], ">>", m._likely_methodname
-                # except IndexError, AttributeError:
-                #     print  "? >>", m._likely_methodname
+                #method = s_active_context.w_method()
+                #print method.get_identifier_string()
 
     def perform(self, w_receiver, selector, *arguments_w):
         if isinstance(selector, str):
diff --git a/spyvm/model.py b/spyvm/model.py
--- a/spyvm/model.py
+++ b/spyvm/model.py
@@ -504,7 +504,7 @@
     def as_string(self, markBytecode=0):
         from spyvm.interpreter import BYTECODE_TABLE
         j = 1
-        retval  = "\nMethodname: " + self._likely_methodname 
+        retval  = "\nMethodname: " + self.get_identifier_string() 
         retval += "\nBytecode:------------\n"
         for i in self.bytes:
             retval += '->' if j is markBytecode else '  '
@@ -512,6 +512,13 @@
             j += 1
         return retval + "---------------------\n"
 
+    def get_identifier_string(self):
+        try:
+            classname = self.literals[-1]._shadow.getname()
+        except (IndexError, AttributeError):
+            classname = "<unknown>"
+        return "%s>>#%s" % (classname, self._likely_methodname)
+
     def invariant(self):
         return (W_Object.invariant(self) and
                 hasattr(self, 'literals') and
diff --git a/spyvm/shadow.py b/spyvm/shadow.py
--- a/spyvm/shadow.py
+++ b/spyvm/shadow.py
@@ -701,7 +701,7 @@
         ContextPartShadow.attach_shadow(self)
 
     def tempsize(self):
-        if self.w_closure_or_nil == self.space.w_nil:
+        if not self.is_closure_context():
             return self.method().tempsize
         else:
             return wrapper.BlockClosureWrapper(self.space, 
@@ -743,18 +743,21 @@
         return self.size() - self.tempsize()
 
     def returnTopFromMethod(self, interp, current_bytecode):
-        if self.w_closure_or_nil is not self.space.w_nil:
+        if self.is_closure_context():
             # this is a context for a blockClosure
             s_outerContext = self.w_closure_or_nil.fetch(self.space, 
                     constants.BLKCLSR_OUTER_CONTEXT).get_shadow(self.space)
             # XXX check whether we can actually return from that context
             if s_outerContext.pc() == -1:
                 raise error.BlockCannotReturnError()
-            s_outerContext._return(self.top(), interp, 
+            return s_outerContext._return(self.top(), interp, 
                                     s_outerContext.s_home().w_sender())
         else:
             return self._return(self.top(), interp, self.s_home().w_sender())
 
+    def is_closure_context(self):
+        return self.w_closure_or_nil is not self.space.w_nil
+
     def __str__(self):
         retval = '\nMethodContext of:'
         retval += self.w_method().as_string(markBytecode=self.pc() + 1)
diff --git a/spyvm/test/test_bootstrappedimage.py b/spyvm/test/test_bootstrappedimage.py
--- a/spyvm/test/test_bootstrappedimage.py
+++ b/spyvm/test/test_bootstrappedimage.py
@@ -17,22 +17,14 @@
                         w_class.shadow_of_my_class(tools.space))
     perform(w_class, initialize_symbol)
 
+#initialize String class, because equality testing requires a class var set.
+initialize_class(w("string").getclass(tools.space))
 
 def test_symbol_asSymbol():
     w_result = perform(tools.image.w_asSymbol, "asSymbol")
     assert w_result is tools.image.w_asSymbol
 
-def test_create_new_symbol():
-    string = w("someString")
-    # initialize String class
-    initialize_class(string.getclass(tools.space))
-
-    w_result = perform(string, "asSymbol")
-    assert w_result is not None
-    assert w_result.as_string() == "someString"
-
 def test_retrieve_symbol():
-    py.test.skip("unknown stack error")
     """asSymbol
     "This is the only place that new Symbols are created. A Symbol is created 
     if and only if there is not already a Symbol with its contents in existance."
@@ -41,10 +33,14 @@
             self = sym
                 ifTrue: [ ^ sym ] ].
     ^ (Symbol basicNew: self size) initFrom: self"""
-    initialize_class(w("ab").getclass(tools.space))
     w_result = perform(w("someString"), "asSymbol")
     w_anotherSymbol = perform(w("someString"), "asSymbol")
     assert w_result is w_anotherSymbol
 
+def test_create_new_symbol():
+    w_result = perform(w("someString"), "asSymbol")
+    assert w_result is not None
+    assert w_result.as_string() == "someString"
+
 def test_all_pointers_are_valid():
     tools.test_all_pointers_are_valid()


More information about the pypy-commit mailing list