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

Side by Side Diff: lib/integers.cc

Issue 9481019: Changes to get rid of dependency on openssl in the dart VM. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 9 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 | « bin/bin.gypi ('k') | platform/globals.h » ('j') | no next file with comments »
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"
(...skipping 16 matching lines...) Expand all
27 return Smi::New(mint.value()); 27 return Smi::New(mint.value());
28 } else { 28 } else {
29 return value.raw(); 29 return value.raw();
30 } 30 }
31 } 31 }
32 ASSERT(value.IsBigint()); 32 ASSERT(value.IsBigint());
33 Bigint& big_value = Bigint::Handle(); 33 Bigint& big_value = Bigint::Handle();
34 big_value ^= value.raw(); 34 big_value ^= value.raw();
35 if (BigintOperations::FitsIntoSmi(big_value)) { 35 if (BigintOperations::FitsIntoSmi(big_value)) {
36 return BigintOperations::ToSmi(big_value); 36 return BigintOperations::ToSmi(big_value);
37 } else if (BigintOperations::FitsIntoInt64(big_value)) { 37 } else if (BigintOperations::FitsIntoMint(big_value)) {
38 return Mint::New(BigintOperations::ToInt64(big_value)); 38 return Mint::New(BigintOperations::ToMint(big_value));
39 } else { 39 } else {
40 return big_value.raw(); 40 return big_value.raw();
41 } 41 }
42 } 42 }
43 43
44 44
45 // Returns value in form of a RawBigint. 45 // Returns value in form of a RawBigint.
46 static RawBigint* AsBigint(const Integer& value) { 46 static RawBigint* AsBigint(const Integer& value) {
47 ASSERT(!value.IsNull()); 47 ASSERT(!value.IsNull());
48 if (value.IsSmi()) { 48 if (value.IsSmi()) {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 switch (kind) { 98 switch (kind) {
99 case Token::kBIT_AND: 99 case Token::kBIT_AND:
100 return Integer::New(a & b); 100 return Integer::New(a & b);
101 case Token::kBIT_OR: 101 case Token::kBIT_OR:
102 return Integer::New(a | b); 102 return Integer::New(a | b);
103 case Token::kBIT_XOR: 103 case Token::kBIT_XOR:
104 return Integer::New(a ^ b); 104 return Integer::New(a ^ b);
105 default: 105 default:
106 UNIMPLEMENTED(); 106 UNIMPLEMENTED();
107 } 107 }
108 } else if (op1_int.IsSmi()) {
109 return IntegerBitOperation(kind, op2_int, op1_int);
110 } else if (op2_int.IsSmi()) {
111 Bigint& op1 = Bigint::Handle(AsBigint(op1_int));
112 Smi& op2 = Smi::Handle();
113 op2 ^= op2_int.raw();
114 switch (kind) {
115 case Token::kBIT_AND:
116 return BigintOperations::BitAndWithSmi(op1, op2);
117 case Token::kBIT_OR:
118 return BigintOperations::BitOrWithSmi(op1, op2);
119 case Token::kBIT_XOR:
120 return BigintOperations::BitXorWithSmi(op1, op2);
121 default:
122 UNIMPLEMENTED();
123 }
124 } else { 108 } else {
125 Bigint& op1 = Bigint::Handle(AsBigint(op1_int)); 109 Bigint& op1 = Bigint::Handle(AsBigint(op1_int));
126 Bigint& op2 = Bigint::Handle(AsBigint(op2_int)); 110 Bigint& op2 = Bigint::Handle(AsBigint(op2_int));
127 switch (kind) { 111 switch (kind) {
128 case Token::kBIT_AND: 112 case Token::kBIT_AND:
129 return BigintOperations::BitAnd(op1, op2); 113 return BigintOperations::BitAnd(op1, op2);
130 case Token::kBIT_OR: 114 case Token::kBIT_OR:
131 return BigintOperations::BitOr(op1, op2); 115 return BigintOperations::BitOr(op1, op2);
132 case Token::kBIT_XOR: 116 case Token::kBIT_XOR:
133 return BigintOperations::BitXor(op1, op2); 117 return BigintOperations::BitXor(op1, op2);
134 default: 118 default:
135 UNIMPLEMENTED(); 119 UNIMPLEMENTED();
136 } 120 }
137 } 121 }
138 return Integer::null(); 122 return Integer::null();
139 } 123 }
140 124
141 125
142 // Returns false if integer is in wrong representation, e.g., as is a Bigint 126 // Returns false if integer is in wrong representation, e.g., as is a Bigint
143 // when it could have been a Smi. 127 // when it could have been a Smi.
144 static bool CheckInteger(const Integer& i) { 128 static bool CheckInteger(const Integer& i) {
145 if (i.IsBigint()) { 129 if (i.IsBigint()) {
146 Bigint& bigint = Bigint::Handle(); 130 Bigint& bigint = Bigint::Handle();
147 bigint ^= i.raw(); 131 bigint ^= i.raw();
148 return !BigintOperations::FitsIntoSmi(bigint) && 132 return !BigintOperations::FitsIntoSmi(bigint) &&
149 !BigintOperations::FitsIntoInt64(bigint); 133 !BigintOperations::FitsIntoMint(bigint);
150 } 134 }
151 if (i.IsMint()) { 135 if (i.IsMint()) {
152 Mint& mint = Mint::Handle(); 136 Mint& mint = Mint::Handle();
153 mint ^= i.raw(); 137 mint ^= i.raw();
154 return !Smi::IsValid64(mint.value()); 138 return !Smi::IsValid64(mint.value());
155 } 139 }
156 return true; 140 return true;
157 } 141 }
158 142
159 143
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 562
579 DEFINE_NATIVE_ENTRY(Bigint_bitNegate, 1) { 563 DEFINE_NATIVE_ENTRY(Bigint_bitNegate, 1) {
580 const Bigint& value = Bigint::CheckedHandle(arguments->At(0)); 564 const Bigint& value = Bigint::CheckedHandle(arguments->At(0));
581 const Bigint& result = Bigint::Handle(BigintOperations::BitNot(value)); 565 const Bigint& result = Bigint::Handle(BigintOperations::BitNot(value));
582 ASSERT(CheckInteger(value)); 566 ASSERT(CheckInteger(value));
583 ASSERT(CheckInteger(result)); 567 ASSERT(CheckInteger(result));
584 arguments->SetReturn(Integer::Handle(AsInteger(result))); 568 arguments->SetReturn(Integer::Handle(AsInteger(result)));
585 } 569 }
586 570
587 } // namespace dart 571 } // namespace dart
OLDNEW
« no previous file with comments | « bin/bin.gypi ('k') | platform/globals.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698