Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Unified Diff: sdk/lib/_internal/lib/js_number.dart

Issue 87783003: Add UInt32 and UInt31 types to better infer bit operations. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sdk/lib/_internal/lib/js_number.dart
===================================================================
--- sdk/lib/_internal/lib/js_number.dart (revision 30666)
+++ sdk/lib/_internal/lib/js_number.dart (working copy)
@@ -224,7 +224,7 @@
// JavaScript only looks at the last 5 bits of the shift-amount. Shifting
// by 33 is hence equivalent to a shift by 1.
if (JS('bool', r'# > 31', other)) return 0;
- return JS('int', r'(# << #) >>> 0', this, other);
+ return JS('JSUInt32', r'(# << #) >>> 0', this, other);
}
num operator >>(num other) {
@@ -238,28 +238,28 @@
// Given that 'a' is positive we must not use '>>'. Otherwise a number
// that has the 31st bit set would be treated as negative and shift in
// ones.
- return JS('int', r'# >>> #', this, other);
+ return JS('JSUInt32', r'# >>> #', this, other);
}
// For negative numbers we just clamp the shift-by amount. 'a' could be
// negative but not have its 31st bit set. The ">>" would then shift in
// 0s instead of 1s. Therefore we cannot simply return 0xFFFFFFFF.
if (JS('num', '#', other) > 31) other = 31;
- return JS('int', r'(# >> #) >>> 0', this, other);
+ return JS('JSUInt32', r'(# >> #) >>> 0', this, other);
}
num operator &(num other) {
if (other is !num) throw new ArgumentError(other);
- return JS('int', r'(# & #) >>> 0', this, other);
+ return JS('JSUInt32', r'(# & #) >>> 0', this, other);
}
num operator |(num other) {
if (other is !num) throw new ArgumentError(other);
- return JS('int', r'(# | #) >>> 0', this, other);
+ return JS('JSUInt32', r'(# | #) >>> 0', this, other);
}
num operator ^(num other) {
if (other is !num) throw new ArgumentError(other);
- return JS('int', r'(# ^ #) >>> 0', this, other);
+ return JS('JSUInt32', r'(# ^ #) >>> 0', this, other);
}
bool operator <(num other) {
@@ -358,10 +358,13 @@
Type get runtimeType => int;
- int operator ~() => JS('int', r'(~#) >>> 0', this);
+ int operator ~() => JS('JSUInt32', r'(~#) >>> 0', this);
}
class JSDouble extends JSNumber implements double {
const JSDouble();
Type get runtimeType => double;
}
+
+class JSUInt32 extends JSInt {}
+class JSUInt31 extends JSUInt32 {}

Powered by Google App Engine
This is Rietveld 408576698