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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
173 GET_NON_NULL_NATIVE_ARGUMENT(Integer, right, arguments->NativeArgAt(1)); | 173 GET_NON_NULL_NATIVE_ARGUMENT(Integer, right, arguments->NativeArgAt(1)); |
174 ASSERT(CheckInteger(left)); | 174 ASSERT(CheckInteger(left)); |
175 ASSERT(CheckInteger(right)); | 175 ASSERT(CheckInteger(right)); |
176 if (FLAG_trace_intrinsified_natives) { | 176 if (FLAG_trace_intrinsified_natives) { |
177 OS::Print("Integer_equalToInteger %s == %s\n", | 177 OS::Print("Integer_equalToInteger %s == %s\n", |
178 left.ToCString(), right.ToCString()); | 178 left.ToCString(), right.ToCString()); |
179 } | 179 } |
180 return Bool::Get(left.CompareWith(right) == 0); | 180 return Bool::Get(left.CompareWith(right) == 0); |
181 } | 181 } |
182 | 182 |
183 // Windows does not have strtoll defined. | |
184 #if defined(_MSC_VER) | |
185 #define strtoll _strtoi64 | |
186 #endif | |
siva
2013/04/19 20:04:36
Could you move this to platform/c99_support_win.h
srdjan
2013/04/19 20:06:53
Done.
| |
187 | |
183 | 188 |
184 DEFINE_NATIVE_ENTRY(Integer_parse, 1) { | 189 DEFINE_NATIVE_ENTRY(Integer_parse, 1) { |
185 GET_NON_NULL_NATIVE_ARGUMENT(String, value, arguments->NativeArgAt(0)); | 190 GET_NON_NULL_NATIVE_ARGUMENT(String, value, arguments->NativeArgAt(0)); |
186 if (value.IsOneByteString()) { | 191 if (value.IsOneByteString()) { |
187 // Quick conversion for unpadded integers in strings. | 192 // Quick conversion for unpadded integers in strings. |
188 const intptr_t len = value.Length(); | 193 const intptr_t len = value.Length(); |
189 if (len > 0) { | 194 if (len > 0) { |
190 const char* cstr = value.ToCString(); | 195 const char* cstr = value.ToCString(); |
191 ASSERT(cstr != NULL); | 196 ASSERT(cstr != NULL); |
192 // Dart differences from strtol: | 197 // Dart differences from strtol: |
193 // a) '+5' is not a valid integer (leading plus). | 198 // a) '+5' is not a valid integer (leading plus). |
194 if (cstr[0] != '+') { | 199 if (cstr[0] != '+') { |
195 char* p_end = NULL; | 200 char* p_end = NULL; |
196 const int64_t int_value = strtol(cstr, &p_end, 10); | 201 const int64_t int_value = strtoll(cstr, &p_end, 10); |
197 if (p_end == (cstr + len)) { | 202 if (p_end == (cstr + len)) { |
198 if ((Smi::kMinValue <= int_value) && (int_value <= Smi::kMaxValue)) { | 203 if ((int_value != LLONG_MIN) && (int_value != LLONG_MAX)) { |
199 return Smi::New(int_value); | 204 return Integer::New(int_value); |
200 } | 205 } |
201 } | 206 } |
202 } | 207 } |
203 } | 208 } |
204 } | 209 } |
205 | 210 |
206 Scanner scanner(value, Symbols::Empty()); | 211 Scanner scanner(value, Symbols::Empty()); |
207 const Scanner::GrowableTokenStream& tokens = scanner.GetStream(); | 212 const Scanner::GrowableTokenStream& tokens = scanner.GetStream(); |
208 String* int_string; | 213 String* int_string; |
209 bool is_positive; | 214 bool is_positive; |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
324 | 329 |
325 DEFINE_NATIVE_ENTRY(Bigint_bitNegate, 1) { | 330 DEFINE_NATIVE_ENTRY(Bigint_bitNegate, 1) { |
326 const Bigint& value = Bigint::CheckedHandle(arguments->NativeArgAt(0)); | 331 const Bigint& value = Bigint::CheckedHandle(arguments->NativeArgAt(0)); |
327 const Bigint& result = Bigint::Handle(BigintOperations::BitNot(value)); | 332 const Bigint& result = Bigint::Handle(BigintOperations::BitNot(value)); |
328 ASSERT(CheckInteger(value)); | 333 ASSERT(CheckInteger(value)); |
329 ASSERT(CheckInteger(result)); | 334 ASSERT(CheckInteger(result)); |
330 return result.AsValidInteger(); | 335 return result.AsValidInteger(); |
331 } | 336 } |
332 | 337 |
333 } // namespace dart | 338 } // namespace dart |
OLD | NEW |