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), // 0 | |
1279 B(Star), R(0), // 1 | |
1280 B(Jump), U8(12), // 3 | |
1281 B(Ldar), R(0), // 5 | |
1282 B(Star), R(1), // 7 | |
1283 B(LdaSmi8), U8(10), // 9 | |
1284 B(Add), R(1), // 11 | |
1285 B(Star), R(0), // 13 | |
1286 B(Ldar), R(0), // 15 | |
1287 B(Star), R(1), // 17 | |
1288 B(LdaSmi8), U8(10), // 19 | |
1289 B(TestEqual), R(1), // 21 | |
1290 B(LogicalNot), // 23 | |
1291 B(JumpIfTrue), U8(-19), // 24 | |
1292 B(Ldar), R(0), // 26 | |
1293 B(Return), // 28 | |
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), // 0 | |
1306 B(Star), R(0), // 1 | |
1307 B(Ldar), R(0), // 3 | |
1308 B(LogicalNot), // 5 | |
1309 B(Star), R(0), // 6 | |
1310 B(Ldar), R(0), // 8 | |
1311 B(Star), R(1), // 10 | |
1312 B(LdaFalse), // 12 | |
1313 B(TestEqual), R(1), // 13 | |
1314 B(JumpIfTrue), U8(-12), // 15 | |
1315 B(Ldar), R(0), // 17 | |
1316 B(Return), // 19 | |
rmcilroy
2015/10/06 10:39:15
nit - be consistent (either bytecode numbers for a
oth
2015/10/06 12:35:06
Done.
oth
2015/10/06 13:52:09
Done.
| |
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), // 0 | |
1343 B(Star), R(0), // 2 | |
1344 B(Ldar), R(0), // 4 | |
1345 B(Star), R(3), // 6 | |
1346 B(Ldar), R(0), // 8 | |
1347 B(Mul), R(3), // 10 | |
1348 B(Star), R(2), // 12 | |
1349 B(LdaSmi8), U8(1), // 14 | |
1350 B(Sub), R(2), // 16 | |
1351 B(LdaUndefined), // 18 | |
1352 B(Star), R(1), // 19 | |
1353 B(Ldar), R(1), // 21 | |
1354 B(Return), // 23 | |
1355 }, | |
1356 1, {1234}}, | |
1357 {"var x = 13;" | |
1358 "return typeof(x);", | |
1359 1 * kPointerSize, | |
1360 1, | |
1361 8, | |
1362 { | |
1363 B(LdaSmi8), U8(13), // | |
1364 B(Star), R(0), // | |
1365 B(Ldar), R(0), // | |
1366 B(TypeOf), // | |
1367 B(Return), // | |
1368 }, | |
1369 0}, | |
1370 }; | |
1371 | |
1372 for (size_t i = 0; i < arraysize(snippets); i++) { | |
1373 Handle<BytecodeArray> bytecode_array = | |
1374 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | |
1375 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | |
1376 } | |
1377 } | |
1378 | |
1379 | |
1263 } // namespace interpreter | 1380 } // namespace interpreter |
1264 } // namespace internal | 1381 } // namespace internal |
1265 } // namespace v8 | 1382 } // namespace v8 |
OLD | NEW |