OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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_entry.h" | 5 #include "vm/dart_entry.h" |
6 | 6 |
7 #include "vm/class_finalizer.h" | 7 #include "vm/class_finalizer.h" |
8 #include "vm/code_generator.h" | 8 #include "vm/code_generator.h" |
9 #include "vm/compiler.h" | 9 #include "vm/compiler.h" |
10 #include "vm/debugger.h" | 10 #include "vm/debugger.h" |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 optional_arguments_names.IsNull() ? 0 : optional_arguments_names.Length(); | 314 optional_arguments_names.IsNull() ? 0 : optional_arguments_names.Length(); |
315 if (num_named_args == 0) { | 315 if (num_named_args == 0) { |
316 return ArgumentsDescriptor::New(num_arguments); | 316 return ArgumentsDescriptor::New(num_arguments); |
317 } | 317 } |
318 const intptr_t num_pos_args = num_arguments - num_named_args; | 318 const intptr_t num_pos_args = num_arguments - num_named_args; |
319 | 319 |
320 // Build the arguments descriptor array, which consists of the total | 320 // Build the arguments descriptor array, which consists of the total |
321 // argument count; the positional argument count; a sequence of (name, | 321 // argument count; the positional argument count; a sequence of (name, |
322 // position) pairs, sorted by name, for each named optional argument; and | 322 // position) pairs, sorted by name, for each named optional argument; and |
323 // a terminating null to simplify iterating in generated code. | 323 // a terminating null to simplify iterating in generated code. |
| 324 Thread* thread = Thread::Current(); |
| 325 Zone* zone = thread->zone(); |
324 const intptr_t descriptor_len = LengthFor(num_named_args); | 326 const intptr_t descriptor_len = LengthFor(num_named_args); |
325 Array& descriptor = Array::Handle(Array::New(descriptor_len, Heap::kOld)); | 327 Array& descriptor = Array::Handle( |
| 328 zone, Array::New(descriptor_len, Heap::kOld)); |
326 | 329 |
327 // Set total number of passed arguments. | 330 // Set total number of passed arguments. |
328 descriptor.SetAt(kCountIndex, Smi::Handle(Smi::New(num_arguments))); | 331 descriptor.SetAt(kCountIndex, Smi::Handle(Smi::New(num_arguments))); |
329 // Set number of positional arguments. | 332 // Set number of positional arguments. |
330 descriptor.SetAt(kPositionalCountIndex, Smi::Handle(Smi::New(num_pos_args))); | 333 descriptor.SetAt(kPositionalCountIndex, Smi::Handle(Smi::New(num_pos_args))); |
331 // Set alphabetically sorted entries for named arguments. | 334 // Set alphabetically sorted entries for named arguments. |
332 String& name = String::Handle(); | 335 String& name = String::Handle(zone); |
333 Smi& pos = Smi::Handle(); | 336 Smi& pos = Smi::Handle(zone); |
| 337 String& previous_name = String::Handle(zone); |
| 338 Smi& previous_pos = Smi::Handle(zone); |
334 for (intptr_t i = 0; i < num_named_args; i++) { | 339 for (intptr_t i = 0; i < num_named_args; i++) { |
335 name ^= optional_arguments_names.At(i); | 340 name ^= optional_arguments_names.At(i); |
336 pos = Smi::New(num_pos_args + i); | 341 pos = Smi::New(num_pos_args + i); |
337 intptr_t insert_index = kFirstNamedEntryIndex + (kNamedEntrySize * i); | 342 intptr_t insert_index = kFirstNamedEntryIndex + (kNamedEntrySize * i); |
338 // Shift already inserted pairs with "larger" names. | 343 // Shift already inserted pairs with "larger" names. |
339 String& previous_name = String::Handle(); | |
340 Smi& previous_pos = Smi::Handle(); | |
341 while (insert_index > kFirstNamedEntryIndex) { | 344 while (insert_index > kFirstNamedEntryIndex) { |
342 intptr_t previous_index = insert_index - kNamedEntrySize; | 345 intptr_t previous_index = insert_index - kNamedEntrySize; |
343 previous_name ^= descriptor.At(previous_index + kNameOffset); | 346 previous_name ^= descriptor.At(previous_index + kNameOffset); |
344 intptr_t result = name.CompareTo(previous_name); | 347 intptr_t result = name.CompareTo(previous_name); |
345 ASSERT(result != 0); // Duplicate argument names checked in parser. | 348 ASSERT(result != 0); // Duplicate argument names checked in parser. |
346 if (result > 0) break; | 349 if (result > 0) break; |
347 previous_pos ^= descriptor.At(previous_index + kPositionOffset); | 350 previous_pos ^= descriptor.At(previous_index + kPositionOffset); |
348 descriptor.SetAt(insert_index + kNameOffset, previous_name); | 351 descriptor.SetAt(insert_index + kNameOffset, previous_name); |
349 descriptor.SetAt(insert_index + kPositionOffset, previous_pos); | 352 descriptor.SetAt(insert_index + kPositionOffset, previous_pos); |
350 insert_index = previous_index; | 353 insert_index = previous_index; |
351 } | 354 } |
352 // Insert pair in descriptor array. | 355 // Insert pair in descriptor array. |
353 descriptor.SetAt(insert_index + kNameOffset, name); | 356 descriptor.SetAt(insert_index + kNameOffset, name); |
354 descriptor.SetAt(insert_index + kPositionOffset, pos); | 357 descriptor.SetAt(insert_index + kPositionOffset, pos); |
355 } | 358 } |
356 // Set terminating null. | 359 // Set terminating null. |
357 descriptor.SetAt(descriptor_len - 1, Object::null_object()); | 360 descriptor.SetAt(descriptor_len - 1, Object::null_object()); |
358 | 361 |
359 // Share the immutable descriptor when possible by canonicalizing it. | 362 // Share the immutable descriptor when possible by canonicalizing it. |
360 descriptor.MakeImmutable(); | 363 descriptor.MakeImmutable(); |
361 descriptor ^= descriptor.CheckAndCanonicalize(NULL); | 364 descriptor ^= descriptor.CheckAndCanonicalize(thread, NULL); |
362 ASSERT(!descriptor.IsNull()); | 365 ASSERT(!descriptor.IsNull()); |
363 return descriptor.raw(); | 366 return descriptor.raw(); |
364 } | 367 } |
365 | 368 |
366 | 369 |
367 RawArray* ArgumentsDescriptor::New(intptr_t num_arguments) { | 370 RawArray* ArgumentsDescriptor::New(intptr_t num_arguments) { |
368 ASSERT(num_arguments >= 0); | 371 ASSERT(num_arguments >= 0); |
369 if (num_arguments < kCachedDescriptorCount) { | 372 if (num_arguments < kCachedDescriptorCount) { |
370 return cached_args_descriptors_[num_arguments]; | 373 return cached_args_descriptors_[num_arguments]; |
371 } | 374 } |
372 return NewNonCached(num_arguments); | 375 return NewNonCached(num_arguments); |
373 } | 376 } |
374 | 377 |
375 | 378 |
376 RawArray* ArgumentsDescriptor::NewNonCached(intptr_t num_arguments, | 379 RawArray* ArgumentsDescriptor::NewNonCached(intptr_t num_arguments, |
377 bool canonicalize) { | 380 bool canonicalize) { |
378 // Build the arguments descriptor array, which consists of the total | 381 // Build the arguments descriptor array, which consists of the total |
379 // argument count; the positional argument count; and | 382 // argument count; the positional argument count; and |
380 // a terminating null to simplify iterating in generated code. | 383 // a terminating null to simplify iterating in generated code. |
| 384 Thread* thread = Thread::Current(); |
| 385 Zone* zone = thread->zone(); |
381 const intptr_t descriptor_len = LengthFor(0); | 386 const intptr_t descriptor_len = LengthFor(0); |
382 Array& descriptor = Array::Handle(Array::New(descriptor_len, Heap::kOld)); | 387 Array& descriptor = Array::Handle( |
383 const Smi& arg_count = Smi::Handle(Smi::New(num_arguments)); | 388 zone, Array::New(descriptor_len, Heap::kOld)); |
| 389 const Smi& arg_count = Smi::Handle(zone, Smi::New(num_arguments)); |
384 | 390 |
385 // Set total number of passed arguments. | 391 // Set total number of passed arguments. |
386 descriptor.SetAt(kCountIndex, arg_count); | 392 descriptor.SetAt(kCountIndex, arg_count); |
387 | 393 |
388 // Set number of positional arguments. | 394 // Set number of positional arguments. |
389 descriptor.SetAt(kPositionalCountIndex, arg_count); | 395 descriptor.SetAt(kPositionalCountIndex, arg_count); |
390 | 396 |
391 // Set terminating null. | 397 // Set terminating null. |
392 descriptor.SetAt((descriptor_len - 1), Object::null_object()); | 398 descriptor.SetAt((descriptor_len - 1), Object::null_object()); |
393 | 399 |
394 // Share the immutable descriptor when possible by canonicalizing it. | 400 // Share the immutable descriptor when possible by canonicalizing it. |
395 descriptor.MakeImmutable(); | 401 descriptor.MakeImmutable(); |
396 if (canonicalize) { | 402 if (canonicalize) { |
397 descriptor ^= descriptor.CheckAndCanonicalize(NULL); | 403 descriptor ^= descriptor.CheckAndCanonicalize(thread, NULL); |
398 } | 404 } |
399 ASSERT(!descriptor.IsNull()); | 405 ASSERT(!descriptor.IsNull()); |
400 return descriptor.raw(); | 406 return descriptor.raw(); |
401 } | 407 } |
402 | 408 |
403 | 409 |
404 void ArgumentsDescriptor::InitOnce() { | 410 void ArgumentsDescriptor::InitOnce() { |
405 for (int i = 0; i < kCachedDescriptorCount; i++) { | 411 for (int i = 0; i < kCachedDescriptorCount; i++) { |
406 cached_args_descriptors_[i] = ArgumentsDescriptor::NewNonCached(i, false); | 412 cached_args_descriptors_[i] = ArgumentsDescriptor::NewNonCached(i, false); |
407 } | 413 } |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
594 const Array& args = Array::Handle(Array::New(kNumArguments)); | 600 const Array& args = Array::Handle(Array::New(kNumArguments)); |
595 args.SetAt(0, map); | 601 args.SetAt(0, map); |
596 args.SetAt(1, key); | 602 args.SetAt(1, key); |
597 args.SetAt(2, value); | 603 args.SetAt(2, value); |
598 const Object& result = Object::Handle(DartEntry::InvokeFunction(function, | 604 const Object& result = Object::Handle(DartEntry::InvokeFunction(function, |
599 args)); | 605 args)); |
600 return result.raw(); | 606 return result.raw(); |
601 } | 607 } |
602 | 608 |
603 } // namespace dart | 609 } // namespace dart |
OLD | NEW |