| 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/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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 } | 81 } |
| 82 | 82 |
| 83 | 83 |
| 84 Dart_CObject* ApiMessageReader::AllocateDartCObjectInt64(int64_t val) { | 84 Dart_CObject* ApiMessageReader::AllocateDartCObjectInt64(int64_t val) { |
| 85 Dart_CObject* value = AllocateDartCObject(Dart_CObject::kInt64); | 85 Dart_CObject* value = AllocateDartCObject(Dart_CObject::kInt64); |
| 86 value->value.as_int64 = val; | 86 value->value.as_int64 = val; |
| 87 return value; | 87 return value; |
| 88 } | 88 } |
| 89 | 89 |
| 90 | 90 |
| 91 Dart_CObject* ApiMessageReader::AllocateDartCObjectBigint(intptr_t length) { |
| 92 // Allocate a Dart_CObject structure followed by an array of chars |
| 93 // for the bigint hex string content. The pointer to the bigint |
| 94 // content is set up to this area. |
| 95 Dart_CObject* value = |
| 96 reinterpret_cast<Dart_CObject*>( |
| 97 alloc_(NULL, 0, sizeof(Dart_CObject) + length + 1)); |
| 98 value->value.as_bigint = reinterpret_cast<char*>(value) + sizeof(*value); |
| 99 value->type = Dart_CObject::kBigint; |
| 100 return value; |
| 101 } |
| 102 |
| 103 |
| 91 Dart_CObject* ApiMessageReader::AllocateDartCObjectDouble(double val) { | 104 Dart_CObject* ApiMessageReader::AllocateDartCObjectDouble(double val) { |
| 92 Dart_CObject* value = AllocateDartCObject(Dart_CObject::kDouble); | 105 Dart_CObject* value = AllocateDartCObject(Dart_CObject::kDouble); |
| 93 value->value.as_double = val; | 106 value->value.as_double = val; |
| 94 return value; | 107 return value; |
| 95 } | 108 } |
| 96 | 109 |
| 97 | 110 |
| 98 Dart_CObject* ApiMessageReader::AllocateDartCObjectString(intptr_t length) { | 111 Dart_CObject* ApiMessageReader::AllocateDartCObjectString(intptr_t length) { |
| 99 // Allocate a Dart_CObject structure followed by an array of chars | 112 // Allocate a Dart_CObject structure followed by an array of chars |
| 100 // for the string content. The pointer to the string content is set | 113 // for the string content. The pointer to the string content is set |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 } | 212 } |
| 200 case ObjectStore::kMintClass: { | 213 case ObjectStore::kMintClass: { |
| 201 int64_t value = Read<int64_t>(); | 214 int64_t value = Read<int64_t>(); |
| 202 if (kMinInt32 <= value && value <= kMaxInt32) { | 215 if (kMinInt32 <= value && value <= kMaxInt32) { |
| 203 return AllocateDartCObjectInt32(value); | 216 return AllocateDartCObjectInt32(value); |
| 204 } else { | 217 } else { |
| 205 return AllocateDartCObjectInt64(value); | 218 return AllocateDartCObjectInt64(value); |
| 206 } | 219 } |
| 207 break; | 220 break; |
| 208 } | 221 } |
| 222 case ObjectStore::kBigintClass: { |
| 223 // Read in the hex string representation of the bigint. |
| 224 intptr_t len = ReadIntptrValue(); |
| 225 Dart_CObject* object = AllocateDartCObjectBigint(len); |
| 226 char* p = object->value.as_bigint; |
| 227 for (intptr_t i = 0; i < len; i++) { |
| 228 p[i] = Read<uint8_t>(); |
| 229 } |
| 230 p[len] = '\0'; |
| 231 return object; |
| 232 break; |
| 233 } |
| 209 case ObjectStore::kDoubleClass: { | 234 case ObjectStore::kDoubleClass: { |
| 210 // Read the double value for the object. | 235 // Read the double value for the object. |
| 211 Dart_CObject* object = AllocateDartCObjectDouble(Read<double>()); | 236 Dart_CObject* object = AllocateDartCObjectDouble(Read<double>()); |
| 212 AddBackwardReference(object_id, object); | 237 AddBackwardReference(object_id, object); |
| 213 return object; | 238 return object; |
| 214 break; | 239 break; |
| 215 } | 240 } |
| 216 case ObjectStore::kOneByteStringClass: { | 241 case ObjectStore::kOneByteStringClass: { |
| 217 intptr_t len = ReadSmiValue(); | 242 intptr_t len = ReadSmiValue(); |
| 218 intptr_t hash = ReadSmiValue(); | 243 intptr_t hash = ReadSmiValue(); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 return ReadObjectImpl(value); | 327 return ReadObjectImpl(value); |
| 303 } | 328 } |
| 304 | 329 |
| 305 | 330 |
| 306 void ApiMessageReader::AddBackwardReference(intptr_t id, Dart_CObject* obj) { | 331 void ApiMessageReader::AddBackwardReference(intptr_t id, Dart_CObject* obj) { |
| 307 ASSERT((id - kMaxPredefinedObjectIds) == backward_references_.length()); | 332 ASSERT((id - kMaxPredefinedObjectIds) == backward_references_.length()); |
| 308 backward_references_.Add(obj); | 333 backward_references_.Add(obj); |
| 309 } | 334 } |
| 310 | 335 |
| 311 } // namespace dart | 336 } // namespace dart |
| OLD | NEW |