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 "bin/dartutils.h" | 5 #include "bin/dartutils.h" |
6 | 6 |
7 #include "bin/file.h" | 7 #include "bin/file.h" |
8 #include "include/dart_api.h" | 8 #include "include/dart_api.h" |
9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
10 #include "platform/globals.h" | 10 #include "platform/globals.h" |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
245 if (canonical_filename == NULL) { | 245 if (canonical_filename == NULL) { |
246 return absolute_filename; | 246 return absolute_filename; |
247 } | 247 } |
248 free(absolute_filename); | 248 free(absolute_filename); |
249 return canonical_filename; | 249 return canonical_filename; |
250 } | 250 } |
251 | 251 |
252 | 252 |
253 bool DartUtils::PostNull(Dart_Port port_id) { | 253 bool DartUtils::PostNull(Dart_Port port_id) { |
254 // Post a message with just the null object. | 254 // Post a message with just the null object. |
255 Dart_CObject object; | 255 return Dart_PostCObject(port_id, CObject::Null()->AsApiCObject()); |
256 object.type = Dart_CObject::kNull; | |
257 return Dart_PostCObject(port_id, &object); | |
258 } | 256 } |
259 | 257 |
260 | 258 |
261 bool DartUtils::PostInt32(Dart_Port port_id, int32_t value) { | 259 bool DartUtils::PostInt32(Dart_Port port_id, int32_t value) { |
262 // Post a message with the integer value. | 260 // Post a message with the integer value. |
263 int32_t min = 0xc0000000; // -1073741824 | 261 int32_t min = 0xc0000000; // -1073741824 |
264 int32_t max = 0x3fffffff; // 1073741823 | 262 int32_t max = 0x3fffffff; // 1073741823 |
265 ASSERT(min <= value && value < max); | 263 ASSERT(min <= value && value < max); |
266 Dart_CObject object; | 264 Dart_CObject object; |
267 object.type = Dart_CObject::kInt32; | 265 object.type = Dart_CObject::kInt32; |
268 object.value.as_int32 = value; | 266 object.value.as_int32 = value; |
269 return Dart_PostCObject(port_id, &object); | 267 return Dart_PostCObject(port_id, &object); |
270 } | 268 } |
269 | |
270 | |
271 // Statically allocated Dart_Cobject instances for immutable | |
Mads Ager (google)
2012/02/20 12:38:38
Dart_CObject?
Søren Gjesse
2012/02/21 08:24:25
Done.
| |
272 // objects. As these will be used by different threads the use of | |
273 // these is depending on that the marking internally in the | |
Mads Ager (google)
2012/02/20 12:38:38
is depending on that -> depends on the fact that ?
Søren Gjesse
2012/02/21 08:24:25
Done.
| |
274 // Dart_CObject structure is not marking simple value objects. | |
275 Dart_CObject CObject::api_null_ = {Dart_CObject::kNull , { 0 } }; | |
Mads Ager (google)
2012/02/20 12:38:38
I would add space between '{' and Dart_CObject.
Søren Gjesse
2012/02/21 08:24:25
Done.
| |
276 Dart_CObject CObject::api_true_ = {Dart_CObject::kBool , { true } }; | |
277 Dart_CObject CObject::api_false_ = {Dart_CObject::kBool, { false } }; | |
278 CObject CObject::null_ = CObject(&api_null_); | |
279 CObject CObject::true_ = CObject(&api_true_); | |
280 CObject CObject::false_ = CObject(&api_false_); | |
281 | |
282 | |
283 CObject* CObject::Null() { | |
284 return &null_; | |
285 } | |
286 | |
287 | |
288 CObject* CObject::True() { | |
289 return &true_; | |
290 } | |
291 | |
292 | |
293 CObject* CObject::False() { | |
294 return &false_; | |
295 } | |
296 | |
297 | |
298 CObject* CObject::Bool(bool value) { | |
299 return value ? &true_ : &false_; | |
300 } | |
301 | |
302 | |
303 Dart_CObject* CObject::New(Dart_CObject::Type type, int additional_bytes) { | |
304 Dart_CObject* cobject = reinterpret_cast<Dart_CObject*>( | |
305 Dart_ScopeAllocate(sizeof(Dart_CObject) + additional_bytes)); | |
306 cobject->type = type; | |
307 return cobject; | |
308 } | |
309 | |
310 | |
311 Dart_CObject* CObject::NewInt32(int32_t value) { | |
312 Dart_CObject* cobject = New(Dart_CObject::kInt32); | |
313 cobject->value.as_int32 = value; | |
314 return cobject; | |
315 } | |
316 | |
317 | |
318 Dart_CObject* CObject::NewInt64(int64_t value) { | |
319 Dart_CObject* cobject = New(Dart_CObject::kInt64); | |
320 cobject->value.as_int64 = value; | |
321 return cobject; | |
322 } | |
323 | |
324 | |
325 Dart_CObject* CObject::NewDouble(double value) { | |
326 Dart_CObject* cobject = New(Dart_CObject::kDouble); | |
327 cobject->value.as_double = value; | |
328 return cobject; | |
329 } | |
330 | |
331 | |
332 Dart_CObject* CObject::NewString(int length) { | |
333 Dart_CObject* cobject = New(Dart_CObject::kString, length + 1); | |
334 cobject->value.as_string = reinterpret_cast<char*>(cobject + 1); | |
335 return cobject; | |
336 } | |
337 | |
338 | |
339 Dart_CObject* CObject::NewString(const char* str) { | |
340 int length = strlen(str); | |
341 Dart_CObject* cobject = NewString(length); | |
342 memmove(cobject->value.as_string, str, length + 1); | |
343 return cobject; | |
344 } | |
345 | |
346 | |
347 Dart_CObject* CObject::NewArray(int length) { | |
348 Dart_CObject* cobject = | |
349 New(Dart_CObject::kArray, length * sizeof(Dart_CObject*)); // NOLINT | |
350 cobject->value.as_array.length = length; | |
351 cobject->value.as_array.values = | |
352 reinterpret_cast<Dart_CObject**>(cobject + 1); | |
353 return cobject; | |
354 } | |
OLD | NEW |