OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
693 void FullCodeGenerator::EmitDeclaration(Variable* variable, | 693 void FullCodeGenerator::EmitDeclaration(Variable* variable, |
694 Variable::Mode mode, | 694 Variable::Mode mode, |
695 FunctionLiteral* function) { | 695 FunctionLiteral* function) { |
696 Comment cmnt(masm_, "[ Declaration"); | 696 Comment cmnt(masm_, "[ Declaration"); |
697 ASSERT(variable != NULL); // Must have been resolved. | 697 ASSERT(variable != NULL); // Must have been resolved. |
698 Slot* slot = variable->AsSlot(); | 698 Slot* slot = variable->AsSlot(); |
699 ASSERT(slot != NULL); | 699 ASSERT(slot != NULL); |
700 switch (slot->type()) { | 700 switch (slot->type()) { |
701 case Slot::PARAMETER: | 701 case Slot::PARAMETER: |
702 case Slot::LOCAL: | 702 case Slot::LOCAL: |
703 if (mode == Variable::CONST) { | 703 if (function != NULL) { |
704 __ LoadRoot(t0, Heap::kTheHoleValueRootIndex); | |
705 __ sw(t0, MemOperand(fp, SlotOffset(slot))); | |
706 } else if (function != NULL) { | |
707 VisitForAccumulatorValue(function); | 704 VisitForAccumulatorValue(function); |
708 __ sw(result_register(), MemOperand(fp, SlotOffset(slot))); | 705 __ sw(result_register(), MemOperand(fp, SlotOffset(slot))); |
| 706 } else if (mode == Variable::CONST || mode == Variable::LET) { |
| 707 __ LoadRoot(t0, Heap::kTheHoleValueRootIndex); |
| 708 __ sw(t0, MemOperand(fp, SlotOffset(slot))); |
709 } | 709 } |
710 break; | 710 break; |
711 | 711 |
712 case Slot::CONTEXT: | 712 case Slot::CONTEXT: |
713 // We bypass the general EmitSlotSearch because we know more about | 713 // We bypass the general EmitSlotSearch because we know more about |
714 // this specific context. | 714 // this specific context. |
715 | 715 |
716 // The variable in the decl always resides in the current function | 716 // The variable in the decl always resides in the current function |
717 // context. | 717 // context. |
718 ASSERT_EQ(0, scope()->ContextChainLength(variable->scope())); | 718 ASSERT_EQ(0, scope()->ContextChainLength(variable->scope())); |
719 if (FLAG_debug_code) { | 719 if (FLAG_debug_code) { |
720 // Check that we're not inside a with or catch context. | 720 // Check that we're not inside a with or catch context. |
721 __ lw(a1, FieldMemOperand(cp, HeapObject::kMapOffset)); | 721 __ lw(a1, FieldMemOperand(cp, HeapObject::kMapOffset)); |
722 __ LoadRoot(t0, Heap::kWithContextMapRootIndex); | 722 __ LoadRoot(t0, Heap::kWithContextMapRootIndex); |
723 __ Check(ne, "Declaration in with context.", | 723 __ Check(ne, "Declaration in with context.", |
724 a1, Operand(t0)); | 724 a1, Operand(t0)); |
725 __ LoadRoot(t0, Heap::kCatchContextMapRootIndex); | 725 __ LoadRoot(t0, Heap::kCatchContextMapRootIndex); |
726 __ Check(ne, "Declaration in catch context.", | 726 __ Check(ne, "Declaration in catch context.", |
727 a1, Operand(t0)); | 727 a1, Operand(t0)); |
728 } | 728 } |
729 if (mode == Variable::CONST) { | 729 if (function != NULL) { |
730 __ LoadRoot(at, Heap::kTheHoleValueRootIndex); | |
731 __ sw(at, ContextOperand(cp, slot->index())); | |
732 // No write barrier since the_hole_value is in old space. | |
733 } else if (function != NULL) { | |
734 VisitForAccumulatorValue(function); | 730 VisitForAccumulatorValue(function); |
735 __ sw(result_register(), ContextOperand(cp, slot->index())); | 731 __ sw(result_register(), ContextOperand(cp, slot->index())); |
736 int offset = Context::SlotOffset(slot->index()); | 732 int offset = Context::SlotOffset(slot->index()); |
737 // We know that we have written a function, which is not a smi. | 733 // We know that we have written a function, which is not a smi. |
738 __ mov(a1, cp); | 734 __ mov(a1, cp); |
739 __ RecordWrite(a1, Operand(offset), a2, result_register()); | 735 __ RecordWrite(a1, Operand(offset), a2, result_register()); |
| 736 } else if (mode == Variable::CONST || mode == Variable::LET) { |
| 737 __ LoadRoot(at, Heap::kTheHoleValueRootIndex); |
| 738 __ sw(at, ContextOperand(cp, slot->index())); |
| 739 // No write barrier since the_hole_value is in old space. |
740 } | 740 } |
741 break; | 741 break; |
742 | 742 |
743 case Slot::LOOKUP: { | 743 case Slot::LOOKUP: { |
744 __ li(a2, Operand(variable->name())); | 744 __ li(a2, Operand(variable->name())); |
745 // Declaration nodes are always introduced in one of two modes. | 745 // Declaration nodes are always introduced in one of two modes. |
746 ASSERT(mode == Variable::VAR || | 746 ASSERT(mode == Variable::VAR || |
747 mode == Variable::CONST || | 747 mode == Variable::CONST || |
748 mode == Variable::LET); | 748 mode == Variable::LET); |
749 PropertyAttributes attr = (mode == Variable::CONST) ? READ_ONLY : NONE; | 749 PropertyAttributes attr = (mode == Variable::CONST) ? READ_ONLY : NONE; |
750 __ li(a1, Operand(Smi::FromInt(attr))); | 750 __ li(a1, Operand(Smi::FromInt(attr))); |
751 // Push initial value, if any. | 751 // Push initial value, if any. |
752 // Note: For variables we must not push an initial value (such as | 752 // Note: For variables we must not push an initial value (such as |
753 // 'undefined') because we may have a (legal) redeclaration and we | 753 // 'undefined') because we may have a (legal) redeclaration and we |
754 // must not destroy the current value. | 754 // must not destroy the current value. |
755 if (mode == Variable::CONST) { | 755 if (function != NULL) { |
756 __ LoadRoot(a0, Heap::kTheHoleValueRootIndex); | |
757 __ Push(cp, a2, a1, a0); | |
758 } else if (function != NULL) { | |
759 __ Push(cp, a2, a1); | 756 __ Push(cp, a2, a1); |
760 // Push initial value for function declaration. | 757 // Push initial value for function declaration. |
761 VisitForStackValue(function); | 758 VisitForStackValue(function); |
| 759 } else if (mode == Variable::CONST || mode == Variable::LET) { |
| 760 __ LoadRoot(a0, Heap::kTheHoleValueRootIndex); |
| 761 __ Push(cp, a2, a1, a0); |
762 } else { | 762 } else { |
763 ASSERT(Smi::FromInt(0) == 0); | 763 ASSERT(Smi::FromInt(0) == 0); |
764 // No initial value! | 764 // No initial value! |
765 __ mov(a0, zero_reg); // Operand(Smi::FromInt(0))); | 765 __ mov(a0, zero_reg); // Operand(Smi::FromInt(0))); |
766 __ Push(cp, a2, a1, a0); | 766 __ Push(cp, a2, a1, a0); |
767 } | 767 } |
768 __ CallRuntime(Runtime::kDeclareContextSlot, 4); | 768 __ CallRuntime(Runtime::kDeclareContextSlot, 4); |
769 break; | 769 break; |
770 } | 770 } |
771 } | 771 } |
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1272 if (var->mode() == Variable::CONST) { | 1272 if (var->mode() == Variable::CONST) { |
1273 // Constants may be the hole value if they have not been initialized. | 1273 // Constants may be the hole value if they have not been initialized. |
1274 // Unhole them. | 1274 // Unhole them. |
1275 MemOperand slot_operand = EmitSlotSearch(slot, a0); | 1275 MemOperand slot_operand = EmitSlotSearch(slot, a0); |
1276 __ lw(v0, slot_operand); | 1276 __ lw(v0, slot_operand); |
1277 __ LoadRoot(at, Heap::kTheHoleValueRootIndex); | 1277 __ LoadRoot(at, Heap::kTheHoleValueRootIndex); |
1278 __ subu(at, v0, at); // Sub as compare: at == 0 on eq. | 1278 __ subu(at, v0, at); // Sub as compare: at == 0 on eq. |
1279 __ LoadRoot(a0, Heap::kUndefinedValueRootIndex); | 1279 __ LoadRoot(a0, Heap::kUndefinedValueRootIndex); |
1280 __ movz(v0, a0, at); // Conditional move. | 1280 __ movz(v0, a0, at); // Conditional move. |
1281 context()->Plug(v0); | 1281 context()->Plug(v0); |
1282 } else { | 1282 } else if (var->mode() == Variable::LET) { |
1283 context()->Plug(slot); | 1283 // Let bindings may be the hole value if they have not been initialized. |
1284 } | 1284 // Throw a type error in this case. |
| 1285 Label done; |
| 1286 MemOperand slot_operand = EmitSlotSearch(slot, a0); |
| 1287 __ lw(v0, slot_operand); |
| 1288 __ LoadRoot(a1, Heap::kTheHoleValueRootIndex); |
| 1289 __ Branch(&done, ne, v0, Operand(a1)); |
| 1290 __ li(v0, Operand(var->name())); |
| 1291 __ push(v0); |
| 1292 __ CallRuntime(Runtime::kThrowReferenceError, 1); |
| 1293 __ bind(&done); |
| 1294 context()->Plug(v0); |
| 1295 } else { |
| 1296 context()->Plug(slot); |
| 1297 } |
1285 } | 1298 } |
1286 } | 1299 } |
1287 | 1300 |
1288 | 1301 |
1289 void FullCodeGenerator::VisitRegExpLiteral(RegExpLiteral* expr) { | 1302 void FullCodeGenerator::VisitRegExpLiteral(RegExpLiteral* expr) { |
1290 Comment cmnt(masm_, "[ RegExpLiteral"); | 1303 Comment cmnt(masm_, "[ RegExpLiteral"); |
1291 Label materialized; | 1304 Label materialized; |
1292 // Registers will be used as follows: | 1305 // Registers will be used as follows: |
1293 // t1 = materialized value (RegExp literal) | 1306 // t1 = materialized value (RegExp literal) |
1294 // t0 = JS function, literals array | 1307 // t0 = JS function, literals array |
(...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1856 break; | 1869 break; |
1857 case Slot::CONTEXT: | 1870 case Slot::CONTEXT: |
1858 case Slot::LOOKUP: | 1871 case Slot::LOOKUP: |
1859 __ push(result_register()); | 1872 __ push(result_register()); |
1860 __ li(a0, Operand(slot->var()->name())); | 1873 __ li(a0, Operand(slot->var()->name())); |
1861 __ Push(cp, a0); // Context and name. | 1874 __ Push(cp, a0); // Context and name. |
1862 __ CallRuntime(Runtime::kInitializeConstContextSlot, 3); | 1875 __ CallRuntime(Runtime::kInitializeConstContextSlot, 3); |
1863 break; | 1876 break; |
1864 } | 1877 } |
1865 __ bind(&skip); | 1878 __ bind(&skip); |
| 1879 } else if (var->mode() == Variable::LET && op != Token::INIT_LET) { |
| 1880 // Perform the assignment for non-const variables. Const assignments |
| 1881 // are simply skipped. |
| 1882 Slot* slot = var->AsSlot(); |
| 1883 switch (slot->type()) { |
| 1884 case Slot::PARAMETER: |
| 1885 case Slot::LOCAL: { |
| 1886 Label assign; |
| 1887 // Check for an initialized let binding. |
| 1888 __ lw(a1, MemOperand(fp, SlotOffset(slot))); |
| 1889 __ LoadRoot(t0, Heap::kTheHoleValueRootIndex); |
| 1890 __ Branch(&assign, ne, a1, Operand(t0)); |
| 1891 __ li(a1, Operand(var->name())); |
| 1892 __ push(a1); |
| 1893 __ CallRuntime(Runtime::kThrowReferenceError, 1); |
| 1894 // Perform the assignment. |
| 1895 __ bind(&assign); |
| 1896 __ sw(result_register(), MemOperand(fp, SlotOffset(slot))); |
| 1897 break; |
| 1898 } |
| 1899 case Slot::CONTEXT: { |
| 1900 // Let variables may be the hole value if they have not been |
| 1901 // initialized. Throw a type error in this case. |
| 1902 Label assign; |
| 1903 MemOperand target = EmitSlotSearch(slot, a1); |
| 1904 // Check for an initialized let binding. |
| 1905 __ lw(a3, target); |
| 1906 __ LoadRoot(t0, Heap::kTheHoleValueRootIndex); |
| 1907 __ Branch(&assign, ne, a3, Operand(t0)); |
| 1908 __ li(a3, Operand(var->name())); |
| 1909 __ push(a3); |
| 1910 __ CallRuntime(Runtime::kThrowReferenceError, 1); |
| 1911 // Perform the assignment. |
| 1912 __ bind(&assign); |
| 1913 __ sw(result_register(), target); |
| 1914 // RecordWrite may destroy all its register arguments. |
| 1915 __ mov(a3, result_register()); |
| 1916 int offset = Context::SlotOffset(slot->index()); |
| 1917 __ RecordWrite(a1, Operand(offset), a2, a3); |
| 1918 break; |
| 1919 } |
| 1920 case Slot::LOOKUP: |
| 1921 // Call the runtime for the assignment. |
| 1922 __ push(v0); // Value. |
| 1923 __ li(a1, Operand(slot->var()->name())); |
| 1924 __ li(a0, Operand(Smi::FromInt(strict_mode_flag()))); |
| 1925 __ Push(cp, a1, a0); // Context, name, strict mode. |
| 1926 __ CallRuntime(Runtime::kStoreContextSlot, 4); |
| 1927 break; |
| 1928 } |
1866 | 1929 |
1867 } else if (var->mode() != Variable::CONST) { | 1930 } else if (var->mode() != Variable::CONST) { |
1868 // Perform the assignment for non-const variables. Const assignments | 1931 // Perform the assignment for non-const variables. Const assignments |
1869 // are simply skipped. | 1932 // are simply skipped. |
1870 Slot* slot = var->AsSlot(); | 1933 Slot* slot = var->AsSlot(); |
1871 switch (slot->type()) { | 1934 switch (slot->type()) { |
1872 case Slot::PARAMETER: | 1935 case Slot::PARAMETER: |
1873 case Slot::LOCAL: | 1936 case Slot::LOCAL: |
1874 // Perform the assignment. | 1937 // Perform the assignment. |
1875 __ sw(result_register(), MemOperand(fp, SlotOffset(slot))); | 1938 __ sw(result_register(), MemOperand(fp, SlotOffset(slot))); |
(...skipping 2342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4218 __ Addu(at, a1, Operand(masm_->CodeObject())); | 4281 __ Addu(at, a1, Operand(masm_->CodeObject())); |
4219 __ Jump(at); | 4282 __ Jump(at); |
4220 } | 4283 } |
4221 | 4284 |
4222 | 4285 |
4223 #undef __ | 4286 #undef __ |
4224 | 4287 |
4225 } } // namespace v8::internal | 4288 } } // namespace v8::internal |
4226 | 4289 |
4227 #endif // V8_TARGET_ARCH_MIPS | 4290 #endif // V8_TARGET_ARCH_MIPS |
OLD | NEW |