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

tverwaes at codespeak.net tverwaes at codespeak.net
Wed Oct 24 11:38:05 CEST 2007


Author: tverwaes
Date: Wed Oct 24 11:38:04 2007
New Revision: 47804

Modified:
   pypy/dist/pypy/lang/smalltalk/interpreter.py
   pypy/dist/pypy/lang/smalltalk/test/test_interpreter.py
Log:
(toon) added singleExtendedSuperBytecode


Modified: pypy/dist/pypy/lang/smalltalk/interpreter.py
==============================================================================
--- pypy/dist/pypy/lang/smalltalk/interpreter.py	(original)
+++ pypy/dist/pypy/lang/smalltalk/interpreter.py	Wed Oct 24 11:38:04 2007
@@ -115,11 +115,21 @@
     def sendLiteralSelectorBytecode(self, interp):
         selector = self.method.literals[self.currentBytecode & 15]
         argcount = ((self.currentBytecode >> 4) & 3) - 1
-        self._sendSelector(selector, argcount, interp)
+        self._sendSelfSelector(selector, argcount, interp)
         
-    def _sendSelector(self, selector, argcount, interp):
+    def _sendSelfSelector(self, selector, argcount, interp):
         receiver = self.peek(argcount)
-        method = receiver.w_class.lookup(selector)
+        self._sendSelector(selector, argcount, interp,
+                           receiver.w_class)
+
+    def _sendSuperSelector(self, selector, argcount, interp):
+        receiver = self.peek(argcount)
+        self._sendSelector(selector, argcount, interp,
+                           receiver.w_class.w_superclass)
+
+    def _sendSelector(self, selector, argcount, interp, receiverclass):
+        receiver = self.peek(argcount)
+        method = receiverclass.lookup(selector)
         assert method
         if method.primitive:
             func = primitives.prim_table[method.primitive]
@@ -195,17 +205,20 @@
         self.extendedStoreBytecode(interp)
         self.pop()
 
-    def singleExtendedSendBytecode(self, interp):
+    def getExtendedSelectorArgcount(self):
         descriptor = self.getByte()
-        selector = self.method.literals[descriptor & 31]
-        argcount = descriptor >> 5
-        self._sendSelector(selector, argcount, interp)
+        return (self.method.literals[descriptor & 31]), (descriptor >> 5)
+
+    def singleExtendedSendBytecode(self, interp):
+        selector, argcount = self.getExtendedSelectorArgcount()
+        self._sendSelfSelector(selector, argcount, interp)
 
     def doubleExtendedDoAnythingBytecode(self, interp):
         raise MissingBytecode
 
     def singleExtendedSuperBytecode(self, interp):
-        raise MissingBytecode
+        selector, argcount = self.getExtendedSelectorArgcount()
+        self._sendSuperSelector(selector, argcount, interp)
 
     def secondExtendedSendBytecode(self, interp):
         raise MissingBytecode
@@ -250,7 +263,7 @@
         try:
             self.push(primitives.prim_table[primitive](self))
         except primitives.PrimitiveFailedError:
-            self._sendSelector(selector, argcount, interp)
+            self._sendSelfSelector(selector, argcount, interp)
 
     def bytecodePrimAdd(self, interp):
         self.callPrimitiveAndPush(primitives.ADD, "+", 1, interp)

Modified: pypy/dist/pypy/lang/smalltalk/test/test_interpreter.py
==============================================================================
--- pypy/dist/pypy/lang/smalltalk/test/test_interpreter.py	(original)
+++ pypy/dist/pypy/lang/smalltalk/test/test_interpreter.py	Wed Oct 24 11:38:04 2007
@@ -427,4 +427,29 @@
         interp.step()
         assert interp.activeContext == callerContext
         assert interp.activeContext.stack == [result]
+
+def test_singleExtendedSuperBytecode():
+    w_super = model.W_Class(None, None)
+    w_class = model.W_Class(None, w_super)
+    w_object = w_class.new()
+    for bytecode, result in [ (returnReceiver, w_object), 
+          (returnTrue, interpreter.Interpreter.TRUE), 
+          (returnFalse, interpreter.Interpreter.FALSE),
+          (returnNil, interpreter.Interpreter.NIL),
+          (returnTopFromMethod, interpreter.Interpreter.ONE) ]:
+        w_super.methoddict["foo"] = model.W_CompiledMethod(None, 0, pushConstantOneBytecode + bytecode)
+        interp = new_interpreter(singleExtendedSuperBytecode + chr(0))
+        interp.activeContext.method.literals = ["foo"]
+        interp.activeContext.push(w_object)
+        callerContext = interp.activeContext
+        interp.step()
+        assert interp.activeContext.sender == callerContext
+        assert interp.activeContext.stack == []
+        assert interp.activeContext.receiver == w_object
+        assert interp.activeContext.method == w_super.methoddict["foo"]
+        assert callerContext.stack == []
+        interp.step()
+        interp.step()
+        assert interp.activeContext == callerContext
+        assert interp.activeContext.stack == [result]
  



More information about the Pypy-commit mailing list