| 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/scopes.h" | 5 #include "vm/scopes.h" |
| 6 | 6 |
| 7 #include "vm/object.h" | 7 #include "vm/object.h" |
| 8 #include "vm/stack_frame.h" | 8 #include "vm/stack_frame.h" |
| 9 #include "vm/symbols.h" | 9 #include "vm/symbols.h" |
| 10 | 10 |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 } else { | 187 } else { |
| 188 ASSERT(context_level() == (*context_owner)->context_level()); | 188 ASSERT(context_level() == (*context_owner)->context_level()); |
| 189 } | 189 } |
| 190 } | 190 } |
| 191 variable->set_index((*context_owner)->num_context_variables_++); | 191 variable->set_index((*context_owner)->num_context_variables_++); |
| 192 } | 192 } |
| 193 | 193 |
| 194 | 194 |
| 195 int LocalScope::AllocateVariables(int first_parameter_index, | 195 int LocalScope::AllocateVariables(int first_parameter_index, |
| 196 int num_parameters, | 196 int num_parameters, |
| 197 int type_args_slot, |
| 197 int first_frame_index, | 198 int first_frame_index, |
| 198 LocalScope* context_owner, | 199 LocalScope* context_owner, |
| 199 bool* found_captured_variables) { | 200 bool* found_captured_variables) { |
| 200 // We should not allocate variables of nested functions while compiling an | 201 // We should not allocate variables of nested functions while compiling an |
| 201 // enclosing function. | 202 // enclosing function. |
| 202 ASSERT(function_level() == 0); | 203 ASSERT(function_level() == 0); |
| 203 ASSERT(num_parameters >= 0); | 204 ASSERT(num_parameters >= 0); |
| 204 // Parameters must be listed first and must all appear in the top scope. | 205 // Parameters must be listed first and must all appear in the top scope. |
| 205 ASSERT(num_parameters <= num_variables()); | 206 ASSERT(num_parameters <= num_variables()); |
| 206 int pos = 0; // Current variable position. | 207 int pos = 0; // Current variable position. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 227 // No overlapping of parameters and locals. | 228 // No overlapping of parameters and locals. |
| 228 ASSERT(frame_index >= first_frame_index); | 229 ASSERT(frame_index >= first_frame_index); |
| 229 frame_index = first_frame_index; | 230 frame_index = first_frame_index; |
| 230 while (pos < num_variables()) { | 231 while (pos < num_variables()) { |
| 231 LocalVariable* variable = VariableAt(pos); | 232 LocalVariable* variable = VariableAt(pos); |
| 232 pos++; | 233 pos++; |
| 233 if (variable->owner() == this) { | 234 if (variable->owner() == this) { |
| 234 if (variable->is_captured()) { | 235 if (variable->is_captured()) { |
| 235 AllocateContextVariable(variable, &context_owner); | 236 AllocateContextVariable(variable, &context_owner); |
| 236 *found_captured_variables = true; | 237 *found_captured_variables = true; |
| 238 if ((pos == num_parameters) && (type_args_slot == 1)) { |
| 239 ASSERT(variable->name().Equals(Symbols::FunctionTypeArgumentsVar())); |
| 240 // A captured type args variable has a slot allocated in the frame and |
| 241 // one in the context, where it gets copied to. |
| 242 frame_index--; |
| 243 } |
| 237 } else { | 244 } else { |
| 238 variable->set_index(frame_index--); | 245 variable->set_index(frame_index--); |
| 239 } | 246 } |
| 240 } | 247 } |
| 241 } | 248 } |
| 242 // Allocate variables of all children. | 249 // Allocate variables of all children. |
| 243 int min_frame_index = frame_index; // Frame index decreases with allocations. | 250 int min_frame_index = frame_index; // Frame index decreases with allocations. |
| 244 LocalScope* child = this->child(); | 251 LocalScope* child = this->child(); |
| 245 while (child != NULL) { | 252 while (child != NULL) { |
| 246 int const dummy_parameter_index = 0; // Ignored, since no parameters. | 253 const int dummy_parameter_index = 0; // Ignored, since no parameters. |
| 247 int const num_parameters_in_child = 0; // No parameters in children scopes. | 254 const int num_parameters_in_child = 0; // No parameters in children scopes. |
| 255 const int no_type_args_slot = 0; // No type args slot in children scopes. |
| 248 int child_frame_index = child->AllocateVariables( | 256 int child_frame_index = child->AllocateVariables( |
| 249 dummy_parameter_index, num_parameters_in_child, frame_index, | 257 dummy_parameter_index, num_parameters_in_child, no_type_args_slot, |
| 250 context_owner, found_captured_variables); | 258 frame_index, context_owner, found_captured_variables); |
| 251 if (child_frame_index < min_frame_index) { | 259 if (child_frame_index < min_frame_index) { |
| 252 min_frame_index = child_frame_index; | 260 min_frame_index = child_frame_index; |
| 253 } | 261 } |
| 254 child = child->sibling(); | 262 child = child->sibling(); |
| 255 } | 263 } |
| 256 return min_frame_index; | 264 return min_frame_index; |
| 257 } | 265 } |
| 258 | 266 |
| 259 | 267 |
| 260 // The parser creates internal variables that start with ":" | 268 // The parser creates internal variables that start with ":" |
| (...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 726 return fixed_parameter_count - (index() - kParamEndSlotFromFp); | 734 return fixed_parameter_count - (index() - kParamEndSlotFromFp); |
| 727 } else { | 735 } else { |
| 728 // Shift negative indexes so that the lowest one is 0 (they are still | 736 // Shift negative indexes so that the lowest one is 0 (they are still |
| 729 // non-positive). | 737 // non-positive). |
| 730 return fixed_parameter_count - (index() - kFirstLocalSlotFromFp); | 738 return fixed_parameter_count - (index() - kFirstLocalSlotFromFp); |
| 731 } | 739 } |
| 732 } | 740 } |
| 733 | 741 |
| 734 | 742 |
| 735 } // namespace dart | 743 } // namespace dart |
| OLD | NEW |