Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 563 void FullCodeGenerator::DoTest(const TestContext* context) { | 563 void FullCodeGenerator::DoTest(const TestContext* context) { |
| 564 DoTest(context->condition(), | 564 DoTest(context->condition(), |
| 565 context->true_label(), | 565 context->true_label(), |
| 566 context->false_label(), | 566 context->false_label(), |
| 567 context->fall_through()); | 567 context->fall_through()); |
| 568 } | 568 } |
| 569 | 569 |
| 570 | 570 |
| 571 void FullCodeGenerator::VisitDeclarations( | 571 void FullCodeGenerator::VisitDeclarations( |
| 572 ZoneList<Declaration*>* declarations) { | 572 ZoneList<Declaration*>* declarations) { |
| 573 ASSERT(globals_.is_empty()); | 573 ZoneList<Handle<Object> >* saved_globals = globals_; |
| 574 ZoneList<Handle<Object> > inner_globals(10); | |
| 575 globals_ = &inner_globals; | |
| 576 | |
| 574 AstVisitor::VisitDeclarations(declarations); | 577 AstVisitor::VisitDeclarations(declarations); |
| 575 if (!globals_.is_empty()) { | 578 if (!globals_->is_empty()) { |
| 576 // Invoke the platform-dependent code generator to do the actual | 579 // Invoke the platform-dependent code generator to do the actual |
| 577 // declaration the global functions and variables. | 580 // declaration the global functions and variables. |
| 578 Handle<FixedArray> array = | 581 Handle<FixedArray> array = |
| 579 isolate()->factory()->NewFixedArray(globals_.length(), TENURED); | 582 isolate()->factory()->NewFixedArray(globals_->length(), TENURED); |
| 580 for (int i = 0; i < globals_.length(); ++i) array->set(i, *globals_.at(i)); | 583 for (int i = 0; i < globals_->length(); ++i) |
| 584 array->set(i, *globals_->at(i)); | |
| 581 DeclareGlobals(array); | 585 DeclareGlobals(array); |
| 582 globals_.Clear(); | |
| 583 } | 586 } |
| 587 | |
| 588 globals_ = saved_globals; | |
| 584 } | 589 } |
| 585 | 590 |
| 586 | 591 |
| 587 void FullCodeGenerator::VisitModuleLiteral(ModuleLiteral* module) { | 592 void FullCodeGenerator::VisitModuleLiteral(ModuleLiteral* module) { |
| 588 // TODO(rossberg) | 593 Handle<JSModule> instance = module->interface()->Instance(); |
| 594 ASSERT(!instance.is_null()); | |
| 595 | |
| 596 // Allocate a module context statically. | |
| 597 Block* block = module->body(); | |
| 598 Scope* saved_scope = scope(); | |
| 599 scope_ = block->scope(); | |
| 600 Handle<ScopeInfo> scope_info = scope_->GetScopeInfo(); | |
| 601 | |
| 602 // Generate code for module creation and linking. | |
| 603 Comment cmnt(masm_, "[ ModuleLiteral"); | |
| 604 SetStatementPosition(block); | |
| 605 | |
| 606 if (scope_info->HasContext()) { | |
| 607 // Set up module context. | |
| 608 __ Push(scope_info); | |
| 609 __ Push(instance); | |
| 610 __ CallRuntime(Runtime::kPushModuleContext, 2); | |
| 611 StoreToFrameField( | |
| 612 StandardFrameConstants::kContextOffset, context_register()); | |
| 613 } | |
| 614 | |
| 615 { | |
| 616 Comment cmnt(masm_, "[ Declarations"); | |
| 617 VisitDeclarations(scope_->declarations()); | |
| 618 } | |
| 619 | |
| 620 scope_ = saved_scope; | |
| 621 if (scope_info->HasContext()) { | |
| 622 // Pop module context. | |
| 623 LoadContextField(context_register(), Context::PREVIOUS_INDEX); | |
| 624 // Update local stack frame context field. | |
| 625 StoreToFrameField( | |
| 626 StandardFrameConstants::kContextOffset, context_register()); | |
| 627 } | |
| 628 | |
| 629 // Populate module instance object. | |
| 630 const PropertyAttributes attr = | |
| 631 static_cast<PropertyAttributes>(READ_ONLY + DONT_DELETE + DONT_ENUM); | |
|
Sven Panne
2012/03/30 11:42:20
Style nit: In the rest of the code we use '|' inst
rossberg
2012/04/10 14:01:15
Done.
| |
| 632 for (Interface::Iterator it = module->interface()->iterator(); | |
| 633 !it.done(); it.Advance()) { | |
| 634 if (it.interface()->IsModule()) { | |
| 635 Handle<Object> value = it.interface()->Instance(); | |
| 636 // TODO(rossberg): temporary hack until URL import is implemented: | |
| 637 if (value.is_null()) | |
| 638 value = Handle<Object>(isolate()->heap()->undefined_value()); | |
| 639 ASSERT(!value.is_null()); | |
|
Sven Panne
2012/03/30 11:42:20
Do we really need this after the test in the previ
rossberg
2012/04/10 14:01:15
Well, the assertion is supposed to stay, while the
| |
| 640 JSReceiver::SetProperty(instance, it.name(), value, attr, kStrictMode); | |
| 641 } else { | |
| 642 // TODO(rossberg): set proper getters instead of undefined... | |
| 643 // instance->DefineAccessor(*it.name(), ACCESSOR_GETTER, *getter, attr); | |
| 644 Handle<Object> value(isolate()->heap()->undefined_value()); | |
| 645 JSReceiver::SetProperty(instance, it.name(), value, attr, kStrictMode); | |
| 646 } | |
| 647 } | |
| 648 USE(instance->PreventExtensions()); | |
| 589 } | 649 } |
| 590 | 650 |
| 591 | 651 |
| 592 void FullCodeGenerator::VisitModuleVariable(ModuleVariable* module) { | 652 void FullCodeGenerator::VisitModuleVariable(ModuleVariable* module) { |
| 593 // TODO(rossberg) | 653 // Noting to do. |
| 654 // The instance object is resolved statically through the module's interface. | |
| 594 } | 655 } |
| 595 | 656 |
| 596 | 657 |
| 597 void FullCodeGenerator::VisitModulePath(ModulePath* module) { | 658 void FullCodeGenerator::VisitModulePath(ModulePath* module) { |
| 598 // TODO(rossberg) | 659 // Noting to do. |
| 660 // The instance object is resolved statically through the module's interface. | |
| 599 } | 661 } |
| 600 | 662 |
| 601 | 663 |
| 602 void FullCodeGenerator::VisitModuleUrl(ModuleUrl* decl) { | 664 void FullCodeGenerator::VisitModuleUrl(ModuleUrl* decl) { |
| 603 // TODO(rossberg) | 665 // TODO(rossberg) |
| 604 } | 666 } |
| 605 | 667 |
| 606 | 668 |
| 607 int FullCodeGenerator::DeclareGlobalsFlags() { | 669 int FullCodeGenerator::DeclareGlobalsFlags() { |
| 608 ASSERT(DeclareGlobalsLanguageMode::is_valid(language_mode())); | 670 ASSERT(DeclareGlobalsLanguageMode::is_valid(language_mode())); |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 850 } | 912 } |
| 851 | 913 |
| 852 | 914 |
| 853 void FullCodeGenerator::VisitBlock(Block* stmt) { | 915 void FullCodeGenerator::VisitBlock(Block* stmt) { |
| 854 Comment cmnt(masm_, "[ Block"); | 916 Comment cmnt(masm_, "[ Block"); |
| 855 NestedBlock nested_block(this, stmt); | 917 NestedBlock nested_block(this, stmt); |
| 856 SetStatementPosition(stmt); | 918 SetStatementPosition(stmt); |
| 857 | 919 |
| 858 Scope* saved_scope = scope(); | 920 Scope* saved_scope = scope(); |
| 859 // Push a block context when entering a block with block scoped variables. | 921 // Push a block context when entering a block with block scoped variables. |
| 860 if (stmt->block_scope() != NULL) { | 922 if (stmt->scope() != NULL) { |
| 861 { Comment cmnt(masm_, "[ Extend block context"); | 923 { Comment cmnt(masm_, "[ Extend block context"); |
| 862 scope_ = stmt->block_scope(); | 924 scope_ = stmt->scope(); |
| 863 Handle<ScopeInfo> scope_info = scope_->GetScopeInfo(); | 925 Handle<ScopeInfo> scope_info = scope_->GetScopeInfo(); |
| 864 int heap_slots = scope_info->ContextLength() - Context::MIN_CONTEXT_SLOTS; | 926 int heap_slots = scope_info->ContextLength() - Context::MIN_CONTEXT_SLOTS; |
| 865 __ Push(scope_info); | 927 __ Push(scope_info); |
| 866 PushFunctionArgumentForContextAllocation(); | 928 PushFunctionArgumentForContextAllocation(); |
| 867 if (heap_slots <= FastNewBlockContextStub::kMaximumSlots) { | 929 if (heap_slots <= FastNewBlockContextStub::kMaximumSlots) { |
| 868 FastNewBlockContextStub stub(heap_slots); | 930 FastNewBlockContextStub stub(heap_slots); |
| 869 __ CallStub(&stub); | 931 __ CallStub(&stub); |
| 870 } else { | 932 } else { |
| 871 __ CallRuntime(Runtime::kPushBlockContext, 2); | 933 __ CallRuntime(Runtime::kPushBlockContext, 2); |
| 872 } | 934 } |
| 873 | 935 |
| 874 // Replace the context stored in the frame. | 936 // Replace the context stored in the frame. |
| 875 StoreToFrameField(StandardFrameConstants::kContextOffset, | 937 StoreToFrameField(StandardFrameConstants::kContextOffset, |
| 876 context_register()); | 938 context_register()); |
| 877 } | 939 } |
| 878 { Comment cmnt(masm_, "[ Declarations"); | 940 { Comment cmnt(masm_, "[ Declarations"); |
| 879 VisitDeclarations(scope_->declarations()); | 941 VisitDeclarations(scope_->declarations()); |
| 880 } | 942 } |
| 881 } | 943 } |
| 882 PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS); | 944 PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS); |
| 883 VisitStatements(stmt->statements()); | 945 VisitStatements(stmt->statements()); |
| 884 scope_ = saved_scope; | 946 scope_ = saved_scope; |
| 885 __ bind(nested_block.break_label()); | 947 __ bind(nested_block.break_label()); |
| 886 PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS); | 948 PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS); |
| 887 | 949 |
| 888 // Pop block context if necessary. | 950 // Pop block context if necessary. |
| 889 if (stmt->block_scope() != NULL) { | 951 if (stmt->scope() != NULL) { |
| 890 LoadContextField(context_register(), Context::PREVIOUS_INDEX); | 952 LoadContextField(context_register(), Context::PREVIOUS_INDEX); |
| 891 // Update local stack frame context field. | 953 // Update local stack frame context field. |
| 892 StoreToFrameField(StandardFrameConstants::kContextOffset, | 954 StoreToFrameField(StandardFrameConstants::kContextOffset, |
| 893 context_register()); | 955 context_register()); |
| 894 } | 956 } |
| 895 } | 957 } |
| 896 | 958 |
| 897 | 959 |
| 898 void FullCodeGenerator::VisitExpressionStatement(ExpressionStatement* stmt) { | 960 void FullCodeGenerator::VisitExpressionStatement(ExpressionStatement* stmt) { |
| 899 Comment cmnt(masm_, "[ ExpressionStatement"); | 961 Comment cmnt(masm_, "[ ExpressionStatement"); |
| (...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1365 } | 1427 } |
| 1366 | 1428 |
| 1367 return false; | 1429 return false; |
| 1368 } | 1430 } |
| 1369 | 1431 |
| 1370 | 1432 |
| 1371 #undef __ | 1433 #undef __ |
| 1372 | 1434 |
| 1373 | 1435 |
| 1374 } } // namespace v8::internal | 1436 } } // namespace v8::internal |
| OLD | NEW |