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

tverwaes at codespeak.net tverwaes at codespeak.net
Mon Feb 25 17:58:34 CET 2008


Author: tverwaes
Date: Mon Feb 25 17:58:32 2008
New Revision: 51855

Modified:
   pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/interpreter.py
   pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/model.py
   pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/primitives.py
   pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/shadow.py
   pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_interpreter.py
   pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_miniimage.py
   pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_primitives.py
Log:
first wave of code cleanup



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 Feb 25 17:58:32 2008
@@ -26,12 +26,15 @@
     ONE = objtable.w_one
     TWO = objtable.w_two
 
-    _s_last_active_context = None
+    _w_last_active_context = None
     
     def __init__(self):
-        self.s_active_context = None
+        self.w_active_context = None
         self.cnt = 0
 
+    def s_active_context(self):
+        return self.w_active_context.as_context_get_shadow()
+
     def interpret(self):
         try:
             while True:
@@ -43,30 +46,29 @@
         return (not objectmodel.we_are_translated()) and option.bc_trace
 
     def step(self):
-        next = self.s_active_context.getNextBytecode()
+        next = self.s_active_context().getNextBytecode()
         # we_are_translated returns false on top of CPython and true when
         # translating the interpreter
         if not objectmodel.we_are_translated():
             bytecodeimpl = BYTECODE_TABLE[next]
-            if self._s_last_active_context != self.s_active_context:
+            if self._w_last_active_context != self.w_active_context:
                 cnt = 0
-                p = self.s_active_context
+                p = self.w_active_context
                 # AK make method
-                while p is not None:
+                while p is not objtable.w_nil:
                     cnt += 1
-                    p = p.s_sender()
+                    p = p.as_context_get_shadow().w_sender()
                 self._last_indent = "  " * cnt
-                self._s_last_active_context = self.s_active_context
+                self._w_last_active_context = self.w_active_context
             if self.should_trace():
-                
                 print "%sStack=%s" % (
                     self._last_indent,
-                    repr(self.s_active_context.stack()),)
+                    repr(self.s_active_context().stack()),)
                 print "%sBytecode at %d (%d:%s):" % (
                     self._last_indent,
-                    self.s_active_context.pc(),
+                    self.s_active_context().pc(),
                     next, bytecodeimpl.__name__,)
-            bytecodeimpl(self.s_active_context, self)
+            bytecodeimpl(self.w_active_context, self)
         else:
             # this is a performance optimization: when translating the
             # interpreter, the bytecode dispatching is not implemented as a
@@ -74,7 +76,7 @@
             # below produces the switch (by being unrolled).
             for code, bytecodeimpl in unrolling_bytecode_table:
                 if code == next:
-                    bytecodeimpl(self.s_active_context, self)
+                    bytecodeimpl(self.w_active_context, self)
                     break
 
         
@@ -201,33 +203,33 @@
                         print "PRIMITIVE FAILED: %d %s" % (method.primitive, selector,)
                     pass # ignore this error and fall back to the Smalltalk version
         arguments = self.pop_and_return_n(argcount)
-        interp.s_active_context = method.create_frame(receiver, arguments, self) 
+        interp.w_active_context = method.create_frame(receiver, arguments, self) 
         self.pop()
 
-    def _return(self, object, interp, s_return_to):
+    def _return(self, object, interp, w_return_to):
         # for tests, when returning from the top-level context
-        if s_return_to is None:
+        if w_return_to is objtable.w_nil:
             raise ReturnFromTopLevel(object)
-        s_return_to.push(object)
-        interp.s_active_context = s_return_to
+        w_return_to.as_context_get_shadow().push(object)
+        interp.w_active_context = w_return_to
 
     def returnReceiver(self, interp):
-        self._return(self.w_receiver(), interp, self.s_home().s_sender())
+        self._return(self.w_receiver(), interp, self.s_home().w_sender())
 
     def returnTrue(self, interp):
-        self._return(interp.TRUE, interp, self.s_home().s_sender())
+        self._return(interp.TRUE, interp, self.s_home().w_sender())
 
     def returnFalse(self, interp):
-        self._return(interp.FALSE, interp, self.s_home().s_sender())
+        self._return(interp.FALSE, interp, self.s_home().w_sender())
 
     def returnNil(self, interp):
-        self._return(interp.NIL, interp, self.s_home().s_sender())
+        self._return(interp.NIL, interp, self.s_home().w_sender())
 
     def returnTopFromMethod(self, interp):
-        self._return(self.top(), interp, self.s_home().s_sender())
+        self._return(self.top(), interp, self.s_home().w_sender())
 
     def returnTopFromBlock(self, interp):
-        self._return(self.top(), interp, self.s_sender())
+        self._return(self.top(), interp, self.w_sender())
 
     def unknownBytecode(self, interp):
         raise MissingBytecode("unknownBytecode")

Modified: pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/model.py
==============================================================================
--- pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/model.py	(original)
+++ pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/model.py	Mon Feb 25 17:58:32 2008
@@ -490,13 +490,13 @@
 
     __metaclass__ = extendabletype
     
-    def __init__(self, s_home, s_sender):
+    def __init__(self, w_home, w_sender):
         self._stack = []
         self._pc = 0
         #assert isinstance(s_home, W_MethodContext)
-        self._s_home = s_home
+        self._w_home = w_home
         #assert w_sender is None or isinstance(w_sender, W_ContextPart)
-        self._s_sender = s_sender
+        self._w_sender = w_sender
 
     def as_context_get_shadow(self):
         # Backward compatibility
@@ -519,15 +519,24 @@
         " Return self of the method, or the method that contains the block "
         return self.s_home().w_receiver()
 
+    def w_home(self):
+        return self._w_home
+
     def s_home(self):
-        return self._s_home
+        return self.w_home().as_methodcontext_get_shadow()
+
+    def store_w_home(self, w_home):
+        self._w_home = w_home
 
