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 1242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1253 0}, | 1253 0}, |
1254 }; | 1254 }; |
1255 | 1255 |
1256 for (size_t i = 0; i < arraysize(snippets); i++) { | 1256 for (size_t i = 0; i < arraysize(snippets); i++) { |
1257 Handle<BytecodeArray> bytecode_array = | 1257 Handle<BytecodeArray> bytecode_array = |
1258 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 1258 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
1259 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 1259 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
1260 } | 1260 } |
1261 } | 1261 } |
1262 | 1262 |
| 1263 |
| 1264 TEST(UnaryOperators) { |
| 1265 InitializedHandleScope handle_scope; |
| 1266 BytecodeGeneratorHelper helper; |
| 1267 |
| 1268 ExpectedSnippet<int> snippets[] = { |
| 1269 {"var x = 0;" |
| 1270 "while (x != 10) {" |
| 1271 " x = x + 10;" |
| 1272 "}" |
| 1273 "return x;", |
| 1274 2 * kPointerSize, |
| 1275 1, |
| 1276 29, |
| 1277 { |
| 1278 B(LdaZero), // |
| 1279 B(Star), R(0), // |
| 1280 B(Jump), U8(12), // |
| 1281 B(Ldar), R(0), // |
| 1282 B(Star), R(1), // |
| 1283 B(LdaSmi8), U8(10), // |
| 1284 B(Add), R(1), // |
| 1285 B(Star), R(0), // |
| 1286 B(Ldar), R(0), // |
| 1287 B(Star), R(1), // |
| 1288 B(LdaSmi8), U8(10), // |
| 1289 B(TestEqual), R(1), // |
| 1290 B(LogicalNot), // |
| 1291 B(JumpIfTrue), U8(-19), // |
| 1292 B(Ldar), R(0), // |
| 1293 B(Return), // |
| 1294 }, |
| 1295 0}, |
| 1296 {"var x = false;" |
| 1297 "do {" |
| 1298 " x = !x;" |
| 1299 "} while(x == false);" |
| 1300 "return x;", |
| 1301 2 * kPointerSize, |
| 1302 1, |
| 1303 20, |
| 1304 { |
| 1305 B(LdaFalse), // |
| 1306 B(Star), R(0), // |
| 1307 B(Ldar), R(0), // |
| 1308 B(LogicalNot), // |
| 1309 B(Star), R(0), // |
| 1310 B(Ldar), R(0), // |
| 1311 B(Star), R(1), // |
| 1312 B(LdaFalse), // |
| 1313 B(TestEqual), R(1), // |
| 1314 B(JumpIfTrue), U8(-12), // |
| 1315 B(Ldar), R(0), // |
| 1316 B(Return), // |
| 1317 }, |
| 1318 0}, |
| 1319 {"var x = 101;" |
| 1320 "return void(x * 3);", |
| 1321 2 * kPointerSize, |
| 1322 1, |
| 1323 14, |
| 1324 { |
| 1325 B(LdaSmi8), U8(101), // |
| 1326 B(Star), R(0), // |
| 1327 B(Ldar), R(0), // |
| 1328 B(Star), R(1), // |
| 1329 B(LdaSmi8), U8(3), // |
| 1330 B(Mul), R(1), // |
| 1331 B(LdaUndefined), // |
| 1332 B(Return), // |
| 1333 }, |
| 1334 0}, |
| 1335 {"var x = 1234;" |
| 1336 "var y = void (x * x - 1);" |
| 1337 "return y;", |
| 1338 4 * kPointerSize, |
| 1339 1, |
| 1340 24, |
| 1341 { |
| 1342 B(LdaConstant), U8(0), // |
| 1343 B(Star), R(0), // |
| 1344 B(Ldar), R(0), // |
| 1345 B(Star), R(3), // |
| 1346 B(Ldar), R(0), // |
| 1347 B(Mul), R(3), // |
| 1348 B(Star), R(2), // |
| 1349 B(LdaSmi8), U8(1), // |
| 1350 B(Sub), R(2), // |
| 1351 B(LdaUndefined), // |
| 1352 B(Star), R(1), // |
| 1353 B(Ldar), R(1), // |
| 1354 B(Return), // |
| 1355 }, |
| 1356 1, |
| 1357 {1234}}, |
| 1358 {"var x = 13;" |
| 1359 "return typeof(x);", |
| 1360 1 * kPointerSize, |
| 1361 1, |
| 1362 8, |
| 1363 { |
| 1364 B(LdaSmi8), U8(13), // |
| 1365 B(Star), R(0), // |
| 1366 B(Ldar), R(0), // |
| 1367 B(TypeOf), // |
| 1368 B(Return), // |
| 1369 }, |
| 1370 0}, |
| 1371 }; |
| 1372 |
| 1373 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 1374 Handle<BytecodeArray> bytecode_array = |
| 1375 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 1376 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 1377 } |
| 1378 } |
| 1379 |
| 1380 |
1263 } // namespace interpreter | 1381 } // namespace interpreter |
1264 } // namespace internal | 1382 } // namespace internal |
1265 } // namespace v8 | 1383 } // namespace v8 |
OLD | NEW |