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 #include "vm/bootstrap_natives.h" | 5 #include "vm/bootstrap_natives.h" |
| 6 | 6 |
| 7 #include "vm/bigint_operations.h" | 7 #include "vm/bigint_operations.h" |
| 8 #include "vm/dart_entry.h" | 8 #include "vm/dart_entry.h" |
| 9 #include "vm/exceptions.h" | 9 #include "vm/exceptions.h" |
| 10 #include "vm/native_entry.h" | 10 #include "vm/native_entry.h" |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 337 const Smi& operand = Smi::CheckedHandle(arguments->NativeArgAt(0)); | 337 const Smi& operand = Smi::CheckedHandle(arguments->NativeArgAt(0)); |
| 338 if (FLAG_trace_intrinsified_natives) { | 338 if (FLAG_trace_intrinsified_natives) { |
| 339 OS::Print("Smi_bitLength: %s\n", operand.ToCString()); | 339 OS::Print("Smi_bitLength: %s\n", operand.ToCString()); |
| 340 } | 340 } |
| 341 int64_t value = operand.AsInt64Value(); | 341 int64_t value = operand.AsInt64Value(); |
| 342 intptr_t result = BitLengthInt64(value); | 342 intptr_t result = BitLengthInt64(value); |
| 343 ASSERT(Smi::IsValid(result)); | 343 ASSERT(Smi::IsValid(result)); |
| 344 return Smi::New(result); | 344 return Smi::New(result); |
| 345 } | 345 } |
| 346 | 346 |
| 347 DEFINE_NATIVE_ENTRY(Smi_toString, 1) { | |
| 348 const Smi& operand = Smi::CheckedHandle(arguments->NativeArgAt(0)); | |
| 349 if (FLAG_trace_intrinsified_natives) { | |
| 350 OS::Print("Smi_toString: %s\n", operand.ToCString()); | |
| 351 } | |
| 352 // Maximal number of digits of a 63 bit number is 19. Add one for minus sign. | |
|
Lasse Reichstein Nielsen
2013/09/23 11:25:18
I decided against using OS::SNPrint(characters, 0,
| |
| 353 const size_t kMaxLength = 20; | |
| 354 uint8_t characters[kMaxLength]; | |
| 355 uint8_t* end = characters + kMaxLength; | |
| 356 uint8_t* cursor = end; | |
| 357 bool negative = false; | |
| 358 int64_t signed_value = operand.AsInt64Value(); | |
| 359 uint64_t value; | |
| 360 if (signed_value < 0) { | |
| 361 negative = true; | |
| 362 value = -signed_value; | |
| 363 } else { | |
| 364 value = signed_value; | |
| 365 } | |
| 366 do { | |
| 367 uint64_t digit = value % 10; | |
| 368 value = (value - digit) / 10; | |
| 369 *--cursor = '0' + digit; | |
| 370 } while (value); | |
| 371 if (negative) { | |
| 372 *--cursor = '-'; | |
| 373 } | |
| 374 intptr_t length = static_cast<intptr_t>(end - cursor); | |
| 375 return OneByteString::New(cursor, length, Heap::kNew); | |
| 376 } | |
| 377 | |
| 347 | 378 |
| 348 // Mint natives. | 379 // Mint natives. |
| 349 | 380 |
| 350 DEFINE_NATIVE_ENTRY(Mint_bitNegate, 1) { | 381 DEFINE_NATIVE_ENTRY(Mint_bitNegate, 1) { |
| 351 const Mint& operand = Mint::CheckedHandle(arguments->NativeArgAt(0)); | 382 const Mint& operand = Mint::CheckedHandle(arguments->NativeArgAt(0)); |
| 352 ASSERT(CheckInteger(operand)); | 383 ASSERT(CheckInteger(operand)); |
| 353 if (FLAG_trace_intrinsified_natives) { | 384 if (FLAG_trace_intrinsified_natives) { |
| 354 OS::Print("Mint_bitNegate: %s\n", operand.ToCString()); | 385 OS::Print("Mint_bitNegate: %s\n", operand.ToCString()); |
| 355 } | 386 } |
| 356 int64_t result = ~operand.value(); | 387 int64_t result = ~operand.value(); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 403 // Use the preallocated out of memory exception to avoid calling | 434 // Use the preallocated out of memory exception to avoid calling |
| 404 // into dart code or allocating any code. | 435 // into dart code or allocating any code. |
| 405 const Instance& exception = | 436 const Instance& exception = |
| 406 Instance::Handle(isolate->object_store()->out_of_memory()); | 437 Instance::Handle(isolate->object_store()->out_of_memory()); |
| 407 Exceptions::Throw(exception); | 438 Exceptions::Throw(exception); |
| 408 UNREACHABLE(); | 439 UNREACHABLE(); |
| 409 return 0; | 440 return 0; |
| 410 } | 441 } |
| 411 | 442 |
| 412 } // namespace dart | 443 } // namespace dart |
| OLD | NEW |