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

tverwaes at codespeak.net tverwaes at codespeak.net
Wed Oct 24 14:02:52 CEST 2007


Author: tverwaes
Date: Wed Oct 24 14:02:51 2007
New Revision: 47818

Modified:
   pypy/dist/pypy/lang/smalltalk/interpreter.py
   pypy/dist/pypy/lang/smalltalk/model.py
   pypy/dist/pypy/lang/smalltalk/test/test_interpreter.py
   pypy/dist/pypy/lang/smalltalk/test/test_model.py
Log:
(toon, armin) fixed supersend and singleextended and secondextended


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 14:02:51 2007
@@ -120,15 +120,14 @@
     def _sendSelfSelector(self, selector, argcount, interp):
         receiver = self.peek(argcount)
         self._sendSelector(selector, argcount, interp,
-                           receiver.w_class)
+                           receiver, receiver.w_class)
 
     def _sendSuperSelector(self, selector, argcount, interp):
-        receiver = self.peek(argcount)
-        self._sendSelector(selector, argcount, interp,
-                           receiver.w_class.w_superclass)
+        self._sendSelector(selector, argcount, interp, self.receiver,
+                           self.method.w_compiledin.w_superclass)
 
-    def _sendSelector(self, selector, argcount, interp, receiverclass):
-        receiver = self.peek(argcount)
+    def _sendSelector(self, selector, argcount, interp,
+                      receiver, receiverclass):
         method = receiverclass.lookup(selector)
         assert method
         if method.primitive:
@@ -221,7 +220,10 @@
         self._sendSuperSelector(selector, argcount, interp)
 
     def secondExtendedSendBytecode(self, interp):
-        raise MissingBytecode
+        descriptor = self.getByte()
+        selector = self.method.literals[descriptor & 63]
+        argcount = descriptor >> 6
+        self._sendSelfSelector(selector, argcount, interp)
 
     def popStackBytecode(self, interp):
         self.pop()

