Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(130)

Side by Side Diff: src/x64/full-codegen-x64.cc

Issue 7992005: Block scoped const variables. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Removed redundant code. Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 666 matching lines...) Expand 10 before | Expand all | Expand 10 after
677 677
678 678
679 void FullCodeGenerator::EmitDeclaration(VariableProxy* proxy, 679 void FullCodeGenerator::EmitDeclaration(VariableProxy* proxy,
680 VariableMode mode, 680 VariableMode mode,
681 FunctionLiteral* function, 681 FunctionLiteral* function,
682 int* global_count) { 682 int* global_count) {
683 // If it was not possible to allocate the variable at compile time, we 683 // If it was not possible to allocate the variable at compile time, we
684 // need to "declare" it at runtime to make sure it actually exists in the 684 // need to "declare" it at runtime to make sure it actually exists in the
685 // local context. 685 // local context.
686 Variable* variable = proxy->var(); 686 Variable* variable = proxy->var();
687 bool binding_needs_init =
688 mode == CONST || mode == CONST_HARMONY || mode == LET;
687 switch (variable->location()) { 689 switch (variable->location()) {
688 case Variable::UNALLOCATED: 690 case Variable::UNALLOCATED:
689 ++(*global_count); 691 ++(*global_count);
690 break; 692 break;
691 693
692 case Variable::PARAMETER: 694 case Variable::PARAMETER:
693 case Variable::LOCAL: 695 case Variable::LOCAL:
694 if (function != NULL) { 696 if (function != NULL) {
695 Comment cmnt(masm_, "[ Declaration"); 697 Comment cmnt(masm_, "[ Declaration");
696 VisitForAccumulatorValue(function); 698 VisitForAccumulatorValue(function);
697 __ movq(StackOperand(variable), result_register()); 699 __ movq(StackOperand(variable), result_register());
698 } else if (mode == CONST || mode == LET) { 700 } else if (binding_needs_init) {
699 Comment cmnt(masm_, "[ Declaration"); 701 Comment cmnt(masm_, "[ Declaration");
700 __ LoadRoot(kScratchRegister, Heap::kTheHoleValueRootIndex); 702 __ LoadRoot(kScratchRegister, Heap::kTheHoleValueRootIndex);
701 __ movq(StackOperand(variable), kScratchRegister); 703 __ movq(StackOperand(variable), kScratchRegister);
702 } 704 }
703 break; 705 break;
704 706
705 case Variable::CONTEXT: 707 case Variable::CONTEXT:
706 // The variable in the decl always resides in the current function 708 // The variable in the decl always resides in the current function
707 // context. 709 // context.
708 ASSERT_EQ(0, scope()->ContextChainLength(variable->scope())); 710 ASSERT_EQ(0, scope()->ContextChainLength(variable->scope()));
(...skipping 12 matching lines...) Expand all
721 int offset = Context::SlotOffset(variable->index()); 723 int offset = Context::SlotOffset(variable->index());
722 // We know that we have written a function, which is not a smi. 724 // We know that we have written a function, which is not a smi.
723 __ RecordWriteContextSlot(rsi, 725 __ RecordWriteContextSlot(rsi,
724 offset, 726 offset,
725 result_register(), 727 result_register(),
726 rcx, 728 rcx,
727 kDontSaveFPRegs, 729 kDontSaveFPRegs,
728 EMIT_REMEMBERED_SET, 730 EMIT_REMEMBERED_SET,
729 OMIT_SMI_CHECK); 731 OMIT_SMI_CHECK);
730 PrepareForBailoutForId(proxy->id(), NO_REGISTERS); 732 PrepareForBailoutForId(proxy->id(), NO_REGISTERS);
731 } else if (mode == CONST || mode == LET) { 733 } else if (binding_needs_init) {
732 Comment cmnt(masm_, "[ Declaration"); 734 Comment cmnt(masm_, "[ Declaration");
733 __ LoadRoot(kScratchRegister, Heap::kTheHoleValueRootIndex); 735 __ LoadRoot(kScratchRegister, Heap::kTheHoleValueRootIndex);
734 __ movq(ContextOperand(rsi, variable->index()), kScratchRegister); 736 __ movq(ContextOperand(rsi, variable->index()), kScratchRegister);
735 // No write barrier since the hole value is in old space. 737 // No write barrier since the hole value is in old space.
736 PrepareForBailoutForId(proxy->id(), NO_REGISTERS); 738 PrepareForBailoutForId(proxy->id(), NO_REGISTERS);
737 } 739 }
738 break; 740 break;
739 741
740 case Variable::LOOKUP: { 742 case Variable::LOOKUP: {
741 Comment cmnt(masm_, "[ Declaration"); 743 Comment cmnt(masm_, "[ Declaration");
742 __ push(rsi); 744 __ push(rsi);
743 __ Push(variable->name()); 745 __ Push(variable->name());
744 // Declaration nodes are always introduced in one of three modes. 746 // Declaration nodes are always introduced in one of four modes.
745 ASSERT(mode == VAR || mode == CONST || mode == LET); 747 ASSERT(mode == VAR ||
746 PropertyAttributes attr = (mode == CONST) ? READ_ONLY : NONE; 748 mode == CONST ||
749 mode == CONST_HARMONY ||
750 mode == LET);
751 PropertyAttributes attr =
752 (mode == CONST || mode == CONST_HARMONY) ? READ_ONLY : NONE;
747 __ Push(Smi::FromInt(attr)); 753 __ Push(Smi::FromInt(attr));
748 // Push initial value, if any. 754 // Push initial value, if any.
749 // Note: For variables we must not push an initial value (such as 755 // Note: For variables we must not push an initial value (such as
750 // 'undefined') because we may have a (legal) redeclaration and we 756 // 'undefined') because we may have a (legal) redeclaration and we
751 // must not destroy the current value. 757 // must not destroy the current value.
752 if (function != NULL) { 758 if (function != NULL) {
753 VisitForStackValue(function); 759 VisitForStackValue(function);
754 } else if (mode == CONST || mode == LET) { 760 } else if (binding_needs_init) {
755 __ PushRoot(Heap::kTheHoleValueRootIndex); 761 __ PushRoot(Heap::kTheHoleValueRootIndex);
756 } else { 762 } else {
757 __ Push(Smi::FromInt(0)); // Indicates no initial value. 763 __ Push(Smi::FromInt(0)); // Indicates no initial value.
758 } 764 }
759 __ CallRuntime(Runtime::kDeclareContextSlot, 4); 765 __ CallRuntime(Runtime::kDeclareContextSlot, 4);
760 break; 766 break;
761 } 767 }
762 } 768 }
763 } 769 }
764 770
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
1175 // eval-introduced variables. Eval is used a lot without 1181 // eval-introduced variables. Eval is used a lot without
1176 // introducing variables. In those cases, we do not want to 1182 // introducing variables. In those cases, we do not want to
1177 // perform a runtime call for all variables in the scope 1183 // perform a runtime call for all variables in the scope
1178 // containing the eval. 1184 // containing the eval.
1179 if (var->mode() == DYNAMIC_GLOBAL) { 1185 if (var->mode() == DYNAMIC_GLOBAL) {
1180 EmitLoadGlobalCheckExtensions(var, typeof_state, slow); 1186 EmitLoadGlobalCheckExtensions(var, typeof_state, slow);
1181 __ jmp(done); 1187 __ jmp(done);
1182 } else if (var->mode() == DYNAMIC_LOCAL) { 1188 } else if (var->mode() == DYNAMIC_LOCAL) {
1183 Variable* local = var->local_if_not_shadowed(); 1189 Variable* local = var->local_if_not_shadowed();
1184 __ movq(rax, ContextSlotOperandCheckExtensions(local, slow)); 1190 __ movq(rax, ContextSlotOperandCheckExtensions(local, slow));
1185 if (local->mode() == CONST || local->mode() == LET) { 1191 if (local->mode() == CONST ||
1192 local->mode() == CONST_HARMONY ||
1193 local->mode() == LET) {
1186 __ CompareRoot(rax, Heap::kTheHoleValueRootIndex); 1194 __ CompareRoot(rax, Heap::kTheHoleValueRootIndex);
1187 __ j(not_equal, done); 1195 __ j(not_equal, done);
1188 if (local->mode() == CONST) { 1196 if (local->mode() == CONST) {
1189 __ LoadRoot(rax, Heap::kUndefinedValueRootIndex); 1197 __ LoadRoot(rax, Heap::kUndefinedValueRootIndex);
1190 } else { // LET 1198 } else { // LET || CONST_HARMONY
1191 __ Push(var->name()); 1199 __ Push(var->name());
1192 __ CallRuntime(Runtime::kThrowReferenceError, 1); 1200 __ CallRuntime(Runtime::kThrowReferenceError, 1);
1193 } 1201 }
1194 } 1202 }
1195 __ jmp(done); 1203 __ jmp(done);
1196 } 1204 }
1197 } 1205 }
1198 1206
1199 1207
1200 void FullCodeGenerator::EmitVariableLoad(VariableProxy* proxy) { 1208 void FullCodeGenerator::EmitVariableLoad(VariableProxy* proxy) {
(...skipping 13 matching lines...) Expand all
1214 Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize(); 1222 Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize();
1215 __ call(ic, RelocInfo::CODE_TARGET_CONTEXT); 1223 __ call(ic, RelocInfo::CODE_TARGET_CONTEXT);
1216 context()->Plug(rax); 1224 context()->Plug(rax);
1217 break; 1225 break;
1218 } 1226 }
1219 1227
1220 case Variable::PARAMETER: 1228 case Variable::PARAMETER:
1221 case Variable::LOCAL: 1229 case Variable::LOCAL:
1222 case Variable::CONTEXT: { 1230 case Variable::CONTEXT: {
1223 Comment cmnt(masm_, var->IsContextSlot() ? "Context slot" : "Stack slot"); 1231 Comment cmnt(masm_, var->IsContextSlot() ? "Context slot" : "Stack slot");
1224 if (var->mode() != LET && var->mode() != CONST) { 1232 if (!var->binding_needs_init()) {
1225 context()->Plug(var); 1233 context()->Plug(var);
1226 } else { 1234 } else {
1227 // Let and const need a read barrier. 1235 // Let and const need a read barrier.
1228 Label done; 1236 Label done;
1229 GetVar(rax, var); 1237 GetVar(rax, var);
1230 __ CompareRoot(rax, Heap::kTheHoleValueRootIndex); 1238 __ CompareRoot(rax, Heap::kTheHoleValueRootIndex);
1231 __ j(not_equal, &done, Label::kNear); 1239 __ j(not_equal, &done, Label::kNear);
1232 if (var->mode() == LET) { 1240 if (var->mode() == LET || var->mode() == CONST_HARMONY) {
1241 // Throw a reference error when using an uninitialized let/const
1242 // binding in harmony mode.
1233 __ Push(var->name()); 1243 __ Push(var->name());
1234 __ CallRuntime(Runtime::kThrowReferenceError, 1); 1244 __ CallRuntime(Runtime::kThrowReferenceError, 1);
1235 } else { // CONST 1245 } else {
1246 // Uninitalized const bindings outside of harmony mode are unholed.
1247 ASSERT(var->mode() == CONST);
1236 __ LoadRoot(rax, Heap::kUndefinedValueRootIndex); 1248 __ LoadRoot(rax, Heap::kUndefinedValueRootIndex);
1237 } 1249 }
1238 __ bind(&done); 1250 __ bind(&done);
1239 context()->Plug(rax); 1251 context()->Plug(rax);
1240 } 1252 }
1241 break; 1253 break;
1242 } 1254 }
1243 1255
1244 case Variable::LOOKUP: { 1256 case Variable::LOOKUP: {
1245 Label done, slow; 1257 Label done, slow;
(...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after
1847 __ CallRuntime(Runtime::kThrowReferenceError, 1); 1859 __ CallRuntime(Runtime::kThrowReferenceError, 1);
1848 __ bind(&assign); 1860 __ bind(&assign);
1849 __ movq(location, rax); 1861 __ movq(location, rax);
1850 if (var->IsContextSlot()) { 1862 if (var->IsContextSlot()) {
1851 __ movq(rdx, rax); 1863 __ movq(rdx, rax);
1852 __ RecordWriteContextSlot( 1864 __ RecordWriteContextSlot(
1853 rcx, Context::SlotOffset(var->index()), rdx, rbx, kDontSaveFPRegs); 1865 rcx, Context::SlotOffset(var->index()), rdx, rbx, kDontSaveFPRegs);
1854 } 1866 }
1855 } 1867 }
1856 1868
1857 } else if (var->mode() != CONST) { 1869 } else if (!var->is_const_mode() || op == Token::INIT_CONST_HARMONY) {
1858 // Assignment to var or initializing assignment to let. 1870 // Assignment to var or initializing assignment to let/const
1871 // in harmony mode.
1859 if (var->IsStackAllocated() || var->IsContextSlot()) { 1872 if (var->IsStackAllocated() || var->IsContextSlot()) {
1860 MemOperand location = VarOperand(var, rcx); 1873 MemOperand location = VarOperand(var, rcx);
1861 if (FLAG_debug_code && op == Token::INIT_LET) { 1874 if (FLAG_debug_code && op == Token::INIT_LET) {
1862 // Check for an uninitialized let binding. 1875 // Check for an uninitialized let binding.
1863 __ movq(rdx, location); 1876 __ movq(rdx, location);
1864 __ CompareRoot(rdx, Heap::kTheHoleValueRootIndex); 1877 __ CompareRoot(rdx, Heap::kTheHoleValueRootIndex);
1865 __ Check(equal, "Let binding re-initialization."); 1878 __ Check(equal, "Let binding re-initialization.");
1866 } 1879 }
1867 // Perform the assignment. 1880 // Perform the assignment.
1868 __ movq(location, rax); 1881 __ movq(location, rax);
(...skipping 2367 matching lines...) Expand 10 before | Expand all | Expand 10 after
4236 *context_length = 0; 4249 *context_length = 0;
4237 return previous_; 4250 return previous_;
4238 } 4251 }
4239 4252
4240 4253
4241 #undef __ 4254 #undef __
4242 4255
4243 } } // namespace v8::internal 4256 } } // namespace v8::internal
4244 4257
4245 #endif // V8_TARGET_ARCH_X64 4258 #endif // V8_TARGET_ARCH_X64
OLDNEW
« src/runtime.cc ('K') | « src/variables.cc ('k') | test/mjsunit/harmony/block-conflicts.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698