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

Side by Side Diff: src/scopes.cc

Issue 7860045: Stack allocating block scoped variables. Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Rebased on tip of tree. Created 9 years 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 | « src/scopes.h ('k') | src/x64/full-codegen-x64.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 inner_scopes_(4), 141 inner_scopes_(4),
142 variables_(), 142 variables_(),
143 temps_(4), 143 temps_(4),
144 params_(4), 144 params_(4),
145 unresolved_(16), 145 unresolved_(16),
146 decls_(4), 146 decls_(4),
147 already_resolved_(true) { 147 already_resolved_(true) {
148 SetDefaults(type, NULL, scope_info); 148 SetDefaults(type, NULL, scope_info);
149 if (!scope_info.is_null()) { 149 if (!scope_info.is_null()) {
150 num_heap_slots_ = scope_info_->ContextLength(); 150 num_heap_slots_ = scope_info_->ContextLength();
151 stack_slots_depth_ = scope_info_->StackSlotsDepth();
151 if (*scope_info != ScopeInfo::Empty()) { 152 if (*scope_info != ScopeInfo::Empty()) {
152 language_mode_ = scope_info->language_mode(); 153 language_mode_ = scope_info->language_mode();
153 } 154 }
154 } else if (is_with_scope()) { 155 } else if (is_with_scope()) {
155 num_heap_slots_ = Context::MIN_CONTEXT_SLOTS; 156 num_heap_slots_ = Context::MIN_CONTEXT_SLOTS;
156 } 157 }
157 AddInnerScope(inner_scope); 158 AddInnerScope(inner_scope);
158 } 159 }
159 160
160 161
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 ? outer_scope->language_mode_ : CLASSIC_MODE; 201 ? outer_scope->language_mode_ : CLASSIC_MODE;
201 outer_scope_calls_non_strict_eval_ = false; 202 outer_scope_calls_non_strict_eval_ = false;
202 inner_scope_calls_eval_ = false; 203 inner_scope_calls_eval_ = false;
203 force_eager_compilation_ = false; 204 force_eager_compilation_ = false;
204 num_var_or_const_ = 0; 205 num_var_or_const_ = 0;
205 num_stack_slots_ = 0; 206 num_stack_slots_ = 0;
206 num_heap_slots_ = 0; 207 num_heap_slots_ = 0;
207 scope_info_ = scope_info; 208 scope_info_ = scope_info;
208 start_position_ = RelocInfo::kNoPosition; 209 start_position_ = RelocInfo::kNoPosition;
209 end_position_ = RelocInfo::kNoPosition; 210 end_position_ = RelocInfo::kNoPosition;
211 stack_slots_depth_ = 0;
210 if (!scope_info.is_null()) { 212 if (!scope_info.is_null()) {
211 scope_calls_eval_ = scope_info->CallsEval(); 213 scope_calls_eval_ = scope_info->CallsEval();
212 language_mode_ = scope_info->language_mode(); 214 language_mode_ = scope_info->language_mode();
213 } 215 }
214 } 216 }
215 217
216 218
217 Scope* Scope::DeserializeScopeChain(Context* context, Scope* global_scope) { 219 Scope* Scope::DeserializeScopeChain(Context* context, Scope* global_scope) {
218 // Reconstruct the outer scope chain from a closure's context chain. 220 // Reconstruct the outer scope chain from a closure's context chain.
219 Scope* current_scope = NULL; 221 Scope* current_scope = NULL;
(...skipping 780 matching lines...) Expand 10 before | Expand all | Expand 10 after
1000 1002
1001 bool Scope::MustAllocate(Variable* var) { 1003 bool Scope::MustAllocate(Variable* var) {
1002 // Give var a read/write use if there is a chance it might be accessed 1004 // Give var a read/write use if there is a chance it might be accessed
1003 // via an eval() call. This is only possible if the variable has a 1005 // via an eval() call. This is only possible if the variable has a
1004 // visible name. 1006 // visible name.
1005 if ((var->is_this() || var->name()->length() > 0) && 1007 if ((var->is_this() || var->name()->length() > 0) &&
1006 (var->has_forced_context_allocation() || 1008 (var->has_forced_context_allocation() ||
1007 scope_calls_eval_ || 1009 scope_calls_eval_ ||
1008 inner_scope_calls_eval_ || 1010 inner_scope_calls_eval_ ||
1009 scope_contains_with_ || 1011 scope_contains_with_ ||
1010 is_catch_scope() || 1012 is_catch_scope())) {
1011 is_block_scope())) {
1012 var->set_is_used(true); 1013 var->set_is_used(true);
1013 } 1014 }
1014 // Global variables do not need to be allocated. 1015 // Global variables do not need to be allocated.
1015 return !var->is_global() && var->is_used(); 1016 return !var->is_global() && var->is_used();
1016 } 1017 }
1017 1018
1018 1019
1019 bool Scope::MustAllocateInContext(Variable* var) { 1020 bool Scope::MustAllocateInContext(Variable* var) {
1020 // If var is accessed from an inner scope, or if there is a possibility 1021 // If var is accessed from an inner scope, or if there is a possibility
1021 // that it might be accessed from the current or an inner scope (through 1022 // that it might be accessed from the current or an inner scope (through
1022 // an eval() call or a runtime with lookup), it must be allocated in the 1023 // an eval() call or a runtime with lookup), it must be allocated in the
1023 // context. 1024 // context.
1024 // 1025 //
1025 // Exceptions: temporary variables are never allocated in a context; 1026 // Exceptions: temporary variables are never allocated in a context;
1026 // catch-bound variables are always allocated in a context. 1027 // catch-bound variables are always allocated in a context.
1027 if (var->mode() == TEMPORARY) return false; 1028 if (var->mode() == TEMPORARY) return false;
1028 if (is_catch_scope() || is_block_scope()) return true; 1029 if (is_catch_scope()) return true;
1029 return var->has_forced_context_allocation() || 1030 return var->has_forced_context_allocation() ||
1030 scope_calls_eval_ || 1031 scope_calls_eval_ ||
1031 inner_scope_calls_eval_ || 1032 inner_scope_calls_eval_ ||
1032 scope_contains_with_ || 1033 scope_contains_with_ ||
1033 var->is_global(); 1034 var->is_global();
1034 } 1035 }
1035 1036
1036 1037
1037 bool Scope::HasArgumentsParameter() { 1038 bool Scope::HasArgumentsParameter() {
1038 for (int i = 0; i < params_.length(); i++) { 1039 for (int i = 0; i < params_.length(); i++) {
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
1189 } 1190 }
1190 1191
1191 1192
1192 int Scope::ContextLocalCount() const { 1193 int Scope::ContextLocalCount() const {
1193 if (num_heap_slots() == 0) return 0; 1194 if (num_heap_slots() == 0) return 0;
1194 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - 1195 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS -
1195 (function_ != NULL && function_->var()->IsContextSlot() ? 1 : 0); 1196 (function_ != NULL && function_->var()->IsContextSlot() ? 1 : 0);
1196 } 1197 }
1197 1198
1198 } } // namespace v8::internal 1199 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/scopes.h ('k') | src/x64/full-codegen-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698