| 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" |
| 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 Loading... |
| 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 } |
| 190 String& temp = String::Handle(); |
| 191 temp = String::Concat(String::Handle(Symbols::New("-")), *int_string); |
| 192 return Integer::New(temp); |
| 193 } |
| 194 |
| 195 GrowableArray<const Object*> args; |
| 196 args.Add(&value); |
| 197 Exceptions::ThrowByType(Exceptions::kFormat, args); |
| 198 return Object::null(); |
| 199 } |
| 200 |
| 201 |
| 175 static RawInteger* ShiftOperationHelper(Token::Kind kind, | 202 static RawInteger* ShiftOperationHelper(Token::Kind kind, |
| 176 const Integer& value, | 203 const Integer& value, |
| 177 const Smi& amount) { | 204 const Smi& amount) { |
| 178 if (amount.Value() < 0) { | 205 if (amount.Value() < 0) { |
| 179 GrowableArray<const Object*> args; | 206 GrowableArray<const Object*> args; |
| 180 args.Add(&amount); | 207 args.Add(&amount); |
| 181 Exceptions::ThrowByType(Exceptions::kArgument, args); | 208 Exceptions::ThrowByType(Exceptions::kArgument, args); |
| 182 } | 209 } |
| 183 if (value.IsSmi()) { | 210 if (value.IsSmi()) { |
| 184 Smi& smi_value = Smi::Handle(); | 211 Smi& smi_value = Smi::Handle(); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 | 298 |
| 272 DEFINE_NATIVE_ENTRY(Bigint_bitNegate, 1) { | 299 DEFINE_NATIVE_ENTRY(Bigint_bitNegate, 1) { |
| 273 const Bigint& value = Bigint::CheckedHandle(arguments->NativeArgAt(0)); | 300 const Bigint& value = Bigint::CheckedHandle(arguments->NativeArgAt(0)); |
| 274 const Bigint& result = Bigint::Handle(BigintOperations::BitNot(value)); | 301 const Bigint& result = Bigint::Handle(BigintOperations::BitNot(value)); |
| 275 ASSERT(CheckInteger(value)); | 302 ASSERT(CheckInteger(value)); |
| 276 ASSERT(CheckInteger(result)); | 303 ASSERT(CheckInteger(result)); |
| 277 return result.AsInteger(); | 304 return result.AsInteger(); |
| 278 } | 305 } |
| 279 | 306 |
| 280 } // namespace dart | 307 } // namespace dart |
| OLD | NEW |