[pypy-commit] lang-smalltalk default: fixed another problem with primitive QUO

lwassermann noreply at buildbot.pypy.org
Tue Jun 18 16:04:22 CEST 2013


Author: Lars Wassermann <lars.wassermann at gmail.com>
Branch: 
Changeset: r460:6dde3110edf1
Date: 2013-06-17 17:14 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/6dde3110edf1/

Log:	fixed another problem with primitive QUO added more test-cases for
	quo

diff --git a/spyvm/primitives.py b/spyvm/primitives.py
--- a/spyvm/primitives.py
+++ b/spyvm/primitives.py
@@ -237,7 +237,7 @@
         raise PrimitiveFailedError()
     res = receiver // argument
     # see http://python-history.blogspot.de/2010/08/why-pythons-integer-division-floors.html
-    if res < 0:
+    if res < 0 and not abs(receiver) == abs(argument):
         res = res + 1
     return interp.space.wrap_int(res)
 
@@ -702,7 +702,8 @@
         w_rcvr.store(interp.space, 0, w_display_bitmap)
 
     w_display_bitmap.flush_to_screen()
-    interp.image.lastWindowSize = (width << 16)  + height
+    if interp.image:
+        interp.image.lastWindowSize = (width << 16)  + height
     interp.space.objtable['w_display'] = w_rcvr
 
     return w_rcvr
diff --git a/spyvm/shadow.py b/spyvm/shadow.py
--- a/spyvm/shadow.py
+++ b/spyvm/shadow.py
@@ -989,8 +989,8 @@
                 self.pc() + 1
             )
         args = '%d' % argcount
-        for i in range(argcount - 1, -1, -1):
-            args += ': %s' % self.peek(i).as_repr_string()
+        for i in range(argcount):
+            args += ': %s' % self.peek(argcount -1 - i).as_repr_string()
         return '%s (rcvr: %s) [pc: %d] (%s)' % (
             self.method_str(),
             self.w_receiver().as_repr_string(),
diff --git a/spyvm/test/test_primitives.py b/spyvm/test/test_primitives.py
--- a/spyvm/test/test_primitives.py
+++ b/spyvm/test/test_primitives.py
@@ -117,6 +117,12 @@
     assert prim(primitives.QUO, [12,3]).value == 4
     assert prim(primitives.QUO, [12,7]).value == 1
     assert prim(primitives.QUO, [-9,4]).value == -2
+    assert prim(primitives.QUO, [-12,12]).value == -1
+    assert prim(primitives.QUO, [-12,11]).value == -1
+    assert prim(primitives.QUO, [-12,13]).value == 0
+    assert prim(primitives.QUO, [-12,-12]).value == 1
+    assert prim(primitives.QUO, [12,-11]).value == -1
+    assert prim(primitives.QUO, [12,-13]).value == 0
 
 def test_small_int_quo_fail():
     prim_fails(primitives.QUO, [12, 0])


More information about the pypy-commit mailing list