OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 2594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2605 __ mov(r2, Operand(r0)); | 2605 __ mov(r2, Operand(r0)); |
2606 | 2606 |
2607 done.Bind(); | 2607 done.Bind(); |
2608 // Push the literal. | 2608 // Push the literal. |
2609 frame_->EmitPush(r2); | 2609 frame_->EmitPush(r2); |
2610 ASSERT(frame_->height() == original_height + 1); | 2610 ASSERT(frame_->height() == original_height + 1); |
2611 } | 2611 } |
2612 | 2612 |
2613 | 2613 |
2614 // This deferred code stub will be used for creating the boilerplate | 2614 // This deferred code stub will be used for creating the boilerplate |
2615 // by calling Runtime_CreateObjectLiteral. | 2615 // by calling Runtime_CreateObjectLiteralBoilerplate. |
2616 // Each created boilerplate is stored in the JSFunction and they are | 2616 // Each created boilerplate is stored in the JSFunction and they are |
2617 // therefore context dependent. | 2617 // therefore context dependent. |
2618 class DeferredObjectLiteral: public DeferredCode { | 2618 class DeferredObjectLiteral: public DeferredCode { |
2619 public: | 2619 public: |
2620 DeferredObjectLiteral(CodeGenerator* generator, ObjectLiteral* node) | 2620 DeferredObjectLiteral(CodeGenerator* generator, ObjectLiteral* node) |
2621 : DeferredCode(generator), node_(node) { | 2621 : DeferredCode(generator), node_(node) { |
2622 set_comment("[ DeferredObjectLiteral"); | 2622 set_comment("[ DeferredObjectLiteral"); |
2623 } | 2623 } |
2624 | 2624 |
2625 virtual void Generate(); | 2625 virtual void Generate(); |
2626 | 2626 |
2627 private: | 2627 private: |
2628 ObjectLiteral* node_; | 2628 ObjectLiteral* node_; |
2629 }; | 2629 }; |
2630 | 2630 |
2631 | 2631 |
2632 void DeferredObjectLiteral::Generate() { | 2632 void DeferredObjectLiteral::Generate() { |
2633 // Argument is passed in r1. | 2633 // Argument is passed in r1. |
2634 enter()->Bind(); | 2634 enter()->Bind(); |
2635 VirtualFrame::SpilledScope spilled_scope(generator()); | 2635 VirtualFrame::SpilledScope spilled_scope(generator()); |
2636 | 2636 |
2637 // If the entry is undefined we call the runtime system to computed | 2637 // If the entry is undefined we call the runtime system to compute |
2638 // the literal. | 2638 // the literal. |
2639 | 2639 |
2640 VirtualFrame* frame = generator()->frame(); | 2640 VirtualFrame* frame = generator()->frame(); |
2641 // Literal array (0). | 2641 // Literal array (0). |
2642 frame->EmitPush(r1); | 2642 frame->EmitPush(r1); |
2643 // Literal index (1). | 2643 // Literal index (1). |
2644 __ mov(r0, Operand(Smi::FromInt(node_->literal_index()))); | 2644 __ mov(r0, Operand(Smi::FromInt(node_->literal_index()))); |
2645 frame->EmitPush(r0); | 2645 frame->EmitPush(r0); |
2646 // Constant properties (2). | 2646 // Constant properties (2). |
2647 __ mov(r0, Operand(node_->constant_properties())); | 2647 __ mov(r0, Operand(node_->constant_properties())); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2679 // Check whether we need to materialize the object literal boilerplate. | 2679 // Check whether we need to materialize the object literal boilerplate. |
2680 // If so, jump to the deferred code. | 2680 // If so, jump to the deferred code. |
2681 __ cmp(r2, Operand(Factory::undefined_value())); | 2681 __ cmp(r2, Operand(Factory::undefined_value())); |
2682 deferred->enter()->Branch(eq); | 2682 deferred->enter()->Branch(eq); |
2683 deferred->BindExit(); | 2683 deferred->BindExit(); |
2684 | 2684 |
2685 // Push the object literal boilerplate. | 2685 // Push the object literal boilerplate. |
2686 frame_->EmitPush(r2); | 2686 frame_->EmitPush(r2); |
2687 | 2687 |
2688 // Clone the boilerplate object. | 2688 // Clone the boilerplate object. |
2689 frame_->CallRuntime(Runtime::kCloneObjectLiteralBoilerplate, 1); | 2689 Runtime::FunctionId clone_function_id = Runtime::kCloneLiteralBoilerplate; |
| 2690 if (node->depth() == 1) { |
| 2691 clone_function_id = Runtime::kCloneShallowLiteralBoilerplate; |
| 2692 } |
| 2693 frame_->CallRuntime(clone_function_id, 1); |
2690 frame_->EmitPush(r0); // save the result | 2694 frame_->EmitPush(r0); // save the result |
2691 // r0: cloned object literal | 2695 // r0: cloned object literal |
2692 | 2696 |
2693 for (int i = 0; i < node->properties()->length(); i++) { | 2697 for (int i = 0; i < node->properties()->length(); i++) { |
2694 ObjectLiteral::Property* property = node->properties()->at(i); | 2698 ObjectLiteral::Property* property = node->properties()->at(i); |
2695 Literal* key = property->key(); | 2699 Literal* key = property->key(); |
2696 Expression* value = property->value(); | 2700 Expression* value = property->value(); |
2697 switch (property->kind()) { | 2701 switch (property->kind()) { |
2698 case ObjectLiteral::Property::CONSTANT: break; | 2702 case ObjectLiteral::Property::CONSTANT: |
| 2703 break; |
| 2704 case ObjectLiteral::Property::MATERIALIZED_LITERAL: |
| 2705 if (property->value()->AsMaterializedLiteral()->is_simple()) break; |
| 2706 // else fall through |
2699 case ObjectLiteral::Property::COMPUTED: // fall through | 2707 case ObjectLiteral::Property::COMPUTED: // fall through |
2700 case ObjectLiteral::Property::PROTOTYPE: { | 2708 case ObjectLiteral::Property::PROTOTYPE: { |
2701 frame_->EmitPush(r0); // dup the result | 2709 frame_->EmitPush(r0); // dup the result |
2702 LoadAndSpill(key); | 2710 LoadAndSpill(key); |
2703 LoadAndSpill(value); | 2711 LoadAndSpill(value); |
2704 frame_->CallRuntime(Runtime::kSetProperty, 3); | 2712 frame_->CallRuntime(Runtime::kSetProperty, 3); |
2705 // restore r0 | 2713 // restore r0 |
2706 __ ldr(r0, frame_->Top()); | 2714 __ ldr(r0, frame_->Top()); |
2707 break; | 2715 break; |
2708 } | 2716 } |
(...skipping 16 matching lines...) Expand all Loading... |
2725 frame_->CallRuntime(Runtime::kDefineAccessor, 4); | 2733 frame_->CallRuntime(Runtime::kDefineAccessor, 4); |
2726 __ ldr(r0, frame_->Top()); | 2734 __ ldr(r0, frame_->Top()); |
2727 break; | 2735 break; |
2728 } | 2736 } |
2729 } | 2737 } |
2730 } | 2738 } |
2731 ASSERT(frame_->height() == original_height + 1); | 2739 ASSERT(frame_->height() == original_height + 1); |
2732 } | 2740 } |
2733 | 2741 |
2734 | 2742 |
| 2743 // This deferred code stub will be used for creating the boilerplate |
| 2744 // by calling Runtime_CreateArrayLiteralBoilerplate. |
| 2745 // Each created boilerplate is stored in the JSFunction and they are |
| 2746 // therefore context dependent. |
| 2747 class DeferredArrayLiteral: public DeferredCode { |
| 2748 public: |
| 2749 DeferredArrayLiteral(CodeGenerator* generator, ArrayLiteral* node) |
| 2750 : DeferredCode(generator), node_(node) { |
| 2751 set_comment("[ DeferredArrayLiteral"); |
| 2752 } |
| 2753 |
| 2754 virtual void Generate(); |
| 2755 |
| 2756 private: |
| 2757 ArrayLiteral* node_; |
| 2758 }; |
| 2759 |
| 2760 |
| 2761 void DeferredArrayLiteral::Generate() { |
| 2762 // Argument is passed in r1. |
| 2763 enter()->Bind(); |
| 2764 VirtualFrame::SpilledScope spilled_scope(generator()); |
| 2765 |
| 2766 // If the entry is undefined we call the runtime system to computed |
| 2767 // the literal. |
| 2768 |
| 2769 VirtualFrame* frame = generator()->frame(); |
| 2770 // Literal array (0). |
| 2771 frame->EmitPush(r1); |
| 2772 // Literal index (1). |
| 2773 __ mov(r0, Operand(Smi::FromInt(node_->literal_index()))); |
| 2774 frame->EmitPush(r0); |
| 2775 // Constant properties (2). |
| 2776 __ mov(r0, Operand(node_->literals())); |
| 2777 frame->EmitPush(r0); |
| 2778 Result boilerplate = |
| 2779 frame->CallRuntime(Runtime::kCreateArrayLiteralBoilerplate, 3); |
| 2780 __ mov(r2, Operand(boilerplate.reg())); |
| 2781 // Result is returned in r2. |
| 2782 exit_.Jump(); |
| 2783 } |
| 2784 |
| 2785 |
2735 void CodeGenerator::VisitArrayLiteral(ArrayLiteral* node) { | 2786 void CodeGenerator::VisitArrayLiteral(ArrayLiteral* node) { |
2736 #ifdef DEBUG | 2787 #ifdef DEBUG |
2737 int original_height = frame_->height(); | 2788 int original_height = frame_->height(); |
2738 #endif | 2789 #endif |
2739 VirtualFrame::SpilledScope spilled_scope(this); | 2790 VirtualFrame::SpilledScope spilled_scope(this); |
2740 Comment cmnt(masm_, "[ ArrayLiteral"); | 2791 Comment cmnt(masm_, "[ ArrayLiteral"); |
2741 | 2792 |
2742 // Call runtime to create the array literal. | 2793 DeferredArrayLiteral* deferred = new DeferredArrayLiteral(this, node); |
2743 __ mov(r0, Operand(node->literals())); | |
2744 frame_->EmitPush(r0); | |
2745 // Load the function of this frame. | |
2746 __ ldr(r0, frame_->Function()); | |
2747 __ ldr(r0, FieldMemOperand(r0, JSFunction::kLiteralsOffset)); | |
2748 frame_->EmitPush(r0); | |
2749 frame_->CallRuntime(Runtime::kCreateArrayLiteral, 2); | |
2750 | 2794 |
2751 // Push the resulting array literal on the stack. | 2795 // Retrieve the literal array and check the allocated entry. |
2752 frame_->EmitPush(r0); | 2796 |
| 2797 // Load the function of this activation. |
| 2798 __ ldr(r1, frame_->Function()); |
| 2799 |
| 2800 // Load the literals array of the function. |
| 2801 __ ldr(r1, FieldMemOperand(r1, JSFunction::kLiteralsOffset)); |
| 2802 |
| 2803 // Load the literal at the ast saved index. |
| 2804 int literal_offset = |
| 2805 FixedArray::kHeaderSize + node->literal_index() * kPointerSize; |
| 2806 __ ldr(r2, FieldMemOperand(r1, literal_offset)); |
| 2807 |
| 2808 // Check whether we need to materialize the object literal boilerplate. |
| 2809 // If so, jump to the deferred code. |
| 2810 __ cmp(r2, Operand(Factory::undefined_value())); |
| 2811 deferred->enter()->Branch(eq); |
| 2812 deferred->BindExit(); |
| 2813 |
| 2814 // Push the object literal boilerplate. |
| 2815 frame_->EmitPush(r2); |
| 2816 |
| 2817 // Clone the boilerplate object. |
| 2818 Runtime::FunctionId clone_function_id = Runtime::kCloneLiteralBoilerplate; |
| 2819 if (node->depth() == 1) { |
| 2820 clone_function_id = Runtime::kCloneShallowLiteralBoilerplate; |
| 2821 } |
| 2822 frame_->CallRuntime(clone_function_id, 1); |
| 2823 frame_->EmitPush(r0); // save the result |
| 2824 // r0: cloned object literal |
2753 | 2825 |
2754 // Generate code to set the elements in the array that are not | 2826 // Generate code to set the elements in the array that are not |
2755 // literals. | 2827 // literals. |
2756 for (int i = 0; i < node->values()->length(); i++) { | 2828 for (int i = 0; i < node->values()->length(); i++) { |
2757 Expression* value = node->values()->at(i); | 2829 Expression* value = node->values()->at(i); |
2758 | 2830 |
2759 // If value is literal the property value is already | 2831 // If value is literal the property value is already |
2760 // set in the boilerplate object. | 2832 // set in the boilerplate object. |
2761 if (value->AsLiteral() == NULL) { | 2833 if (value->AsLiteral() == NULL) { |
2762 // The property must be set by generated code. | 2834 // The property must be set by generated code. |
(...skipping 2323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5086 __ mov(r2, Operand(0)); | 5158 __ mov(r2, Operand(0)); |
5087 __ GetBuiltinEntry(r3, Builtins::CALL_NON_FUNCTION); | 5159 __ GetBuiltinEntry(r3, Builtins::CALL_NON_FUNCTION); |
5088 __ Jump(Handle<Code>(Builtins::builtin(Builtins::ArgumentsAdaptorTrampoline)), | 5160 __ Jump(Handle<Code>(Builtins::builtin(Builtins::ArgumentsAdaptorTrampoline)), |
5089 RelocInfo::CODE_TARGET); | 5161 RelocInfo::CODE_TARGET); |
5090 } | 5162 } |
5091 | 5163 |
5092 | 5164 |
5093 #undef __ | 5165 #undef __ |
5094 | 5166 |
5095 } } // namespace v8::internal | 5167 } } // namespace v8::internal |
OLD | NEW |