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

Side by Side Diff: src/full-codegen.cc

Issue 716833002: Various clean-ups after top-level lexical declarations are done. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 1 month 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/factory.cc ('k') | src/globals.h » ('j') | src/globals.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/ast.h" 7 #include "src/ast.h"
8 #include "src/ast-numbering.h" 8 #include "src/ast-numbering.h"
9 #include "src/code-factory.h" 9 #include "src/code-factory.h"
10 #include "src/codegen.h" 10 #include "src/codegen.h"
(...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 596
597 void FullCodeGenerator::DoTest(const TestContext* context) { 597 void FullCodeGenerator::DoTest(const TestContext* context) {
598 DoTest(context->condition(), 598 DoTest(context->condition(),
599 context->true_label(), 599 context->true_label(),
600 context->false_label(), 600 context->false_label(),
601 context->fall_through()); 601 context->fall_through());
602 } 602 }
603 603
604 604
605 void FullCodeGenerator::AllocateModules(ZoneList<Declaration*>* declarations) { 605 void FullCodeGenerator::AllocateModules(ZoneList<Declaration*>* declarations) {
606 DCHECK(scope_->is_global_scope()); 606 DCHECK(scope_->is_script_scope());
607 607
608 for (int i = 0; i < declarations->length(); i++) { 608 for (int i = 0; i < declarations->length(); i++) {
609 ModuleDeclaration* declaration = declarations->at(i)->AsModuleDeclaration(); 609 ModuleDeclaration* declaration = declarations->at(i)->AsModuleDeclaration();
610 if (declaration != NULL) { 610 if (declaration != NULL) {
611 ModuleLiteral* module = declaration->module()->AsModuleLiteral(); 611 ModuleLiteral* module = declaration->module()->AsModuleLiteral();
612 if (module != NULL) { 612 if (module != NULL) {
613 Comment cmnt(masm_, "[ Link nested modules"); 613 Comment cmnt(masm_, "[ Link nested modules");
614 Scope* scope = module->body()->scope(); 614 Scope* scope = module->body()->scope();
615 Interface* interface = scope->interface(); 615 Interface* interface = scope->interface();
616 DCHECK(interface->IsModule() && interface->IsFrozen()); 616 DCHECK(interface->IsModule() && interface->IsFrozen());
(...skipping 20 matching lines...) Expand all
637 } 637 }
638 } 638 }
639 639
640 640
641 // Modules have their own local scope, represented by their own context. 641 // Modules have their own local scope, represented by their own context.
642 // Module instance objects have an accessor for every export that forwards 642 // Module instance objects have an accessor for every export that forwards
643 // access to the respective slot from the module's context. (Exports that are 643 // access to the respective slot from the module's context. (Exports that are
644 // modules themselves, however, are simple data properties.) 644 // modules themselves, however, are simple data properties.)
645 // 645 //
646 // All modules have a _hosting_ scope/context, which (currently) is the 646 // All modules have a _hosting_ scope/context, which (currently) is the
647 // (innermost) enclosing global scope. To deal with recursion, nested modules 647 // (innermost) enclosing script scope. To deal with recursion, nested modules
rossberg 2014/11/12 09:49:27 Nit: can remove the "(innermost)"
Dmitry Lomov (no reviews) 2014/11/12 10:16:26 Done.
648 // are hosted by the same scope as global ones. 648 // are hosted by the same scope as global ones.
649 // 649 //
650 // For every (global or nested) module literal, the hosting context has an 650 // For every (global or nested) module literal, the hosting context has an
651 // internal slot that points directly to the respective module context. This 651 // internal slot that points directly to the respective module context. This
652 // enables quick access to (statically resolved) module members by 2-dimensional 652 // enables quick access to (statically resolved) module members by 2-dimensional
653 // access through the hosting context. For example, 653 // access through the hosting context. For example,
654 // 654 //
655 // module A { 655 // module A {
656 // let x; 656 // let x;
657 // module B { let y; } 657 // module B { let y; }
(...skipping 10 matching lines...) Expand all
668 // | 668 // |
669 // +------------ [header| x | B ] (module) 669 // +------------ [header| x | B ] (module)
670 // 670 //
671 // Here, .A, .B, .C are the internal slots pointing to the hosted module 671 // Here, .A, .B, .C are the internal slots pointing to the hosted module
672 // contexts, whereas A, B, C hold the actual instance objects (note that every 672 // contexts, whereas A, B, C hold the actual instance objects (note that every
673 // module context also points to the respective instance object through its 673 // module context also points to the respective instance object through its
674 // extension slot in the header). 674 // extension slot in the header).
675 // 675 //
676 // To deal with arbitrary recursion and aliases between modules, 676 // To deal with arbitrary recursion and aliases between modules,
677 // they are created and initialized in several stages. Each stage applies to 677 // they are created and initialized in several stages. Each stage applies to
678 // all modules in the hosting global scope, including nested ones. 678 // all modules in the hosting script scope, including nested ones.
679 // 679 //
680 // 1. Allocate: for each module _literal_, allocate the module contexts and 680 // 1. Allocate: for each module _literal_, allocate the module contexts and
681 // respective instance object and wire them up. This happens in the 681 // respective instance object and wire them up. This happens in the
682 // PushModuleContext runtime function, as generated by AllocateModules 682 // PushModuleContext runtime function, as generated by AllocateModules
683 // (invoked by VisitDeclarations in the hosting scope). 683 // (invoked by VisitDeclarations in the hosting scope).
684 // 684 //
685 // 2. Bind: for each module _declaration_ (i.e. literals as well as aliases), 685 // 2. Bind: for each module _declaration_ (i.e. literals as well as aliases),
686 // assign the respective instance object to respective local variables. This 686 // assign the respective instance object to respective local variables. This
687 // happens in VisitModuleDeclaration, and uses the instance objects created 687 // happens in VisitModuleDeclaration, and uses the instance objects created
688 // in the previous stage. 688 // in the previous stage.
(...skipping 14 matching lines...) Expand all
703 Handle<FixedArray> saved_modules = modules_; 703 Handle<FixedArray> saved_modules = modules_;
704 int saved_module_index = module_index_; 704 int saved_module_index = module_index_;
705 ZoneList<Handle<Object> >* saved_globals = globals_; 705 ZoneList<Handle<Object> >* saved_globals = globals_;
706 ZoneList<Handle<Object> > inner_globals(10, zone()); 706 ZoneList<Handle<Object> > inner_globals(10, zone());
707 globals_ = &inner_globals; 707 globals_ = &inner_globals;
708 708
709 if (scope_->num_modules() != 0) { 709 if (scope_->num_modules() != 0) {
710 // This is a scope hosting modules. Allocate a descriptor array to pass 710 // This is a scope hosting modules. Allocate a descriptor array to pass
711 // to the runtime for initialization. 711 // to the runtime for initialization.
712 Comment cmnt(masm_, "[ Allocate modules"); 712 Comment cmnt(masm_, "[ Allocate modules");
713 DCHECK(scope_->is_global_scope()); 713 DCHECK(scope_->is_script_scope());
714 modules_ = 714 modules_ =
715 isolate()->factory()->NewFixedArray(scope_->num_modules(), TENURED); 715 isolate()->factory()->NewFixedArray(scope_->num_modules(), TENURED);
716 module_index_ = 0; 716 module_index_ = 0;
717 717
718 // Generate code for allocating all modules, including nested ones. 718 // Generate code for allocating all modules, including nested ones.
719 // The allocated contexts are stored in internal variables in this scope. 719 // The allocated contexts are stored in internal variables in this scope.
720 AllocateModules(declarations); 720 AllocateModules(declarations);
721 } 721 }
722 722
723 AstVisitor::VisitDeclarations(declarations); 723 AstVisitor::VisitDeclarations(declarations);
(...skipping 1023 matching lines...) Expand 10 before | Expand all | Expand 10 after
1747 } 1747 }
1748 return true; 1748 return true;
1749 } 1749 }
1750 #endif // DEBUG 1750 #endif // DEBUG
1751 1751
1752 1752
1753 #undef __ 1753 #undef __
1754 1754
1755 1755
1756 } } // namespace v8::internal 1756 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/factory.cc ('k') | src/globals.h » ('j') | src/globals.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698