| 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 #include "vm/object.h" | 5 #include "vm/object.h" |
| 6 | 6 |
| 7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
| 8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
| 9 #include "vm/assembler.h" | 9 #include "vm/assembler.h" |
| 10 #include "vm/become.h" | 10 #include "vm/become.h" |
| (...skipping 19150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 19161 result.set_digits( | 19161 result.set_digits( |
| 19162 TypedData::Handle(zone, TypedData::EmptyUint32Array(thread))); | 19162 TypedData::Handle(zone, TypedData::EmptyUint32Array(thread))); |
| 19163 } | 19163 } |
| 19164 result.SetNeg(neg); | 19164 result.SetNeg(neg); |
| 19165 result.SetUsed(used); | 19165 result.SetUsed(used); |
| 19166 return result.raw(); | 19166 return result.raw(); |
| 19167 } | 19167 } |
| 19168 | 19168 |
| 19169 | 19169 |
| 19170 RawBigint* Bigint::NewFromInt64(int64_t value, Heap::Space space) { | 19170 RawBigint* Bigint::NewFromInt64(int64_t value, Heap::Space space) { |
| 19171 // Currently only used to convert Smi or Mint to hex String, therefore do |
| 19172 // not throw RangeError if --limit-ints-to-64-bits. |
| 19171 const TypedData& digits = TypedData::Handle(NewDigits(2, space)); | 19173 const TypedData& digits = TypedData::Handle(NewDigits(2, space)); |
| 19172 bool neg; | 19174 bool neg; |
| 19173 uint64_t abs_value; | 19175 uint64_t abs_value; |
| 19174 if (value < 0) { | 19176 if (value < 0) { |
| 19175 neg = true; | 19177 neg = true; |
| 19176 abs_value = -value; | 19178 abs_value = -value; |
| 19177 } else { | 19179 } else { |
| 19178 neg = false; | 19180 neg = false; |
| 19179 abs_value = value; | 19181 abs_value = value; |
| 19180 } | 19182 } |
| 19181 SetDigitAt(digits, 0, static_cast<uint32_t>(abs_value)); | 19183 SetDigitAt(digits, 0, static_cast<uint32_t>(abs_value)); |
| 19182 SetDigitAt(digits, 1, static_cast<uint32_t>(abs_value >> 32)); | 19184 SetDigitAt(digits, 1, static_cast<uint32_t>(abs_value >> 32)); |
| 19183 return New(neg, 2, digits, space); | 19185 return New(neg, 2, digits, space); |
| 19184 } | 19186 } |
| 19185 | 19187 |
| 19186 | 19188 |
| 19187 RawBigint* Bigint::NewFromUint64(uint64_t value, Heap::Space space) { | 19189 RawBigint* Bigint::NewFromUint64(uint64_t value, Heap::Space space) { |
| 19190 if (FLAG_limit_ints_to_64_bits) { |
| 19191 Exceptions::ThrowRangeErrorMsg( |
| 19192 "Integer operand requires conversion to Bigint"); |
| 19193 } |
| 19188 const TypedData& digits = TypedData::Handle(NewDigits(2, space)); | 19194 const TypedData& digits = TypedData::Handle(NewDigits(2, space)); |
| 19189 SetDigitAt(digits, 0, static_cast<uint32_t>(value)); | 19195 SetDigitAt(digits, 0, static_cast<uint32_t>(value)); |
| 19190 SetDigitAt(digits, 1, static_cast<uint32_t>(value >> 32)); | 19196 SetDigitAt(digits, 1, static_cast<uint32_t>(value >> 32)); |
| 19191 return New(false, 2, digits, space); | 19197 return New(false, 2, digits, space); |
| 19192 } | 19198 } |
| 19193 | 19199 |
| 19194 | 19200 |
| 19195 RawBigint* Bigint::NewFromShiftedInt64(int64_t value, | 19201 RawBigint* Bigint::NewFromShiftedInt64(int64_t value, |
| 19196 intptr_t shift, | 19202 intptr_t shift, |
| 19197 Heap::Space space) { | 19203 Heap::Space space) { |
| 19204 if (FLAG_limit_ints_to_64_bits) { |
| 19205 // The allocated Bigint value is not necessarily out of range, but it may |
| 19206 // be used as an operand in an operation resulting in a Bigint. |
| 19207 Exceptions::ThrowRangeErrorMsg( |
| 19208 "Integer operand requires conversion to Bigint"); |
| 19209 } |
| 19198 ASSERT(kBitsPerDigit == 32); | 19210 ASSERT(kBitsPerDigit == 32); |
| 19199 ASSERT(shift >= 0); | 19211 ASSERT(shift >= 0); |
| 19200 const intptr_t digit_shift = shift / kBitsPerDigit; | 19212 const intptr_t digit_shift = shift / kBitsPerDigit; |
| 19201 const intptr_t bit_shift = shift % kBitsPerDigit; | 19213 const intptr_t bit_shift = shift % kBitsPerDigit; |
| 19202 const intptr_t used = 3 + digit_shift; | 19214 const intptr_t used = 3 + digit_shift; |
| 19203 const TypedData& digits = TypedData::Handle(NewDigits(used, space)); | 19215 const TypedData& digits = TypedData::Handle(NewDigits(used, space)); |
| 19204 bool neg; | 19216 bool neg; |
| 19205 uint64_t abs_value; | 19217 uint64_t abs_value; |
| 19206 if (value < 0) { | 19218 if (value < 0) { |
| 19207 neg = true; | 19219 neg = true; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 19218 SetDigitAt(digits, 1 + digit_shift, | 19230 SetDigitAt(digits, 1 + digit_shift, |
| 19219 static_cast<uint32_t>(abs_value >> (32 - bit_shift))); | 19231 static_cast<uint32_t>(abs_value >> (32 - bit_shift))); |
| 19220 SetDigitAt(digits, 2 + digit_shift, | 19232 SetDigitAt(digits, 2 + digit_shift, |
| 19221 (bit_shift == 0) ? 0 : static_cast<uint32_t>(abs_value >> | 19233 (bit_shift == 0) ? 0 : static_cast<uint32_t>(abs_value >> |
| 19222 (64 - bit_shift))); | 19234 (64 - bit_shift))); |
| 19223 return New(neg, used, digits, space); | 19235 return New(neg, used, digits, space); |
| 19224 } | 19236 } |
| 19225 | 19237 |
| 19226 | 19238 |
| 19227 RawBigint* Bigint::NewFromCString(const char* str, Heap::Space space) { | 19239 RawBigint* Bigint::NewFromCString(const char* str, Heap::Space space) { |
| 19240 // Allow parser to scan Bigint literal, even with --limit-ints-to-64-bits. |
| 19228 ASSERT(str != NULL); | 19241 ASSERT(str != NULL); |
| 19229 bool neg = false; | 19242 bool neg = false; |
| 19230 TypedData& digits = TypedData::Handle(); | 19243 TypedData& digits = TypedData::Handle(); |
| 19231 if (str[0] == '-') { | 19244 if (str[0] == '-') { |
| 19232 ASSERT(str[1] != '-'); | 19245 ASSERT(str[1] != '-'); |
| 19233 neg = true; | 19246 neg = true; |
| 19234 str++; | 19247 str++; |
| 19235 } | 19248 } |
| 19236 intptr_t used; | 19249 intptr_t used; |
| 19237 const intptr_t str_length = strlen(str); | 19250 const intptr_t str_length = strlen(str); |
| 19238 if ((str_length >= 2) && (str[0] == '0') && | 19251 if ((str_length >= 2) && (str[0] == '0') && |
| 19239 ((str[1] == 'x') || (str[1] == 'X'))) { | 19252 ((str[1] == 'x') || (str[1] == 'X'))) { |
| 19240 digits = NewDigitsFromHexCString(&str[2], &used, space); | 19253 digits = NewDigitsFromHexCString(&str[2], &used, space); |
| 19241 } else { | 19254 } else { |
| 19242 digits = NewDigitsFromDecCString(str, &used, space); | 19255 digits = NewDigitsFromDecCString(str, &used, space); |
| 19243 } | 19256 } |
| 19244 return New(neg, used, digits, space); | 19257 return New(neg, used, digits, space); |
| 19245 } | 19258 } |
| 19246 | 19259 |
| 19247 | 19260 |
| 19248 RawBigint* Bigint::NewCanonical(const String& str) { | 19261 RawBigint* Bigint::NewCanonical(const String& str) { |
| 19262 // Allow parser to scan Bigint literal, even with --limit-ints-to-64-bits. |
| 19249 Thread* thread = Thread::Current(); | 19263 Thread* thread = Thread::Current(); |
| 19250 Zone* zone = thread->zone(); | 19264 Zone* zone = thread->zone(); |
| 19251 Isolate* isolate = thread->isolate(); | 19265 Isolate* isolate = thread->isolate(); |
| 19252 const Bigint& value = | 19266 const Bigint& value = |
| 19253 Bigint::Handle(zone, Bigint::NewFromCString(str.ToCString(), Heap::kOld)); | 19267 Bigint::Handle(zone, Bigint::NewFromCString(str.ToCString(), Heap::kOld)); |
| 19254 const Class& cls = | 19268 const Class& cls = |
| 19255 Class::Handle(zone, isolate->object_store()->bigint_class()); | 19269 Class::Handle(zone, isolate->object_store()->bigint_class()); |
| 19256 intptr_t index = 0; | 19270 intptr_t index = 0; |
| 19257 Bigint& canonical_value = Bigint::Handle(zone); | 19271 Bigint& canonical_value = Bigint::Handle(zone); |
| 19258 canonical_value ^= cls.LookupCanonicalBigint(zone, value, &index); | 19272 canonical_value ^= cls.LookupCanonicalBigint(zone, value, &index); |
| (...skipping 3633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 22892 return UserTag::null(); | 22906 return UserTag::null(); |
| 22893 } | 22907 } |
| 22894 | 22908 |
| 22895 | 22909 |
| 22896 const char* UserTag::ToCString() const { | 22910 const char* UserTag::ToCString() const { |
| 22897 const String& tag_label = String::Handle(label()); | 22911 const String& tag_label = String::Handle(label()); |
| 22898 return tag_label.ToCString(); | 22912 return tag_label.ToCString(); |
| 22899 } | 22913 } |
| 22900 | 22914 |
| 22901 } // namespace dart | 22915 } // namespace dart |
| OLD | NEW |