[pypy-svn] r62120 - pypy/trunk/pypy/lang/smalltalk
tverwaes at codespeak.net
tverwaes at codespeak.net
Tue Feb 24 18:01:19 CET 2009
Author: tverwaes
Date: Tue Feb 24 18:01:15 2009
New Revision: 62120
Modified:
pypy/trunk/pypy/lang/smalltalk/primitives.py
Log:
making it a bit more sane. we still have to fix 0<<(too big) cases.
Modified: pypy/trunk/pypy/lang/smalltalk/primitives.py
==============================================================================
--- pypy/trunk/pypy/lang/smalltalk/primitives.py (original)
+++ pypy/trunk/pypy/lang/smalltalk/primitives.py Tue Feb 24 18:01:15 2009
@@ -183,7 +183,7 @@
raise PrimitiveFailedError()
return interp.space.wrap_int(receiver // argument)
-# #// -- return the result of a division, rounded towards negative infinity
+# #// -- return the result of a division, rounded towards negative infinite
@expose_primitive(QUO, unwrap_spec=[int, int])
def func(interp, receiver, argument):
if argument == 0:
@@ -194,11 +194,26 @@
@expose_primitive(BIT_SHIFT, unwrap_spec=[int, int])
def func(interp, receiver, argument):
- # left shift, must fail if we loose bits beyond 32
+ # TODO: 1 << 100 will overflow to 0. Catch this gracefully by Primitive
+ # Failing! Use ovfcheck_lfshift
+ # (http://codespeak.net/pypy/dist/pypy/doc/coding-guide.html#integer-types)
+
+ # left shift, must fail if we lose bits beyond 32
if argument > 0:
shifted = receiver << argument
- if (shifted >> argument) != receiver:
- raise PrimitiveFailedError()
+
+ # Make sure we respect our bitlimits set by TAGGED_XXXINT.
+ if shifted < 0:
+ # If negative, check if there are no bits unset outside the MAXINT
+ # region
+ if constants.TAGGED_MININT ^ shifted > constants.TAGGED_MAXINT:
+ raise PrimitiveFailedError()
+ else:
+ # If possitive, check if there are no bits set outside the MAXINT
+ # region
+ if shifted & constants.TAGGED_MAXINT != shifted:
+ raise PrimitiveFailedError()
+
return interp.space.wrap_int(shifted)
# right shift, ok to lose bits
More information about the Pypy-commit
mailing list