OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 <set> | 5 #include <set> |
6 | 6 |
7 #include "vm/kernel_to_il.h" | 7 #include "vm/kernel_to_il.h" |
8 | 8 |
9 #include "vm/compiler.h" | 9 #include "vm/compiler.h" |
10 #include "vm/intermediate_language.h" | 10 #include "vm/intermediate_language.h" |
(...skipping 1543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1554 } | 1554 } |
1555 | 1555 |
1556 | 1556 |
1557 RawObject* ConstantEvaluator::EvaluateConstConstructorCall( | 1557 RawObject* ConstantEvaluator::EvaluateConstConstructorCall( |
1558 const dart::Class& type_class, | 1558 const dart::Class& type_class, |
1559 const TypeArguments& type_arguments, | 1559 const TypeArguments& type_arguments, |
1560 const Function& constructor, | 1560 const Function& constructor, |
1561 const Object& argument) { | 1561 const Object& argument) { |
1562 // Factories have one extra argument: the type arguments. | 1562 // Factories have one extra argument: the type arguments. |
1563 // Constructors have 1 extra arguments: receiver. | 1563 // Constructors have 1 extra arguments: receiver. |
| 1564 const int kTypeArgsLen = 0; |
1564 const int kNumArgs = 1; | 1565 const int kNumArgs = 1; |
1565 const int kNumExtraArgs = 1; | 1566 const int kNumExtraArgs = 1; |
1566 const int num_arguments = kNumArgs + kNumExtraArgs; | 1567 const int num_arguments = kNumArgs + kNumExtraArgs; |
1567 const Array& arg_values = | 1568 const Array& arg_values = |
1568 Array::Handle(Z, Array::New(num_arguments, Heap::kOld)); | 1569 Array::Handle(Z, Array::New(num_arguments, Heap::kOld)); |
1569 Instance& instance = Instance::Handle(Z); | 1570 Instance& instance = Instance::Handle(Z); |
1570 if (!constructor.IsFactory()) { | 1571 if (!constructor.IsFactory()) { |
1571 instance = Instance::New(type_class, Heap::kOld); | 1572 instance = Instance::New(type_class, Heap::kOld); |
1572 if (!type_arguments.IsNull()) { | 1573 if (!type_arguments.IsNull()) { |
1573 ASSERT(type_arguments.IsInstantiated()); | 1574 ASSERT(type_arguments.IsInstantiated()); |
1574 instance.SetTypeArguments( | 1575 instance.SetTypeArguments( |
1575 TypeArguments::Handle(Z, type_arguments.Canonicalize())); | 1576 TypeArguments::Handle(Z, type_arguments.Canonicalize())); |
1576 } | 1577 } |
1577 arg_values.SetAt(0, instance); | 1578 arg_values.SetAt(0, instance); |
1578 } else { | 1579 } else { |
1579 // Prepend type_arguments to list of arguments to factory. | 1580 // Prepend type_arguments to list of arguments to factory. |
1580 ASSERT(type_arguments.IsZoneHandle()); | 1581 ASSERT(type_arguments.IsZoneHandle()); |
1581 arg_values.SetAt(0, type_arguments); | 1582 arg_values.SetAt(0, type_arguments); |
1582 } | 1583 } |
1583 arg_values.SetAt((0 + kNumExtraArgs), argument); | 1584 arg_values.SetAt((0 + kNumExtraArgs), argument); |
1584 const Array& args_descriptor = Array::Handle( | 1585 const Array& args_descriptor = |
1585 Z, ArgumentsDescriptor::New(num_arguments, Object::empty_array())); | 1586 Array::Handle(Z, ArgumentsDescriptor::New(kTypeArgsLen, num_arguments, |
| 1587 Object::empty_array())); |
1586 const Object& result = Object::Handle( | 1588 const Object& result = Object::Handle( |
1587 Z, DartEntry::InvokeFunction(constructor, arg_values, args_descriptor)); | 1589 Z, DartEntry::InvokeFunction(constructor, arg_values, args_descriptor)); |
1588 ASSERT(!result.IsError()); | 1590 ASSERT(!result.IsError()); |
1589 if (constructor.IsFactory()) { | 1591 if (constructor.IsFactory()) { |
1590 // The factory method returns the allocated object. | 1592 // The factory method returns the allocated object. |
1591 instance ^= result.raw(); | 1593 instance ^= result.raw(); |
1592 } | 1594 } |
1593 return H.Canonicalize(instance); | 1595 return H.Canonicalize(instance); |
1594 } | 1596 } |
1595 | 1597 |
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1988 arguments.SetAt(pos++, result_); | 1990 arguments.SetAt(pos++, result_); |
1989 names.SetAt(i, H.DartSymbol(named_expression->name())); | 1991 names.SetAt(i, H.DartSymbol(named_expression->name())); |
1990 } | 1992 } |
1991 return RunFunction(function, arguments, names); | 1993 return RunFunction(function, arguments, names); |
1992 } | 1994 } |
1993 | 1995 |
1994 | 1996 |
1995 const Object& ConstantEvaluator::RunFunction(const Function& function, | 1997 const Object& ConstantEvaluator::RunFunction(const Function& function, |
1996 const Array& arguments, | 1998 const Array& arguments, |
1997 const Array& names) { | 1999 const Array& names) { |
1998 const Array& args_descriptor = | 2000 const int kTypeArgsLen = 0; // Generic functions not yet supported. |
1999 Array::Handle(Z, ArgumentsDescriptor::New(arguments.Length(), names)); | 2001 const Array& args_descriptor = Array::Handle( |
| 2002 Z, ArgumentsDescriptor::New(kTypeArgsLen, arguments.Length(), names)); |
2000 const Object& result = Object::Handle( | 2003 const Object& result = Object::Handle( |
2001 Z, DartEntry::InvokeFunction(function, arguments, args_descriptor)); | 2004 Z, DartEntry::InvokeFunction(function, arguments, args_descriptor)); |
2002 if (result.IsError()) { | 2005 if (result.IsError()) { |
2003 H.ReportError(Error::Cast(result), "error evaluating constant constructor"); | 2006 H.ReportError(Error::Cast(result), "error evaluating constant constructor"); |
2004 } | 2007 } |
2005 return result; | 2008 return result; |
2006 } | 2009 } |
2007 | 2010 |
2008 | 2011 |
2009 FlowGraphBuilder::FlowGraphBuilder( | 2012 FlowGraphBuilder::FlowGraphBuilder( |
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2525 } | 2528 } |
2526 | 2529 |
2527 | 2530 |
2528 Fragment FlowGraphBuilder::InstanceCall(TokenPosition position, | 2531 Fragment FlowGraphBuilder::InstanceCall(TokenPosition position, |
2529 const dart::String& name, | 2532 const dart::String& name, |
2530 Token::Kind kind, | 2533 Token::Kind kind, |
2531 intptr_t argument_count, | 2534 intptr_t argument_count, |
2532 const Array& argument_names, | 2535 const Array& argument_names, |
2533 intptr_t num_args_checked) { | 2536 intptr_t num_args_checked) { |
2534 ArgumentArray arguments = GetArguments(argument_count); | 2537 ArgumentArray arguments = GetArguments(argument_count); |
2535 InstanceCallInstr* call = | 2538 const intptr_t kTypeArgsLen = 0; // Generic instance calls not yet supported. |
2536 new (Z) InstanceCallInstr(position, name, kind, arguments, argument_names, | 2539 InstanceCallInstr* call = new (Z) |
2537 num_args_checked, ic_data_array_); | 2540 InstanceCallInstr(position, name, kind, arguments, kTypeArgsLen, |
| 2541 argument_names, num_args_checked, ic_data_array_); |
2538 Push(call); | 2542 Push(call); |
2539 return Fragment(call); | 2543 return Fragment(call); |
2540 } | 2544 } |
2541 | 2545 |
2542 | 2546 |
2543 Fragment FlowGraphBuilder::ClosureCall(int argument_count, | 2547 Fragment FlowGraphBuilder::ClosureCall(int argument_count, |
2544 const Array& argument_names) { | 2548 const Array& argument_names) { |
2545 Value* function = Pop(); | 2549 Value* function = Pop(); |
2546 ArgumentArray arguments = GetArguments(argument_count); | 2550 ArgumentArray arguments = GetArguments(argument_count); |
2547 ClosureCallInstr* call = new (Z) ClosureCallInstr( | 2551 const intptr_t kTypeArgsLen = 0; // Generic closures not yet supported. |
2548 function, arguments, argument_names, TokenPosition::kNoSource); | 2552 ClosureCallInstr* call = |
| 2553 new (Z) ClosureCallInstr(function, arguments, kTypeArgsLen, |
| 2554 argument_names, TokenPosition::kNoSource); |
2549 Push(call); | 2555 Push(call); |
2550 return Fragment(call); | 2556 return Fragment(call); |
2551 } | 2557 } |
2552 | 2558 |
2553 | 2559 |
2554 Fragment FlowGraphBuilder::ThrowException(TokenPosition position) { | 2560 Fragment FlowGraphBuilder::ThrowException(TokenPosition position) { |
2555 Fragment instructions; | 2561 Fragment instructions; |
2556 instructions += Drop(); | 2562 instructions += Drop(); |
2557 instructions += Fragment(new (Z) ThrowInstr(position)).closed(); | 2563 instructions += Fragment(new (Z) ThrowInstr(position)).closed(); |
2558 // Use it's side effect of leaving a constant on the stack (does not change | 2564 // Use it's side effect of leaving a constant on the stack (does not change |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2751 } | 2757 } |
2752 return FactoryRecognizer::ResultCid(function); | 2758 return FactoryRecognizer::ResultCid(function); |
2753 } | 2759 } |
2754 | 2760 |
2755 | 2761 |
2756 Fragment FlowGraphBuilder::StaticCall(TokenPosition position, | 2762 Fragment FlowGraphBuilder::StaticCall(TokenPosition position, |
2757 const Function& target, | 2763 const Function& target, |
2758 intptr_t argument_count, | 2764 intptr_t argument_count, |
2759 const Array& argument_names) { | 2765 const Array& argument_names) { |
2760 ArgumentArray arguments = GetArguments(argument_count); | 2766 ArgumentArray arguments = GetArguments(argument_count); |
2761 StaticCallInstr* call = new (Z) StaticCallInstr( | 2767 const intptr_t kTypeArgsLen = 0; // Generic static calls not yet supported. |
2762 position, target, argument_names, arguments, ic_data_array_); | 2768 StaticCallInstr* call = |
| 2769 new (Z) StaticCallInstr(position, target, kTypeArgsLen, argument_names, |
| 2770 arguments, ic_data_array_); |
2763 const intptr_t list_cid = | 2771 const intptr_t list_cid = |
2764 GetResultCidOfListFactory(Z, target, argument_count); | 2772 GetResultCidOfListFactory(Z, target, argument_count); |
2765 if (list_cid != kDynamicCid) { | 2773 if (list_cid != kDynamicCid) { |
2766 call->set_result_cid(list_cid); | 2774 call->set_result_cid(list_cid); |
2767 call->set_is_known_list_constructor(true); | 2775 call->set_is_known_list_constructor(true); |
2768 } else if (target.recognized_kind() != MethodRecognizer::kUnknown) { | 2776 } else if (target.recognized_kind() != MethodRecognizer::kUnknown) { |
2769 call->set_result_cid(MethodRecognizer::ResultCid(target)); | 2777 call->set_result_cid(MethodRecognizer::ResultCid(target)); |
2770 } | 2778 } |
2771 Push(call); | 2779 Push(call); |
2772 return Fragment(call); | 2780 return Fragment(call); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2873 Fragment FlowGraphBuilder::StringInterpolate(TokenPosition position) { | 2881 Fragment FlowGraphBuilder::StringInterpolate(TokenPosition position) { |
2874 Value* array = Pop(); | 2882 Value* array = Pop(); |
2875 StringInterpolateInstr* interpolate = | 2883 StringInterpolateInstr* interpolate = |
2876 new (Z) StringInterpolateInstr(array, position); | 2884 new (Z) StringInterpolateInstr(array, position); |
2877 Push(interpolate); | 2885 Push(interpolate); |
2878 return Fragment(interpolate); | 2886 return Fragment(interpolate); |
2879 } | 2887 } |
2880 | 2888 |
2881 | 2889 |
2882 Fragment FlowGraphBuilder::StringInterpolateSingle(TokenPosition position) { | 2890 Fragment FlowGraphBuilder::StringInterpolateSingle(TokenPosition position) { |
| 2891 const int kTypeArgsLen = 0; |
2883 const int kNumberOfArguments = 1; | 2892 const int kNumberOfArguments = 1; |
2884 const Array& kNoArgumentNames = Object::null_array(); | 2893 const Array& kNoArgumentNames = Object::null_array(); |
2885 const dart::Class& cls = dart::Class::Handle( | 2894 const dart::Class& cls = dart::Class::Handle( |
2886 dart::Library::LookupCoreClass(Symbols::StringBase())); | 2895 dart::Library::LookupCoreClass(Symbols::StringBase())); |
2887 ASSERT(!cls.IsNull()); | 2896 ASSERT(!cls.IsNull()); |
2888 const Function& function = Function::ZoneHandle( | 2897 const Function& function = Function::ZoneHandle( |
2889 Z, Resolver::ResolveStatic(cls, dart::Library::PrivateCoreLibName( | 2898 Z, |
2890 Symbols::InterpolateSingle()), | 2899 Resolver::ResolveStatic( |
2891 kNumberOfArguments, kNoArgumentNames)); | 2900 cls, dart::Library::PrivateCoreLibName(Symbols::InterpolateSingle()), |
| 2901 kTypeArgsLen, kNumberOfArguments, kNoArgumentNames)); |
2892 Fragment instructions; | 2902 Fragment instructions; |
2893 instructions += PushArgument(); | 2903 instructions += PushArgument(); |
2894 instructions += StaticCall(position, function, 1); | 2904 instructions += StaticCall(position, function, 1); |
2895 return instructions; | 2905 return instructions; |
2896 } | 2906 } |
2897 | 2907 |
2898 | 2908 |
2899 Fragment FlowGraphBuilder::ThrowTypeError() { | 2909 Fragment FlowGraphBuilder::ThrowTypeError() { |
2900 const dart::Class& klass = dart::Class::ZoneHandle( | 2910 const dart::Class& klass = dart::Class::ZoneHandle( |
2901 Z, dart::Library::LookupCoreClass(Symbols::TypeError())); | 2911 Z, dart::Library::LookupCoreClass(Symbols::TypeError())); |
(...skipping 1145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4047 ZoneGrowableArray<const Instance*>* default_values = | 4057 ZoneGrowableArray<const Instance*>* default_values = |
4048 new ZoneGrowableArray<const Instance*>(Z, descriptor.NamedCount()); | 4058 new ZoneGrowableArray<const Instance*>(Z, descriptor.NamedCount()); |
4049 for (intptr_t i = 0; i < descriptor.NamedCount(); ++i) { | 4059 for (intptr_t i = 0; i < descriptor.NamedCount(); ++i) { |
4050 default_values->Add(&Object::null_instance()); | 4060 default_values->Add(&Object::null_instance()); |
4051 } | 4061 } |
4052 parsed_function_->set_default_parameter_values(default_values); | 4062 parsed_function_->set_default_parameter_values(default_values); |
4053 | 4063 |
4054 Fragment body(normal_entry); | 4064 Fragment body(normal_entry); |
4055 body += CheckStackOverflowInPrologue(); | 4065 body += CheckStackOverflowInPrologue(); |
4056 | 4066 |
| 4067 // TODO(regis): Check if a type argument vector is passed. |
| 4068 |
4057 // The receiver is the first argument to noSuchMethod, and it is the first | 4069 // The receiver is the first argument to noSuchMethod, and it is the first |
4058 // argument passed to the dispatcher function. | 4070 // argument passed to the dispatcher function. |
4059 LocalScope* scope = parsed_function_->node_sequence()->scope(); | 4071 LocalScope* scope = parsed_function_->node_sequence()->scope(); |
4060 body += LoadLocal(scope->VariableAt(0)); | 4072 body += LoadLocal(scope->VariableAt(0)); |
4061 body += PushArgument(); | 4073 body += PushArgument(); |
4062 | 4074 |
4063 // The second argument to noSuchMethod is an invocation mirror. Push the | 4075 // The second argument to noSuchMethod is an invocation mirror. Push the |
4064 // arguments for allocating the invocation mirror. First, the name. | 4076 // arguments for allocating the invocation mirror. First, the name. |
4065 body += Constant(dart::String::ZoneHandle(Z, function.name())); | 4077 body += Constant(dart::String::ZoneHandle(Z, function.name())); |
4066 body += PushArgument(); | 4078 body += PushArgument(); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4102 const dart::Class& mirror_class = dart::Class::Handle( | 4114 const dart::Class& mirror_class = dart::Class::Handle( |
4103 Z, dart::Library::LookupCoreClass(Symbols::InvocationMirror())); | 4115 Z, dart::Library::LookupCoreClass(Symbols::InvocationMirror())); |
4104 ASSERT(!mirror_class.IsNull()); | 4116 ASSERT(!mirror_class.IsNull()); |
4105 const Function& allocation_function = Function::ZoneHandle( | 4117 const Function& allocation_function = Function::ZoneHandle( |
4106 Z, mirror_class.LookupStaticFunction(dart::Library::PrivateCoreLibName( | 4118 Z, mirror_class.LookupStaticFunction(dart::Library::PrivateCoreLibName( |
4107 Symbols::AllocateInvocationMirror()))); | 4119 Symbols::AllocateInvocationMirror()))); |
4108 ASSERT(!allocation_function.IsNull()); | 4120 ASSERT(!allocation_function.IsNull()); |
4109 body += StaticCall(TokenPosition::kMinSource, allocation_function, 4); | 4121 body += StaticCall(TokenPosition::kMinSource, allocation_function, 4); |
4110 body += PushArgument(); // For the call to noSuchMethod. | 4122 body += PushArgument(); // For the call to noSuchMethod. |
4111 | 4123 |
| 4124 const int kTypeArgsLen = 0; |
4112 ArgumentsDescriptor two_arguments( | 4125 ArgumentsDescriptor two_arguments( |
4113 Array::Handle(Z, ArgumentsDescriptor::New(2))); | 4126 Array::Handle(Z, ArgumentsDescriptor::New(kTypeArgsLen, 2))); |
4114 Function& no_such_method = | 4127 Function& no_such_method = |
4115 Function::ZoneHandle(Z, Resolver::ResolveDynamicForReceiverClass( | 4128 Function::ZoneHandle(Z, Resolver::ResolveDynamicForReceiverClass( |
4116 dart::Class::Handle(Z, function.Owner()), | 4129 dart::Class::Handle(Z, function.Owner()), |
4117 Symbols::NoSuchMethod(), two_arguments)); | 4130 Symbols::NoSuchMethod(), two_arguments)); |
4118 if (no_such_method.IsNull()) { | 4131 if (no_such_method.IsNull()) { |
4119 // If noSuchMethod is not found on the receiver class, call | 4132 // If noSuchMethod is not found on the receiver class, call |
4120 // Object.noSuchMethod. | 4133 // Object.noSuchMethod. |
4121 no_such_method = Resolver::ResolveDynamicForReceiverClass( | 4134 no_such_method = Resolver::ResolveDynamicForReceiverClass( |
4122 dart::Class::Handle(Z, I->object_store()->object_class()), | 4135 dart::Class::Handle(Z, I->object_store()->object_class()), |
4123 Symbols::NoSuchMethod(), two_arguments); | 4136 Symbols::NoSuchMethod(), two_arguments); |
(...skipping 886 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5010 if (target.IsGenerativeConstructor() || target.IsFactory()) { | 5023 if (target.IsGenerativeConstructor() || target.IsFactory()) { |
5011 // The VM requires a TypeArguments object as first parameter for | 5024 // The VM requires a TypeArguments object as first parameter for |
5012 // every factory constructor. | 5025 // every factory constructor. |
5013 ++argument_count; | 5026 ++argument_count; |
5014 } | 5027 } |
5015 | 5028 |
5016 List<NamedExpression>& named = node->arguments()->named(); | 5029 List<NamedExpression>& named = node->arguments()->named(); |
5017 const Array& argument_names = H.ArgumentNames(&named); | 5030 const Array& argument_names = H.ArgumentNames(&named); |
5018 | 5031 |
5019 // The frontend ensures we the [StaticInvocation] has matching arguments. | 5032 // The frontend ensures we the [StaticInvocation] has matching arguments. |
5020 ASSERT(target.AreValidArguments(argument_count, argument_names, NULL)); | 5033 const intptr_t kTypeArgsLen = 0; // Generic functions not yet supported. |
| 5034 ASSERT(target.AreValidArguments(kTypeArgsLen, argument_count, argument_names, |
| 5035 NULL)); |
5021 | 5036 |
5022 Fragment instructions; | 5037 Fragment instructions; |
5023 LocalVariable* instance_variable = NULL; | 5038 LocalVariable* instance_variable = NULL; |
5024 | 5039 |
5025 // If we cross the Kernel -> VM core library boundary, a [StaticInvocation] | 5040 // If we cross the Kernel -> VM core library boundary, a [StaticInvocation] |
5026 // can appear, but the thing we're calling is not a static method, but a | 5041 // can appear, but the thing we're calling is not a static method, but a |
5027 // factory constructor. | 5042 // factory constructor. |
5028 // The `H.LookupStaticmethodByKernelProcedure` will potentially resolve to the | 5043 // The `H.LookupStaticmethodByKernelProcedure` will potentially resolve to the |
5029 // forwarded constructor. | 5044 // forwarded constructor. |
5030 // In that case we'll make an instance and pass it as first argument. | 5045 // In that case we'll make an instance and pass it as first argument. |
(...skipping 1784 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6815 thread->clear_sticky_error(); | 6830 thread->clear_sticky_error(); |
6816 return error.raw(); | 6831 return error.raw(); |
6817 } | 6832 } |
6818 } | 6833 } |
6819 | 6834 |
6820 | 6835 |
6821 } // namespace kernel | 6836 } // namespace kernel |
6822 } // namespace dart | 6837 } // namespace dart |
6823 | 6838 |
6824 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 6839 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
OLD | NEW |