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 736 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
747 PrepareForBailout(expr, TOS_REG); | 747 PrepareForBailout(expr, TOS_REG); |
748 if (should_normalize) { | 748 if (should_normalize) { |
749 __ cmp(eax, isolate()->factory()->true_value()); | 749 __ cmp(eax, isolate()->factory()->true_value()); |
750 Split(equal, if_true, if_false, NULL); | 750 Split(equal, if_true, if_false, NULL); |
751 __ bind(&skip); | 751 __ bind(&skip); |
752 } | 752 } |
753 } | 753 } |
754 | 754 |
755 | 755 |
756 void FullCodeGenerator::EmitDebugCheckDeclarationContext(Variable* variable) { | 756 void FullCodeGenerator::EmitDebugCheckDeclarationContext(Variable* variable) { |
757 // The variable in the declaration always resides in the current function | 757 // The variable in the declaration always resides in the current context. |
758 // context. | |
759 ASSERT_EQ(0, scope()->ContextChainLength(variable->scope())); | 758 ASSERT_EQ(0, scope()->ContextChainLength(variable->scope())); |
760 if (generate_debug_code_) { | 759 if (generate_debug_code_) { |
761 // Check that we're not inside a with or catch context. | 760 // Check that we're not inside a with or catch context. |
762 __ mov(ebx, FieldOperand(esi, HeapObject::kMapOffset)); | 761 __ mov(ebx, FieldOperand(esi, HeapObject::kMapOffset)); |
763 __ cmp(ebx, isolate()->factory()->with_context_map()); | 762 __ cmp(ebx, isolate()->factory()->with_context_map()); |
764 __ Check(not_equal, "Declaration in with context."); | 763 __ Check(not_equal, "Declaration in with context."); |
765 __ cmp(ebx, isolate()->factory()->catch_context_map()); | 764 __ cmp(ebx, isolate()->factory()->catch_context_map()); |
766 __ Check(not_equal, "Declaration in catch context."); | 765 __ Check(not_equal, "Declaration in catch context."); |
767 } | 766 } |
768 } | 767 } |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
877 __ push(Immediate(Smi::FromInt(NONE))); | 876 __ push(Immediate(Smi::FromInt(NONE))); |
878 VisitForStackValue(declaration->fun()); | 877 VisitForStackValue(declaration->fun()); |
879 __ CallRuntime(Runtime::kDeclareContextSlot, 4); | 878 __ CallRuntime(Runtime::kDeclareContextSlot, 4); |
880 break; | 879 break; |
881 } | 880 } |
882 } | 881 } |
883 } | 882 } |
884 | 883 |
885 | 884 |
886 void FullCodeGenerator::VisitModuleDeclaration(ModuleDeclaration* declaration) { | 885 void FullCodeGenerator::VisitModuleDeclaration(ModuleDeclaration* declaration) { |
887 VariableProxy* proxy = declaration->proxy(); | 886 Variable* variable = declaration->proxy()->var(); |
888 Variable* variable = proxy->var(); | 887 ASSERT(variable->location() == Variable::CONTEXT); |
889 Handle<JSModule> instance = declaration->module()->interface()->Instance(); | 888 ASSERT(variable->interface()->IsFrozen()); |
890 ASSERT(!instance.is_null()); | |
891 | 889 |
892 switch (variable->location()) { | 890 Comment cmnt(masm_, "[ ModuleDeclaration"); |
893 case Variable::UNALLOCATED: { | 891 EmitDebugCheckDeclarationContext(variable); |
894 Comment cmnt(masm_, "[ ModuleDeclaration"); | |
895 globals_->Add(variable->name(), zone()); | |
896 globals_->Add(instance, zone()); | |
897 Visit(declaration->module()); | |
898 break; | |
899 } | |
900 | 892 |
901 case Variable::CONTEXT: { | 893 // Find hosting scope. |
902 Comment cmnt(masm_, "[ ModuleDeclaration"); | 894 Scope* host = scope_; |
903 EmitDebugCheckDeclarationContext(variable); | 895 while (host->is_module_scope()) host = host->outer_scope(); |
Michael Starzinger
2012/11/20 12:05:05
Can we move this into a Scope::GlobalScope() helpe
rossberg
2012/11/20 17:23:45
Done.
| |
904 __ mov(ContextOperand(esi, variable->index()), Immediate(instance)); | 896 ASSERT(host->is_global_scope()); |
905 Visit(declaration->module()); | |
906 break; | |
907 } | |
908 | 897 |
909 case Variable::PARAMETER: | 898 // Load instance object. |
910 case Variable::LOCAL: | 899 __ LoadContext(eax, scope_->ContextChainLength(host)); |
911 case Variable::LOOKUP: | 900 __ mov(eax, ContextOperand(eax, variable->interface()->Index())); |
912 UNREACHABLE(); | 901 __ mov(eax, ContextOperand(eax, Context::EXTENSION_INDEX)); |
913 } | 902 |
903 // Assign it. | |
904 __ mov(ContextOperand(esi, variable->index()), eax); | |
905 // We know that we have written a module, which is not a smi. | |
906 __ RecordWriteContextSlot(esi, | |
907 Context::SlotOffset(variable->index()), | |
908 eax, | |
909 ecx, | |
910 kDontSaveFPRegs, | |
911 EMIT_REMEMBERED_SET, | |
912 OMIT_SMI_CHECK); | |
913 PrepareForBailoutForId(declaration->proxy()->id(), NO_REGISTERS); | |
914 | |
915 // Traverse into body. | |
916 Visit(declaration->module()); | |
914 } | 917 } |
915 | 918 |
916 | 919 |
917 void FullCodeGenerator::VisitImportDeclaration(ImportDeclaration* declaration) { | 920 void FullCodeGenerator::VisitImportDeclaration(ImportDeclaration* declaration) { |
918 VariableProxy* proxy = declaration->proxy(); | 921 VariableProxy* proxy = declaration->proxy(); |
919 Variable* variable = proxy->var(); | 922 Variable* variable = proxy->var(); |
920 switch (variable->location()) { | 923 switch (variable->location()) { |
921 case Variable::UNALLOCATED: | 924 case Variable::UNALLOCATED: |
922 // TODO(rossberg) | 925 // TODO(rossberg) |
923 break; | 926 break; |
(...skipping 21 matching lines...) Expand all Loading... | |
945 void FullCodeGenerator::DeclareGlobals(Handle<FixedArray> pairs) { | 948 void FullCodeGenerator::DeclareGlobals(Handle<FixedArray> pairs) { |
946 // Call the runtime to declare the globals. | 949 // Call the runtime to declare the globals. |
947 __ push(esi); // The context is the first argument. | 950 __ push(esi); // The context is the first argument. |
948 __ push(Immediate(pairs)); | 951 __ push(Immediate(pairs)); |
949 __ push(Immediate(Smi::FromInt(DeclareGlobalsFlags()))); | 952 __ push(Immediate(Smi::FromInt(DeclareGlobalsFlags()))); |
950 __ CallRuntime(Runtime::kDeclareGlobals, 3); | 953 __ CallRuntime(Runtime::kDeclareGlobals, 3); |
951 // Return value is ignored. | 954 // Return value is ignored. |
952 } | 955 } |
953 | 956 |
954 | 957 |
958 void FullCodeGenerator::DeclareModules(Handle<FixedArray> descriptions) { | |
959 // Call the runtime to declare the modules. | |
960 __ push(Immediate(descriptions)); | |
961 __ CallRuntime(Runtime::kDeclareModules, 1); | |
962 // Return value is ignored. | |
963 } | |
964 | |
965 | |
955 void FullCodeGenerator::VisitSwitchStatement(SwitchStatement* stmt) { | 966 void FullCodeGenerator::VisitSwitchStatement(SwitchStatement* stmt) { |
956 Comment cmnt(masm_, "[ SwitchStatement"); | 967 Comment cmnt(masm_, "[ SwitchStatement"); |
957 Breakable nested_statement(this, stmt); | 968 Breakable nested_statement(this, stmt); |
958 SetStatementPosition(stmt); | 969 SetStatementPosition(stmt); |
959 | 970 |
960 // Keep the switch value on the stack until a case matches. | 971 // Keep the switch value on the stack until a case matches. |
961 VisitForStackValue(stmt->tag()); | 972 VisitForStackValue(stmt->tag()); |
962 PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS); | 973 PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS); |
963 | 974 |
964 ZoneList<CaseClause*>* clauses = stmt->cases(); | 975 ZoneList<CaseClause*>* clauses = stmt->cases(); |
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1339 // eval-introduced variables. Eval is used a lot without | 1350 // eval-introduced variables. Eval is used a lot without |
1340 // introducing variables. In those cases, we do not want to | 1351 // introducing variables. In those cases, we do not want to |
1341 // perform a runtime call for all variables in the scope | 1352 // perform a runtime call for all variables in the scope |
1342 // containing the eval. | 1353 // containing the eval. |
1343 if (var->mode() == DYNAMIC_GLOBAL) { | 1354 if (var->mode() == DYNAMIC_GLOBAL) { |
1344 EmitLoadGlobalCheckExtensions(var, typeof_state, slow); | 1355 EmitLoadGlobalCheckExtensions(var, typeof_state, slow); |
1345 __ jmp(done); | 1356 __ jmp(done); |
1346 } else if (var->mode() == DYNAMIC_LOCAL) { | 1357 } else if (var->mode() == DYNAMIC_LOCAL) { |
1347 Variable* local = var->local_if_not_shadowed(); | 1358 Variable* local = var->local_if_not_shadowed(); |
1348 __ mov(eax, ContextSlotOperandCheckExtensions(local, slow)); | 1359 __ mov(eax, ContextSlotOperandCheckExtensions(local, slow)); |
1349 if (local->mode() == CONST || | 1360 if (local->mode() == LET || |
1350 local->mode() == CONST_HARMONY || | 1361 local->mode() == CONST || |
1351 local->mode() == LET) { | 1362 local->mode() == CONST_HARMONY) { |
1352 __ cmp(eax, isolate()->factory()->the_hole_value()); | 1363 __ cmp(eax, isolate()->factory()->the_hole_value()); |
1353 __ j(not_equal, done); | 1364 __ j(not_equal, done); |
1354 if (local->mode() == CONST) { | 1365 if (local->mode() == CONST) { |
1355 __ mov(eax, isolate()->factory()->undefined_value()); | 1366 __ mov(eax, isolate()->factory()->undefined_value()); |
1356 } else { // LET || CONST_HARMONY | 1367 } else { // LET || CONST_HARMONY |
1357 __ push(Immediate(var->name())); | 1368 __ push(Immediate(var->name())); |
1358 __ CallRuntime(Runtime::kThrowReferenceError, 1); | 1369 __ CallRuntime(Runtime::kThrowReferenceError, 1); |
1359 } | 1370 } |
1360 } | 1371 } |
1361 __ jmp(done); | 1372 __ jmp(done); |
(...skipping 3155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4517 *stack_depth = 0; | 4528 *stack_depth = 0; |
4518 *context_length = 0; | 4529 *context_length = 0; |
4519 return previous_; | 4530 return previous_; |
4520 } | 4531 } |
4521 | 4532 |
4522 #undef __ | 4533 #undef __ |
4523 | 4534 |
4524 } } // namespace v8::internal | 4535 } } // namespace v8::internal |
4525 | 4536 |
4526 #endif // V8_TARGET_ARCH_IA32 | 4537 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |