OLD | NEW |
---|---|
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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/ast/ast.h" | 5 #include "src/ast/ast.h" |
6 #include "src/messages.h" | 6 #include "src/messages.h" |
7 #include "src/parsing/parameter-initializer-rewriter.h" | 7 #include "src/parsing/parameter-initializer-rewriter.h" |
8 #include "src/parsing/parser.h" | 8 #include "src/parsing/parser.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
540 } | 540 } |
541 } | 541 } |
542 set_context(context); | 542 set_context(context); |
543 } | 543 } |
544 | 544 |
545 if (spread != nullptr) { | 545 if (spread != nullptr) { |
546 // A spread can only occur as the last component. It is not handled by | 546 // A spread can only occur as the last component. It is not handled by |
547 // RecurseIntoSubpattern above. | 547 // RecurseIntoSubpattern above. |
548 | 548 |
549 // let array = []; | 549 // let array = []; |
550 // if (!done) %concat_iterable_to_array(array, iterator); | 550 // while (!done) { |
551 // result = IteratorNext(iterator); | |
552 // if (result.done) { | |
553 // done = true; | |
554 // } else { | |
555 // %AppendElement(array, result.value); | |
556 // } | |
557 // } | |
558 | |
559 // let array = []; | |
560 Variable* array; | |
561 { | |
562 auto empty_exprs = new (zone()) ZoneList<Expression*>(0, zone()); | |
563 array = CreateTempVar(factory()->NewArrayLiteral( | |
564 empty_exprs, | |
565 // Reuse pattern's literal index - it is unused since there is no | |
566 // actual literal allocated. | |
567 node->literal_index(), RelocInfo::kNoPosition)); | |
568 } | |
569 | |
570 // result = IteratorNext(iterator); | |
571 Statement* get_next = factory()->NewExpressionStatement( | |
572 parser_->BuildIteratorNextResult(factory()->NewVariableProxy(iterator), | |
573 result, nopos), | |
574 nopos); | |
575 | |
551 // done = true; | 576 // done = true; |
577 Statement* set_done = factory()->NewExpressionStatement( | |
578 factory()->NewAssignment( | |
579 Token::ASSIGN, factory()->NewVariableProxy(done), | |
580 factory()->NewBooleanLiteral(true, nopos), nopos), | |
581 nopos); | |
552 | 582 |
553 auto empty_exprs = new (zone()) ZoneList<Expression*>(0, zone()); | 583 // result.value |
554 auto array = CreateTempVar(factory()->NewArrayLiteral( | 584 Expression* result_value = factory()->NewProperty( |
adamk
2016/04/04 19:32:46
Can you move this inside the AppendElement block b
| |
555 empty_exprs, | 585 factory()->NewVariableProxy(result), |
556 // Reuse pattern's literal index - it is unused since there is no | 586 factory()->NewStringLiteral(ast_value_factory()->value_string(), nopos), |
557 // actual literal allocated. | 587 nopos); |
558 node->literal_index(), RelocInfo::kNoPosition)); | |
559 | 588 |
560 auto arguments = new (zone()) ZoneList<Expression*>(2, zone()); | 589 // %AppendElement(array, #result_value); |
adamk
2016/04/04 19:32:46
When you do the above you can just make this "resu
| |
561 arguments->Add(factory()->NewVariableProxy(array), zone()); | 590 Statement* append_element; |
562 arguments->Add(factory()->NewVariableProxy(iterator), zone()); | 591 { |
563 auto spread_into_array_call = | 592 auto args = new (zone()) ZoneList<Expression*>(2, zone()); |
564 factory()->NewCallRuntime(Context::CONCAT_ITERABLE_TO_ARRAY_INDEX, | 593 args->Add(factory()->NewVariableProxy(array), zone()); |
565 arguments, RelocInfo::kNoPosition); | 594 args->Add(result_value, zone()); |
595 append_element = factory()->NewExpressionStatement( | |
596 factory()->NewCallRuntime(Runtime::kAppendElement, args, nopos), | |
597 nopos); | |
598 } | |
566 | 599 |
567 auto if_statement = factory()->NewIfStatement( | 600 // if (result.done) { #set_done } else { #append_element } |
568 factory()->NewUnaryOperation(Token::NOT, | 601 Statement* set_done_or_append; |
569 factory()->NewVariableProxy(done), | 602 { |
570 RelocInfo::kNoPosition), | 603 Expression* result_done = |
571 factory()->NewExpressionStatement(spread_into_array_call, | 604 factory()->NewProperty(factory()->NewVariableProxy(result), |
572 RelocInfo::kNoPosition), | 605 factory()->NewStringLiteral( |
573 factory()->NewEmptyStatement(RelocInfo::kNoPosition), | 606 ast_value_factory()->done_string(), nopos), |
574 RelocInfo::kNoPosition); | 607 nopos); |
575 block_->statements()->Add(if_statement, zone()); | 608 set_done_or_append = factory()->NewIfStatement(result_done, set_done, |
609 append_element, nopos); | |
610 } | |
576 | 611 |
577 auto set_done = factory()->NewAssignment( | 612 // while (!done) { |
578 Token::ASSIGN, factory()->NewVariableProxy(done), | 613 // #get_next; |
579 factory()->NewBooleanLiteral(true, nopos), nopos); | 614 // #set_done_or_append; |
580 block_->statements()->Add( | 615 // } |
581 factory()->NewExpressionStatement(set_done, nopos), zone()); | 616 WhileStatement* loop = factory()->NewWhileStatement(nullptr, nopos); |
617 { | |
618 Expression* condition = factory()->NewUnaryOperation( | |
619 Token::NOT, factory()->NewVariableProxy(done), nopos); | |
620 Block* body = factory()->NewBlock(nullptr, 2, true, nopos); | |
621 body->statements()->Add(get_next, zone()); | |
622 body->statements()->Add(set_done_or_append, zone()); | |
623 loop->Initialize(condition, body); | |
624 } | |
582 | 625 |
626 block_->statements()->Add(loop, zone()); | |
583 RecurseIntoSubpattern(spread->expression(), | 627 RecurseIntoSubpattern(spread->expression(), |
584 factory()->NewVariableProxy(array)); | 628 factory()->NewVariableProxy(array)); |
585 } | 629 } |
586 | 630 |
587 if (FLAG_harmony_iterator_close) { | 631 if (FLAG_harmony_iterator_close) { |
588 Expression* closing_condition = factory()->NewUnaryOperation( | 632 Expression* closing_condition = factory()->NewUnaryOperation( |
589 Token::NOT, factory()->NewVariableProxy(done), nopos); | 633 Token::NOT, factory()->NewVariableProxy(done), nopos); |
590 parser_->FinalizeIteratorUse(completion, closing_condition, iterator, | 634 parser_->FinalizeIteratorUse(completion, closing_condition, iterator, |
591 block_, target); | 635 block_, target); |
592 block_ = target; | 636 block_ = target; |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
699 NOT_A_PATTERN(TryFinallyStatement) | 743 NOT_A_PATTERN(TryFinallyStatement) |
700 NOT_A_PATTERN(UnaryOperation) | 744 NOT_A_PATTERN(UnaryOperation) |
701 NOT_A_PATTERN(VariableDeclaration) | 745 NOT_A_PATTERN(VariableDeclaration) |
702 NOT_A_PATTERN(WhileStatement) | 746 NOT_A_PATTERN(WhileStatement) |
703 NOT_A_PATTERN(WithStatement) | 747 NOT_A_PATTERN(WithStatement) |
704 NOT_A_PATTERN(Yield) | 748 NOT_A_PATTERN(Yield) |
705 | 749 |
706 #undef NOT_A_PATTERN | 750 #undef NOT_A_PATTERN |
707 } // namespace internal | 751 } // namespace internal |
708 } // namespace v8 | 752 } // namespace v8 |
OLD | NEW |