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

Side by Side Diff: lib/integers.cc

Issue 12052033: Added macros OBJECT_IMPLEMENTATION and FINAL_OBJECT_IMPLEMENTATION (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 7 years, 11 months 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « lib/byte_array.cc ('k') | lib/isolate.cc » ('j') | vm/object.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "vm/object.h" 11 #include "vm/object.h"
12 #include "vm/symbols.h" 12 #include "vm/symbols.h"
13 13
14 namespace dart { 14 namespace dart {
15 15
16 DEFINE_FLAG(bool, trace_intrinsified_natives, false, 16 DEFINE_FLAG(bool, trace_intrinsified_natives, false,
17 "Report if any of the intrinsified natives are called"); 17 "Report if any of the intrinsified natives are called");
18 18
19 // Smi natives. 19 // Smi natives.
20 20
21 // Returns false if integer is in wrong representation, e.g., as is a Bigint 21 // Returns false if integer is in wrong representation, e.g., as is a Bigint
22 // when it could have been a Smi. 22 // when it could have been a Smi.
23 static bool CheckInteger(const Integer& i) { 23 static bool CheckInteger(const Integer& i) {
24 if (i.IsBigint()) { 24 if (i.IsBigint()) {
25 Bigint& bigint = Bigint::Handle(); 25 Bigint& bigint = Bigint::Handle();
26 bigint |= i.raw(); 26 bigint ^= i.raw();
27 return !BigintOperations::FitsIntoSmi(bigint) && 27 return !BigintOperations::FitsIntoSmi(bigint) &&
28 !BigintOperations::FitsIntoMint(bigint); 28 !BigintOperations::FitsIntoMint(bigint);
29 } 29 }
30 if (i.IsMint()) { 30 if (i.IsMint()) {
31 Mint& mint = Mint::Handle(); 31 Mint& mint = Mint::Handle();
32 mint |= i.raw(); 32 mint ^= i.raw();
33 return !Smi::IsValid64(mint.value()); 33 return !Smi::IsValid64(mint.value());
34 } 34 }
35 return true; 35 return true;
36 } 36 }
37 37
38 38
39 DEFINE_NATIVE_ENTRY(Integer_bitAndFromInteger, 2) { 39 DEFINE_NATIVE_ENTRY(Integer_bitAndFromInteger, 2) {
40 const Integer& right = Integer::CheckedHandle(arguments->NativeArgAt(0)); 40 const Integer& right = Integer::CheckedHandle(arguments->NativeArgAt(0));
41 GET_NON_NULL_NATIVE_ARGUMENT(Integer, left, arguments->NativeArgAt(1)); 41 GET_NON_NULL_NATIVE_ARGUMENT(Integer, left, arguments->NativeArgAt(1));
42 ASSERT(CheckInteger(right)); 42 ASSERT(CheckInteger(right));
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 static RawInteger* ShiftOperationHelper(Token::Kind kind, 211 static RawInteger* ShiftOperationHelper(Token::Kind kind,
212 const Integer& value, 212 const Integer& value,
213 const Smi& amount) { 213 const Smi& amount) {
214 if (amount.Value() < 0) { 214 if (amount.Value() < 0) {
215 const Array& args = Array::Handle(Array::New(1)); 215 const Array& args = Array::Handle(Array::New(1));
216 args.SetAt(0, amount); 216 args.SetAt(0, amount);
217 Exceptions::ThrowByType(Exceptions::kArgument, args); 217 Exceptions::ThrowByType(Exceptions::kArgument, args);
218 } 218 }
219 if (value.IsSmi()) { 219 if (value.IsSmi()) {
220 Smi& smi_value = Smi::Handle(); 220 Smi& smi_value = Smi::Handle();
221 smi_value |= value.raw(); 221 smi_value ^= value.raw();
222 return smi_value.ShiftOp(kind, amount); 222 return smi_value.ShiftOp(kind, amount);
223 } 223 }
224 Bigint& big_value = Bigint::Handle(); 224 Bigint& big_value = Bigint::Handle();
225 if (value.IsMint()) { 225 if (value.IsMint()) {
226 const int64_t mint_value = value.AsInt64Value(); 226 const int64_t mint_value = value.AsInt64Value();
227 const int count = Utils::HighestBit(mint_value); 227 const int count = Utils::HighestBit(mint_value);
228 if ((count + amount.Value()) < Mint::kBits) { 228 if ((count + amount.Value()) < Mint::kBits) {
229 switch (kind) { 229 switch (kind) {
230 case Token::kSHL: 230 case Token::kSHL:
231 return Integer::New(mint_value << amount.Value()); 231 return Integer::New(mint_value << amount.Value());
232 case Token::kSHR: 232 case Token::kSHR:
233 return Integer::New(mint_value >> amount.Value()); 233 return Integer::New(mint_value >> amount.Value());
234 default: 234 default:
235 UNIMPLEMENTED(); 235 UNIMPLEMENTED();
236 } 236 }
237 } else { 237 } else {
238 // Overflow in shift, use Bigints 238 // Overflow in shift, use Bigints
239 big_value = BigintOperations::NewFromInt64(mint_value); 239 big_value = BigintOperations::NewFromInt64(mint_value);
240 } 240 }
241 } else { 241 } else {
242 ASSERT(value.IsBigint()); 242 ASSERT(value.IsBigint());
243 big_value |= value.raw(); 243 big_value ^= value.raw();
244 } 244 }
245 switch (kind) { 245 switch (kind) {
246 case Token::kSHL: 246 case Token::kSHL:
247 return BigintOperations::ShiftLeft(big_value, amount.Value()); 247 return BigintOperations::ShiftLeft(big_value, amount.Value());
248 case Token::kSHR: 248 case Token::kSHR:
249 return BigintOperations::ShiftRight(big_value, amount.Value()); 249 return BigintOperations::ShiftRight(big_value, amount.Value());
250 default: 250 default:
251 UNIMPLEMENTED(); 251 UNIMPLEMENTED();
252 } 252 }
253 return Integer::null(); 253 return Integer::null();
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 307
308 DEFINE_NATIVE_ENTRY(Bigint_bitNegate, 1) { 308 DEFINE_NATIVE_ENTRY(Bigint_bitNegate, 1) {
309 const Bigint& value = Bigint::CheckedHandle(arguments->NativeArgAt(0)); 309 const Bigint& value = Bigint::CheckedHandle(arguments->NativeArgAt(0));
310 const Bigint& result = Bigint::Handle(BigintOperations::BitNot(value)); 310 const Bigint& result = Bigint::Handle(BigintOperations::BitNot(value));
311 ASSERT(CheckInteger(value)); 311 ASSERT(CheckInteger(value));
312 ASSERT(CheckInteger(result)); 312 ASSERT(CheckInteger(result));
313 return result.AsValidInteger(); 313 return result.AsValidInteger();
314 } 314 }
315 315
316 } // namespace dart 316 } // namespace dart
OLDNEW
« no previous file with comments | « lib/byte_array.cc ('k') | lib/isolate.cc » ('j') | vm/object.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698