| 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 "include/dart_api.h" | 7 #include "include/dart_api.h" |
| 8 #include "vm/dart_entry.h" | 8 #include "vm/dart_entry.h" |
| 9 #include "vm/dart_api_impl.h" | 9 #include "vm/dart_api_impl.h" |
| 10 #include "vm/exceptions.h" | 10 #include "vm/exceptions.h" |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 // Overflow in shift, use Bigints | 283 // Overflow in shift, use Bigints |
| 284 return Integer::null(); | 284 return Integer::null(); |
| 285 } | 285 } |
| 286 } else { | 286 } else { |
| 287 ASSERT(value.IsBigint()); | 287 ASSERT(value.IsBigint()); |
| 288 } | 288 } |
| 289 return Integer::null(); | 289 return Integer::null(); |
| 290 } | 290 } |
| 291 | 291 |
| 292 | 292 |
| 293 DEFINE_NATIVE_ENTRY(Integer_leftShiftWithMask32, 3) { | |
| 294 const Integer& value = Integer::CheckedHandle(arguments->NativeArgAt(0)); | |
| 295 GET_NON_NULL_NATIVE_ARGUMENT(Integer, shift_count, arguments->NativeArgAt(1)); | |
| 296 GET_NON_NULL_NATIVE_ARGUMENT(Integer, mask, arguments->NativeArgAt(2)); | |
| 297 ASSERT(CheckInteger(value)); | |
| 298 ASSERT(CheckInteger(shift_count)); | |
| 299 ASSERT(CheckInteger(mask)); | |
| 300 if (!shift_count.IsSmi()) { | |
| 301 // Shift count is too large.. | |
| 302 const Instance& exception = | |
| 303 Instance::Handle(isolate->object_store()->out_of_memory()); | |
| 304 Exceptions::Throw(thread, exception); | |
| 305 } | |
| 306 const Smi& smi_shift_count = Smi::Cast(shift_count); | |
| 307 const Integer& shift_result = Integer::Handle( | |
| 308 ShiftOperationHelper(Token::kSHL, value, smi_shift_count)); | |
| 309 const Integer& result = | |
| 310 Integer::Handle(shift_result.BitOp(Token::kBIT_AND, mask)); | |
| 311 return result.AsValidInteger(); | |
| 312 } | |
| 313 | |
| 314 | |
| 315 DEFINE_NATIVE_ENTRY(Smi_shrFromInt, 2) { | 293 DEFINE_NATIVE_ENTRY(Smi_shrFromInt, 2) { |
| 316 const Smi& amount = Smi::CheckedHandle(arguments->NativeArgAt(0)); | 294 const Smi& amount = Smi::CheckedHandle(arguments->NativeArgAt(0)); |
| 317 GET_NON_NULL_NATIVE_ARGUMENT(Integer, value, arguments->NativeArgAt(1)); | 295 GET_NON_NULL_NATIVE_ARGUMENT(Integer, value, arguments->NativeArgAt(1)); |
| 318 ASSERT(CheckInteger(amount)); | 296 ASSERT(CheckInteger(amount)); |
| 319 ASSERT(CheckInteger(value)); | 297 ASSERT(CheckInteger(value)); |
| 320 const Integer& result = Integer::Handle( | 298 const Integer& result = Integer::Handle( |
| 321 ShiftOperationHelper(Token::kSHR, value, amount)); | 299 ShiftOperationHelper(Token::kSHR, value, amount)); |
| 322 // A null result indicates that a bigint operation is required. | 300 // A null result indicates that a bigint operation is required. |
| 323 return result.IsNull() ? result.raw() : result.AsValidInteger(); | 301 return result.IsNull() ? result.raw() : result.AsValidInteger(); |
| 324 } | 302 } |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 DEFINE_NATIVE_ENTRY(Bigint_allocate, 4) { | 402 DEFINE_NATIVE_ENTRY(Bigint_allocate, 4) { |
| 425 // First arg is null type arguments, since class Bigint is not parameterized. | 403 // First arg is null type arguments, since class Bigint is not parameterized. |
| 426 const Bool& neg = Bool::CheckedHandle(arguments->NativeArgAt(1)); | 404 const Bool& neg = Bool::CheckedHandle(arguments->NativeArgAt(1)); |
| 427 const Smi& used = Smi::CheckedHandle(arguments->NativeArgAt(2)); | 405 const Smi& used = Smi::CheckedHandle(arguments->NativeArgAt(2)); |
| 428 const TypedData& digits = TypedData::CheckedHandle(arguments->NativeArgAt(3)); | 406 const TypedData& digits = TypedData::CheckedHandle(arguments->NativeArgAt(3)); |
| 429 ASSERT(!digits.IsNull()); | 407 ASSERT(!digits.IsNull()); |
| 430 return Bigint::New(neg.value(), used.Value(), digits); | 408 return Bigint::New(neg.value(), used.Value(), digits); |
| 431 } | 409 } |
| 432 | 410 |
| 433 } // namespace dart | 411 } // namespace dart |
| OLD | NEW |