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

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

Issue 10915022: Implement argument definition test in the vm. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 3 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/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/code_patcher.h" 9 #include "vm/code_patcher.h"
10 #include "vm/compiler.h" 10 #include "vm/compiler.h"
(...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 dst_name, malformed_error_message); 647 dst_name, malformed_error_message);
648 UNREACHABLE(); 648 UNREACHABLE();
649 } 649 }
650 UpdateTypeTestCache(src_instance, dst_type, 650 UpdateTypeTestCache(src_instance, dst_type,
651 dst_instantiator, instantiator_type_arguments, 651 dst_instantiator, instantiator_type_arguments,
652 Bool::ZoneHandle(Bool::True()), cache); 652 Bool::ZoneHandle(Bool::True()), cache);
653 arguments.SetReturn(src_instance); 653 arguments.SetReturn(src_instance);
654 } 654 }
655 655
656 656
657 // Test whether a formal parameter was defined by a passed-in argument.
658 // Arg0: formal parameter index as Smi.
659 // Arg1: formal parameter name as Symbol.
660 // Arg2: arguments descriptor array.
661 // Return value: true or false.
662 DEFINE_RUNTIME_ENTRY(ArgumentDefinitionTest, 3) {
663 ASSERT(arguments.Count() ==
664 kArgumentDefinitionTestRuntimeEntry.argument_count());
665 const Smi& param_index = Smi::CheckedHandle(arguments.At(0));
666 const String& param_name = String::CheckedHandle(arguments.At(1));
667 ASSERT(param_name.IsSymbol());
668 const Array& arg_desc = Array::CheckedHandle(arguments.At(2));
669 const intptr_t num_pos_args = Smi::CheckedHandle(arg_desc.At(1)).Value();
670 // Check if the formal parameter is defined by a positional argument.
671 bool is_defined = num_pos_args > param_index.Value();
672 if (!is_defined) {
673 // Check if the formal parameter is defined by a named argument.
674 const intptr_t num_named_args =
675 Smi::CheckedHandle(arg_desc.At(0)).Value() - num_pos_args;
676 String& arg_name = String::Handle();
677 for (intptr_t i = 0; i < num_named_args; i++) {
678 arg_name ^= arg_desc.At(2*i + 2);
679 if (arg_name.raw() == param_name.raw()) {
680 is_defined = true;
681 break;
682 }
683 }
684 }
685 arguments.SetReturn(Bool::Handle(Bool::Get(is_defined)));
686 }
687
688
657 // Report that the type of the given object is not bool in conditional context. 689 // Report that the type of the given object is not bool in conditional context.
658 // Arg0: bad object. 690 // Arg0: bad object.
659 // Return value: none, throws a TypeError. 691 // Return value: none, throws a TypeError.
660 DEFINE_RUNTIME_ENTRY(ConditionTypeError, 1) { 692 DEFINE_RUNTIME_ENTRY(ConditionTypeError, 1) {
661 ASSERT(arguments.Count() == 693 ASSERT(arguments.Count() ==
662 kConditionTypeErrorRuntimeEntry.argument_count()); 694 kConditionTypeErrorRuntimeEntry.argument_count());
663 const intptr_t location = GetCallerLocation(); 695 const intptr_t location = GetCallerLocation();
664 const Instance& src_instance = Instance::CheckedHandle(arguments.At(0)); 696 const Instance& src_instance = Instance::CheckedHandle(arguments.At(0));
665 ASSERT(src_instance.IsNull() || !src_instance.IsBool()); 697 ASSERT(src_instance.IsNull() || !src_instance.IsBool());
666 const Type& bool_interface = Type::Handle(Type::BoolType()); 698 const Type& bool_interface = Type::Handle(Type::BoolType());
(...skipping 1003 matching lines...) Expand 10 before | Expand all | Expand 10 after
1670 current->slot(), 1702 current->slot(),
1671 current->value()); 1703 current->value());
1672 } 1704 }
1673 1705
1674 delete current; 1706 delete current;
1675 } 1707 }
1676 } 1708 }
1677 1709
1678 1710
1679 } // namespace dart 1711 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698