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

cfbolz at codespeak.net cfbolz at codespeak.net
Sat Oct 27 12:01:16 CEST 2007


Author: cfbolz
Date: Sat Oct 27 12:01:14 2007
New Revision: 48101

Modified:
   pypy/dist/pypy/lang/smalltalk/constants.py
   pypy/dist/pypy/lang/smalltalk/primitives.py
   pypy/dist/pypy/lang/smalltalk/test/test_primitives.py
Log:
replace all these nasty 32-bit centered magic numbers with proper constants


Modified: pypy/dist/pypy/lang/smalltalk/constants.py
==============================================================================
--- pypy/dist/pypy/lang/smalltalk/constants.py	(original)
+++ pypy/dist/pypy/lang/smalltalk/constants.py	Sat Oct 27 12:01:14 2007
@@ -1,3 +1,4 @@
+from pypy.rlib.rarithmetic import LONG_BIT
 
 # ___________________________________________________________________________
 # Slot Names
@@ -116,3 +117,6 @@
     "true": SO_TRUE,
     "false": SO_FALSE,
 }
+
+TAGGED_MAXINT = 2 ** (LONG_BIT - 2) - 1
+TAGGED_MININT = -2 ** (LONG_BIT - 2)

Modified: pypy/dist/pypy/lang/smalltalk/primitives.py
==============================================================================
--- pypy/dist/pypy/lang/smalltalk/primitives.py	(original)
+++ pypy/dist/pypy/lang/smalltalk/primitives.py	Sat Oct 27 12:01:14 2007
@@ -126,9 +126,9 @@
     raise PrimitiveFailedError()
 
 def wrap_int(value):
-    if value > 1073741823:
+    if value > constants.TAGGED_MAXINT:
         raise PrimitiveFailedError()
-    if value < -1073741824:
+    if value < constants.TAGGED_MININT:
         raise PrimitiveFailedError()
     return objtable.wrap_int(value)
     
@@ -532,7 +532,7 @@
 def func(interp, w_arg):
     import time
     import math
-    return wrap_int(int(math.fmod(time.time()*1000,1073741823/2)))
+    return wrap_int(int(math.fmod(time.time()*1000, constants.TAGGED_MAXINT/2)))
 
 @expose_primitive(SECONDS_CLOCK, unwrap_spec=[object])
 def func(interp, w_arg):

Modified: pypy/dist/pypy/lang/smalltalk/test/test_primitives.py
==============================================================================
--- pypy/dist/pypy/lang/smalltalk/test/test_primitives.py	(original)
+++ pypy/dist/pypy/lang/smalltalk/test/test_primitives.py	Sat Oct 27 12:01:14 2007
@@ -51,22 +51,24 @@
     assert prim(primitives.ADD, [3,4]).value == 7
 
 def test_small_int_add_fail():
-    prim_fails(primitives.ADD, [1073741823,2])
+    prim_fails(primitives.ADD, [constants.TAGGED_MAXINT,2])
 
 def test_small_int_minus():
     assert prim(primitives.SUBTRACT, [5,9]).value == -4
 
 def test_small_int_minus_fail():
-    prim_fails(primitives.SUBTRACT, [-1073741823,2])
+    prim_fails(primitives.SUBTRACT, [constants.TAGGED_MININT,1])
+    prim_fails(primitives.SUBTRACT,
+               [constants.TAGGED_MININT, constants.TAGGED_MAXINT])
     
 def test_small_int_multiply():
     assert prim(primitives.MULTIPLY, [6,3]).value == 18
 
 def test_small_int_multiply_overflow():
-    prim_fails(primitives.MULTIPLY, [1073741823, 2])
-    prim_fails(primitives.MULTIPLY, [1073741823, 1073741823])
-    prim_fails(primitives.MULTIPLY, [1073741823, -4])
-    prim_fails(primitives.MULTIPLY, [-1073741823, 2])
+    prim_fails(primitives.MULTIPLY, [constants.TAGGED_MAXINT, 2])
+    prim_fails(primitives.MULTIPLY, [constants.TAGGED_MAXINT, constants.TAGGED_MAXINT])
+    prim_fails(primitives.MULTIPLY, [constants.TAGGED_MAXINT, -4])
+    prim_fails(primitives.MULTIPLY, [constants.TAGGED_MININT, 2])
     
 def test_small_int_divide():
     assert prim(primitives.DIVIDE, [6,3]).value == 2



More information about the Pypy-commit mailing list