[pypy-svn] r55025 - in pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk: . test

tverwaes at codespeak.net tverwaes at codespeak.net
Tue May 20 18:06:57 CEST 2008


Author: tverwaes
Date: Tue May 20 18:06:54 2008
New Revision: 55025

Modified:
   pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/shadow.py
   pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_shadow.py
Log:
(cfbolz, tverwaes) assuring consistency between before attaching shadows and
after detaching them


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 18:06:54 2008
@@ -347,7 +347,7 @@
         # tempframe start
         # Stackpointer from smalltalk world == stacksize in python world
         self.store_stackpointer(utility.unwrap_int(w_sp1) -
-                                self.w_method().tempframesize())
+                                self.tempframesize())
 
     # TODO test
     def store_stackpointer(self, size):
@@ -359,8 +359,8 @@
             self._stack.extend(add)
 
     def wrap_stackpointer(self):
-        return utility.wrap_int(len(self._stack) +
-                                self.w_method().tempframesize())
+        return utility.wrap_int(len(self._stack) + 
+                                self.tempframesize())
 
     # TODO test
     def external_stackpointer(self):
@@ -482,6 +482,10 @@
         del self._stack[start:]
         return res
 
+    def stackend(self):
+        # XXX this is incorrect when there is subclassing
+        return self._w_self_size
+
 class BlockContextShadow(ContextPartShadow):
 
     @staticmethod
@@ -513,18 +517,18 @@
         if n0 == constants.BLKCTX_HOME_INDEX:
             return self.store_w_home(w_value)
         if n0 == constants.BLKCTX_INITIAL_IP_INDEX:
-            return self.uwrap_store_initialip(w_value)
+            return self.unwrap_store_initialip(w_value)
         if n0 == constants.BLKCTX_BLOCK_ARGUMENT_COUNT_INDEX:
             return self.unwrap_store_eargc(w_value)
         else:
-            return ContextPartShadow.fetch(self, n0)
+            return ContextPartShadow.store(self, n0, w_value)
 
     def attach_shadow(self):
         # Make sure the home context is updated first
         self.copy_from_w_self(constants.BLKCTX_HOME_INDEX)
         ContextPartShadow.attach_shadow(self)
 
-    def store_unwrap_initialip(self, w_value):
+    def unwrap_store_initialip(self, w_value):
         initialip = utility.unwrap_int(w_value)
         initialip -= 1 + self.w_method().getliteralsize()
         self.store_initialip(initialip)
@@ -568,6 +572,10 @@
     def stackpointer_offset(self):
         return constants.BLKCTX_STACK_START
 
+    def tempframesize(self):
+        # A blockcontext doesn't have any temps
+        return 0
+
 class MethodContextShadow(ContextPartShadow):
     def __init__(self, w_self):
         from pypy.lang.smalltalk import objtable
@@ -637,6 +645,9 @@
         self._temps = [objtable.w_nil] * self.w_method().tempframesize()
         ContextPartShadow.attach_shadow(self)
 
+    def tempframesize(self):
+        return self.w_method().tempframesize()
+
     def w_method(self):
         return self._w_method
 
@@ -668,7 +679,3 @@
     def stackstart(self):
         return (constants.MTHDCTX_TEMP_FRAME_START +
                 self.w_method().tempframesize())
-
-    def stackend(self):
-        # XXX this is incorrect when there is subclassing
-        return self._w_self_size

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	Tue May 20 18:06:54 2008
@@ -91,6 +91,18 @@
     w_object.store(constants.MTHDCTX_TEMP_FRAME_START, 'el')
     return w_object
 
+def blockcontext(w_sender=objtable.w_nil, pc=1, stackpointer=1, stacksize=5,
+                  home=methodcontext()):
+    w_object = model.W_PointersObject(classtable.w_MethodContext, constants.MTHDCTX_TEMP_FRAME_START+stacksize)
+    w_object.store(constants.CTXPART_SENDER_INDEX, w_sender)
+    w_object.store(constants.CTXPART_PC_INDEX, utility.wrap_int(pc))
+    w_object.store(constants.CTXPART_STACKP_INDEX, utility.wrap_int(stackpointer))
+    w_object.store(constants.BLKCTX_BLOCK_ARGUMENT_COUNT_INDEX, utility.wrap_int(54))
+    w_object.store(constants.BLKCTX_INITIAL_IP_INDEX, utility.wrap_int(17))
+    w_object.store(constants.BLKCTX_HOME_INDEX, home)
+    w_object.store(constants.BLKCTX_STACK_START, 'el')
+    return w_object
+
 def test_context():
     w_m = method()
     w_object = methodcontext(stackpointer=3, method=w_m)
@@ -135,7 +147,7 @@
     assert s_object.getbytecode() == 101
     assert s_object.s_home() == s_object
 
-def test_swap_shadows():
+def test_attach_detach_mc():
     w_m = method()
     w_object = methodcontext(pc=13, method=w_m)
     old_vars = w_object._vars
@@ -144,3 +156,12 @@
     s_object.detach_shadow()
     assert w_object._vars == old_vars
     assert w_object._vars is not old_vars
+
+def test_attach_detach_bc():
+    w_object = blockcontext(pc=13)
+    old_vars = w_object._vars
+    s_object = w_object.as_blockcontext_get_shadow()
+    assert w_object._vars is None
+    s_object.detach_shadow()
+    assert w_object._vars == old_vars
+    assert w_object._vars is not old_vars



More information about the Pypy-commit mailing list