-    def s_sender(self):
-        if self._s_sender:
-            return self._s_sender    
+    def w_sender(self):
+        if self._w_sender is not None:
+            return self._w_sender    
+        else:    
+            from pypy.lang.smalltalk import objtable
+            return objtable.w_nil
 
-    def store_s_sender(self, s_sender):
-        self._s_sender = s_sender
+    def store_w_sender(self, w_sender):
+        self._w_sender = w_sender
 
     def stackpointer(self):
         return len(self.stack()) + self.stackstart() - 1
@@ -537,11 +546,7 @@
     def fetch(self, index):
         from pypy.lang.smalltalk import utility, objtable
         if index == constants.CTXPART_SENDER_INDEX:
-            sender = self.s_sender()
-            if sender is None:
-                return objtable.w_nil
-            else:
-                return sender.w_self()
+            return self.w_sender()
         elif index == constants.CTXPART_PC_INDEX:
             return utility.wrap_int(self.pc())
         elif index == constants.CTXPART_STACKP_INDEX:
@@ -555,7 +560,7 @@
         from pypy.lang.smalltalk import utility, objtable
         if index == constants.CTXPART_SENDER_INDEX:
             if w_value != objtable.w_nil:
-                self._s_sender = w_value.as_context_get_shadow()
+                self.store_w_sender(w_value)
         elif index == constants.CTXPART_PC_INDEX:
             self._pc = utility.unwrap_int(w_value)
         elif index == constants.CTXPART_STACKP_INDEX:
@@ -567,13 +572,13 @@
             raise IndexError
 
     def become(self, w_old, w_new):
-        if self._s_sender is not None and self._s_sender.w_self() == w_old:
-            self._s_sender = w_new.as_context_get_shadow()
+        if self.w_sender() == w_old:
+            self.store_w_sender(w_new)
         for i in range(len(self._stack)):
             if self._stack[i] == w_old:
                 self._stack[i] = w_new
-        if self._s_home is not None and self._s_home.w_self() == w_old:
-            self._s_home = w_new.as_context_get_shadow()
+        if self.w_home() == w_old:
+            self.store_w_home(w_new)
 
     def stackstart(self):
         return constants.MTHDCTX_TEMP_FRAME_START
@@ -643,8 +648,8 @@
 
 class W_BlockContext(W_ContextPart):
 
-    def __init__(self, s_home, s_sender, argcnt, initialip):
-        W_ContextPart.__init__(self, s_home, s_sender)
+    def __init__(self, w_home, w_sender, argcnt, initialip):
+        W_ContextPart.__init__(self, w_home, w_sender)
         self.argcnt = argcnt
         self._initialip = initialip
 
@@ -669,7 +674,7 @@
         elif index == constants.BLKCTX_INITIAL_IP_INDEX:
             return utility.wrap_int(self.initialip)
         elif index == constants.BLKCTX_HOME_INDEX:
-            return self.s_home().w_self()
+            return self.w_home()
         elif index >= constants.BLKCTX_TEMP_FRAME_START:
             stack_index = len(self.stack()) - index - 1
             return self.stack()[stack_index]
@@ -685,7 +690,7 @@
         elif index == constants.BLKCTX_INITIAL_IP_INDEX:
             self.pc = utility.unwrap_int(value)
         elif index == constants.BLKCTX_HOME_INDEX:
-            self._s_home = value.as_methodcontext_get_shadow()
+            self.store_w_home(value)
         elif index >= constants.BLKCTX_TEMP_FRAME_START:
             stack_index = len(self.stack()) - index - 1
             self.stack()[stack_index] = value
@@ -697,8 +702,8 @@
 
 class W_MethodContext(W_ContextPart):
     def __init__(self, w_method, w_receiver,
-                 arguments, s_sender=None):
-        W_ContextPart.__init__(self, self, s_sender)
+                 arguments, w_sender=None):
+        W_ContextPart.__init__(self, self, w_sender)
         self._w_method = w_method
         self._w_receiver = w_receiver
         self.temps = arguments + [w_nil] * w_method.tempsize
@@ -743,7 +748,7 @@
         elif index == constants.MTHDCTX_RECEIVER_MAP: # what is this thing?
             return w_nil
         elif index == constants.MTHDCTX_RECEIVER:
-            return self._w_receiver
+            return self.w_receiver()
         elif index >= constants.MTHDCTX_TEMP_FRAME_START:
             # First set of indices are temporary variables:
             offset = index - constants.MTHDCTX_TEMP_FRAME_START
@@ -763,7 +768,7 @@
         elif index == constants.MTHDCTX_RECEIVER_MAP: # what is this thing?
             pass
         elif index == constants.MTHDCTX_RECEIVER:
-            self._w_receiver = w_object
+            self.store_w_receiver(w_object)
         elif index >= constants.MTHDCTX_TEMP_FRAME_START:
             # First set of indices are temporary variables:
             offset = index - constants.MTHDCTX_TEMP_FRAME_START

Modified: pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/primitives.py
==============================================================================
--- pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/primitives.py	(original)
+++ pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/primitives.py	Mon Feb 25 17:58:32 2008
@@ -68,7 +68,7 @@
                 w_result = func(interp, argument_count_m1)
                 if not no_result:
                     assert w_result is not None
-                    interp.s_active_context.push(w_result)
+                    interp.w_active_context.as_context_get_shadow().push(w_result)
                 return w_result
         else:
             len_unwrap_spec = len(unwrap_spec)
@@ -77,14 +77,15 @@
             unrolling_unwrap_spec = unrolling_iterable(enumerate(unwrap_spec))
             def wrapped(interp, argument_count_m1):
                 argument_count = argument_count_m1 + 1 # to account for the rcvr
-                frame = interp.s_active_context
+                frame = interp.w_active_context
+                s_frame = frame.as_context_get_shadow()
                 assert argument_count == len_unwrap_spec
