OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 "include/dart_api.h" | 7 #include "include/dart_api.h" |
8 | 8 |
9 #include "vm/bigint_operations.h" | 9 #include "vm/bigint_operations.h" |
10 #include "vm/exceptions.h" | 10 #include "vm/exceptions.h" |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 array.LengthInBytes(), access_size); \ | 180 array.LengthInBytes(), access_size); \ |
181 return object::New(array.getter(offsetInBytes.Value())); \ | 181 return object::New(array.getter(offsetInBytes.Value())); \ |
182 } \ | 182 } \ |
183 const String& error = String::Handle(String::NewFormatted( \ | 183 const String& error = String::Handle(String::NewFormatted( \ |
184 "Expected a TypedData object but found %s", instance.ToCString())); \ | 184 "Expected a TypedData object but found %s", instance.ToCString())); \ |
185 Exceptions::ThrowArgumentError(error); \ | 185 Exceptions::ThrowArgumentError(error); \ |
186 return object::null(); \ | 186 return object::null(); \ |
187 } \ | 187 } \ |
188 | 188 |
189 | 189 |
190 #define TYPED_DATA_SETTER(setter, object, get_object_value, access_size) \ | 190 #define TYPED_DATA_SETTER(setter, \ |
| 191 object, \ |
| 192 get_object_value, \ |
| 193 access_size, \ |
| 194 access_type) \ |
191 DEFINE_NATIVE_ENTRY(TypedData_##setter, 3) { \ | 195 DEFINE_NATIVE_ENTRY(TypedData_##setter, 3) { \ |
192 GET_NON_NULL_NATIVE_ARGUMENT(Instance, instance, arguments->NativeArgAt(0)); \ | 196 GET_NON_NULL_NATIVE_ARGUMENT(Instance, instance, arguments->NativeArgAt(0)); \ |
193 GET_NON_NULL_NATIVE_ARGUMENT(Smi, offsetInBytes, arguments->NativeArgAt(1)); \ | 197 GET_NON_NULL_NATIVE_ARGUMENT(Smi, offsetInBytes, arguments->NativeArgAt(1)); \ |
194 GET_NON_NULL_NATIVE_ARGUMENT(object, value, arguments->NativeArgAt(2)); \ | 198 GET_NON_NULL_NATIVE_ARGUMENT(object, value, arguments->NativeArgAt(2)); \ |
195 if (instance.IsTypedData()) { \ | 199 if (instance.IsTypedData()) { \ |
196 const TypedData& array = TypedData::Cast(instance); \ | 200 const TypedData& array = TypedData::Cast(instance); \ |
197 RangeCheck(offsetInBytes.Value(), access_size, \ | 201 RangeCheck(offsetInBytes.Value(), access_size, \ |
198 array.LengthInBytes(), access_size); \ | 202 array.LengthInBytes(), access_size); \ |
199 array.setter(offsetInBytes.Value(), value.get_object_value()); \ | 203 array.setter(offsetInBytes.Value(), \ |
| 204 static_cast<access_type>(value.get_object_value())); \ |
200 } else if (instance.IsExternalTypedData()) { \ | 205 } else if (instance.IsExternalTypedData()) { \ |
201 const ExternalTypedData& array = ExternalTypedData::Cast(instance); \ | 206 const ExternalTypedData& array = ExternalTypedData::Cast(instance); \ |
202 RangeCheck(offsetInBytes.Value(), access_size, \ | 207 RangeCheck(offsetInBytes.Value(), access_size, \ |
203 array.LengthInBytes(), access_size); \ | 208 array.LengthInBytes(), access_size); \ |
204 array.setter(offsetInBytes.Value(), value.get_object_value()); \ | 209 array.setter(offsetInBytes.Value(), \ |
| 210 static_cast<access_type>(value.get_object_value())); \ |
205 } else { \ | 211 } else { \ |
206 const String& error = String::Handle(String::NewFormatted( \ | 212 const String& error = String::Handle(String::NewFormatted( \ |
207 "Expected a TypedData object but found %s", instance.ToCString())); \ | 213 "Expected a TypedData object but found %s", instance.ToCString())); \ |
208 Exceptions::ThrowArgumentError(error); \ | 214 Exceptions::ThrowArgumentError(error); \ |
209 } \ | 215 } \ |
210 return Object::null(); \ | 216 return Object::null(); \ |
211 } | 217 } |
212 | 218 |
213 | 219 |
214 #define TYPED_DATA_UINT64_GETTER(getter, object) \ | 220 #define TYPED_DATA_UINT64_GETTER(getter, object) \ |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 Exceptions::ThrowArgumentError(error); \ | 269 Exceptions::ThrowArgumentError(error); \ |
264 } \ | 270 } \ |
265 return Object::null(); \ | 271 return Object::null(); \ |
266 } | 272 } |
267 | 273 |
268 | 274 |
269 #define TYPED_DATA_NATIVES(getter, \ | 275 #define TYPED_DATA_NATIVES(getter, \ |
270 setter, \ | 276 setter, \ |
271 object, \ | 277 object, \ |
272 get_object_value, \ | 278 get_object_value, \ |
273 access_size) \ | 279 access_size, \ |
| 280 access_type) \ |
274 TYPED_DATA_GETTER(getter, object, access_size) \ | 281 TYPED_DATA_GETTER(getter, object, access_size) \ |
275 TYPED_DATA_SETTER(setter, object, get_object_value, access_size) \ | 282 TYPED_DATA_SETTER(setter, object, get_object_value, access_size, access_type)\ |
276 | 283 |
277 | 284 |
278 #define TYPED_DATA_UINT64_NATIVES(getter, setter, object) \ | 285 #define TYPED_DATA_UINT64_NATIVES(getter, setter, object) \ |
279 TYPED_DATA_UINT64_GETTER(getter, object) \ | 286 TYPED_DATA_UINT64_GETTER(getter, object) \ |
280 TYPED_DATA_UINT64_SETTER(setter, object) \ | 287 TYPED_DATA_UINT64_SETTER(setter, object) \ |
281 | 288 |
282 | 289 |
283 TYPED_DATA_NATIVES(GetInt8, SetInt8, Smi, Value, 1) | 290 TYPED_DATA_NATIVES(GetInt8, SetInt8, Smi, Value, 1, int8_t) |
284 TYPED_DATA_NATIVES(GetUint8, SetUint8, Smi, Value, 1) | 291 TYPED_DATA_NATIVES(GetUint8, SetUint8, Smi, Value, 1, uint8_t) |
285 TYPED_DATA_NATIVES(GetInt16, SetInt16, Smi, Value, 2) | 292 TYPED_DATA_NATIVES(GetInt16, SetInt16, Smi, Value, 2, int16_t) |
286 TYPED_DATA_NATIVES(GetUint16, SetUint16, Smi, Value, 2) | 293 TYPED_DATA_NATIVES(GetUint16, SetUint16, Smi, Value, 2, uint16_t) |
287 TYPED_DATA_NATIVES(GetInt32, SetInt32, Integer, AsInt64Value, 4) | 294 TYPED_DATA_NATIVES(GetInt32, SetInt32, Integer, AsInt64Value, 4, int32_t) |
288 TYPED_DATA_NATIVES(GetUint32, SetUint32, Integer, AsInt64Value, 4) | 295 TYPED_DATA_NATIVES(GetUint32, SetUint32, Integer, AsInt64Value, 4, uint32_t) |
289 TYPED_DATA_NATIVES(GetInt64, SetInt64, Integer, AsInt64Value, 8) | 296 TYPED_DATA_NATIVES(GetInt64, SetInt64, Integer, AsInt64Value, 8, int64_t) |
290 TYPED_DATA_UINT64_NATIVES(GetUint64, SetUint64, Integer) | 297 TYPED_DATA_UINT64_NATIVES(GetUint64, SetUint64, Integer) |
291 TYPED_DATA_NATIVES(GetFloat32, SetFloat32, Double, value, 4) | 298 TYPED_DATA_NATIVES(GetFloat32, SetFloat32, Double, value, 4, float) |
292 TYPED_DATA_NATIVES(GetFloat64, SetFloat64, Double, value, 8) | 299 TYPED_DATA_NATIVES(GetFloat64, SetFloat64, Double, value, 8, double) |
293 TYPED_DATA_NATIVES(GetFloat32x4, SetFloat32x4, Float32x4, value, 16) | 300 TYPED_DATA_NATIVES( |
294 TYPED_DATA_NATIVES(GetInt32x4, SetInt32x4, Int32x4, value, 16) | 301 GetFloat32x4, SetFloat32x4, Float32x4, value, 16, simd128_value_t) |
| 302 TYPED_DATA_NATIVES(GetInt32x4, SetInt32x4, Int32x4, value, 16, simd128_value_t) |
295 | 303 |
296 | 304 |
297 DEFINE_NATIVE_ENTRY(ByteData_ToEndianInt16, 2) { | 305 DEFINE_NATIVE_ENTRY(ByteData_ToEndianInt16, 2) { |
298 GET_NON_NULL_NATIVE_ARGUMENT(Smi, host_value, arguments->NativeArgAt(0)); | 306 GET_NON_NULL_NATIVE_ARGUMENT(Smi, host_value, arguments->NativeArgAt(0)); |
299 GET_NON_NULL_NATIVE_ARGUMENT(Bool, little_endian, arguments->NativeArgAt(1)); | 307 GET_NON_NULL_NATIVE_ARGUMENT(Bool, little_endian, arguments->NativeArgAt(1)); |
300 int16_t value = host_value.Value(); | 308 int16_t value = host_value.Value(); |
301 if (little_endian.value()) { | 309 if (little_endian.value()) { |
302 value = Utils::HostToLittleEndian16(value); | 310 value = Utils::HostToLittleEndian16(value); |
303 } else { | 311 } else { |
304 value = Utils::HostToBigEndian16(value); | 312 value = Utils::HostToBigEndian16(value); |
305 } | 313 } |
306 return Smi::New(value); | 314 return Smi::New(value); |
307 } | 315 } |
308 | 316 |
309 | 317 |
310 DEFINE_NATIVE_ENTRY(ByteData_ToEndianUint16, 2) { | 318 DEFINE_NATIVE_ENTRY(ByteData_ToEndianUint16, 2) { |
311 GET_NON_NULL_NATIVE_ARGUMENT(Smi, host_value, arguments->NativeArgAt(0)); | 319 GET_NON_NULL_NATIVE_ARGUMENT(Smi, host_value, arguments->NativeArgAt(0)); |
312 GET_NON_NULL_NATIVE_ARGUMENT(Bool, little_endian, arguments->NativeArgAt(1)); | 320 GET_NON_NULL_NATIVE_ARGUMENT(Bool, little_endian, arguments->NativeArgAt(1)); |
313 uint16_t value = host_value.Value(); | 321 uint16_t value = host_value.Value(); |
314 if (little_endian.value()) { | 322 if (little_endian.value()) { |
315 return Smi::New(Utils::HostToLittleEndian16(value)); | 323 return Smi::New(Utils::HostToLittleEndian16(value)); |
316 } | 324 } |
317 return Smi::New(Utils::HostToBigEndian16(value)); | 325 return Smi::New(Utils::HostToBigEndian16(value)); |
318 } | 326 } |
319 | 327 |
320 | 328 |
321 DEFINE_NATIVE_ENTRY(ByteData_ToEndianInt32, 2) { | 329 DEFINE_NATIVE_ENTRY(ByteData_ToEndianInt32, 2) { |
322 GET_NON_NULL_NATIVE_ARGUMENT(Integer, host_value, arguments->NativeArgAt(0)); | 330 GET_NON_NULL_NATIVE_ARGUMENT(Integer, host_value, arguments->NativeArgAt(0)); |
323 GET_NON_NULL_NATIVE_ARGUMENT(Bool, little_endian, arguments->NativeArgAt(1)); | 331 GET_NON_NULL_NATIVE_ARGUMENT(Bool, little_endian, arguments->NativeArgAt(1)); |
324 ASSERT(host_value.AsInt64Value() <= kMaxInt32); | 332 ASSERT((host_value.AsInt64Value() >= kMinInt32) || |
325 int32_t value = host_value.AsInt64Value(); | 333 (host_value.AsInt64Value() <= kMaxInt32)); |
| 334 int32_t value = static_cast<int32_t>(host_value.AsInt64Value()); |
326 if (little_endian.value()) { | 335 if (little_endian.value()) { |
327 value = Utils::HostToLittleEndian32(value); | 336 value = Utils::HostToLittleEndian32(value); |
328 } else { | 337 } else { |
329 value = Utils::HostToBigEndian32(value); | 338 value = Utils::HostToBigEndian32(value); |
330 } | 339 } |
331 return Integer::New(value); | 340 return Integer::New(value); |
332 } | 341 } |
333 | 342 |
334 | 343 |
335 DEFINE_NATIVE_ENTRY(ByteData_ToEndianUint32, 2) { | 344 DEFINE_NATIVE_ENTRY(ByteData_ToEndianUint32, 2) { |
336 GET_NON_NULL_NATIVE_ARGUMENT(Integer, host_value, arguments->NativeArgAt(0)); | 345 GET_NON_NULL_NATIVE_ARGUMENT(Integer, host_value, arguments->NativeArgAt(0)); |
337 GET_NON_NULL_NATIVE_ARGUMENT(Bool, little_endian, arguments->NativeArgAt(1)); | 346 GET_NON_NULL_NATIVE_ARGUMENT(Bool, little_endian, arguments->NativeArgAt(1)); |
338 ASSERT(host_value.AsInt64Value() <= kMaxUint32); | 347 ASSERT(host_value.AsInt64Value() <= kMaxUint32); |
339 uint32_t value = host_value.AsInt64Value(); | 348 uint32_t value = static_cast<uint32_t>(host_value.AsInt64Value()); |
340 if (little_endian.value()) { | 349 if (little_endian.value()) { |
341 value = Utils::HostToLittleEndian32(value); | 350 value = Utils::HostToLittleEndian32(value); |
342 } else { | 351 } else { |
343 value = Utils::HostToBigEndian32(value); | 352 value = Utils::HostToBigEndian32(value); |
344 } | 353 } |
345 return Integer::New(value); | 354 return Integer::New(value); |
346 } | 355 } |
347 | 356 |
348 | 357 |
349 DEFINE_NATIVE_ENTRY(ByteData_ToEndianInt64, 2) { | 358 DEFINE_NATIVE_ENTRY(ByteData_ToEndianInt64, 2) { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 value = bit_cast<double>( | 412 value = bit_cast<double>( |
404 Utils::HostToLittleEndian64(bit_cast<uint64_t>(value))); | 413 Utils::HostToLittleEndian64(bit_cast<uint64_t>(value))); |
405 } else { | 414 } else { |
406 value = bit_cast<double>( | 415 value = bit_cast<double>( |
407 Utils::HostToBigEndian64(bit_cast<uint64_t>(value))); | 416 Utils::HostToBigEndian64(bit_cast<uint64_t>(value))); |
408 } | 417 } |
409 return Double::New(value); | 418 return Double::New(value); |
410 } | 419 } |
411 | 420 |
412 } // namespace dart | 421 } // namespace dart |
OLD | NEW |