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

Side by Side Diff: runtime/lib/integers.cc

Issue 11316031: - Move MathNatives from dart:core to dart:math. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 1 month 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
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 13
13 namespace dart { 14 namespace dart {
14 15
15 DEFINE_FLAG(bool, trace_intrinsified_natives, false, 16 DEFINE_FLAG(bool, trace_intrinsified_natives, false,
16 "Report if any of the intrinsified natives are called"); 17 "Report if any of the intrinsified natives are called");
17 18
18 // Smi natives. 19 // Smi natives.
19 20
20 // 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
21 // when it could have been a Smi. 22 // when it could have been a Smi.
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 ASSERT(CheckInteger(left)); 166 ASSERT(CheckInteger(left));
166 ASSERT(CheckInteger(right)); 167 ASSERT(CheckInteger(right));
167 if (FLAG_trace_intrinsified_natives) { 168 if (FLAG_trace_intrinsified_natives) {
168 OS::Print("Integer_equalToInteger %s == %s\n", 169 OS::Print("Integer_equalToInteger %s == %s\n",
169 left.ToCString(), right.ToCString()); 170 left.ToCString(), right.ToCString());
170 } 171 }
171 return Bool::Get(left.CompareWith(right) == 0); 172 return Bool::Get(left.CompareWith(right) == 0);
172 } 173 }
173 174
174 175
176 DEFINE_NATIVE_ENTRY(Integer_parse, 1) {
177 GET_NATIVE_ARGUMENT(String, value, arguments->NativeArgAt(0));
178 const String& dummy_key = String::Handle(Symbols::Empty());
179 Scanner scanner(value, dummy_key);
180 const Scanner::GrowableTokenStream& tokens = scanner.GetStream();
181 String* int_string;
182 bool is_positive;
183 if (Scanner::IsValidLiteral(tokens,
184 Token::kINTEGER,
185 &is_positive,
186 &int_string)) {
187 if (is_positive) {
188 return Integer::New(*int_string);
189 } else {
190 String& temp = String::Handle();
191 temp = String::Concat(String::Handle(Symbols::New("-")),
192 *int_string);
193 return Integer::New(temp);
194 }
195 } else {
siva 2012/11/16 01:34:26 Is the else needed here? It could be similar to th
Ivan Posva 2012/11/16 19:26:43 Done here and in similar places such as line 189 a
196 GrowableArray<const Object*> args;
197 args.Add(&value);
198 Exceptions::ThrowByType(Exceptions::kFormat, args);
199 return Object::null();
200 }
201 }
202
203
175 static RawInteger* ShiftOperationHelper(Token::Kind kind, 204 static RawInteger* ShiftOperationHelper(Token::Kind kind,
176 const Integer& value, 205 const Integer& value,
177 const Smi& amount) { 206 const Smi& amount) {
178 if (amount.Value() < 0) { 207 if (amount.Value() < 0) {
179 GrowableArray<const Object*> args; 208 GrowableArray<const Object*> args;
180 args.Add(&amount); 209 args.Add(&amount);
181 Exceptions::ThrowByType(Exceptions::kArgument, args); 210 Exceptions::ThrowByType(Exceptions::kArgument, args);
182 } 211 }
183 if (value.IsSmi()) { 212 if (value.IsSmi()) {
184 Smi& smi_value = Smi::Handle(); 213 Smi& smi_value = Smi::Handle();
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 300
272 DEFINE_NATIVE_ENTRY(Bigint_bitNegate, 1) { 301 DEFINE_NATIVE_ENTRY(Bigint_bitNegate, 1) {
273 const Bigint& value = Bigint::CheckedHandle(arguments->NativeArgAt(0)); 302 const Bigint& value = Bigint::CheckedHandle(arguments->NativeArgAt(0));
274 const Bigint& result = Bigint::Handle(BigintOperations::BitNot(value)); 303 const Bigint& result = Bigint::Handle(BigintOperations::BitNot(value));
275 ASSERT(CheckInteger(value)); 304 ASSERT(CheckInteger(value));
276 ASSERT(CheckInteger(result)); 305 ASSERT(CheckInteger(result));
277 return result.AsInteger(); 306 return result.AsInteger();
278 } 307 }
279 308
280 } // namespace dart 309 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698