-                if frame.stackpointer() - frame.stackstart() + 1 < len_unwrap_spec:
+                if s_frame.stackpointer() - s_frame.stackstart() + 1 < len_unwrap_spec:
                     raise PrimitiveFailedError()
                 args = ()
                 for i, spec in unrolling_unwrap_spec:
                     index = len_unwrap_spec - 1 - i
-                    w_arg = frame.peek(index)
+                    w_arg = s_frame.peek(index)
                     if spec is int:
                         args += (utility.unwrap_int(w_arg), )
                     elif spec is index1_0:
@@ -101,10 +102,13 @@
                         raise NotImplementedError(
                             "unknown unwrap_spec %s" % (spec, ))
                 w_result = func(interp, *args)
-                frame.pop_n(len_unwrap_spec)   # only if no exception occurs!
+                # After calling primitive, reload context-shadow in case it
+                # needs to be updated
+                new_s_frame = interp.w_active_context.as_context_get_shadow()
+                frame.as_context_get_shadow().pop_n(len_unwrap_spec)   # only if no exception occurs!
                 if not no_result:
                     assert w_result is not None
-                    interp.s_active_context.push(w_result)
+                    new_s_frame.push(w_result)
         wrapped.func_name = "wrap_prim_" + name
         prim_table[code] = wrapped
         prim_table_implemented_only.append((code, wrapped))
@@ -618,7 +622,7 @@
 
 @expose_primitive(PRIMITIVE_BLOCK_COPY, unwrap_spec=[object, int])
 def func(interp, w_context, argcnt):
-    frame = interp.s_active_context
+    frame = interp.w_active_context.as_context_get_shadow()
 
     # From B.B.: If receiver is a MethodContext, then it becomes
     # the new BlockContext's home context.  Otherwise, the home
@@ -626,20 +630,20 @@
     # Note that in our impl, MethodContext.w_home == self
     if not isinstance(w_context, model.W_ContextPart):
         raise PrimitiveFailedError()
-    s_method_context = w_context.as_context_get_shadow().s_home()
+    w_method_context = w_context.as_context_get_shadow().w_home()
 
     # The block bytecodes are stored inline: so we skip past the
     # byteodes to invoke this primitive to find them (hence +2)
     initialip = frame.pc() + 2
-    s_new_context = model.W_BlockContext(
-        s_method_context, None, argcnt, initialip)
-    return s_new_context.w_self()
+    w_new_context = model.W_BlockContext(
+        w_method_context, None, argcnt, initialip)
+    return w_new_context
 
 def finalize_block_ctx(interp, s_block_ctx, frame):
     # Set some fields
     s_block_ctx.store_pc(s_block_ctx.initialip())
-    s_block_ctx.store_s_sender(frame)
-    interp.s_active_context = s_block_ctx
+    s_block_ctx.store_w_sender(frame)
+    interp.w_active_context = s_block_ctx.w_self()
     
 @expose_primitive(PRIMITIVE_VALUE, no_result=True)
 def func(interp, argument_count):
@@ -649,7 +653,7 @@
     #  Rcvr | Arg 0 | Arg1 | Arg 2
     #
     
-    frame = interp.s_active_context
+    frame = interp.w_active_context.as_context_get_shadow()
     
     # Validate that we have a block on the stack and that it received
     # the proper number of arguments:
@@ -667,7 +671,7 @@
     s_block_ctx.push_all(block_args)
 
     frame.pop()
-    finalize_block_ctx(interp, s_block_ctx, frame)
+    finalize_block_ctx(interp, s_block_ctx, frame.w_self())
     
 @expose_primitive(PRIMITIVE_VALUE_WITH_ARGS, unwrap_spec=[object, object],
                   no_result=True)
@@ -687,8 +691,7 @@
 
     # XXX Check original logic. Image does not test this anyway
     # because falls back to value + internal implementation
-
-    finalize_block_ctx(interp, s_block_ctx, interp.s_active_context)
+    finalize_block_ctx(interp, s_block_ctx, interp.w_active_context)
 
 @expose_primitive(PRIMITIVE_PERFORM)
 def func(interp, argcount):
@@ -701,11 +704,11 @@
     w_method = w_rcvr.shadow_of_my_class().lookup(sel)
     assert w_method
 
