Skip to content

Commit

Permalink
JS cannot shift by 32. So don't try. Duh!
Browse files Browse the repository at this point in the history
  • Loading branch information
codefrau committed Sep 3, 2014
1 parent de63a85 commit 6d694d0
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions vm.js
Expand Up @@ -1913,11 +1913,15 @@ Object.subclass('Squeak.Interpreter',
if (arg === 0) return Squeak.NonSmallInt; // fail if divide by zero
return rcvr - Math.floor(rcvr/arg) * arg;
},
safeShift: function(bitsToShift, shiftCount) {
if (shiftCount<0) return bitsToShift>>-shiftCount; //OK to lose bits shifting right
//check for lost bits by seeing if computation is reversible
var shifted = bitsToShift<<shiftCount;
if ((shifted>>shiftCount) === bitsToShift) return shifted;
safeShift: function(smallInt, shiftCount) {
if (shiftCount < 0) {
if (shiftCount < -31) return 0; // JS shifts only up to 31 bits
return smallInt >> -shiftCount; // OK to lose bits shifting right
}
if (shiftCount > 31) return smallInt == 0 ? 0 : Squeak.NonSmallInt;
// check for lost bits by seeing if computation is reversible
var shifted = smallInt << shiftCount;
if ((shifted>>shiftCount) === smallInt) return shifted;
return Squeak.NonSmallInt; //non-small result will cause failure
},
},
Expand Down

0 comments on commit 6d694d0

Please sign in to comment.