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

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: Patch for landing 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') | no next file with comments »
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 583 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 594
595 void FullCodeGenerator::DoTest(const TestContext* context) { 595 void FullCodeGenerator::DoTest(const TestContext* context) {
596 DoTest(context->condition(), 596 DoTest(context->condition(),
597 context->true_label(), 597 context->true_label(),
598 context->false_label(), 598 context->false_label(),
599 context->fall_through()); 599 context->fall_through());
600 } 600 }
601 601
602 602
603 void FullCodeGenerator::AllocateModules(ZoneList<Declaration*>* declarations) { 603 void FullCodeGenerator::AllocateModules(ZoneList<Declaration*>* declarations) {
604 DCHECK(scope_->is_global_scope()); 604 DCHECK(scope_->is_script_scope());
605 605
606 for (int i = 0; i < declarations->length(); i++) { 606 for (int i = 0; i < declarations->length(); i++) {
607 ModuleDeclaration* declaration = declarations->at(i)->AsModuleDeclaration(); 607 ModuleDeclaration* declaration = declarations->at(i)->AsModuleDeclaration();
608 if (declaration != NULL) { 608 if (declaration != NULL) {
609 ModuleLiteral* module = declaration->module()->AsModuleLiteral(); 609 ModuleLiteral* module = declaration->module()->AsModuleLiteral();
610 if (module != NULL) { 610 if (module != NULL) {
611 Comment cmnt(masm_, "[ Link nested modules"); 611 Comment cmnt(masm_, "[ Link nested modules");
612 Scope* scope = module->body()->scope(); 612 Scope* scope = module->body()->scope();
613 Interface* interface = scope->interface(); 613 Interface* interface = scope->interface();
614 DCHECK(interface->IsModule() && interface->IsFrozen()); 614 DCHECK(interface->IsModule() && interface->IsFrozen());
(...skipping 20 matching lines...) Expand all
635 } 635 }
636 } 636 }
637 637
638 638
639 // Modules have their own local scope, represented by their own context. 639 // Modules have their own local scope, represented by their own context.
640 // Module instance objects have an accessor for every export that forwards 640 // Module instance objects have an accessor for every export that forwards
641 // access to the respective slot from the module's context. (Exports that are 641 // access to the respective slot from the module's context. (Exports that are
642 // modules themselves, however, are simple data properties.) 642 // modules themselves, however, are simple data properties.)
643 // 643 //
644 // All modules have a _hosting_ scope/context, which (currently) is the 644 // All modules have a _hosting_ scope/context, which (currently) is the
645 // (innermost) enclosing global scope. To deal with recursion, nested modules 645 // enclosing script scope. To deal with recursion, nested modules are hosted
646 // are hosted by the same scope as global ones. 646 // by the same scope as global ones.
647 // 647 //
648 // For every (global or nested) module literal, the hosting context has an 648 // For every (global or nested) module literal, the hosting context has an
649 // internal slot that points directly to the respective module context. This 649 // internal slot that points directly to the respective module context. This
650 // enables quick access to (statically resolved) module members by 2-dimensional 650 // enables quick access to (statically resolved) module members by 2-dimensional
651 // access through the hosting context. For example, 651 // access through the hosting context. For example,
652 // 652 //
653 // module A { 653 // module A {
654 // let x; 654 // let x;
655 // module B { let y; } 655 // module B { let y; }
656 // } 656 // }
657 // module C { let z; } 657 // module C { let z; }
658 // 658 //
659 // allocates contexts as follows: 659 // allocates contexts as follows:
660 // 660 //
661 // [header| .A | .B | .C | A | C ] (global) 661 // [header| .A | .B | .C | A | C ] (global)
662 // | | | 662 // | | |
663 // | | +-- [header| z ] (module) 663 // | | +-- [header| z ] (module)
664 // | | 664 // | |
665 // | +------- [header| y ] (module) 665 // | +------- [header| y ] (module)
666 // | 666 // |
667 // +------------ [header| x | B ] (module) 667 // +------------ [header| x | B ] (module)
668 // 668 //
669 // Here, .A, .B, .C are the internal slots pointing to the hosted module 669 // Here, .A, .B, .C are the internal slots pointing to the hosted module
670 // contexts, whereas A, B, C hold the actual instance objects (note that every 670 // contexts, whereas A, B, C hold the actual instance objects (note that every
671 // module context also points to the respective instance object through its 671 // module context also points to the respective instance object through its
672 // extension slot in the header). 672 // extension slot in the header).
673 // 673 //
674 // To deal with arbitrary recursion and aliases between modules, 674 // To deal with arbitrary recursion and aliases between modules,
675 // they are created and initialized in several stages. Each stage applies to 675 // they are created and initialized in several stages. Each stage applies to
676 // all modules in the hosting global scope, including nested ones. 676 // all modules in the hosting script scope, including nested ones.
677 // 677 //
678 // 1. Allocate: for each module _literal_, allocate the module contexts and 678 // 1. Allocate: for each module _literal_, allocate the module contexts and
679 // respective instance object and wire them up. This happens in the 679 // respective instance object and wire them up. This happens in the
680 // PushModuleContext runtime function, as generated by AllocateModules 680 // PushModuleContext runtime function, as generated by AllocateModules
681 // (invoked by VisitDeclarations in the hosting scope). 681 // (invoked by VisitDeclarations in the hosting scope).
682 // 682 //
683 // 2. Bind: for each module _declaration_ (i.e. literals as well as aliases), 683 // 2. Bind: for each module _declaration_ (i.e. literals as well as aliases),
684 // assign the respective instance object to respective local variables. This 684 // assign the respective instance object to respective local variables. This
685 // happens in VisitModuleDeclaration, and uses the instance objects created 685 // happens in VisitModuleDeclaration, and uses the instance objects created
686 // in the previous stage. 686 // in the previous stage.
(...skipping 14 matching lines...) Expand all
701 Handle<FixedArray> saved_modules = modules_; 701 Handle<FixedArray> saved_modules = modules_;
702 int saved_module_index = module_index_; 702 int saved_module_index = module_index_;
703 ZoneList<Handle<Object> >* saved_globals = globals_; 703 ZoneList<Handle<Object> >* saved_globals = globals_;
704 ZoneList<Handle<Object> > inner_globals(10, zone()); 704 ZoneList<Handle<Object> > inner_globals(10, zone());
705 globals_ = &inner_globals; 705 globals_ = &inner_globals;
706 706
707 if (scope_->num_modules() != 0) { 707 if (scope_->num_modules() != 0) {
708 // This is a scope hosting modules. Allocate a descriptor array to pass 708 // This is a scope hosting modules. Allocate a descriptor array to pass
709 // to the runtime for initialization. 709 // to the runtime for initialization.
710 Comment cmnt(masm_, "[ Allocate modules"); 710 Comment cmnt(masm_, "[ Allocate modules");
711 DCHECK(scope_->is_global_scope()); 711 DCHECK(scope_->is_script_scope());
712 modules_ = 712 modules_ =
713 isolate()->factory()->NewFixedArray(scope_->num_modules(), TENURED); 713 isolate()->factory()->NewFixedArray(scope_->num_modules(), TENURED);
714 module_index_ = 0; 714 module_index_ = 0;
715 715
716 // Generate code for allocating all modules, including nested ones. 716 // Generate code for allocating all modules, including nested ones.
717 // The allocated contexts are stored in internal variables in this scope. 717 // The allocated contexts are stored in internal variables in this scope.
718 AllocateModules(declarations); 718 AllocateModules(declarations);
719 } 719 }
720 720
721 AstVisitor::VisitDeclarations(declarations); 721 AstVisitor::VisitDeclarations(declarations);
(...skipping 1067 matching lines...) Expand 10 before | Expand all | Expand 10 after
1789 } 1789 }
1790 return true; 1790 return true;
1791 } 1791 }
1792 #endif // DEBUG 1792 #endif // DEBUG
1793 1793
1794 1794
1795 #undef __ 1795 #undef __
1796 1796
1797 1797
1798 } } // namespace v8::internal 1798 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/factory.cc ('k') | src/globals.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698