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

Side by Side Diff: src/scopeinfo.cc

Issue 1258213002: [stubs] Use a single slot for context globals. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 4 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
« no previous file with comments | « src/hydrogen.cc ('k') | src/scopes.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 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stdlib.h> 5 #include <stdlib.h>
6 6
7 #include "src/v8.h" 7 #include "src/v8.h"
8 8
9 #include "src/bootstrapper.h" 9 #include "src/bootstrapper.h"
10 #include "src/scopeinfo.h" 10 #include "src/scopeinfo.h"
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 bool function_name_context_slot = 333 bool function_name_context_slot =
334 FunctionVariableField::decode(Flags()) == CONTEXT; 334 FunctionVariableField::decode(Flags()) == CONTEXT;
335 bool has_context = context_locals > 0 || context_globals > 0 || 335 bool has_context = context_locals > 0 || context_globals > 0 ||
336 function_name_context_slot || 336 function_name_context_slot ||
337 scope_type() == WITH_SCOPE || 337 scope_type() == WITH_SCOPE ||
338 (scope_type() == ARROW_SCOPE && CallsSloppyEval()) || 338 (scope_type() == ARROW_SCOPE && CallsSloppyEval()) ||
339 (scope_type() == FUNCTION_SCOPE && CallsSloppyEval()) || 339 (scope_type() == FUNCTION_SCOPE && CallsSloppyEval()) ||
340 scope_type() == MODULE_SCOPE; 340 scope_type() == MODULE_SCOPE;
341 341
342 if (has_context) { 342 if (has_context) {
343 return Context::MIN_CONTEXT_SLOTS + context_locals + 2 * context_globals + 343 return Context::MIN_CONTEXT_SLOTS + context_locals + context_globals +
344 (function_name_context_slot ? 1 : 0); 344 (function_name_context_slot ? 1 : 0);
345 } 345 }
346 } 346 }
347 return 0; 347 return 0;
348 } 348 }
349 349
350 350
351 bool ScopeInfo::HasReceiver() { 351 bool ScopeInfo::HasReceiver() {
352 if (length() > 0) { 352 if (length() > 0) {
353 return NONE != ReceiverVariableField::decode(Flags()); 353 return NONE != ReceiverVariableField::decode(Flags());
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 *init_flag = scope_info->ContextLocalInitFlag(var); 546 *init_flag = scope_info->ContextLocalInitFlag(var);
547 *maybe_assigned_flag = scope_info->ContextLocalMaybeAssignedFlag(var); 547 *maybe_assigned_flag = scope_info->ContextLocalMaybeAssignedFlag(var);
548 548
549 if (var < scope_info->ContextLocalCount()) { 549 if (var < scope_info->ContextLocalCount()) {
550 *location = VariableLocation::CONTEXT; 550 *location = VariableLocation::CONTEXT;
551 result = Context::MIN_CONTEXT_SLOTS + var; 551 result = Context::MIN_CONTEXT_SLOTS + var;
552 } else { 552 } else {
553 var -= scope_info->ContextLocalCount(); 553 var -= scope_info->ContextLocalCount();
554 *location = VariableLocation::GLOBAL; 554 *location = VariableLocation::GLOBAL;
555 result = Context::MIN_CONTEXT_SLOTS + 555 result = Context::MIN_CONTEXT_SLOTS +
556 scope_info->ContextLocalCount() + 2 * var; 556 scope_info->ContextLocalCount() + var;
557 } 557 }
558 558
559 context_slot_cache->Update(scope_info, name, *mode, *location, 559 context_slot_cache->Update(scope_info, name, *mode, *location,
560 *init_flag, *maybe_assigned_flag, result); 560 *init_flag, *maybe_assigned_flag, result);
561 DCHECK(result < scope_info->ContextLength()); 561 DCHECK(result < scope_info->ContextLength());
562 return result; 562 return result;
563 } 563 }
564 } 564 }
565 // Cache as not found. Mode, location, init flag and maybe assigned flag 565 // Cache as not found. Mode, location, init flag and maybe assigned flag
566 // don't matter. 566 // don't matter.
567 context_slot_cache->Update(scope_info, name, TEMPORARY, 567 context_slot_cache->Update(scope_info, name, TEMPORARY,
568 VariableLocation::CONTEXT, kNeedsInitialization, 568 VariableLocation::CONTEXT, kNeedsInitialization,
569 kNotAssigned, -1); 569 kNotAssigned, -1);
570 } 570 }
571 return -1; 571 return -1;
572 } 572 }
573 573
574 574
575 String* ScopeInfo::ContextSlotName(int slot_index) { 575 String* ScopeInfo::ContextSlotName(int slot_index) {
576 // TODO(bmeurer): Simplify this once we have only a single slot for both reads 576 int const var = slot_index - Context::MIN_CONTEXT_SLOTS;
577 // and writes to context globals; currently we have 2 slots per context
578 // global, and these are located after the common context slots (of which we
579 // always have Context::MIN_CONTEXT_SLOTS) and the context locals.
580 int const var =
581 slot_index - (Context::MIN_CONTEXT_SLOTS + ContextLocalCount());
582 DCHECK_LE(0, var); 577 DCHECK_LE(0, var);
583 DCHECK_LT(var, 2 * ContextGlobalCount()); 578 DCHECK_LT(var, ContextLocalCount() + ContextGlobalCount());
584 return ContextLocalName(ContextLocalCount() + var / 2); 579 return ContextLocalName(var);
585 } 580 }
586 581
587 582
588 int ScopeInfo::ParameterIndex(String* name) { 583 int ScopeInfo::ParameterIndex(String* name) {
589 DCHECK(name->IsInternalizedString()); 584 DCHECK(name->IsInternalizedString());
590 if (length() > 0) { 585 if (length() > 0) {
591 // We must read parameters from the end since for 586 // We must read parameters from the end since for
592 // multiply declared parameters the value of the 587 // multiply declared parameters the value of the
593 // last declaration of that parameter is used 588 // last declaration of that parameter is used
594 // inside a function (and thus we need to look 589 // inside a function (and thus we need to look
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
859 info->set_mode(i, var->mode()); 854 info->set_mode(i, var->mode());
860 DCHECK(var->index() >= 0); 855 DCHECK(var->index() >= 0);
861 info->set_index(i, var->index()); 856 info->set_index(i, var->index());
862 } 857 }
863 DCHECK(i == info->length()); 858 DCHECK(i == info->length());
864 return info; 859 return info;
865 } 860 }
866 861
867 } // namespace internal 862 } // namespace internal
868 } // namespace v8 863 } // namespace v8
OLDNEW
« no previous file with comments | « src/hydrogen.cc ('k') | src/scopes.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698