OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/interpreter/bytecode-generator.h" | 5 #include "src/interpreter/bytecode-generator.h" |
6 | 6 |
7 #include "src/ast/scopes.h" | 7 #include "src/ast/scopes.h" |
8 #include "src/compiler.h" | 8 #include "src/compiler.h" |
9 #include "src/interpreter/control-flow-builders.h" | 9 #include "src/interpreter/control-flow-builders.h" |
10 #include "src/objects.h" | 10 #include "src/objects.h" |
(...skipping 833 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
844 } | 844 } |
845 case NAMED_SUPER_PROPERTY: | 845 case NAMED_SUPER_PROPERTY: |
846 case KEYED_SUPER_PROPERTY: | 846 case KEYED_SUPER_PROPERTY: |
847 UNIMPLEMENTED(); | 847 UNIMPLEMENTED(); |
848 } | 848 } |
849 } | 849 } |
850 | 850 |
851 | 851 |
852 void BytecodeGenerator::VisitForInStatement(ForInStatement* stmt) { | 852 void BytecodeGenerator::VisitForInStatement(ForInStatement* stmt) { |
853 EffectResultScope statement_result_scope(this); | 853 EffectResultScope statement_result_scope(this); |
854 | |
855 if (stmt->subject()->IsNullLiteral() || | 854 if (stmt->subject()->IsNullLiteral() || |
856 stmt->subject()->IsUndefinedLiteral(isolate())) { | 855 stmt->subject()->IsUndefinedLiteral(isolate())) { |
857 // ForIn generates lots of code, skip if it wouldn't produce any effects. | 856 // ForIn generates lots of code, skip if it wouldn't produce any effects. |
858 return; | 857 return; |
859 } | 858 } |
860 | 859 |
861 LoopBuilder loop_builder(builder()); | 860 LoopBuilder loop_builder(builder()); |
862 ControlScopeForIteration control_scope(this, stmt, &loop_builder); | 861 ControlScopeForIteration control_scope(this, stmt, &loop_builder); |
863 | 862 |
864 // Prepare the state for executing ForIn. | 863 // Prepare the state for executing ForIn. |
865 VisitForAccumulatorValue(stmt->subject()); | 864 VisitForAccumulatorValue(stmt->subject()); |
866 loop_builder.BreakIfUndefined(); | 865 loop_builder.BreakIfUndefined(); |
867 loop_builder.BreakIfNull(); | 866 loop_builder.BreakIfNull(); |
868 | |
869 Register receiver = execution_result()->NewRegister(); | 867 Register receiver = execution_result()->NewRegister(); |
870 builder()->CastAccumulatorToJSObject(); | 868 Register cache_type = execution_result()->NewRegister(); |
871 builder()->StoreAccumulatorInRegister(receiver); | 869 Register cache_array = execution_result()->NewRegister(); |
872 builder()->CallRuntime(Runtime::kGetPropertyNamesFast, receiver, 1); | 870 Register cache_length = execution_result()->NewRegister(); |
873 builder()->ForInPrepare(receiver); | 871 builder()->ForInPrepare(receiver, cache_type, cache_array, cache_length); |
874 loop_builder.BreakIfUndefined(); | |
875 | |
876 Register for_in_state = execution_result()->NewRegister(); | |
877 builder()->StoreAccumulatorInRegister(for_in_state); | |
878 | 872 |
879 // Check loop termination (accumulator holds index). | 873 // Check loop termination (accumulator holds index). |
880 Register index = receiver; // Re-using register as receiver no longer used. | 874 Register index = execution_result()->NewRegister(); |
881 builder()->LoadLiteral(Smi::FromInt(0)); | 875 builder()->LoadLiteral(Smi::FromInt(0)); |
| 876 builder()->StoreAccumulatorInRegister(index); |
882 loop_builder.LoopHeader(); | 877 loop_builder.LoopHeader(); |
883 loop_builder.Condition(); | 878 loop_builder.Condition(); |
884 builder()->StoreAccumulatorInRegister(index).ForInDone(for_in_state); | 879 builder()->ForInDone(index, cache_length); |
885 loop_builder.BreakIfTrue(); | 880 loop_builder.BreakIfTrue(); |
886 builder()->ForInNext(for_in_state, index); | 881 builder()->ForInNext(receiver, cache_type, cache_array, index); |
887 loop_builder.ContinueIfUndefined(); | 882 loop_builder.ContinueIfUndefined(); |
888 | |
889 VisitForInAssignment(stmt->each(), stmt->EachFeedbackSlot()); | 883 VisitForInAssignment(stmt->each(), stmt->EachFeedbackSlot()); |
890 Visit(stmt->body()); | 884 Visit(stmt->body()); |
891 | |
892 // TODO(oth): replace CountOperation here with ForInStep. | |
893 loop_builder.Next(); | 885 loop_builder.Next(); |
894 builder()->LoadAccumulatorWithRegister(index).CountOperation( | 886 builder()->ForInStep(index); |
895 Token::Value::ADD, language_mode_strength()); | |
896 loop_builder.JumpToHeader(); | 887 loop_builder.JumpToHeader(); |
897 loop_builder.LoopEnd(); | 888 loop_builder.LoopEnd(); |
898 } | 889 } |
899 | 890 |
900 | 891 |
901 void BytecodeGenerator::VisitForOfStatement(ForOfStatement* stmt) { | 892 void BytecodeGenerator::VisitForOfStatement(ForOfStatement* stmt) { |
902 UNIMPLEMENTED(); | 893 UNIMPLEMENTED(); |
903 } | 894 } |
904 | 895 |
905 | 896 |
(...skipping 1292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2198 } | 2189 } |
2199 | 2190 |
2200 | 2191 |
2201 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { | 2192 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { |
2202 return info()->feedback_vector()->GetIndex(slot); | 2193 return info()->feedback_vector()->GetIndex(slot); |
2203 } | 2194 } |
2204 | 2195 |
2205 } // namespace interpreter | 2196 } // namespace interpreter |
2206 } // namespace internal | 2197 } // namespace internal |
2207 } // namespace v8 | 2198 } // namespace v8 |
OLD | NEW |