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 1950 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1961 }; | 1961 }; |
1962 | 1962 |
1963 for (size_t i = 0; i < arraysize(snippets); i++) { | 1963 for (size_t i = 0; i < arraysize(snippets); i++) { |
1964 Handle<BytecodeArray> bytecode_array = | 1964 Handle<BytecodeArray> bytecode_array = |
1965 helper.MakeTopLevelBytecode(snippets[i].code_snippet); | 1965 helper.MakeTopLevelBytecode(snippets[i].code_snippet); |
1966 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 1966 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
1967 } | 1967 } |
1968 } | 1968 } |
1969 | 1969 |
1970 | 1970 |
| 1971 TEST(BreakableBlocks) { |
| 1972 InitializedHandleScope handle_scope; |
| 1973 BytecodeGeneratorHelper helper; |
| 1974 |
| 1975 ExpectedSnippet<int> snippets[] = { |
| 1976 {"var x = 0;\n" |
| 1977 "label: {\n" |
| 1978 " x = x + 1;\n" |
| 1979 " break label;\n" |
| 1980 " x = x + 1;\n" |
| 1981 "}\n" |
| 1982 "return x;", |
| 1983 1 * kPointerSize, |
| 1984 1, |
| 1985 14, |
| 1986 { |
| 1987 B(LdaZero), // |
| 1988 B(Star), R(0), // |
| 1989 B(LdaSmi8), U8(1), // |
| 1990 B(Add), R(0), // |
| 1991 B(Star), R(0), // |
| 1992 B(Jump), U8(2), // |
| 1993 B(Ldar), R(0), // |
| 1994 B(Return) // |
| 1995 }}, |
| 1996 {"var sum = 0;\n" |
| 1997 "outer: {\n" |
| 1998 " for (var x = 0; x < 10; ++x) {\n" |
| 1999 " for (var y = 0; y < 3; ++y) {\n" |
| 2000 " ++sum;\n" |
| 2001 " if (x + y == 12) { break outer; }\n" |
| 2002 " }\n" |
| 2003 " }\n" |
| 2004 "}\n" |
| 2005 "return sum;", |
| 2006 4 * kPointerSize, |
| 2007 1, |
| 2008 60, |
| 2009 { |
| 2010 B(LdaZero), // |
| 2011 B(Star), R(0), // |
| 2012 B(LdaZero), // |
| 2013 B(Star), R(1), // |
| 2014 B(LdaSmi8), U8(10), // |
| 2015 B(TestLessThan), R(1), // |
| 2016 B(JumpIfFalse), U8(47), // |
| 2017 B(LdaZero), // |
| 2018 B(Star), R(2), // |
| 2019 B(LdaSmi8), U8(3), // |
| 2020 B(TestLessThan), R(2), // |
| 2021 B(JumpIfFalse), U8(30), // |
| 2022 B(Ldar), R(0), // |
| 2023 B(ToNumber), // |
| 2024 B(Inc), // |
| 2025 B(Star), R(0), // |
| 2026 B(Ldar), R(2), // |
| 2027 B(Add), R(1), // |
| 2028 B(Star), R(3), // |
| 2029 B(LdaSmi8), U8(12), // |
| 2030 B(TestEqual), R(3), // |
| 2031 B(JumpIfFalse), U8(4), // |
| 2032 B(Jump), U8(18), // |
| 2033 B(Ldar), R(2), // |
| 2034 B(ToNumber), // |
| 2035 B(Inc), // |
| 2036 B(Star), R(2), // |
| 2037 B(Jump), U8(-32), // |
| 2038 B(Ldar), R(1), // |
| 2039 B(ToNumber), // |
| 2040 B(Inc), // |
| 2041 B(Star), R(1), // |
| 2042 B(Jump), U8(-49), // |
| 2043 B(Ldar), R(0), // |
| 2044 B(Return), // |
| 2045 }}, |
| 2046 }; |
| 2047 |
| 2048 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 2049 Handle<BytecodeArray> bytecode_array = |
| 2050 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 2051 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 2052 } |
| 2053 } |
| 2054 |
| 2055 |
1971 TEST(BasicLoops) { | 2056 TEST(BasicLoops) { |
1972 InitializedHandleScope handle_scope; | 2057 InitializedHandleScope handle_scope; |
1973 BytecodeGeneratorHelper helper; | 2058 BytecodeGeneratorHelper helper; |
1974 | 2059 |
1975 ExpectedSnippet<int> snippets[] = { | 2060 ExpectedSnippet<int> snippets[] = { |
1976 {"var x = 0;\n" | 2061 {"var x = 0;\n" |
1977 "while (false) { x = 99; break; continue; }\n" | 2062 "while (false) { x = 99; break; continue; }\n" |
1978 "return x;", | 2063 "return x;", |
1979 1 * kPointerSize, | 2064 1 * kPointerSize, |
1980 1, | 2065 1, |
(...skipping 3649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5630 for (size_t i = 0; i < arraysize(snippets); i++) { | 5715 for (size_t i = 0; i < arraysize(snippets); i++) { |
5631 Handle<BytecodeArray> bytecode_array = | 5716 Handle<BytecodeArray> bytecode_array = |
5632 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 5717 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
5633 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 5718 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
5634 } | 5719 } |
5635 } | 5720 } |
5636 | 5721 |
5637 } // namespace interpreter | 5722 } // namespace interpreter |
5638 } // namespace internal | 5723 } // namespace internal |
5639 } // namespace v8 | 5724 } // namespace v8 |
OLD | NEW |