Modified: pypy/dist/pypy/lang/smalltalk/model.py
==============================================================================
--- pypy/dist/pypy/lang/smalltalk/model.py	(original)
+++ pypy/dist/pypy/lang/smalltalk/model.py	Wed Oct 24 14:02:51 2007
@@ -93,10 +93,11 @@
 
     The trailer has two variant formats.  In the first variant, the last byte is at least 252 and the last four bytes represent a source pointer into one of the sources files (see #sourcePointer).  In the second variant, the last byte is less than 252, and the last several bytes are a compressed version of the names of the method's temporary variables.  The number of bytes used for this purpose is the value of the last byte in the method.
     """
-    def __init__(self, w_class, size,
-                 bytes="", argsize=0, tempsize=0, primitive=0):
+    def __init__(self, w_class, size, bytes="", argsize=0, 
+                 tempsize=0, primitive=0, w_compiledin=None):
         W_Object.__init__(self, w_class)
         self.literals = [None] * size
+        self.w_compiledin = w_compiledin
         self.bytes = bytes
         self.argsize = argsize
         self.tempsize = tempsize
@@ -155,6 +156,10 @@
         else:
             return None
 
+    def installmethod(self, selector, method):
+        self.methoddict[selector] = method
+        method.w_compiledin = self
+
 class W_MetaClass(W_Class):
     def ismetaclass(self):
         return True

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 14:02:51 2007
@@ -200,7 +200,8 @@
           (returnFalse, interpreter.Interpreter.FALSE),
           (returnNil, interpreter.Interpreter.NIL),
           (returnTopFromMethod, interpreter.Interpreter.ONE) ]:
-        w_class.methoddict["foo"] = model.W_CompiledMethod(None, 0, pushConstantOneBytecode + bytecode)
+        w_class.installmethod("foo",
+                              model.W_CompiledMethod(None, 0, pushConstantOneBytecode + bytecode))
         interp = new_interpreter(bytecodes)
         interp.activeContext.method.literals = ["foo"]
         interp.activeContext.push(w_object)
@@ -224,7 +225,7 @@
 def test_fibWithArgument():
     bytecode = ''.join(map(chr, [ 16, 119, 178, 154, 118, 164, 11, 112, 16, 118, 177, 224, 112, 16, 119, 177, 224, 176, 124 ]))
     w_class = model.W_Class(None, None)
-    w_class.methoddict["fib:"] = model.W_CompiledMethod(None, 1, bytecode, 1)
+    w_class.installmethod("fib:", model.W_CompiledMethod(None, 1, bytecode, 1))
     w_class.methoddict["fib:"].literals[0] = "fib:"
     w_object = w_class.new()
     interp = new_interpreter(sendLiteralSelectorBytecode(16) + returnTopFromMethod)
@@ -238,7 +239,7 @@
     w_smallintclass = model.W_Class(None, None)
     prim_meth = model.W_CompiledMethod(None, 0, "", argsize=1,
                                        primitive=primitives.SUBTRACT)
-    w_smallintclass.methoddict["sub"] = prim_meth
+    w_smallintclass.installmethod("sub", prim_meth)
     w_50 = model.W_SmallInteger(w_smallintclass, 50)
     w_50.w_class = w_smallintclass
     w_8 = model.W_SmallInteger(w_smallintclass, 8)
@@ -386,7 +387,7 @@
 def test_callPrimitiveAndPush_fallback():
     interp = new_interpreter(bytecodePrimAdd)
     w_class = model.W_Class(None, None)
-    w_class.methoddict["+"] = model.W_CompiledMethod(None, 1, "", 1)
+    w_class.installmethod("+", model.W_CompiledMethod(None, 1, "", 1))
     w_object = w_class.new()
     interp.activeContext.push(w_object)
     interp.activeContext.push(interp.ONE)
@@ -417,8 +418,35 @@
     sendBytecodesTest(w_class, w_object, singleExtendedSendBytecode + chr(0))
 
 def test_singleExtendedSuperBytecode():
-    w_super = model.W_Class(None, None)
+    w_supersuper = model.W_Class(None, None)
+    w_super = model.W_Class(None, w_supersuper)
     w_class = model.W_Class(None, w_super)
     w_object = w_class.new()
-    sendBytecodesTest(w_super, w_object, singleExtendedSuperBytecode + chr(0))
- 
+    # first call method installed in w_class
+    bytecodes = singleExtendedSendBytecode + chr(0)
+    # which does a call to its super
+    w_class.installmethod("foo",
+                          model.W_CompiledMethod(None, 0, singleExtendedSuperBytecode + chr(0)))
+    # and that one again to its super
+    w_super.installmethod("foo",
+                          model.W_CompiledMethod(None, 0, singleExtendedSuperBytecode + chr(0)))
+    w_supersuper.installmethod("foo",
+                               model.W_CompiledMethod(None, 0, ""))
+    w_class.methoddict["foo"].literals = ["foo"]
+    w_super.methoddict["foo"].literals = ["foo"]
+    interp = new_interpreter(bytecodes)
+    interp.activeContext.method.literals = ["foo"]
+    interp.activeContext.push(w_object)
+    for w_specificclass in [w_class, w_super, w_supersuper]:
+        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_specificclass.methoddict["foo"]
+        assert callerContext.stack == []
+
+def test_secondExtendedSendBytecode():
+    w_class = model.W_Class(None, None)
+    w_object = w_class.new()
+    sendBytecodesTest(w_class, w_object, secondExtendedSendBytecode + chr(0)) 

Modified: pypy/dist/pypy/lang/smalltalk/test/test_model.py
==============================================================================
--- pypy/dist/pypy/lang/smalltalk/test/test_model.py	(original)
+++ pypy/dist/pypy/lang/smalltalk/test/test_model.py	Wed Oct 24 14:02:51 2007
@@ -66,4 +66,11 @@
 	assert w_class.lookup("zork") == None
 	assert w_subclass.lookup("foo") == 3
 	assert w_subclass.lookup("bar") == 2
-	assert w_subclass.lookup("zork") == None
\ No newline at end of file
+	assert w_subclass.lookup("zork") == None
+
+def test_w_compiledin():
+        w_super = model.W_Class(None,None)
+        w_class = model.W_Class(None,w_super)
+        w_super.installmethod("foo",
+                              model.W_CompiledMethod(None, 0))
+        assert w_class.lookup("foo").w_compiledin == w_super



More information about the Pypy-commit mailing list