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

Side by Side Diff: runtime/vm/dart_api_message.cc

Issue 10379018: Revert "Revert "Implement {Int,Uint}{8,16,32,64} and Float{32,64} typed arrays."" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 7 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
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/dart_api_message.h" 5 #include "vm/dart_api_message.h"
6 #include "vm/object.h" 6 #include "vm/object.h"
7 #include "vm/object_store.h" 7 #include "vm/object_store.h"
8 8
9 namespace dart { 9 namespace dart {
10 10
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 Dart_CObject* value = 115 Dart_CObject* value =
116 reinterpret_cast<Dart_CObject*>( 116 reinterpret_cast<Dart_CObject*>(
117 alloc_(NULL, 0, sizeof(Dart_CObject) + length + 1)); 117 alloc_(NULL, 0, sizeof(Dart_CObject) + length + 1));
118 ASSERT(value != NULL); 118 ASSERT(value != NULL);
119 value->value.as_string = reinterpret_cast<char*>(value) + sizeof(*value); 119 value->value.as_string = reinterpret_cast<char*>(value) + sizeof(*value);
120 value->type = Dart_CObject::kString; 120 value->type = Dart_CObject::kString;
121 return value; 121 return value;
122 } 122 }
123 123
124 124
125 Dart_CObject* ApiMessageReader::AllocateDartCObjectByteArray(intptr_t length) { 125 Dart_CObject* ApiMessageReader::AllocateDartCObjectUint8Array(intptr_t length) {
126 // Allocate a Dart_CObject structure followed by an array of bytes 126 // Allocate a Dart_CObject structure followed by an array of bytes
127 // for the byte array content. The pointer to the byte array content 127 // for the byte array content. The pointer to the byte array content
128 // is set up to this area. 128 // is set up to this area.
129 Dart_CObject* value = 129 Dart_CObject* value =
130 reinterpret_cast<Dart_CObject*>( 130 reinterpret_cast<Dart_CObject*>(
131 alloc_(NULL, 0, sizeof(Dart_CObject) + length)); 131 alloc_(NULL, 0, sizeof(Dart_CObject) + length));
132 ASSERT(value != NULL); 132 ASSERT(value != NULL);
133 value->type = Dart_CObject::kByteArray; 133 value->type = Dart_CObject::kUint8Array;
134 value->value.as_array.length = length; 134 value->value.as_array.length = length;
135 if (length > 0) { 135 if (length > 0) {
136 value->value.as_byte_array.values = 136 value->value.as_byte_array.values =
137 reinterpret_cast<uint8_t*>(value) + sizeof(*value); 137 reinterpret_cast<uint8_t*>(value) + sizeof(*value);
138 } else { 138 } else {
139 value->value.as_byte_array.values = NULL; 139 value->value.as_byte_array.values = NULL;
140 } 140 }
141 return value; 141 return value;
142 } 142 }
143 143
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 } 269 }
270 p[len] = '\0'; 270 p[len] = '\0';
271 return object; 271 return object;
272 } 272 }
273 case ObjectStore::kTwoByteStringClass: 273 case ObjectStore::kTwoByteStringClass:
274 // Two byte strings not supported. 274 // Two byte strings not supported.
275 return NULL; 275 return NULL;
276 case ObjectStore::kFourByteStringClass: 276 case ObjectStore::kFourByteStringClass:
277 // Four byte strings not supported. 277 // Four byte strings not supported.
278 return NULL; 278 return NULL;
279 case ObjectStore::kInternalByteArrayClass: { 279 case ObjectStore::kUint8ArrayClass: {
280 intptr_t len = ReadSmiValue(); 280 intptr_t len = ReadSmiValue();
281 Dart_CObject* object = AllocateDartCObjectByteArray(len); 281 Dart_CObject* object = AllocateDartCObjectUint8Array(len);
282 AddBackwardReference(object_id, object); 282 AddBackwardReference(object_id, object);
283 if (len > 0) { 283 if (len > 0) {
284 uint8_t* p = object->value.as_byte_array.values; 284 uint8_t* p = object->value.as_byte_array.values;
285 for (intptr_t i = 0; i < len; i++) { 285 for (intptr_t i = 0; i < len; i++) {
286 p[i] = Read<uint8_t>(); 286 p[i] = Read<uint8_t>();
287 } 287 }
288 } 288 }
289 return object; 289 return object;
290 } 290 }
291 default: 291 default:
292 // Everything else not supported. 292 // Everything else not supported.
293 return NULL; 293 return NULL;
294 } 294 }
295 } 295 }
296 296
297 297
298 Dart_CObject* ApiMessageReader::ReadIndexedObject(intptr_t object_id) { 298 Dart_CObject* ApiMessageReader::ReadIndexedObject(intptr_t object_id) {
299 if (object_id == Object::kNullObject) { 299 if (object_id == Object::kNullObject) {
300 return AllocateDartCObjectNull(); 300 return AllocateDartCObjectNull();
301 } else if (object_id == ObjectStore::kTrueValue) { 301 } else if (object_id == ObjectStore::kTrueValue) {
302 return AllocateDartCObjectBool(true); 302 return AllocateDartCObjectBool(true);
303 } else if (object_id == ObjectStore::kFalseValue) { 303 } else if (object_id == ObjectStore::kFalseValue) {
304 return AllocateDartCObjectBool(false); 304 return AllocateDartCObjectBool(false);
305 } else if (object_id == ObjectStore::kDynamicType || 305 } else if (object_id == ObjectStore::kDynamicType ||
306 object_id == ObjectStore::kDoubleInterface || 306 object_id == ObjectStore::kDoubleInterface ||
307 object_id == ObjectStore::kIntInterface || 307 object_id == ObjectStore::kIntInterface ||
308 object_id == ObjectStore::kBoolInterface || 308 object_id == ObjectStore::kBoolInterface ||
309 object_id == ObjectStore::kStringInterface || 309 object_id == ObjectStore::kStringInterface) {
310 object_id == ObjectStore::kByteArrayInterface) {
311 // Always return dynamic type (this is only a marker). 310 // Always return dynamic type (this is only a marker).
312 return &dynamic_type_marker; 311 return &dynamic_type_marker;
313 } else { 312 } else {
314 intptr_t index = object_id - kMaxPredefinedObjectIds; 313 intptr_t index = object_id - kMaxPredefinedObjectIds;
315 ASSERT((0 <= index) && (index < backward_references_.length())); 314 ASSERT((0 <= index) && (index < backward_references_.length()));
316 ASSERT(backward_references_[index] != NULL); 315 ASSERT(backward_references_[index] != NULL);
317 return backward_references_[index]; 316 return backward_references_[index];
318 } 317 }
319 return NULL; 318 return NULL;
320 } 319 }
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 WriteObjectHeader(ObjectStore::kArrayClass, 0); 531 WriteObjectHeader(ObjectStore::kArrayClass, 0);
533 WriteSmi(object->value.as_array.length); 532 WriteSmi(object->value.as_array.length);
534 // Write out the type arguments. 533 // Write out the type arguments.
535 WriteIndexedObject(Object::kNullObject); 534 WriteIndexedObject(Object::kNullObject);
536 // Write out array elements. 535 // Write out array elements.
537 for (int i = 0; i < object->value.as_array.length; i++) { 536 for (int i = 0; i < object->value.as_array.length; i++) {
538 WriteCObject(object->value.as_array.values[i]); 537 WriteCObject(object->value.as_array.values[i]);
539 } 538 }
540 break; 539 break;
541 } 540 }
542 case Dart_CObject::kByteArray: { 541 case Dart_CObject::kUint8Array: {
543 // Write out the serialization header value for this object. 542 // Write out the serialization header value for this object.
544 WriteInlinedHeader(object); 543 WriteInlinedHeader(object);
545 // Write out the class and tags information. 544 // Write out the class and tags information.
546 WriteObjectHeader(ObjectStore::kInternalByteArrayClass, 0); 545 WriteObjectHeader(ObjectStore::kUint8ArrayClass, 0);
547 uint8_t* bytes = object->value.as_byte_array.values; 546 uint8_t* bytes = object->value.as_byte_array.values;
548 intptr_t len = object->value.as_byte_array.length; 547 intptr_t len = object->value.as_byte_array.length;
549 WriteSmi(len); 548 WriteSmi(len);
550 for (intptr_t i = 0; i < len; i++) { 549 for (intptr_t i = 0; i < len; i++) {
551 Write<uint8_t>(bytes[i]); 550 Write<uint8_t>(bytes[i]);
552 } 551 }
553 break; 552 break;
554 } 553 }
555 default: 554 default:
556 UNREACHABLE(); 555 UNREACHABLE();
557 } 556 }
558 } 557 }
559 558
560 559
561 void ApiMessageWriter::WriteCMessage(Dart_CObject* object) { 560 void ApiMessageWriter::WriteCMessage(Dart_CObject* object) {
562 WriteCObject(object); 561 WriteCObject(object);
563 UnmarkAllCObjects(object); 562 UnmarkAllCObjects(object);
564 FinalizeBuffer(); 563 FinalizeBuffer();
565 } 564 }
566 565
567 } // namespace dart 566 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698