OLD | NEW |
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/ast/context-slot-cache.h" |
7 #include "src/ast/scopes.h" | 8 #include "src/ast/scopes.h" |
8 #include "src/bootstrapper.h" | 9 #include "src/bootstrapper.h" |
9 | 10 |
10 namespace v8 { | 11 namespace v8 { |
11 namespace internal { | 12 namespace internal { |
12 | 13 |
13 | 14 |
14 Handle<ScopeInfo> ScopeInfo::Create(Isolate* isolate, Zone* zone, | 15 Handle<ScopeInfo> ScopeInfo::Create(Isolate* isolate, Zone* zone, |
15 Scope* scope) { | 16 Scope* scope) { |
16 // Collect variables. | 17 // Collect variables. |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 int ScopeInfo::ContextSlotIndex(Handle<ScopeInfo> scope_info, | 472 int ScopeInfo::ContextSlotIndex(Handle<ScopeInfo> scope_info, |
472 Handle<String> name, VariableMode* mode, | 473 Handle<String> name, VariableMode* mode, |
473 InitializationFlag* init_flag, | 474 InitializationFlag* init_flag, |
474 MaybeAssignedFlag* maybe_assigned_flag) { | 475 MaybeAssignedFlag* maybe_assigned_flag) { |
475 DCHECK(name->IsInternalizedString()); | 476 DCHECK(name->IsInternalizedString()); |
476 DCHECK_NOT_NULL(mode); | 477 DCHECK_NOT_NULL(mode); |
477 DCHECK_NOT_NULL(init_flag); | 478 DCHECK_NOT_NULL(init_flag); |
478 DCHECK_NOT_NULL(maybe_assigned_flag); | 479 DCHECK_NOT_NULL(maybe_assigned_flag); |
479 | 480 |
480 if (scope_info->length() > 0) { | 481 if (scope_info->length() > 0) { |
| 482 ContextSlotCache* context_slot_cache = |
| 483 scope_info->GetIsolate()->context_slot_cache(); |
| 484 int result = context_slot_cache->Lookup(*scope_info, *name, mode, init_flag, |
| 485 maybe_assigned_flag); |
| 486 if (result != ContextSlotCache::kNotFound) { |
| 487 DCHECK(result < scope_info->ContextLength()); |
| 488 return result; |
| 489 } |
| 490 |
481 int start = scope_info->ContextLocalNameEntriesIndex(); | 491 int start = scope_info->ContextLocalNameEntriesIndex(); |
482 int end = start + scope_info->ContextLocalCount(); | 492 int end = start + scope_info->ContextLocalCount(); |
483 for (int i = start; i < end; ++i) { | 493 for (int i = start; i < end; ++i) { |
484 if (*name == scope_info->get(i)) { | 494 if (*name == scope_info->get(i)) { |
485 int var = i - start; | 495 int var = i - start; |
486 *mode = scope_info->ContextLocalMode(var); | 496 *mode = scope_info->ContextLocalMode(var); |
487 *init_flag = scope_info->ContextLocalInitFlag(var); | 497 *init_flag = scope_info->ContextLocalInitFlag(var); |
488 *maybe_assigned_flag = scope_info->ContextLocalMaybeAssignedFlag(var); | 498 *maybe_assigned_flag = scope_info->ContextLocalMaybeAssignedFlag(var); |
489 int result = Context::MIN_CONTEXT_SLOTS + var; | 499 result = Context::MIN_CONTEXT_SLOTS + var; |
| 500 |
| 501 context_slot_cache->Update(scope_info, name, *mode, *init_flag, |
| 502 *maybe_assigned_flag, result); |
490 DCHECK(result < scope_info->ContextLength()); | 503 DCHECK(result < scope_info->ContextLength()); |
491 return result; | 504 return result; |
492 } | 505 } |
493 } | 506 } |
| 507 // Cache as not found. Mode, init flag and maybe assigned flag don't matter. |
| 508 context_slot_cache->Update(scope_info, name, TEMPORARY, |
| 509 kNeedsInitialization, kNotAssigned, -1); |
494 } | 510 } |
495 | 511 |
496 return -1; | 512 return -1; |
497 } | 513 } |
498 | 514 |
499 int ScopeInfo::ContextGlobalSlotIndex(Handle<ScopeInfo> scope_info, | 515 int ScopeInfo::ContextGlobalSlotIndex(Handle<ScopeInfo> scope_info, |
500 Handle<String> name, VariableMode* mode, | 516 Handle<String> name, VariableMode* mode, |
501 InitializationFlag* init_flag, | 517 InitializationFlag* init_flag, |
502 MaybeAssignedFlag* maybe_assigned_flag) { | 518 MaybeAssignedFlag* maybe_assigned_flag) { |
503 DCHECK(name->IsInternalizedString()); | 519 DCHECK(name->IsInternalizedString()); |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
667 ContextLocalNameEntriesIndex() + ContextLocalCount(), this); | 683 ContextLocalNameEntriesIndex() + ContextLocalCount(), this); |
668 } | 684 } |
669 | 685 |
670 PrintF("}\n"); | 686 PrintF("}\n"); |
671 } | 687 } |
672 #endif // DEBUG | 688 #endif // DEBUG |
673 | 689 |
674 | 690 |
675 } // namespace internal | 691 } // namespace internal |
676 } // namespace v8 | 692 } // namespace v8 |
OLD | NEW |