| 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 "vm/parser.h" | 5 #include "vm/parser.h" |
| 6 | 6 |
| 7 #include "vm/bigint_operations.h" | 7 #include "vm/bigint_operations.h" |
| 8 #include "vm/class_finalizer.h" | 8 #include "vm/class_finalizer.h" |
| 9 #include "vm/compiler.h" | 9 #include "vm/compiler.h" |
| 10 #include "vm/compiler_stats.h" | 10 #include "vm/compiler_stats.h" |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 } | 136 } |
| 137 node_sequence_->set_last_parameter_id(parameter_id); | 137 node_sequence_->set_last_parameter_id(parameter_id); |
| 138 } | 138 } |
| 139 | 139 |
| 140 | 140 |
| 141 void ParsedFunction::AllocateVariables() { | 141 void ParsedFunction::AllocateVariables() { |
| 142 LocalScope* scope = node_sequence()->scope(); | 142 LocalScope* scope = node_sequence()->scope(); |
| 143 const int fixed_parameter_count = function().num_fixed_parameters(); | 143 const int fixed_parameter_count = function().num_fixed_parameters(); |
| 144 const int optional_parameter_count = function().num_optional_parameters(); | 144 const int optional_parameter_count = function().num_optional_parameters(); |
| 145 const int parameter_count = fixed_parameter_count + optional_parameter_count; | 145 const int parameter_count = fixed_parameter_count + optional_parameter_count; |
| 146 const bool is_native_instance_closure = |
| 147 function().is_native() && function().IsImplicitInstanceClosureFunction(); |
| 146 // Compute start indices to parameters and locals, and the number of | 148 // Compute start indices to parameters and locals, and the number of |
| 147 // parameters to copy. | 149 // parameters to copy. |
| 148 if (optional_parameter_count == 0) { | 150 if (optional_parameter_count == 0 && !is_native_instance_closure) { |
| 149 // Parameter i will be at fp[1 + parameter_count - i] and local variable | 151 // Parameter i will be at fp[1 + parameter_count - i] and local variable |
| 150 // j will be at fp[kFirstLocalSlotIndex - j]. | 152 // j will be at fp[kFirstLocalSlotIndex - j]. |
| 151 first_parameter_index_ = 1 + parameter_count; | 153 first_parameter_index_ = 1 + parameter_count; |
| 152 first_stack_local_index_ = kFirstLocalSlotIndex; | 154 first_stack_local_index_ = kFirstLocalSlotIndex; |
| 153 copied_parameter_count_ = 0; | 155 copied_parameter_count_ = 0; |
| 154 } else { | 156 } else { |
| 155 // Parameter i will be at fp[kFirstLocalSlotIndex - i] and local variable | 157 // Parameter i will be at fp[kFirstLocalSlotIndex - i] and local variable |
| 156 // j will be at fp[kFirstLocalSlotIndex - parameter_count - j]. | 158 // j will be at fp[kFirstLocalSlotIndex - parameter_count - j]. |
| 157 first_parameter_index_ = kFirstLocalSlotIndex; | 159 first_parameter_index_ = kFirstLocalSlotIndex; |
| 158 first_stack_local_index_ = first_parameter_index_ - parameter_count; | 160 first_stack_local_index_ = first_parameter_index_ - parameter_count; |
| 159 copied_parameter_count_ = parameter_count; | 161 copied_parameter_count_ = parameter_count; |
| 162 if (is_native_instance_closure) { |
| 163 copied_parameter_count_ += 1; |
| 164 } |
| 160 } | 165 } |
| 161 | 166 |
| 162 // Allocate parameters and local variables, either in the local frame or | 167 // Allocate parameters and local variables, either in the local frame or |
| 163 // in the context(s). | 168 // in the context(s). |
| 164 LocalScope* context_owner = NULL; // No context needed yet. | 169 LocalScope* context_owner = NULL; // No context needed yet. |
| 165 int next_free_frame_index = | 170 int next_free_frame_index = |
| 166 scope->AllocateVariables(first_parameter_index_, | 171 scope->AllocateVariables(first_parameter_index_, |
| 167 parameter_count, | 172 parameter_count, |
| 168 first_stack_local_index_, | 173 first_stack_local_index_, |
| 169 scope, | 174 scope, |
| (...skipping 3777 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3947 if (param_desc.is_final) { | 3952 if (param_desc.is_final) { |
| 3948 parameter->set_is_final(); | 3953 parameter->set_is_final(); |
| 3949 } | 3954 } |
| 3950 } | 3955 } |
| 3951 } | 3956 } |
| 3952 | 3957 |
| 3953 | 3958 |
| 3954 // Builds ReturnNode/NativeBodyNode for a native function. | 3959 // Builds ReturnNode/NativeBodyNode for a native function. |
| 3955 void Parser::ParseNativeFunctionBlock(const ParamList* params, | 3960 void Parser::ParseNativeFunctionBlock(const ParamList* params, |
| 3956 const Function& func) { | 3961 const Function& func) { |
| 3962 func.set_is_native(true); |
| 3957 TRACE_PARSER("ParseNativeFunctionBlock"); | 3963 TRACE_PARSER("ParseNativeFunctionBlock"); |
| 3958 const Class& cls = Class::Handle(func.owner()); | 3964 const Class& cls = Class::Handle(func.owner()); |
| 3959 const int num_parameters = params->parameters->length(); | 3965 const int num_parameters = params->parameters->length(); |
| 3966 const bool is_instance_closure = func.IsImplicitInstanceClosureFunction(); |
| 3967 int num_params_for_resolution = num_parameters; |
| 3960 | 3968 |
| 3961 // Parse the function name out. | 3969 // Parse the function name out. |
| 3962 const intptr_t native_pos = token_index_; | 3970 const intptr_t native_pos = token_index_; |
| 3963 const String& native_name = ParseNativeDeclaration(); | 3971 const String& native_name = ParseNativeDeclaration(); |
| 3964 | 3972 |
| 3973 if (is_instance_closure) { |
| 3974 num_params_for_resolution += 1; // account for 'this' when resolving. |
| 3975 } |
| 3965 // Now resolve the native function to the corresponding native entrypoint. | 3976 // Now resolve the native function to the corresponding native entrypoint. |
| 3966 NativeFunction native_function = NativeEntry::ResolveNative(cls, | 3977 NativeFunction native_function = NativeEntry::ResolveNative( |
| 3967 native_name, | 3978 cls, native_name, num_params_for_resolution); |
| 3968 num_parameters); | |
| 3969 if (native_function == NULL) { | 3979 if (native_function == NULL) { |
| 3970 ErrorMsg(native_pos, "native function '%s' cannot be found", | 3980 ErrorMsg(native_pos, "native function '%s' cannot be found", |
| 3971 native_name.ToCString()); | 3981 native_name.ToCString()); |
| 3972 } | 3982 } |
| 3973 | 3983 |
| 3974 const bool has_opt_params = (params->num_optional_parameters > 0); | 3984 const bool has_opt_params = (params->num_optional_parameters > 0); |
| 3975 | 3985 |
| 3976 // Now add the NativeBodyNode and return statement. | 3986 // Now add the NativeBodyNode and return statement. |
| 3977 current_block_->statements->Add( | 3987 current_block_->statements->Add( |
| 3978 new ReturnNode(token_index_, new NativeBodyNode(token_index_, | 3988 new ReturnNode(token_index_, new NativeBodyNode(token_index_, |
| 3979 native_name, | 3989 native_name, |
| 3980 native_function, | 3990 native_function, |
| 3981 num_parameters, | 3991 num_parameters, |
| 3982 has_opt_params))); | 3992 has_opt_params, |
| 3993 is_instance_closure))); |
| 3983 } | 3994 } |
| 3984 | 3995 |
| 3985 | 3996 |
| 3986 LocalVariable* Parser::LookupReceiver(LocalScope* from_scope, | 3997 LocalVariable* Parser::LookupReceiver(LocalScope* from_scope, |
| 3987 bool test_only) { | 3998 bool test_only) { |
| 3988 const String& this_name = String::Handle(String::NewSymbol(kThisName)); | 3999 const String& this_name = String::Handle(String::NewSymbol(kThisName)); |
| 3989 return from_scope->LookupVariable(this_name, test_only); | 4000 return from_scope->LookupVariable(this_name, test_only); |
| 3990 } | 4001 } |
| 3991 | 4002 |
| 3992 | 4003 |
| (...skipping 4594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8587 void Parser::SkipQualIdent() { | 8598 void Parser::SkipQualIdent() { |
| 8588 ASSERT(IsIdentifier()); | 8599 ASSERT(IsIdentifier()); |
| 8589 ConsumeToken(); | 8600 ConsumeToken(); |
| 8590 if (CurrentToken() == Token::kPERIOD) { | 8601 if (CurrentToken() == Token::kPERIOD) { |
| 8591 ConsumeToken(); // Consume the kPERIOD token. | 8602 ConsumeToken(); // Consume the kPERIOD token. |
| 8592 ExpectIdentifier("identifier expected after '.'"); | 8603 ExpectIdentifier("identifier expected after '.'"); |
| 8593 } | 8604 } |
| 8594 } | 8605 } |
| 8595 | 8606 |
| 8596 } // namespace dart | 8607 } // namespace dart |
| OLD | NEW |