| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 741 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 752 PrepareForBailout(expr, TOS_REG); | 752 PrepareForBailout(expr, TOS_REG); |
| 753 if (should_normalize) { | 753 if (should_normalize) { |
| 754 __ CompareRoot(rax, Heap::kTrueValueRootIndex); | 754 __ CompareRoot(rax, Heap::kTrueValueRootIndex); |
| 755 Split(equal, if_true, if_false, NULL); | 755 Split(equal, if_true, if_false, NULL); |
| 756 __ bind(&skip); | 756 __ bind(&skip); |
| 757 } | 757 } |
| 758 } | 758 } |
| 759 | 759 |
| 760 | 760 |
| 761 void FullCodeGenerator::EmitDebugCheckDeclarationContext(Variable* variable) { | 761 void FullCodeGenerator::EmitDebugCheckDeclarationContext(Variable* variable) { |
| 762 // The variable in the declaration always resides in the current function | 762 // The variable in the declaration always resides in the current context. |
| 763 // context. | |
| 764 ASSERT_EQ(0, scope()->ContextChainLength(variable->scope())); | 763 ASSERT_EQ(0, scope()->ContextChainLength(variable->scope())); |
| 765 if (generate_debug_code_) { | 764 if (generate_debug_code_) { |
| 766 // Check that we're not inside a with or catch context. | 765 // Check that we're not inside a with or catch context. |
| 767 __ movq(rbx, FieldOperand(rsi, HeapObject::kMapOffset)); | 766 __ movq(rbx, FieldOperand(rsi, HeapObject::kMapOffset)); |
| 768 __ CompareRoot(rbx, Heap::kWithContextMapRootIndex); | 767 __ CompareRoot(rbx, Heap::kWithContextMapRootIndex); |
| 769 __ Check(not_equal, "Declaration in with context."); | 768 __ Check(not_equal, "Declaration in with context."); |
| 770 __ CompareRoot(rbx, Heap::kCatchContextMapRootIndex); | 769 __ CompareRoot(rbx, Heap::kCatchContextMapRootIndex); |
| 771 __ Check(not_equal, "Declaration in catch context."); | 770 __ Check(not_equal, "Declaration in catch context."); |
| 772 } | 771 } |
| 773 } | 772 } |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 884 __ Push(Smi::FromInt(NONE)); | 883 __ Push(Smi::FromInt(NONE)); |
| 885 VisitForStackValue(declaration->fun()); | 884 VisitForStackValue(declaration->fun()); |
| 886 __ CallRuntime(Runtime::kDeclareContextSlot, 4); | 885 __ CallRuntime(Runtime::kDeclareContextSlot, 4); |
| 887 break; | 886 break; |
| 888 } | 887 } |
| 889 } | 888 } |
| 890 } | 889 } |
| 891 | 890 |
| 892 | 891 |
| 893 void FullCodeGenerator::VisitModuleDeclaration(ModuleDeclaration* declaration) { | 892 void FullCodeGenerator::VisitModuleDeclaration(ModuleDeclaration* declaration) { |
| 894 VariableProxy* proxy = declaration->proxy(); | 893 Variable* variable = declaration->proxy()->var(); |
| 895 Variable* variable = proxy->var(); | 894 ASSERT(variable->location() == Variable::CONTEXT); |
| 896 Handle<JSModule> instance = declaration->module()->interface()->Instance(); | 895 ASSERT(variable->interface()->IsFrozen()); |
| 897 ASSERT(!instance.is_null()); | |
| 898 | 896 |
| 899 switch (variable->location()) { | 897 Comment cmnt(masm_, "[ ModuleDeclaration"); |
| 900 case Variable::UNALLOCATED: { | 898 EmitDebugCheckDeclarationContext(variable); |
| 901 Comment cmnt(masm_, "[ ModuleDeclaration"); | |
| 902 globals_->Add(variable->name(), zone()); | |
| 903 globals_->Add(instance, zone()); | |
| 904 Visit(declaration->module()); | |
| 905 break; | |
| 906 } | |
| 907 | 899 |
| 908 case Variable::CONTEXT: { | 900 // Load instance object. |
| 909 Comment cmnt(masm_, "[ ModuleDeclaration"); | 901 __ LoadContext(rax, scope_->ContextChainLength(scope_->GlobalScope())); |
| 910 EmitDebugCheckDeclarationContext(variable); | 902 __ movq(rax, ContextOperand(rax, variable->interface()->Index())); |
| 911 __ Move(ContextOperand(rsi, variable->index()), instance); | 903 __ movq(rax, ContextOperand(rax, Context::EXTENSION_INDEX)); |
| 912 Visit(declaration->module()); | |
| 913 break; | |
| 914 } | |
| 915 | 904 |
| 916 case Variable::PARAMETER: | 905 // Assign it. |
| 917 case Variable::LOCAL: | 906 __ movq(ContextOperand(rsi, variable->index()), rax); |
| 918 case Variable::LOOKUP: | 907 // We know that we have written a module, which is not a smi. |
| 919 UNREACHABLE(); | 908 __ RecordWriteContextSlot(rsi, |
| 920 } | 909 Context::SlotOffset(variable->index()), |
| 910 rax, |
| 911 rcx, |
| 912 kDontSaveFPRegs, |
| 913 EMIT_REMEMBERED_SET, |
| 914 OMIT_SMI_CHECK); |
| 915 PrepareForBailoutForId(declaration->proxy()->id(), NO_REGISTERS); |
| 916 |
| 917 // Traverse into body. |
| 918 Visit(declaration->module()); |
| 921 } | 919 } |
| 922 | 920 |
| 923 | 921 |
| 924 void FullCodeGenerator::VisitImportDeclaration(ImportDeclaration* declaration) { | 922 void FullCodeGenerator::VisitImportDeclaration(ImportDeclaration* declaration) { |
| 925 VariableProxy* proxy = declaration->proxy(); | 923 VariableProxy* proxy = declaration->proxy(); |
| 926 Variable* variable = proxy->var(); | 924 Variable* variable = proxy->var(); |
| 927 switch (variable->location()) { | 925 switch (variable->location()) { |
| 928 case Variable::UNALLOCATED: | 926 case Variable::UNALLOCATED: |
| 929 // TODO(rossberg) | 927 // TODO(rossberg) |
| 930 break; | 928 break; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 952 void FullCodeGenerator::DeclareGlobals(Handle<FixedArray> pairs) { | 950 void FullCodeGenerator::DeclareGlobals(Handle<FixedArray> pairs) { |
| 953 // Call the runtime to declare the globals. | 951 // Call the runtime to declare the globals. |
| 954 __ push(rsi); // The context is the first argument. | 952 __ push(rsi); // The context is the first argument. |
| 955 __ Push(pairs); | 953 __ Push(pairs); |
| 956 __ Push(Smi::FromInt(DeclareGlobalsFlags())); | 954 __ Push(Smi::FromInt(DeclareGlobalsFlags())); |
| 957 __ CallRuntime(Runtime::kDeclareGlobals, 3); | 955 __ CallRuntime(Runtime::kDeclareGlobals, 3); |
| 958 // Return value is ignored. | 956 // Return value is ignored. |
| 959 } | 957 } |
| 960 | 958 |
| 961 | 959 |
| 960 void FullCodeGenerator::DeclareModules(Handle<FixedArray> descriptions) { |
| 961 // Call the runtime to declare the modules. |
| 962 __ Push(descriptions); |
| 963 __ CallRuntime(Runtime::kDeclareModules, 1); |
| 964 // Return value is ignored. |
| 965 } |
| 966 |
| 967 |
| 962 void FullCodeGenerator::VisitSwitchStatement(SwitchStatement* stmt) { | 968 void FullCodeGenerator::VisitSwitchStatement(SwitchStatement* stmt) { |
| 963 Comment cmnt(masm_, "[ SwitchStatement"); | 969 Comment cmnt(masm_, "[ SwitchStatement"); |
| 964 Breakable nested_statement(this, stmt); | 970 Breakable nested_statement(this, stmt); |
| 965 SetStatementPosition(stmt); | 971 SetStatementPosition(stmt); |
| 966 | 972 |
| 967 // Keep the switch value on the stack until a case matches. | 973 // Keep the switch value on the stack until a case matches. |
| 968 VisitForStackValue(stmt->tag()); | 974 VisitForStackValue(stmt->tag()); |
| 969 PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS); | 975 PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS); |
| 970 | 976 |
| 971 ZoneList<CaseClause*>* clauses = stmt->cases(); | 977 ZoneList<CaseClause*>* clauses = stmt->cases(); |
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1361 // eval-introduced variables. Eval is used a lot without | 1367 // eval-introduced variables. Eval is used a lot without |
| 1362 // introducing variables. In those cases, we do not want to | 1368 // introducing variables. In those cases, we do not want to |
| 1363 // perform a runtime call for all variables in the scope | 1369 // perform a runtime call for all variables in the scope |
| 1364 // containing the eval. | 1370 // containing the eval. |
| 1365 if (var->mode() == DYNAMIC_GLOBAL) { | 1371 if (var->mode() == DYNAMIC_GLOBAL) { |
| 1366 EmitLoadGlobalCheckExtensions(var, typeof_state, slow); | 1372 EmitLoadGlobalCheckExtensions(var, typeof_state, slow); |
| 1367 __ jmp(done); | 1373 __ jmp(done); |
| 1368 } else if (var->mode() == DYNAMIC_LOCAL) { | 1374 } else if (var->mode() == DYNAMIC_LOCAL) { |
| 1369 Variable* local = var->local_if_not_shadowed(); | 1375 Variable* local = var->local_if_not_shadowed(); |
| 1370 __ movq(rax, ContextSlotOperandCheckExtensions(local, slow)); | 1376 __ movq(rax, ContextSlotOperandCheckExtensions(local, slow)); |
| 1371 if (local->mode() == CONST || | 1377 if (local->mode() == LET || |
| 1372 local->mode() == CONST_HARMONY || | 1378 local->mode() == CONST || |
| 1373 local->mode() == LET) { | 1379 local->mode() == CONST_HARMONY) { |
| 1374 __ CompareRoot(rax, Heap::kTheHoleValueRootIndex); | 1380 __ CompareRoot(rax, Heap::kTheHoleValueRootIndex); |
| 1375 __ j(not_equal, done); | 1381 __ j(not_equal, done); |
| 1376 if (local->mode() == CONST) { | 1382 if (local->mode() == CONST) { |
| 1377 __ LoadRoot(rax, Heap::kUndefinedValueRootIndex); | 1383 __ LoadRoot(rax, Heap::kUndefinedValueRootIndex); |
| 1378 } else { // LET || CONST_HARMONY | 1384 } else { // LET || CONST_HARMONY |
| 1379 __ Push(var->name()); | 1385 __ Push(var->name()); |
| 1380 __ CallRuntime(Runtime::kThrowReferenceError, 1); | 1386 __ CallRuntime(Runtime::kThrowReferenceError, 1); |
| 1381 } | 1387 } |
| 1382 } | 1388 } |
| 1383 __ jmp(done); | 1389 __ jmp(done); |
| (...skipping 3130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4514 *context_length = 0; | 4520 *context_length = 0; |
| 4515 return previous_; | 4521 return previous_; |
| 4516 } | 4522 } |
| 4517 | 4523 |
| 4518 | 4524 |
| 4519 #undef __ | 4525 #undef __ |
| 4520 | 4526 |
| 4521 } } // namespace v8::internal | 4527 } } // namespace v8::internal |
| 4522 | 4528 |
| 4523 #endif // V8_TARGET_ARCH_X64 | 4529 #endif // V8_TARGET_ARCH_X64 |
| OLD | NEW |