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/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/compiler.h" | 7 #include "src/compiler.h" |
8 #include "src/interpreter/bytecode-array-iterator.h" | 8 #include "src/interpreter/bytecode-array-iterator.h" |
9 #include "src/interpreter/bytecode-generator.h" | 9 #include "src/interpreter/bytecode-generator.h" |
10 #include "src/interpreter/interpreter.h" | 10 #include "src/interpreter/interpreter.h" |
(...skipping 2283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2294 B(Ldar), R(0), // | 2294 B(Ldar), R(0), // |
2295 B(Star), R(1), // | 2295 B(Star), R(1), // |
2296 B(Jump), U8(2), // | 2296 B(Jump), U8(2), // |
2297 B(PopContext), R(context), // | 2297 B(PopContext), R(context), // |
2298 B(LdaUndefined), // | 2298 B(LdaUndefined), // |
2299 B(Return), // | 2299 B(Return), // |
2300 }, | 2300 }, |
2301 2, | 2301 2, |
2302 {InstanceType::FIXED_ARRAY_TYPE, | 2302 {InstanceType::FIXED_ARRAY_TYPE, |
2303 InstanceType::SHARED_FUNCTION_INFO_TYPE}}, | 2303 InstanceType::SHARED_FUNCTION_INFO_TYPE}}, |
| 2304 {"let x = 1;\n" |
| 2305 "outer: {\n" |
| 2306 " inner: {\n" |
| 2307 " let y = 2;\n" |
| 2308 " function f() { return x + y; }\n" |
| 2309 " if (y) break outer;\n" |
| 2310 " y = 3;\n" |
| 2311 " }\n" |
| 2312 "}\n" |
| 2313 "x = 4;", |
| 2314 6 * kPointerSize, |
| 2315 1, |
| 2316 72, |
| 2317 { |
| 2318 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // |
| 2319 U8(1), // |
| 2320 B(PushContext), R(2), // |
| 2321 B(LdaTheHole), // |
| 2322 B(StaContextSlot), R(2), U8(4), // |
| 2323 B(LdaSmi8), U8(1), // |
| 2324 B(StaContextSlot), R(2), U8(4), // |
| 2325 B(LdaConstant), U8(0), // |
| 2326 B(Star), R(4), // |
| 2327 B(Ldar), R(closure), // |
| 2328 B(Star), R(5), // |
| 2329 B(CallRuntime), U16(Runtime::kPushBlockContext), R(4), U8(2), // |
| 2330 B(PushContext), R(3), // |
| 2331 B(LdaTheHole), // |
| 2332 B(StaContextSlot), R(3), U8(4), // |
| 2333 B(CreateClosure), U8(1), U8(0), // |
| 2334 B(Star), R(0), // |
| 2335 B(LdaSmi8), U8(2), // |
| 2336 B(StaContextSlot), R(3), U8(4), // |
| 2337 B(Ldar), R(0), // |
| 2338 B(Star), R(1), // |
| 2339 B(LdaContextSlot), R(3), U8(4), // |
| 2340 B(JumpIfToBooleanFalse), U8(6), // |
| 2341 B(PopContext), R(2), // |
| 2342 B(Jump), U8(9), // |
| 2343 B(LdaSmi8), U8(3), // |
| 2344 B(StaContextSlot), R(3), U8(4), // |
| 2345 B(PopContext), R(2), // |
| 2346 B(LdaSmi8), U8(4), // |
| 2347 B(StaContextSlot), R(2), U8(4), // |
| 2348 B(LdaUndefined), // |
| 2349 B(Return), // |
| 2350 }, |
| 2351 2, |
| 2352 {InstanceType::FIXED_ARRAY_TYPE, |
| 2353 InstanceType::SHARED_FUNCTION_INFO_TYPE}}, |
2304 }; | 2354 }; |
2305 | 2355 |
2306 for (size_t i = 0; i < arraysize(snippets); i++) { | 2356 for (size_t i = 0; i < arraysize(snippets); i++) { |
2307 Handle<BytecodeArray> bytecode_array = | 2357 Handle<BytecodeArray> bytecode_array = |
2308 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 2358 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
2309 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 2359 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
2310 } | 2360 } |
2311 } | 2361 } |
2312 | 2362 |
2313 | 2363 |
2314 TEST(BasicLoops) { | 2364 TEST(BasicLoops) { |
2315 InitializedHandleScope handle_scope; | 2365 InitializedHandleScope handle_scope; |
2316 BytecodeGeneratorHelper helper; | 2366 BytecodeGeneratorHelper helper; |
2317 | 2367 |
2318 ExpectedSnippet<int> snippets[] = { | 2368 int closure = Register::function_closure().index(); |
| 2369 int context = Register::function_context().index(); |
| 2370 |
| 2371 ExpectedSnippet<InstanceType> snippets[] = { |
2319 {"var x = 0;\n" | 2372 {"var x = 0;\n" |
2320 "while (false) { x = 99; break; continue; }\n" | 2373 "while (false) { x = 99; break; continue; }\n" |
2321 "return x;", | 2374 "return x;", |
2322 1 * kPointerSize, | 2375 1 * kPointerSize, |
2323 1, | 2376 1, |
2324 4, | 2377 4, |
2325 { | 2378 { |
2326 B(LdaZero), // | 2379 B(LdaZero), // |
2327 B(Star), R(0), // | 2380 B(Star), R(0), // |
2328 B(Return) // | 2381 B(Return) // |
(...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2920 B(Jump), U8(10), // | 2973 B(Jump), U8(10), // |
2921 B(Ldar), R(1), // | 2974 B(Ldar), R(1), // |
2922 B(ToNumber), // | 2975 B(ToNumber), // |
2923 B(Inc), // | 2976 B(Inc), // |
2924 B(Star), R(1), // | 2977 B(Star), R(1), // |
2925 B(Jump), U8(-26), // | 2978 B(Jump), U8(-26), // |
2926 B(Ldar), R(0), // | 2979 B(Ldar), R(0), // |
2927 B(Return), // | 2980 B(Return), // |
2928 }, | 2981 }, |
2929 0}, | 2982 0}, |
| 2983 {"var a = 0;\n" |
| 2984 "while (a) {\n" |
| 2985 " { \n" |
| 2986 " let z = 1;\n" |
| 2987 " function f() { z = 2; }\n" |
| 2988 " if (z) continue;\n" |
| 2989 " z++;\n" |
| 2990 " }\n" |
| 2991 "}\n", |
| 2992 6 * kPointerSize, |
| 2993 1, |
| 2994 65, |
| 2995 { |
| 2996 B(LdaZero), // |
| 2997 B(Star), R(1), // |
| 2998 B(Ldar), R(1), // |
| 2999 B(JumpIfToBooleanFalse), U8(58), // |
| 3000 B(LdaConstant), U8(0), // |
| 3001 B(Star), R(4), // |
| 3002 B(Ldar), R(closure), // |
| 3003 B(Star), R(5), // |
| 3004 B(CallRuntime), U16(Runtime::kPushBlockContext), R(4), U8(2), // |
| 3005 B(PushContext), R(3), // |
| 3006 B(LdaTheHole), // |
| 3007 B(StaContextSlot), R(3), U8(4), // |
| 3008 B(CreateClosure), U8(1), U8(0), // |
| 3009 B(Star), R(0), // |
| 3010 B(LdaSmi8), U8(1), // |
| 3011 B(StaContextSlot), R(3), U8(4), // |
| 3012 B(Ldar), R(0), // |
| 3013 B(Star), R(2), // |
| 3014 B(LdaContextSlot), R(3), U8(4), // |
| 3015 B(JumpIfToBooleanFalse), U8(6), // |
| 3016 B(PopContext), R(context), // |
| 3017 B(Jump), U8(-44), // |
| 3018 B(LdaContextSlot), R(3), U8(4), // |
| 3019 B(ToNumber), // |
| 3020 B(Star), R(4), // |
| 3021 B(Inc), // |
| 3022 B(StaContextSlot), R(3), U8(4), // |
| 3023 B(PopContext), R(context), // |
| 3024 B(Jump), U8(-58), // |
| 3025 B(LdaUndefined), // |
| 3026 B(Return), // |
| 3027 }, |
| 3028 2, |
| 3029 {InstanceType::FIXED_ARRAY_TYPE, |
| 3030 InstanceType::SHARED_FUNCTION_INFO_TYPE}}, |
2930 }; | 3031 }; |
2931 | 3032 |
2932 for (size_t i = 0; i < arraysize(snippets); i++) { | 3033 for (size_t i = 0; i < arraysize(snippets); i++) { |
2933 Handle<BytecodeArray> bytecode_array = | 3034 Handle<BytecodeArray> bytecode_array = |
2934 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 3035 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
2935 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 3036 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
2936 } | 3037 } |
2937 } | 3038 } |
2938 | 3039 |
2939 | 3040 |
(...skipping 3822 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6762 std::string(function_epilogue); | 6863 std::string(function_epilogue); |
6763 Handle<BytecodeArray> bytecode_array = | 6864 Handle<BytecodeArray> bytecode_array = |
6764 helper.MakeBytecode(script.c_str(), "*", "f"); | 6865 helper.MakeBytecode(script.c_str(), "*", "f"); |
6765 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 6866 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
6766 } | 6867 } |
6767 } | 6868 } |
6768 | 6869 |
6769 } // namespace interpreter | 6870 } // namespace interpreter |
6770 } // namespace internal | 6871 } // namespace internal |
6771 } // namespace v8 | 6872 } // namespace v8 |
OLD | NEW |