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_CreateObjectLiteralBoilerplate. | 2615 // by calling Runtime_CreateObjectLiteral. |
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(); |
(...skipping 53 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::kCloneLiteralBoilerplate, 1); | 2689 frame_->CallRuntime(Runtime::kCloneObjectLiteralBoilerplate, 1); |
2690 frame_->EmitPush(r0); // save the result | 2690 frame_->EmitPush(r0); // save the result |
2691 // r0: cloned object literal | 2691 // r0: cloned object literal |
2692 | 2692 |
2693 for (int i = 0; i < node->properties()->length(); i++) { | 2693 for (int i = 0; i < node->properties()->length(); i++) { |
2694 ObjectLiteral::Property* property = node->properties()->at(i); | 2694 ObjectLiteral::Property* property = node->properties()->at(i); |
2695 Literal* key = property->key(); | 2695 Literal* key = property->key(); |
2696 Expression* value = property->value(); | 2696 Expression* value = property->value(); |
2697 switch (property->kind()) { | 2697 switch (property->kind()) { |
2698 case ObjectLiteral::Property::CONSTANT: | 2698 case ObjectLiteral::Property::CONSTANT: break; |
2699 break; | |
2700 case ObjectLiteral::Property::MATERIALIZED_LITERAL: | |
2701 if (property->value()->AsMaterializedLiteral()->is_simple()) break; | |
2702 // else fall through | |
2703 case ObjectLiteral::Property::COMPUTED: // fall through | 2699 case ObjectLiteral::Property::COMPUTED: // fall through |
2704 case ObjectLiteral::Property::PROTOTYPE: { | 2700 case ObjectLiteral::Property::PROTOTYPE: { |
2705 frame_->EmitPush(r0); // dup the result | 2701 frame_->EmitPush(r0); // dup the result |
2706 LoadAndSpill(key); | 2702 LoadAndSpill(key); |
2707 LoadAndSpill(value); | 2703 LoadAndSpill(value); |
2708 frame_->CallRuntime(Runtime::kSetProperty, 3); | 2704 frame_->CallRuntime(Runtime::kSetProperty, 3); |
2709 // restore r0 | 2705 // restore r0 |
2710 __ ldr(r0, frame_->Top()); | 2706 __ ldr(r0, frame_->Top()); |
2711 break; | 2707 break; |
2712 } | 2708 } |
(...skipping 16 matching lines...) Expand all Loading... |
2729 frame_->CallRuntime(Runtime::kDefineAccessor, 4); | 2725 frame_->CallRuntime(Runtime::kDefineAccessor, 4); |
2730 __ ldr(r0, frame_->Top()); | 2726 __ ldr(r0, frame_->Top()); |
2731 break; | 2727 break; |
2732 } | 2728 } |
2733 } | 2729 } |
2734 } | 2730 } |
2735 ASSERT(frame_->height() == original_height + 1); | 2731 ASSERT(frame_->height() == original_height + 1); |
2736 } | 2732 } |
2737 | 2733 |
2738 | 2734 |
2739 // This deferred code stub will be used for creating the boilerplate | |
2740 // by calling Runtime_CreateArrayLiteralBoilerplate. | |
2741 // Each created boilerplate is stored in the JSFunction and they are | |
2742 // therefore context dependent. | |
2743 class DeferredArrayLiteral: public DeferredCode { | |
2744 public: | |
2745 DeferredArrayLiteral(CodeGenerator* generator, ArrayLiteral* node) | |
2746 : DeferredCode(generator), node_(node) { | |
2747 set_comment("[ DeferredArrayLiteral"); | |
2748 } | |
2749 | |
2750 virtual void Generate(); | |
2751 | |
2752 private: | |
2753 ArrayLiteral* node_; | |
2754 }; | |
2755 | |
2756 | |
2757 void DeferredArrayLiteral::Generate() { | |
2758 // Argument is passed in r1. | |
2759 enter()->Bind(); | |
2760 VirtualFrame::SpilledScope spilled_scope(generator()); | |
2761 | |
2762 // If the entry is undefined we call the runtime system to computed | |
2763 // the literal. | |
2764 | |
2765 VirtualFrame* frame = generator()->frame(); | |
2766 // Literal array (0). | |
2767 frame->EmitPush(r1); | |
2768 // Literal index (1). | |
2769 __ mov(r0, Operand(Smi::FromInt(node_->literal_index()))); | |
2770 frame->EmitPush(r0); | |
2771 // Constant properties (2). | |
2772 __ mov(r0, Operand(node_->literals())); | |
2773 frame->EmitPush(r0); | |
2774 Result boilerplate = | |
2775 frame->CallRuntime(Runtime::kCreateArrayLiteralBoilerplate, 3); | |
2776 __ mov(r2, Operand(boilerplate.reg())); | |
2777 // Result is returned in r2. | |
2778 exit_.Jump(); | |
2779 } | |
2780 | |
2781 | |
2782 void CodeGenerator::VisitArrayLiteral(ArrayLiteral* node) { | 2735 void CodeGenerator::VisitArrayLiteral(ArrayLiteral* node) { |
2783 #ifdef DEBUG | 2736 #ifdef DEBUG |
2784 int original_height = frame_->height(); | 2737 int original_height = frame_->height(); |
2785 #endif | 2738 #endif |
2786 VirtualFrame::SpilledScope spilled_scope(this); | 2739 VirtualFrame::SpilledScope spilled_scope(this); |
2787 Comment cmnt(masm_, "[ ArrayLiteral"); | 2740 Comment cmnt(masm_, "[ ArrayLiteral"); |
2788 | 2741 |
2789 DeferredArrayLiteral* deferred = new DeferredArrayLiteral(this, node); | 2742 // Call runtime to create the array literal. |
| 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); |
2790 | 2750 |
2791 // Retrieve the literal array and check the allocated entry. | 2751 // Push the resulting array literal on the stack. |
2792 | 2752 frame_->EmitPush(r0); |
2793 // Load the function of this activation. | |
2794 __ ldr(r1, frame_->Function()); | |
2795 | |
2796 // Load the literals array of the function. | |
2797 __ ldr(r1, FieldMemOperand(r1, JSFunction::kLiteralsOffset)); | |
2798 | |
2799 // Load the literal at the ast saved index. | |
2800 int literal_offset = | |
2801 FixedArray::kHeaderSize + node->literal_index() * kPointerSize; | |
2802 __ ldr(r2, FieldMemOperand(r1, literal_offset)); | |
2803 | |
2804 // Check whether we need to materialize the object literal boilerplate. | |
2805 // If so, jump to the deferred code. | |
2806 __ cmp(r2, Operand(Factory::undefined_value())); | |
2807 deferred->enter()->Branch(eq); | |
2808 deferred->BindExit(); | |
2809 | |
2810 // Push the object literal boilerplate. | |
2811 frame_->EmitPush(r2); | |
2812 | |
2813 // Clone the boilerplate object. | |
2814 frame_->CallRuntime(Runtime::kCloneLiteralBoilerplate, 1); | |
2815 frame_->EmitPush(r0); // save the result | |
2816 // r0: cloned object literal | |
2817 | 2753 |
2818 // Generate code to set the elements in the array that are not | 2754 // Generate code to set the elements in the array that are not |
2819 // literals. | 2755 // literals. |
2820 for (int i = 0; i < node->values()->length(); i++) { | 2756 for (int i = 0; i < node->values()->length(); i++) { |
2821 Expression* value = node->values()->at(i); | 2757 Expression* value = node->values()->at(i); |
2822 | 2758 |
2823 // If value is literal the property value is already | 2759 // If value is literal the property value is already |
2824 // set in the boilerplate object. | 2760 // set in the boilerplate object. |
2825 if (value->AsLiteral() == NULL) { | 2761 if (value->AsLiteral() == NULL) { |
2826 // The property must be set by generated code. | 2762 // The property must be set by generated code. |
(...skipping 2323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5150 __ mov(r2, Operand(0)); | 5086 __ mov(r2, Operand(0)); |
5151 __ GetBuiltinEntry(r3, Builtins::CALL_NON_FUNCTION); | 5087 __ GetBuiltinEntry(r3, Builtins::CALL_NON_FUNCTION); |
5152 __ Jump(Handle<Code>(Builtins::builtin(Builtins::ArgumentsAdaptorTrampoline)), | 5088 __ Jump(Handle<Code>(Builtins::builtin(Builtins::ArgumentsAdaptorTrampoline)), |
5153 RelocInfo::CODE_TARGET); | 5089 RelocInfo::CODE_TARGET); |
5154 } | 5090 } |
5155 | 5091 |
5156 | 5092 |
5157 #undef __ | 5093 #undef __ |
5158 | 5094 |
5159 } } // namespace v8::internal | 5095 } } // namespace v8::internal |
OLD | NEW |