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

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

Issue 266783002: Save the entry context for a function that has captured loop variables. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 7 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 | « runtime/vm/scopes.h ('k') | no next file » | 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/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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 ASSERT(variable->owner()->context_level() == context_level()); 145 ASSERT(variable->owner()->context_level() == context_level());
146 } 146 }
147 variable->set_index(num_context_variables_++); 147 variable->set_index(num_context_variables_++);
148 } 148 }
149 149
150 150
151 int LocalScope::AllocateVariables(int first_parameter_index, 151 int LocalScope::AllocateVariables(int first_parameter_index,
152 int num_parameters, 152 int num_parameters,
153 int first_frame_index, 153 int first_frame_index,
154 LocalScope* loop_owner, 154 LocalScope* loop_owner,
155 LocalScope** context_owner) { 155 LocalScope** context_owner,
156 bool* found_captured_variables) {
156 // We should not allocate variables of nested functions while compiling an 157 // We should not allocate variables of nested functions while compiling an
157 // enclosing function. 158 // enclosing function.
158 ASSERT(function_level() == 0); 159 ASSERT(function_level() == 0);
159 ASSERT(num_parameters >= 0); 160 ASSERT(num_parameters >= 0);
160 161
161 // Keep track of the current loop owner scope, that is of the highest parent 162 // Keep track of the current loop owner scope, that is of the highest parent
162 // scope at the same loop level as this scope. 163 // scope at the same loop level as this scope.
163 if (loop_level() > loop_owner->loop_level()) { 164 if (loop_level() > loop_owner->loop_level()) {
164 loop_owner = this; 165 loop_owner = this;
165 } 166 }
166 // Parameters must be listed first and must all appear in the top scope. 167 // Parameters must be listed first and must all appear in the top scope.
167 ASSERT(num_parameters <= num_variables()); 168 ASSERT(num_parameters <= num_variables());
168 int pos = 0; // Current variable position. 169 int pos = 0; // Current variable position.
169 int frame_index = first_parameter_index; // Current free frame index. 170 int frame_index = first_parameter_index; // Current free frame index.
170 while (pos < num_parameters) { 171 while (pos < num_parameters) {
171 LocalVariable* parameter = VariableAt(pos); 172 LocalVariable* parameter = VariableAt(pos);
172 pos++; 173 pos++;
173 ASSERT(parameter->owner() == this); 174 ASSERT(parameter->owner() == this);
174 if (parameter->is_captured()) { 175 if (parameter->is_captured()) {
175 // A captured parameter has a slot allocated in the frame and one in the 176 // A captured parameter has a slot allocated in the frame and one in the
176 // context, where it gets copied to. The parameter index reflects the 177 // context, where it gets copied to. The parameter index reflects the
177 // context allocation index. 178 // context allocation index.
178 frame_index--; 179 frame_index--;
179 loop_owner->AllocateContextVariable(parameter, context_owner); 180 loop_owner->AllocateContextVariable(parameter, context_owner);
181 *found_captured_variables = true;
180 } else { 182 } else {
181 parameter->set_index(frame_index--); 183 parameter->set_index(frame_index--);
182 } 184 }
183 } 185 }
184 // No overlapping of parameters and locals. 186 // No overlapping of parameters and locals.
185 ASSERT(frame_index >= first_frame_index); 187 ASSERT(frame_index >= first_frame_index);
186 frame_index = first_frame_index; 188 frame_index = first_frame_index;
187 while (pos < num_variables()) { 189 while (pos < num_variables()) {
188 LocalVariable* variable = VariableAt(pos); 190 LocalVariable* variable = VariableAt(pos);
189 pos++; 191 pos++;
190 if (variable->owner() == this) { 192 if (variable->owner() == this) {
191 if (variable->is_captured()) { 193 if (variable->is_captured()) {
192 loop_owner->AllocateContextVariable(variable, context_owner); 194 loop_owner->AllocateContextVariable(variable, context_owner);
195 *found_captured_variables = true;
193 } else { 196 } else {
194 variable->set_index(frame_index--); 197 variable->set_index(frame_index--);
195 } 198 }
196 } 199 }
197 } 200 }
198 // Allocate variables of all children. 201 // Allocate variables of all children.
199 int min_frame_index = frame_index; 202 int min_frame_index = frame_index;
200 LocalScope* child = this->child(); 203 LocalScope* child = this->child();
201 while (child != NULL) { 204 while (child != NULL) {
202 LocalScope* child_context_owner = *context_owner; 205 LocalScope* child_context_owner = *context_owner;
203 int const dummy_parameter_index = 0; // Ignored, since no parameters. 206 int const dummy_parameter_index = 0; // Ignored, since no parameters.
204 int const num_parameters_in_child = 0; // No parameters in children scopes. 207 int const num_parameters_in_child = 0; // No parameters in children scopes.
205 int child_frame_index = child->AllocateVariables(dummy_parameter_index, 208 int child_frame_index = child->AllocateVariables(dummy_parameter_index,
206 num_parameters_in_child, 209 num_parameters_in_child,
207 frame_index, 210 frame_index,
208 loop_owner, 211 loop_owner,
209 &child_context_owner); 212 &child_context_owner,
213 found_captured_variables);
210 if (child_frame_index < min_frame_index) { 214 if (child_frame_index < min_frame_index) {
211 min_frame_index = child_frame_index; 215 min_frame_index = child_frame_index;
212 } 216 }
213 // A context allocated at a deeper loop level than the current loop level is 217 // A context allocated at a deeper loop level than the current loop level is
214 // not shared between children. 218 // not shared between children.
215 if ((child_context_owner != *context_owner) && 219 if ((child_context_owner != *context_owner) &&
216 (child_context_owner->loop_level() <= loop_owner->loop_level())) { 220 (child_context_owner->loop_level() <= loop_owner->loop_level())) {
217 *context_owner = child_context_owner; // Share context between siblings. 221 *context_owner = child_context_owner; // Share context between siblings.
218 } 222 }
219 child = child->sibling(); 223 child = child->sibling();
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 return fixed_parameter_count - (index() - kParamEndSlotFromFp); 631 return fixed_parameter_count - (index() - kParamEndSlotFromFp);
628 } else { 632 } else {
629 // Shift negative indexes so that the lowest one is 0 (they are still 633 // Shift negative indexes so that the lowest one is 0 (they are still
630 // non-positive). 634 // non-positive).
631 return fixed_parameter_count - (index() - kFirstLocalSlotFromFp); 635 return fixed_parameter_count - (index() - kFirstLocalSlotFromFp);
632 } 636 }
633 } 637 }
634 638
635 639
636 } // namespace dart 640 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/scopes.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698