Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #library("dart:coreimpl"); | 5 #library("dart:coreimpl"); |
| 6 | 6 |
| 7 #source("../../corelib/src/implementation/dual_pivot_quicksort.dart"); | 7 #source("../../corelib/src/implementation/dual_pivot_quicksort.dart"); |
| 8 #source("../../corelib/src/implementation/duration_implementation.dart"); | 8 #source("../../corelib/src/implementation/duration_implementation.dart"); |
| 9 #source("../../corelib/src/implementation/exceptions.dart"); | 9 #source("../../corelib/src/implementation/exceptions.dart"); |
| 10 #source("../../corelib/src/implementation/future_implementation.dart"); | 10 #source("../../corelib/src/implementation/future_implementation.dart"); |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 if (!hasNext()) { | 134 if (!hasNext()) { |
| 135 throw const NoMoreElementsException(); | 135 throw const NoMoreElementsException(); |
| 136 } | 136 } |
| 137 return _array[_pos++]; | 137 return _array[_pos++]; |
| 138 } | 138 } |
| 139 | 139 |
| 140 final List<T> _array; | 140 final List<T> _array; |
| 141 int _pos; | 141 int _pos; |
| 142 } | 142 } |
| 143 | 143 |
| 144 // TODO(jimhug): Enforce immutability on IE | |
| 145 ImmutableList _constList(List other) native ''' | |
| 146 other.__proto__ = ImmutableList.prototype; | |
| 147 return other; | |
| 148 ''' | |
| 149 { new ImmutableList(other.length); } | |
| 150 | |
| 151 | |
| 144 /** An immutable list. Attempting to modify the list will throw an exception. */ | 152 /** An immutable list. Attempting to modify the list will throw an exception. */ |
| 145 class ImmutableList<E> extends ListFactory<E> { | 153 class ImmutableList<E> extends ListFactory<E> { |
| 146 final int _length; | 154 // TODO(jimhug): Can this go away now? |
| 147 | 155 int get length() native "return this.length;"; |
| 148 // TODO(sigmund): remove this when we stop overriding the [length] property | |
| 149 // in Array. | |
| 150 int get length() => _length; | |
| 151 | 156 |
| 152 void set length(int length) { | 157 void set length(int length) { |
| 153 throw const IllegalAccessException(); | 158 throw const IllegalAccessException(); |
| 154 } | 159 } |
| 155 | 160 |
| 156 ImmutableList([int length]) : _length = length, super(length); | 161 ImmutableList(int length) : super(length); |
| 157 | 162 |
| 158 factory ImmutableList.from(List other) { | 163 factory ImmutableList.from(List other) { |
| 159 final list = new ImmutableList(other.length); | 164 return _constList(other); |
| 160 for (int i = 0; i < other.length; i++) { | |
| 161 // Note: push invokes the setter of [length], which we override. So | |
| 162 // instead we use the native []= operator that cannot be overriden. | |
| 163 list._setindex(i, other[i]); | |
| 164 } | |
| 165 return list; | |
| 166 } | 165 } |
| 167 | 166 |
| 168 void _setindex(int index, E value) native "return this[index] = value;"; | |
| 169 | |
| 170 void operator []=(int index, E value) { | 167 void operator []=(int index, E value) { |
| 171 throw const IllegalAccessException(); | 168 throw const IllegalAccessException(); |
| 172 } | 169 } |
| 173 | 170 |
| 174 void copyFrom(List src, int srcStart, int dstStart, int count) { | 171 void copyFrom(List src, int srcStart, int dstStart, int count) { |
| 175 throw const IllegalAccessException(); | 172 throw const IllegalAccessException(); |
| 176 } | 173 } |
| 177 | 174 |
| 178 void setRange(int start, int length, List<E> from, [int startFrom = 0]) { | 175 void setRange(int start, int length, List<E> from, [int startFrom = 0]) { |
| 179 throw const IllegalAccessException(); | 176 throw const IllegalAccessException(); |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 402 _done = true; | 399 _done = true; |
| 403 return false; | 400 return false; |
| 404 } else { | 401 } else { |
| 405 return true; | 402 return true; |
| 406 } | 403 } |
| 407 } | 404 } |
| 408 } | 405 } |
| 409 | 406 |
| 410 | 407 |
| 411 class NumImplementation implements int, double native "Number" { | 408 class NumImplementation implements int, double native "Number" { |
| 409 // Arithmetic operations. | |
|
Jennifer Messerly
2012/01/18 00:03:00
nice!
| |
| 410 num operator +(num other) native; | |
| 411 num operator -(num other) native; | |
| 412 num operator *(num other) native; | |
| 413 num operator %(num other) native; | |
| 414 num operator /(num other) native; | |
| 415 // Truncating division. | |
| 416 // TODO(jimhug): Implement | |
| 417 num operator ~/(num other) native; | |
| 418 // The unary '-' operator. | |
| 419 num operator negate() native "'use strict'; return -this;"; | |
| 420 | |
| 421 // Relational operations. | |
| 422 bool operator <(num other) native; | |
| 423 bool operator <=(num other) native; | |
| 424 bool operator >(num other) native; | |
| 425 bool operator >=(num other) native; | |
| 426 | |
| 427 // Bitwise operations | |
| 428 int operator &(int other) native; | |
| 429 int operator |(int other) native; | |
| 430 int operator ^(int other) native; | |
| 431 int operator ~() native; | |
| 432 int operator <<(int shiftAmount) native; | |
| 433 int operator >>(int shiftAmount) native; | |
| 434 | |
| 435 | |
| 412 // TODO(jimhug): Move these out of methods to avoid boxing when not needed. | 436 // TODO(jimhug): Move these out of methods to avoid boxing when not needed. |
| 413 // TODO(jmesserly): for now I'm avoiding boxing with "use strict", however, | 437 // TODO(jmesserly): for now I'm avoiding boxing with "use strict", however, |
| 414 // we might want to do something better. It would be nice if operators and | 438 // we might want to do something better. It would be nice if operators and |
| 415 // methods on String/num were handled in a uniform way. | 439 // methods on String/num were handled in a uniform way. |
| 416 num remainder(num other) native "'use strict'; return this % other;"; | 440 num remainder(num other) native "'use strict'; return this % other;"; |
| 417 | 441 |
| 418 bool isEven() native "'use strict'; return ((this & 1) == 0);"; | 442 bool isEven() native "'use strict'; return ((this & 1) == 0);"; |
| 419 bool isOdd() native "'use strict'; return ((this & 1) == 1);"; | 443 bool isOdd() native "'use strict'; return ((this & 1) == 1);"; |
| 420 bool isNaN() native "'use strict'; return isNaN(this);"; | 444 bool isNaN() native "'use strict'; return isNaN(this);"; |
| 421 bool isNegative() native | 445 bool isNegative() native |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 479 } else if (isNaN()) { | 503 } else if (isNaN()) { |
| 480 if (other.isNaN()) { | 504 if (other.isNaN()) { |
| 481 return 0; | 505 return 0; |
| 482 } | 506 } |
| 483 return 1; | 507 return 1; |
| 484 } else { | 508 } else { |
| 485 return -1; | 509 return -1; |
| 486 } | 510 } |
| 487 } | 511 } |
| 488 } | 512 } |
| OLD | NEW |