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

Side by Side Diff: vm/code_generator.cc

Issue 11745022: - Make Boolean 'true' and 'false' singleton VM isolate objects. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 7 years, 11 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
« no previous file with comments | « vm/ast.cc ('k') | vm/code_generator_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/code_generator.h" 5 #include "vm/code_generator.h"
6 6
7 #include "vm/assembler_macros.h" 7 #include "vm/assembler_macros.h"
8 #include "vm/ast.h" 8 #include "vm/ast.h"
9 #include "vm/bigint_operations.h" 9 #include "vm/bigint_operations.h"
10 #include "vm/code_patcher.h" 10 #include "vm/code_patcher.h"
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 StackFrame* caller_frame = iterator.NextFrame(); 360 StackFrame* caller_frame = iterator.NextFrame();
361 ASSERT(caller_frame != NULL); 361 ASSERT(caller_frame != NULL);
362 362
363 const Type& instance_type = Type::Handle(instance.GetType()); 363 const Type& instance_type = Type::Handle(instance.GetType());
364 ASSERT(instance_type.IsInstantiated()); 364 ASSERT(instance_type.IsInstantiated());
365 if (type.IsInstantiated()) { 365 if (type.IsInstantiated()) {
366 OS::Print("%s: '%s' %"Pd" %s '%s' %"Pd" (pc: %#"Px").\n", 366 OS::Print("%s: '%s' %"Pd" %s '%s' %"Pd" (pc: %#"Px").\n",
367 message, 367 message,
368 String::Handle(instance_type.Name()).ToCString(), 368 String::Handle(instance_type.Name()).ToCString(),
369 Class::Handle(instance_type.type_class()).id(), 369 Class::Handle(instance_type.type_class()).id(),
370 (result.raw() == Bool::True()) ? "is" : "is !", 370 (result.raw() == Bool::True().raw()) ? "is" : "is !",
371 String::Handle(type.Name()).ToCString(), 371 String::Handle(type.Name()).ToCString(),
372 Class::Handle(type.type_class()).id(), 372 Class::Handle(type.type_class()).id(),
373 caller_frame->pc()); 373 caller_frame->pc());
374 } else { 374 } else {
375 // Instantiate type before printing. 375 // Instantiate type before printing.
376 const AbstractType& instantiated_type = 376 const AbstractType& instantiated_type =
377 AbstractType::Handle(type.InstantiateFrom(instantiator_type_arguments)); 377 AbstractType::Handle(type.InstantiateFrom(instantiator_type_arguments));
378 OS::Print("%s: '%s' %s '%s' instantiated from '%s' (pc: %#"Px").\n", 378 OS::Print("%s: '%s' %s '%s' instantiated from '%s' (pc: %#"Px").\n",
379 message, 379 message,
380 String::Handle(instance_type.Name()).ToCString(), 380 String::Handle(instance_type.Name()).ToCString(),
381 (result.raw() == Bool::True()) ? "is" : "is !", 381 (result.raw() == Bool::True().raw()) ? "is" : "is !",
382 String::Handle(instantiated_type.Name()).ToCString(), 382 String::Handle(instantiated_type.Name()).ToCString(),
383 String::Handle(type.Name()).ToCString(), 383 String::Handle(type.Name()).ToCString(),
384 caller_frame->pc()); 384 caller_frame->pc());
385 } 385 }
386 const Function& function = Function::Handle( 386 const Function& function = Function::Handle(
387 caller_frame->LookupDartFunction()); 387 caller_frame->LookupDartFunction());
388 OS::Print(" -> Function %s\n", function.ToFullyQualifiedCString()); 388 OS::Print(" -> Function %s\n", function.ToFullyQualifiedCString());
389 } 389 }
390 390
391 391
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 ASSERT(arguments.ArgCount() == kInstanceofRuntimeEntry.argument_count()); 557 ASSERT(arguments.ArgCount() == kInstanceofRuntimeEntry.argument_count());
558 const Instance& instance = Instance::CheckedHandle(arguments.ArgAt(0)); 558 const Instance& instance = Instance::CheckedHandle(arguments.ArgAt(0));
559 const AbstractType& type = AbstractType::CheckedHandle(arguments.ArgAt(1)); 559 const AbstractType& type = AbstractType::CheckedHandle(arguments.ArgAt(1));
560 const Instance& instantiator = Instance::CheckedHandle(arguments.ArgAt(2)); 560 const Instance& instantiator = Instance::CheckedHandle(arguments.ArgAt(2));
561 const AbstractTypeArguments& instantiator_type_arguments = 561 const AbstractTypeArguments& instantiator_type_arguments =
562 AbstractTypeArguments::CheckedHandle(arguments.ArgAt(3)); 562 AbstractTypeArguments::CheckedHandle(arguments.ArgAt(3));
563 const SubtypeTestCache& cache = 563 const SubtypeTestCache& cache =
564 SubtypeTestCache::CheckedHandle(arguments.ArgAt(4)); 564 SubtypeTestCache::CheckedHandle(arguments.ArgAt(4));
565 ASSERT(type.IsFinalized()); 565 ASSERT(type.IsFinalized());
566 Error& malformed_error = Error::Handle(); 566 Error& malformed_error = Error::Handle();
567 const Bool& result = Bool::Handle( 567 const Bool& result =
568 instance.IsInstanceOf(type, 568 instance.IsInstanceOf(type,
569 instantiator_type_arguments, 569 instantiator_type_arguments,
570 &malformed_error) ? 570 &malformed_error) ? Bool::True() : Bool::False();
571 Bool::True() : Bool::False());
572 if (FLAG_trace_type_checks) { 571 if (FLAG_trace_type_checks) {
573 PrintTypeCheck("InstanceOf", 572 PrintTypeCheck("InstanceOf",
574 instance, type, instantiator_type_arguments, result); 573 instance, type, instantiator_type_arguments, result);
575 } 574 }
576 if (!result.value() && !malformed_error.IsNull()) { 575 if (!result.value() && !malformed_error.IsNull()) {
577 // Throw a dynamic type error only if the instanceof test fails. 576 // Throw a dynamic type error only if the instanceof test fails.
578 const intptr_t location = GetCallerLocation(); 577 const intptr_t location = GetCallerLocation();
579 String& malformed_error_message = String::Handle( 578 String& malformed_error_message = String::Handle(
580 String::New(malformed_error.ToErrorCString())); 579 String::New(malformed_error.ToErrorCString()));
581 Exceptions::CreateAndThrowTypeError( 580 Exceptions::CreateAndThrowTypeError(
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 ASSERT(!dst_type.IsDynamicType()); // No need to check assignment. 612 ASSERT(!dst_type.IsDynamicType()); // No need to check assignment.
614 ASSERT(!dst_type.IsMalformed()); // Already checked in code generator. 613 ASSERT(!dst_type.IsMalformed()); // Already checked in code generator.
615 ASSERT(!src_instance.IsNull()); // Already checked in inlined code. 614 ASSERT(!src_instance.IsNull()); // Already checked in inlined code.
616 615
617 Error& malformed_error = Error::Handle(); 616 Error& malformed_error = Error::Handle();
618 const bool is_instance_of = src_instance.IsInstanceOf( 617 const bool is_instance_of = src_instance.IsInstanceOf(
619 dst_type, instantiator_type_arguments, &malformed_error); 618 dst_type, instantiator_type_arguments, &malformed_error);
620 619
621 if (FLAG_trace_type_checks) { 620 if (FLAG_trace_type_checks) {
622 PrintTypeCheck("TypeCheck", 621 PrintTypeCheck("TypeCheck",
623 src_instance, dst_type, instantiator_type_arguments, 622 src_instance, dst_type, instantiator_type_arguments,
624 Bool::Handle(is_instance_of ? Bool::True() : Bool::False())); 623 is_instance_of ? Bool::True() : Bool::False());
625 } 624 }
626 if (!is_instance_of) { 625 if (!is_instance_of) {
627 // Throw a dynamic type error. 626 // Throw a dynamic type error.
628 const intptr_t location = GetCallerLocation(); 627 const intptr_t location = GetCallerLocation();
629 const AbstractType& src_type = AbstractType::Handle(src_instance.GetType()); 628 const AbstractType& src_type = AbstractType::Handle(src_instance.GetType());
630 const String& src_type_name = String::Handle(src_type.UserVisibleName()); 629 const String& src_type_name = String::Handle(src_type.UserVisibleName());
631 String& dst_type_name = String::Handle(); 630 String& dst_type_name = String::Handle();
632 if (!dst_type.IsInstantiated()) { 631 if (!dst_type.IsInstantiated()) {
633 // Instantiate dst_type before reporting the error. 632 // Instantiate dst_type before reporting the error.
634 const AbstractType& instantiated_dst_type = AbstractType::Handle( 633 const AbstractType& instantiated_dst_type = AbstractType::Handle(
635 dst_type.InstantiateFrom(instantiator_type_arguments)); 634 dst_type.InstantiateFrom(instantiator_type_arguments));
636 dst_type_name = instantiated_dst_type.UserVisibleName(); 635 dst_type_name = instantiated_dst_type.UserVisibleName();
637 } else { 636 } else {
638 dst_type_name = dst_type.UserVisibleName(); 637 dst_type_name = dst_type.UserVisibleName();
639 } 638 }
640 String& malformed_error_message = String::Handle(); 639 String& malformed_error_message = String::Handle();
641 if (!malformed_error.IsNull()) { 640 if (!malformed_error.IsNull()) {
642 ASSERT(FLAG_enable_type_checks); 641 ASSERT(FLAG_enable_type_checks);
643 malformed_error_message = String::New(malformed_error.ToErrorCString()); 642 malformed_error_message = String::New(malformed_error.ToErrorCString());
644 } 643 }
645 Exceptions::CreateAndThrowTypeError(location, src_type_name, dst_type_name, 644 Exceptions::CreateAndThrowTypeError(location, src_type_name, dst_type_name,
646 dst_name, malformed_error_message); 645 dst_name, malformed_error_message);
647 UNREACHABLE(); 646 UNREACHABLE();
648 } 647 }
649 UpdateTypeTestCache(src_instance, dst_type, 648 UpdateTypeTestCache(src_instance, dst_type,
650 dst_instantiator, instantiator_type_arguments, 649 dst_instantiator, instantiator_type_arguments,
651 Bool::ZoneHandle(Bool::True()), cache); 650 Bool::True(), cache);
652 arguments.SetReturn(src_instance); 651 arguments.SetReturn(src_instance);
653 } 652 }
654 653
655 654
656 // Test whether a formal parameter was defined by a passed-in argument. 655 // Test whether a formal parameter was defined by a passed-in argument.
657 // Arg0: formal parameter index as Smi. 656 // Arg0: formal parameter index as Smi.
658 // Arg1: formal parameter name as Symbol. 657 // Arg1: formal parameter name as Symbol.
659 // Arg2: arguments descriptor array. 658 // Arg2: arguments descriptor array.
660 // Return value: true or false. 659 // Return value: true or false.
661 DEFINE_RUNTIME_ENTRY(ArgumentDefinitionTest, 3) { 660 DEFINE_RUNTIME_ENTRY(ArgumentDefinitionTest, 3) {
(...skipping 10 matching lines...) Expand all
672 if (!is_defined) { 671 if (!is_defined) {
673 // Check if the formal parameter is defined by a named argument. 672 // Check if the formal parameter is defined by a named argument.
674 const intptr_t num_named_args = arg_desc.NamedCount(); 673 const intptr_t num_named_args = arg_desc.NamedCount();
675 for (intptr_t i = 0; i < num_named_args; i++) { 674 for (intptr_t i = 0; i < num_named_args; i++) {
676 if (arg_desc.MatchesNameAt(i, param_name)) { 675 if (arg_desc.MatchesNameAt(i, param_name)) {
677 is_defined = true; 676 is_defined = true;
678 break; 677 break;
679 } 678 }
680 } 679 }
681 } 680 }
682 arguments.SetReturn(Bool::Handle(Bool::Get(is_defined))); 681 arguments.SetReturn(is_defined ? Bool::True() : Bool::False());
683 } 682 }
684 683
685 684
686 // Report that the type of the given object is not bool in conditional context. 685 // Report that the type of the given object is not bool in conditional context.
687 // Arg0: bad object. 686 // Arg0: bad object.
688 // Return value: none, throws a TypeError. 687 // Return value: none, throws a TypeError.
689 DEFINE_RUNTIME_ENTRY(ConditionTypeError, 1) { 688 DEFINE_RUNTIME_ENTRY(ConditionTypeError, 1) {
690 ASSERT(arguments.ArgCount() == 689 ASSERT(arguments.ArgCount() ==
691 kConditionTypeErrorRuntimeEntry.argument_count()); 690 kConditionTypeErrorRuntimeEntry.argument_count());
692 const intptr_t location = GetCallerLocation(); 691 const intptr_t location = GetCallerLocation();
(...skipping 1096 matching lines...) Expand 10 before | Expand all | Expand 10 after
1789 return; 1788 return;
1790 } 1789 }
1791 HeapTrace* heap_trace = Isolate::Current()->heap()->trace(); 1790 HeapTrace* heap_trace = Isolate::Current()->heap()->trace();
1792 heap_trace->TraceStoreIntoObject(RawObject::ToAddr(object), 1791 heap_trace->TraceStoreIntoObject(RawObject::ToAddr(object),
1793 field_addr, 1792 field_addr,
1794 RawObject::ToAddr(value)); 1793 RawObject::ToAddr(value));
1795 } 1794 }
1796 END_LEAF_RUNTIME_ENTRY 1795 END_LEAF_RUNTIME_ENTRY
1797 1796
1798 } // namespace dart 1797 } // namespace dart
OLDNEW
« no previous file with comments | « vm/ast.cc ('k') | vm/code_generator_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698