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

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

Issue 10690043: Implement proper module linking. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed Michael's comments. Created 8 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « src/factory.cc ('k') | src/heap.h » ('j') | src/scopes.cc » ('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 // 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 571 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 for (int i = 0; i < globals_->length(); ++i) 582 for (int i = 0; i < globals_->length(); ++i)
583 array->set(i, *globals_->at(i)); 583 array->set(i, *globals_->at(i));
584 DeclareGlobals(array); 584 DeclareGlobals(array);
585 } 585 }
586 586
587 globals_ = saved_globals; 587 globals_ = saved_globals;
588 } 588 }
589 589
590 590
591 void FullCodeGenerator::VisitModuleLiteral(ModuleLiteral* module) { 591 void FullCodeGenerator::VisitModuleLiteral(ModuleLiteral* module) {
592 Handle<JSModule> instance = module->interface()->Instance();
593 ASSERT(!instance.is_null());
594
595 // Allocate a module context statically. 592 // Allocate a module context statically.
596 Block* block = module->body(); 593 Block* block = module->body();
597 Scope* saved_scope = scope(); 594 Scope* saved_scope = scope();
598 scope_ = block->scope(); 595 scope_ = block->scope();
599 Handle<ScopeInfo> scope_info = scope_->GetScopeInfo(); 596 Handle<ScopeInfo> scope_info = scope_->GetScopeInfo();
Jakob Kummerow 2012/07/09 11:03:12 unused variable.
597 Interface* interface = module->interface();
598 Handle<JSModule> instance = interface->Instance();
600 599
601 // Generate code for module creation and linking.
602 Comment cmnt(masm_, "[ ModuleLiteral"); 600 Comment cmnt(masm_, "[ ModuleLiteral");
603 SetStatementPosition(block); 601 SetStatementPosition(block);
604 602
605 if (scope_info->HasContext()) { 603 // Set up module context.
606 // Set up module context. 604 __ Push(instance);
607 __ Push(scope_info); 605 __ CallRuntime(Runtime::kPushModuleContext, 1);
608 __ Push(instance); 606 StoreToFrameField(StandardFrameConstants::kContextOffset, context_register());
609 __ CallRuntime(Runtime::kPushModuleContext, 2);
610 StoreToFrameField(
611 StandardFrameConstants::kContextOffset, context_register());
612 }
613 607
614 { 608 {
615 Comment cmnt(masm_, "[ Declarations"); 609 Comment cmnt(masm_, "[ Declarations");
616 VisitDeclarations(scope_->declarations()); 610 VisitDeclarations(scope_->declarations());
617 } 611 }
618 612
619 scope_ = saved_scope; 613 scope_ = saved_scope;
620 if (scope_info->HasContext()) { 614 // Pop module context.
621 // Pop module context. 615 LoadContextField(context_register(), Context::PREVIOUS_INDEX);
622 LoadContextField(context_register(), Context::PREVIOUS_INDEX); 616 // Update local stack frame context field.
623 // Update local stack frame context field. 617 StoreToFrameField(StandardFrameConstants::kContextOffset, context_register());
624 StoreToFrameField(
625 StandardFrameConstants::kContextOffset, context_register());
626 }
627
628 // Populate module instance object.
629 const PropertyAttributes attr =
630 static_cast<PropertyAttributes>(READ_ONLY | DONT_DELETE | DONT_ENUM);
631 for (Interface::Iterator it = module->interface()->iterator();
632 !it.done(); it.Advance()) {
633 if (it.interface()->IsModule()) {
634 Handle<Object> value = it.interface()->Instance();
635 ASSERT(!value.is_null());
636 JSReceiver::SetProperty(instance, it.name(), value, attr, kStrictMode);
637 } else {
638 // TODO(rossberg): set proper getters instead of undefined...
639 // instance->DefineAccessor(*it.name(), ACCESSOR_GETTER, *getter, attr);
640 Handle<Object> value(isolate()->heap()->undefined_value());
641 JSReceiver::SetProperty(instance, it.name(), value, attr, kStrictMode);
642 }
643 }
644 USE(instance->PreventExtensions());
645 } 618 }
646 619
647 620
648 void FullCodeGenerator::VisitModuleVariable(ModuleVariable* module) { 621 void FullCodeGenerator::VisitModuleVariable(ModuleVariable* module) {
649 // Noting to do. 622 // Nothing to do.
650 // The instance object is resolved statically through the module's interface. 623 // The instance object is resolved statically through the module's interface.
651 } 624 }
652 625
653 626
654 void FullCodeGenerator::VisitModulePath(ModulePath* module) { 627 void FullCodeGenerator::VisitModulePath(ModulePath* module) {
655 // Noting to do. 628 // Nothing to do.
656 // The instance object is resolved statically through the module's interface. 629 // The instance object is resolved statically through the module's interface.
657 } 630 }
658 631
659 632
660 void FullCodeGenerator::VisitModuleUrl(ModuleUrl* decl) { 633 void FullCodeGenerator::VisitModuleUrl(ModuleUrl* decl) {
661 // TODO(rossberg) 634 // TODO(rossberg)
662 } 635 }
663 636
664 637
665 int FullCodeGenerator::DeclareGlobalsFlags() { 638 int FullCodeGenerator::DeclareGlobalsFlags() {
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
909 882
910 883
911 void FullCodeGenerator::VisitBlock(Block* stmt) { 884 void FullCodeGenerator::VisitBlock(Block* stmt) {
912 Comment cmnt(masm_, "[ Block"); 885 Comment cmnt(masm_, "[ Block");
913 NestedBlock nested_block(this, stmt); 886 NestedBlock nested_block(this, stmt);
914 SetStatementPosition(stmt); 887 SetStatementPosition(stmt);
915 888
916 Scope* saved_scope = scope(); 889 Scope* saved_scope = scope();
917 // Push a block context when entering a block with block scoped variables. 890 // Push a block context when entering a block with block scoped variables.
918 if (stmt->scope() != NULL) { 891 if (stmt->scope() != NULL) {
919 { Comment cmnt(masm_, "[ Extend block context"); 892 scope_ = stmt->scope();
920 scope_ = stmt->scope(); 893 if (scope_->is_module_scope()) {
921 Handle<ScopeInfo> scope_info = scope_->GetScopeInfo(); 894 // If this block is a module body, then we have already allocated and
922 int heap_slots = scope_info->ContextLength() - Context::MIN_CONTEXT_SLOTS; 895 // initialized the declarations earlier. Just push the context.
923 __ Push(scope_info); 896 ASSERT(!scope_->interface()->Instance().is_null());
924 PushFunctionArgumentForContextAllocation(); 897 __ Push(scope_->interface()->Instance());
925 if (heap_slots <= FastNewBlockContextStub::kMaximumSlots) { 898 __ CallRuntime(Runtime::kPushModuleContext, 1);
926 FastNewBlockContextStub stub(heap_slots); 899 StoreToFrameField(
927 __ CallStub(&stub); 900 StandardFrameConstants::kContextOffset, context_register());
928 } else { 901 } else {
929 __ CallRuntime(Runtime::kPushBlockContext, 2); 902 { Comment cmnt(masm_, "[ Extend block context");
903 Handle<ScopeInfo> scope_info = scope_->GetScopeInfo();
904 int heap_slots =
905 scope_info->ContextLength() - Context::MIN_CONTEXT_SLOTS;
906 __ Push(scope_info);
907 PushFunctionArgumentForContextAllocation();
908 if (heap_slots <= FastNewBlockContextStub::kMaximumSlots) {
909 FastNewBlockContextStub stub(heap_slots);
910 __ CallStub(&stub);
911 } else {
912 __ CallRuntime(Runtime::kPushBlockContext, 2);
913 }
914
915 // Replace the context stored in the frame.
916 StoreToFrameField(StandardFrameConstants::kContextOffset,
917 context_register());
930 } 918 }
931 919 { Comment cmnt(masm_, "[ Declarations");
932 // Replace the context stored in the frame. 920 VisitDeclarations(scope_->declarations());
933 StoreToFrameField(StandardFrameConstants::kContextOffset, 921 }
934 context_register());
935 }
936 { Comment cmnt(masm_, "[ Declarations");
937 VisitDeclarations(scope_->declarations());
938 } 922 }
939 } 923 }
940 PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS); 924 PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS);
941 VisitStatements(stmt->statements()); 925 VisitStatements(stmt->statements());
942 scope_ = saved_scope; 926 scope_ = saved_scope;
943 __ bind(nested_block.break_label()); 927 __ bind(nested_block.break_label());
944 PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS); 928 PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS);
945 929
946 // Pop block context if necessary. 930 // Pop block context if necessary.
947 if (stmt->scope() != NULL) { 931 if (stmt->scope() != NULL) {
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after
1423 } 1407 }
1424 1408
1425 return false; 1409 return false;
1426 } 1410 }
1427 1411
1428 1412
1429 #undef __ 1413 #undef __
1430 1414
1431 1415
1432 } } // namespace v8::internal 1416 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/factory.cc ('k') | src/heap.h » ('j') | src/scopes.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698