-    s_frame = w_method.create_frame(w_rcvr,
+    w_frame = w_method.create_frame(w_rcvr,
         [w_args.fetch(i) for i in range(w_args.size())])
 
-    s_frame.store_s_sender(interp.s_active_context)
-    interp.s_active_context = s_frame
+    w_frame.as_context_get_shadow().store_w_sender(interp.w_active_context)
+    interp.w_active_context = w_frame
 
 
 @expose_primitive(PRIMITIVE_SIGNAL, unwrap_spec=[object])

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 Feb 25 17:58:32 2008
@@ -432,17 +432,19 @@
         " Return self of the method, or the method that contains the block "
         return self.s_home().w_receiver()
 
+    def w_sender(self):
+        return self.w_self().fetch(constants.CTXPART_SENDER_INDEX)
+
     def s_sender(self):
-        # XXX XXX
         from pypy.lang.smalltalk import objtable
-        w_sender = self.w_self().fetch(constants.CTXPART_SENDER_INDEX)
+        w_sender = self.w_sender()
         if w_sender == objtable.w_nil:
             return None
         else:
             return w_sender.as_context_get_shadow()
 
-    def store_s_sender(self, s_sender):
-        self.w_self().store(constants.CTXPART_SENDER_INDEX, s_sender.w_self())
+    def store_w_sender(self, s_sender):
+        self.w_self().store(constants.CTXPART_SENDER_INDEX, w_sender)
 
     def pc(self):
         return utility.unwrap_int(self.w_self().fetch(constants.CTXPART_PC_INDEX))
@@ -536,9 +538,12 @@
     def initialip(self):
         return utility.unwrap_int(self.w_self().fetch(constants.BLKCTX_INITIAL_IP_INDEX))
         
-    def s_home(self):
-        return self.w_self().fetch(constants.BLKCTX_HOME_INDEX).as_methodcontext_get_shadow()
+    def w_home(self):
+        return self.w_self().fetch(constants.BLKCTX_HOME_INDEX)
 
+    def s_home(self):
+        return self.w_home().as_methodcontext_get_shadow()
+        
     def stackstart(self):
         return constants.BLKCTX_TEMP_FRAME_START
 
@@ -561,6 +566,9 @@
     def settemp(self, index, w_value):
         self.w_self().store(constants.MTHDCTX_TEMP_FRAME_START + index, w_value) 
 
+    def w_home(self):
+        return self.w_self()
+
     def s_home(self):
         return self
 

Modified: pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_interpreter.py
==============================================================================
--- pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_interpreter.py	(original)
+++ pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_interpreter.py	Mon Feb 25 17:58:32 2008
@@ -74,7 +74,7 @@
     w_method.tempsize=1
     w_frame = w_method.create_frame(receiver, ["foo", "bar"])
     interp = interpreter.Interpreter()
-    interp.s_active_context = w_frame.as_methodcontext_get_shadow()
+    interp.w_active_context = w_frame
     return interp
 
 def test_create_frame():
@@ -95,7 +95,7 @@
 
 def test_push_pop():
     interp = new_interpreter("")
-    frame = interp.s_active_context
+    frame = interp.s_active_context()
     frame.push(12)
     frame.push(34)
     frame.push(56)
@@ -116,7 +116,7 @@
 def test_pushReceiverBytecode():
     interp = new_interpreter(pushReceiverBytecode)
     interp.step()
-    assert interp.s_active_context.top() == interp.s_active_context.w_receiver()
+    assert interp.s_active_context().top() == interp.w_active_context.as_methodcontext_get_shadow().w_receiver()
 
 def test_pushReceiverVariableBytecode(bytecode = (pushReceiverVariableBytecode(0) +
                                                   pushReceiverVariableBytecode(1) +
@@ -129,27 +129,27 @@
     interp.step()
     interp.step()
     interp.step()
-    assert interp.s_active_context.stack() == ["egg", "bar", "baz"]
+    assert interp.s_active_context().stack() == ["egg", "bar", "baz"]
 
 def test_pushTemporaryVariableBytecode(bytecode=(pushTemporaryVariableBytecode(0) +
                                                  pushTemporaryVariableBytecode(1) +
                                                  pushTemporaryVariableBytecode(2))):
     interp = new_interpreter(bytecode)
-    interp.s_active_context.settemp(2, "temp")
+    interp.w_active_context.as_methodcontext_get_shadow().settemp(2, "temp")
     interp.step()
     interp.step()
     interp.step()
-    assert interp.s_active_context.stack() == ["foo", "bar", "temp"]
+    assert interp.s_active_context().stack() == ["foo", "bar", "temp"]
 
 def test_pushLiteralConstantBytecode(bytecode=pushLiteralConstantBytecode(0) +
                                               pushLiteralConstantBytecode(1) +
                                               pushLiteralConstantBytecode(2)):
     interp = new_interpreter(bytecode)
-    interp.s_active_context.w_method().literals = fakeliterals("a", "b", "c")
+    interp.w_active_context.as_methodcontext_get_shadow().w_method().literals = fakeliterals("a", "b", "c")
     interp.step()
     interp.step()
     interp.step()
-    assert interp.s_active_context.stack() == [fakesymbol("a"),
+    assert interp.s_active_context().stack() == [fakesymbol("a"),
                                              fakesymbol("b"),
                                              fakesymbol("c")]
 
@@ -158,9 +158,9 @@
     w_association.store(0, "mykey")
     w_association.store(1, "myvalue")
     interp = new_interpreter(bytecode)
-    interp.s_active_context.w_method().literals = fakeliterals(w_association)
+    interp.w_active_context.as_methodcontext_get_shadow().w_method().literals = fakeliterals(w_association)
     interp.step()
-    assert interp.s_active_context.stack() == ["myvalue"]
+    assert interp.s_active_context().stack() == ["myvalue"]
 
 def test_storeAndPopReceiverVariableBytecode(bytecode=storeAndPopReceiverVariableBytecode,
                                              popped=True):
@@ -168,13 +168,13 @@
     for index in range(8):
         w_object = shadow.new()
         interp = new_interpreter(pushConstantTrueBytecode + bytecode(index))
-        interp.s_active_context.store_w_receiver(w_object)
+        interp.w_active_context.as_methodcontext_get_shadow().store_w_receiver(w_object)
         interp.step()
         interp.step()
         if popped:
-            assert interp.s_active_context.stack() == []
+            assert interp.s_active_context().stack() == []
         else:
-            assert interp.s_active_context.stack() == [interp.TRUE]
+            assert interp.s_active_context().stack() == [interp.TRUE]
 
         for test_index in range(8):
             if test_index == index:
@@ -185,167 +185,167 @@
 def test_storeAndPopTemporaryVariableBytecode(bytecode=storeAndPopTemporaryVariableBytecode):
     for index in range(8):
         interp = new_interpreter(pushConstantTrueBytecode + bytecode(index))
-        interp.s_active_context.temps = [None] * 8
+        interp.w_active_context.as_methodcontext_get_shadow().temps = [None] * 8
         interp.step()
         interp.step()
-        assert interp.s_active_context.stack() == []
+        assert interp.s_active_context().stack() == []
         for test_index in range(8):
             if test_index == index:
-                assert interp.s_active_context.temps[test_index] == interp.TRUE
+                assert interp.w_active_context.as_methodcontext_get_shadow().temps[test_index] == interp.TRUE
             else:
-                assert interp.s_active_context.temps[test_index] == None
+                assert interp.w_active_context.as_methodcontext_get_shadow().temps[test_index] == None
 
 def test_pushConstantTrueBytecode():
     interp = new_interpreter(pushConstantTrueBytecode)
     interp.step()
-    assert interp.s_active_context.pop() == interp.TRUE
-    assert interp.s_active_context.stack() == []
+    assert interp.s_active_context().pop() == interp.TRUE
+    assert interp.s_active_context().stack() == []
 
 def test_pushConstantFalseBytecode():
     interp = new_interpreter(pushConstantFalseBytecode)
     interp.step()
-    assert interp.s_active_context.pop() == interp.FALSE
-    assert interp.s_active_context.stack() == []
+    assert interp.s_active_context().pop() == interp.FALSE
+    assert interp.s_active_context().stack() == []
 
 def test_pushConstantNilBytecode():
     interp = new_interpreter(pushConstantNilBytecode)
     interp.step()
-    assert interp.s_active_context.pop() == interp.NIL
-    assert interp.s_active_context.stack() == []
+    assert interp.s_active_context().pop() == interp.NIL
+    assert interp.s_active_context().stack() == []
 
 def test_pushConstantMinusOneBytecode():
     interp = new_interpreter(pushConstantMinusOneBytecode)
     interp.step()
-    assert interp.s_active_context.pop() == interp.MINUS_ONE
-    assert interp.s_active_context.stack() == []
+    assert interp.s_active_context().pop() == interp.MINUS_ONE
+    assert interp.s_active_context().stack() == []
 
 def test_pushConstantZeroBytecode():
     interp = new_interpreter(pushConstantZeroBytecode)
     interp.step()
-    assert interp.s_active_context.pop() == interp.ZERO
-    assert interp.s_active_context.stack() == []
+    assert interp.s_active_context().pop() == interp.ZERO
+    assert interp.s_active_context().stack() == []
     
 def test_pushConstantOneBytecode():
     interp = new_interpreter(pushConstantOneBytecode)
     interp.step()
-    assert interp.s_active_context.pop() == interp.ONE
-    assert interp.s_active_context.stack() == []
+    assert interp.s_active_context().pop() == interp.ONE
+    assert interp.s_active_context().stack() == []
 
 def test_pushConstantTwoBytecode():
     interp = new_interpreter(pushConstantTwoBytecode)
     interp.step()
-    assert interp.s_active_context.pop() == interp.TWO
-    assert interp.s_active_context.stack() == []
+    assert interp.s_active_context().pop() == interp.TWO
+    assert interp.s_active_context().stack() == []
 
 def test_pushActiveContextBytecode():
     interp = new_interpreter(pushActiveContextBytecode)
     interp.step()
-    assert interp.s_active_context.pop() == interp.s_active_context.w_self()
-    assert interp.s_active_context.stack() == []
+    assert interp.s_active_context().pop() == interp.w_active_context
+    assert interp.s_active_context().stack() == []
     
 def test_duplicateTopBytecode():
     interp = new_interpreter(pushConstantZeroBytecode + duplicateTopBytecode)
     interp.step()
     interp.step()
-    assert interp.s_active_context.stack() == [interp.ZERO, interp.ZERO]
+    assert interp.s_active_context().stack() == [interp.ZERO, interp.ZERO]
     
 def test_bytecodePrimBitAnd():
     interp = new_interpreter(pushConstantOneBytecode + pushConstantTwoBytecode + bytecodePrimBitAnd)
     interp.step()
     interp.step()
     interp.step()
-    assert interp.s_active_context.pop().value == 0
-    assert interp.s_active_context.stack() == []
+    assert interp.s_active_context().pop().value == 0
+    assert interp.s_active_context().stack() == []
     
 def test_bytecodePrimBitOr():
     interp = new_interpreter(pushConstantOneBytecode + pushConstantTwoBytecode + bytecodePrimBitOr)
     interp.step()
     interp.step()
     interp.step()
-    assert interp.s_active_context.pop().value == 3
-    assert interp.s_active_context.stack() == []
+    assert interp.s_active_context().pop().value == 3
+    assert interp.s_active_context().stack() == []
 
 def test_bytecodePrimBitShift():
     interp = new_interpreter(pushConstantOneBytecode + pushConstantTwoBytecode + bytecodePrimBitShift)
     interp.step()
     interp.step()
     interp.step()
-    assert interp.s_active_context.pop().value == 4
-    assert interp.s_active_context.stack() == []
+    assert interp.s_active_context().pop().value == 4
+    assert interp.s_active_context().stack() == []
     
 def test_bytecodePrimClass():
     interp = new_interpreter(pushConstantOneBytecode + bytecodePrimClass)
     interp.step()
     interp.step()
-    assert interp.s_active_context.pop() == classtable.w_SmallInteger
-    assert interp.s_active_context.stack() == []
+    assert interp.s_active_context().pop() == classtable.w_SmallInteger
+    assert interp.s_active_context().stack() == []
     
 def test_bytecodePrimSubtract():
     interp = new_interpreter(pushConstantOneBytecode + pushConstantTwoBytecode + bytecodePrimSubtract)
     interp.step()
     interp.step()
     interp.step()
-    assert interp.s_active_context.pop().value == -1
-    assert interp.s_active_context.stack() == []
+    assert interp.s_active_context().pop().value == -1
+    assert interp.s_active_context().stack() == []
 
 def test_bytecodePrimMultiply():
     interp = new_interpreter(pushConstantMinusOneBytecode + pushConstantTwoBytecode + bytecodePrimMultiply)
     interp.step()
     interp.step()
     interp.step()
-    assert interp.s_active_context.pop().value == -2
-    assert interp.s_active_context.stack() == []
+    assert interp.s_active_context().pop().value == -2
+    assert interp.s_active_context().stack() == []
     
 def test_bytecodePrimDivide():
     interp = new_interpreter(pushConstantTwoBytecode + pushConstantMinusOneBytecode + bytecodePrimDivide)
     interp.step()
     interp.step()
     interp.step()
-    assert interp.s_active_context.pop().value == -2    
-    assert interp.s_active_context.stack() == []
+    assert interp.s_active_context().pop().value == -2    
+    assert interp.s_active_context().stack() == []
     
 def test_bytecodePrimDiv():
     interp = new_interpreter(pushConstantTwoBytecode + pushConstantMinusOneBytecode + bytecodePrimDiv)
     interp.step()
     interp.step()
     interp.step()
-    assert interp.s_active_context.pop().value == -2
-    assert interp.s_active_context.stack() == []
+    assert interp.s_active_context().pop().value == -2
+    assert interp.s_active_context().stack() == []
 
 def test_bytecodePrimMod():
     interp = new_interpreter(pushConstantTwoBytecode + pushConstantMinusOneBytecode + bytecodePrimMod)
     interp.step()
     interp.step()
     interp.step()
-    assert interp.s_active_context.pop().value == 0
-    assert interp.s_active_context.stack() == []
+    assert interp.s_active_context().pop().value == 0
+    assert interp.s_active_context().stack() == []
 
 def test_bytecodePrimEquivalent():
     interp = new_interpreter(pushConstantTwoBytecode + pushConstantMinusOneBytecode + bytecodePrimEquivalent)
     interp.step()
     interp.step()
     interp.step()
-    assert interp.s_active_context.pop() == interpreter.Interpreter.FALSE
-    assert interp.s_active_context.stack() == []
+    assert interp.s_active_context().pop() == interpreter.Interpreter.FALSE
+    assert interp.s_active_context().stack() == []
     
     interp = new_interpreter(pushConstantOneBytecode + pushConstantOneBytecode + bytecodePrimEquivalent)
     interp.step()
     interp.step()
     interp.step()
-    assert interp.s_active_context.pop() == interpreter.Interpreter.TRUE
-    assert interp.s_active_context.stack() == []
+    assert interp.s_active_context().pop() == interpreter.Interpreter.TRUE
+    assert interp.s_active_context().stack() == []
     
 def test_bytecodePrimNew():
     w_fakeclassclass = mockclass(10, name='fakeclassclass')
     w_fakeclass = mockclass(1, name='fakeclass', varsized=False,
                             w_metaclass=w_fakeclassclass)
     interp = new_interpreter(bytecodePrimNew)
-    interp.s_active_context.push(w_fakeclass)
+    interp.s_active_context().push(w_fakeclass)
     run_with_faked_methods(
         [[w_fakeclassclass, primitives.NEW, 0, "new"]],
         interp.step)
-    w_fakeinst = interp.s_active_context.pop()
-    assert interp.s_active_context.stack() == []
+    w_fakeinst = interp.s_active_context().pop()
+    assert interp.s_active_context().stack() == []
     assert w_fakeinst.getclass() == w_fakeclass
     assert w_fakeinst.size() == 1
     
@@ -354,13 +354,13 @@
     w_fakeclass = mockclass(1, name='fakeclass', varsized=True,
                             w_metaclass=w_fakeclassclass)
     interp = new_interpreter(bytecodePrimNewWithArg)
-    interp.s_active_context.push(w_fakeclass)
-    interp.s_active_context.push(interpreter.Interpreter.TWO)
+    interp.s_active_context().push(w_fakeclass)
+    interp.s_active_context().push(interpreter.Interpreter.TWO)
     run_with_faked_methods(
         [[w_fakeclassclass, primitives.NEW_WITH_ARG, 1, "new:"]],
         interp.step)
-    w_fakeinst = interp.s_active_context.pop()
-    assert interp.s_active_context.stack() == []
+    w_fakeinst = interp.s_active_context().pop()
+    assert interp.s_active_context().stack() == []
     assert w_fakeinst.getclass() == w_fakeclass
     assert w_fakeinst.size() == 3
  
@@ -368,12 +368,12 @@
     w_fakeclass = mockclass(2, name='fakeclass', varsized=True)
     w_fakeinst = w_fakeclass.as_class_get_shadow().new(5)
     interp = new_interpreter(bytecodePrimSize)
-    interp.s_active_context.push(w_fakeinst)
+    interp.s_active_context().push(w_fakeinst)
     run_with_faked_methods(
         [[w_fakeclass, primitives.SIZE, 0, "size"]],
         interp.step)
-    assert interp.s_active_context.pop().value == 5
-    assert interp.s_active_context.stack() == []
+    assert interp.s_active_context().pop().value == 5
+    assert interp.s_active_context().stack() == []
 
 # w_class - the class from which the method is going to be called
 # (and on which it is going to be installed)
@@ -390,19 +390,19 @@
         w_method.bytes = pushConstantOneBytecode + bytecode
         shadow.installmethod("foo", w_method)
         interp = new_interpreter(bytecodes)
-        interp.s_active_context.w_method().literals = fakeliterals("foo")
-        interp.s_active_context.push(w_object)
-        callerContext = interp.s_active_context
-        interp.step()
-        assert interp.s_active_context.s_sender() == callerContext
-        assert interp.s_active_context.stack() == []
-        assert interp.s_active_context.w_receiver() == w_object
-        assert interp.s_active_context.w_method() == shadow.methoddict["foo"]
+        interp.w_active_context.as_methodcontext_get_shadow().w_method().literals = fakeliterals("foo")
+        interp.s_active_context().push(w_object)
+        callerContext = interp.w_active_context
+        interp.step()
+        assert interp.s_active_context().w_sender() == callerContext
+        assert interp.s_active_context().stack() == []
+        assert interp.w_active_context.as_methodcontext_get_shadow().w_receiver() == w_object
+        assert interp.w_active_context.as_methodcontext_get_shadow().w_method() == shadow.methoddict["foo"]
         assert callerContext.stack() == []
         interp.step()
         interp.step()
-        assert interp.s_active_context == callerContext
-        assert interp.s_active_context.stack() == [result]
+        assert interp.w_active_context == callerContext
+        assert interp.s_active_context().stack() == [result]
 
 def test_sendLiteralSelectorBytecode():
     w_class = mockclass(0)
@@ -420,9 +420,9 @@
     shadow.installmethod("fib:", method)
     w_object = shadow.new()
     interp = new_interpreter(sendLiteralSelectorBytecode(16) + returnTopFromMethod)
-    interp.s_active_context.w_method().literals = fakeliterals("fib:")
-    interp.s_active_context.push(w_object)
-    interp.s_active_context.push(wrap_int(8))
+    interp.w_active_context.as_methodcontext_get_shadow().w_method().literals = fakeliterals("fib:")
+    interp.s_active_context().push(w_object)
+    interp.s_active_context().push(wrap_int(8))
     result = interp.interpret()
     assert unwrap_int(result) == 34
 
@@ -430,14 +430,14 @@
 
     def test():
         interp = new_interpreter(sendLiteralSelectorBytecode(1 + 16))
-        interp.s_active_context.w_method().literals = fakeliterals("foo", "sub")
-        interp.s_active_context.push(wrap_int(50))
-        interp.s_active_context.push(wrap_int(8))
-        callerContext = interp.s_active_context
-        interp.step()
-        assert interp.s_active_context is callerContext
-        assert len(interp.s_active_context.stack()) == 1
-        w_result = interp.s_active_context.pop()
+        interp.w_active_context.as_methodcontext_get_shadow().w_method().literals = fakeliterals("foo", "sub")
+        interp.s_active_context().push(wrap_int(50))
+        interp.s_active_context().push(wrap_int(8))
+        callerContext = interp.w_active_context
+        interp.step()
+        assert interp.w_active_context is callerContext
+        assert len(interp.s_active_context().stack()) == 1
+        w_result = interp.s_active_context().pop()
         assert unwrap_int(w_result) == 42
         
     run_with_faked_methods(
@@ -447,58 +447,58 @@
 
 def test_longJumpIfTrue():
     interp = new_interpreter(longJumpIfTrue(0) + chr(15) + longJumpIfTrue(0) + chr(15))
-    interp.s_active_context.push(interp.FALSE)
-    pc = interp.s_active_context.pc() + 2
+    interp.s_active_context().push(interp.FALSE)
+    pc = interp.w_active_context.pc() + 2
     interp.step()
-    assert interp.s_active_context.pc() == pc
-    interp.s_active_context.push(interp.TRUE)
-    pc = interp.s_active_context.pc() + 2
+    assert interp.s_active_context().pc() == pc
+    interp.s_active_context().push(interp.TRUE)
+    pc = interp.s_active_context().pc() + 2
     interp.step()
-    assert interp.s_active_context.pc() == pc + 15
+    assert interp.s_active_context().pc() == pc + 15
 
 def test_longJumpIfFalse():
     interp = new_interpreter(pushConstantTrueBytecode + longJumpIfFalse(0) + chr(15) +
                              pushConstantFalseBytecode + longJumpIfFalse(0) + chr(15))
     interp.step()
-    pc = interp.s_active_context.pc() + 2
+    pc = interp.s_active_context().pc() + 2
     interp.step()
-    assert interp.s_active_context.pc() == pc
+    assert interp.s_active_context().pc() == pc
     interp.step()
-    pc = interp.s_active_context.pc() + 2
+    pc = interp.s_active_context().pc() + 2
     interp.step()
-    assert interp.s_active_context.pc() == pc + 15
+    assert interp.s_active_context().pc() == pc + 15
 
 def test_longUnconditionalJump():
     interp = new_interpreter(longUnconditionalJump(4) + chr(15))
-    pc = interp.s_active_context.pc() + 2
+    pc = interp.s_active_context().pc() + 2
     interp.step()
-    assert interp.s_active_context.pc() == pc + 15
+    assert interp.s_active_context().pc() == pc + 15
 
 def test_shortUnconditionalJump():
     interp = new_interpreter(chr(145))
-    pc = interp.s_active_context.pc() + 1
+    pc = interp.s_active_context().pc() + 1
     interp.step()
-    assert interp.s_active_context.pc() == pc + 2
+    assert interp.s_active_context().pc() == pc + 2
 
 def test_shortConditionalJump():
     interp = new_interpreter(pushConstantTrueBytecode + shortConditionalJump(3) +
                              pushConstantFalseBytecode + shortConditionalJump(3))
     interp.step()
-    pc = interp.s_active_context.pc() + 1
+    pc = interp.s_active_context().pc() + 1
     interp.step()
-    assert interp.s_active_context.pc() == pc
+    assert interp.s_active_context().pc() == pc
     interp.step()
-    pc = interp.s_active_context.pc() + 1
+    pc = interp.s_active_context().pc() + 1
     interp.step()
-    assert interp.s_active_context.pc() == pc + 4
+    assert interp.s_active_context().pc() == pc + 4
 
 def test_popStackBytecode():
     interp = new_interpreter(pushConstantTrueBytecode +
                              popStackBytecode)
     interp.step()
-    assert interp.s_active_context.stack() == [interp.TRUE]
+    assert interp.s_active_context().stack() == [interp.TRUE]
     interp.step()
-    assert interp.s_active_context.stack() == []
+    assert interp.s_active_context().stack() == []
 
 def test_extendedPushBytecode():
     test_pushReceiverVariableBytecode(extendedPushBytecode + chr((0<<6) + 0) +
@@ -520,7 +520,7 @@
     w_association.store(0, "mykey")
     w_association.store(1, "myvalue")
     interp = new_interpreter(pushConstantOneBytecode + bytecode)
-    interp.s_active_context.w_method().literals = fakeliterals(w_association)
+    interp.w_active_context.as_methodcontext_get_shadow().w_method().literals = fakeliterals(w_association)
     interp.step()
     interp.step()
     assert w_association.fetch(1) == interp.ONE
@@ -545,13 +545,13 @@
     shadow.installmethod("+", w_method) 
     
     w_object = shadow.new()
-    interp.s_active_context.push(w_object)
-    interp.s_active_context.push(interp.ONE)
+    interp.s_active_context().push(w_object)
+    interp.s_active_context().push(interp.ONE)
     interp.step()
-    assert interp.s_active_context.w_method() == shadow.methoddict["+"]
-    assert interp.s_active_context.w_receiver() is w_object
-    assert interp.s_active_context.gettemp(0) == interp.ONE
-    assert interp.s_active_context.stack() == []
+    assert interp.w_active_context.as_methodcontext_get_shadow().w_method() == shadow.methoddict["+"]
+    assert interp.s_active_context().w_receiver() is w_object
+    assert interp.w_active_context.as_methodcontext_get_shadow().gettemp(0) == interp.ONE
+    assert interp.s_active_context().stack() == []
 
 def test_bytecodePrimBool():
     interp = new_interpreter(bytecodePrimLessThan +
@@ -561,10 +561,10 @@
                              bytecodePrimEqual +
                              bytecodePrimNotEqual)
     for i in range(6):
-        interp.s_active_context.push(interp.ONE)
-        interp.s_active_context.push(interp.TWO)
+        interp.s_active_context().push(interp.ONE)
+        interp.s_active_context().push(interp.TWO)
         interp.step()
-    assert interp.s_active_context.stack() == [interp.TRUE, interp.FALSE,
+    assert interp.s_active_context().stack() == [interp.TRUE, interp.FALSE,
                                           interp.TRUE, interp.FALSE,
                                           interp.FALSE, interp.TRUE]
 
@@ -593,18 +593,18 @@
     meth1.literals = fakeliterals("foo")
     meth2.literals = fakeliterals("foo")
     interp = new_interpreter(bytecodes)
-    interp.s_active_context.w_method().literals = fakeliterals("foo")
-    interp.s_active_context.push(w_object)
+    interp.w_active_context.as_methodcontext_get_shadow().w_method().literals = fakeliterals("foo")
+    interp.s_active_context().push(w_object)
     interp.step()
     for w_specificclass in [w_super, w_supersuper]:
-        callerContext = interp.s_active_context
+        callerContext = interp.w_active_context
         interp.step()
         interp.step()
-        assert interp.s_active_context.s_sender() == callerContext
-        assert interp.s_active_context.stack() == []
-        assert interp.s_active_context.w_receiver() == w_object
+        assert interp.s_active_context().w_sender() == callerContext
+        assert interp.s_active_context().stack() == []
+        assert interp.w_active_context.as_methodcontext_get_shadow().w_receiver() == w_object
         meth = w_specificclass.as_class_get_shadow().methoddict["foo"]
-        assert interp.s_active_context.w_method() == meth
+        assert interp.w_active_context.as_methodcontext_get_shadow().w_method() == meth
         assert callerContext.stack() == []
 
 def test_secondExtendedSendBytecode():
@@ -639,7 +639,7 @@
 def interpret_bc(bcodes, literals, receiver=objtable.w_nil):
     bcode = "".join([chr(x) for x in bcodes])
     interp = new_interpreter(bcode, receiver=receiver)
-    interp.s_active_context.w_method().literals = literals
+    interp.w_active_context.as_methodcontext_get_shadow().w_method().literals = literals
     return interp.interpret()
 
 # tests: bytecodePrimValue & bytecodePrimValueWithArg

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 Feb 25 17:58:32 2008
@@ -201,15 +201,15 @@
     w_method = s_class.lookup("abs")
 
     assert w_method
-    s_frame = w_method.create_frame(w_object, [])
-    interp.s_active_context = s_frame
+    w_frame = w_method.create_frame(w_object, [])
+    interp.w_active_context = w_frame
 
     print w_method
 
     while True:
         try:
             interp.step()
-            print interp.s_active_context.stack
+            print interp.s_active_context().stack()
         except interpreter.ReturnFromTopLevel, e:
             assert e.object.value == abs(int)
             return
@@ -236,7 +236,7 @@
     s_ctx = s_ap.s_suspended_context()
     s_ap.store_w_suspended_context(objtable.w_nil)
     interp = interpreter.Interpreter()
-    interp.s_active_context = s_ctx
+    interp.w_active_context = s_ctx.w_self()
     interp.interpret()
     
 def test_compile_method():
@@ -270,8 +270,8 @@
     s_class = w_receiver.shadow_of_my_class()
     w_method = s_class.lookup(selector)
     assert w_method
-    s_frame = w_method.create_frame(w_receiver, list(arguments_w))
-    interp.s_active_context = s_frame
+    w_frame = w_method.create_frame(w_receiver, list(arguments_w))
+    interp.w_active_context = w_frame
     while True:
         try:
             interp.step()

Modified: pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_primitives.py
==============================================================================
--- pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_primitives.py	(original)
+++ pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_primitives.py	Mon Feb 25 17:58:32 2008
@@ -25,24 +25,24 @@
     mapped_stack = [wrap(x) for x in stack]
     frame = MockFrame(mapped_stack)
     interp = interpreter.Interpreter()
-    interp.s_active_context = frame
+    interp.w_active_context = frame
     return (interp, len(stack))
 
 def prim(code, stack):
     interp, argument_count = mock(stack)
     prim_table[code](interp, argument_count-1)
-    res = interp.s_active_context.pop()
-    assert not len(interp.s_active_context.stack()) # check args are consumed
+    res = interp.s_active_context().pop()
+    assert not len(interp.s_active_context().stack()) # check args are consumed
     return res
 
 def prim_fails(code, stack):
     interp, argument_count = mock(stack)
-    orig_stack = list(interp.s_active_context.stack())
+    orig_stack = list(interp.s_active_context().stack())
     try:
         prim_table[code](interp, argument_count-1)
         py.test.fail("Expected PrimitiveFailedError")
     except PrimitiveFailedError:
-        assert interp.s_active_context.stack() == orig_stack
+        assert interp.s_active_context().stack() == orig_stack
         
 # smallinteger tests
 def test_small_int_add():



More information about the Pypy-commit mailing list