| ... | @@ -65,6 +65,7 @@ pub fn addCases(ctx: *TestContext) !void { | ... | @@ -65,6 +65,7 @@ pub fn addCases(ctx: *TestContext) !void { |
| 65 | , | 65 | , |
| 66 | "Hello, World!\n", | 66 | "Hello, World!\n", |
| 67 | ); | 67 | ); |
| | 68 | |
| 68 | // Now change the message only | 69 | // Now change the message only |
| 69 | case.addCompareOutput( | 70 | case.addCompareOutput( |
| 70 | \\pub export fn _start() noreturn { | 71 | \\pub export fn _start() noreturn { |
| ... | @@ -237,25 +238,13 @@ pub fn addCases(ctx: *TestContext) !void { | ... | @@ -237,25 +238,13 @@ pub fn addCases(ctx: *TestContext) !void { |
| 237 | { | 238 | { |
| 238 | var case = ctx.exe("subtracting numbers at runtime", linux_x64); | 239 | var case = ctx.exe("subtracting numbers at runtime", linux_x64); |
| 239 | case.addCompareOutput( | 240 | case.addCompareOutput( |
| 240 | \\pub export fn _start() noreturn { | 241 | \\pub fn main() void { |
| 241 | \\ sub(7, 4); | 242 | \\ sub(7, 4); |
| 242 | \\ | | |
| 243 | \\ exit(); | | |
| 244 | \\} | 243 | \\} |
| 245 | \\ | 244 | \\ |
| 246 | \\fn sub(a: u32, b: u32) void { | 245 | \\fn sub(a: u32, b: u32) void { |
| 247 | \\ if (a - b != 3) unreachable; | 246 | \\ if (a - b != 3) unreachable; |
| 248 | \\} | 247 | \\} |
| 249 | \\ | | |
| 250 | \\fn exit() noreturn { | | |
| 251 | \\ asm volatile ("syscall" | | |
| 252 | \\ : | | |
| 253 | \\ : [number] "{rax}" (231), | | |
| 254 | \\ [arg1] "{rdi}" (0) | | |
| 255 | \\ : "rcx", "r11", "memory" | | |
| 256 | \\ ); | | |
| 257 | \\ unreachable; | | |
| 258 | \\} | | |
| 259 | , | 248 | , |
| 260 | "", | 249 | "", |
| 261 | ); | 250 | ); |
| ... | @@ -263,58 +252,33 @@ pub fn addCases(ctx: *TestContext) !void { | ... | @@ -263,58 +252,33 @@ pub fn addCases(ctx: *TestContext) !void { |
| 263 | { | 252 | { |
| 264 | var case = ctx.exe("@TypeOf", linux_x64); | 253 | var case = ctx.exe("@TypeOf", linux_x64); |
| 265 | case.addCompareOutput( | 254 | case.addCompareOutput( |
| 266 | \\pub export fn _start() noreturn { | 255 | \\pub fn main() void { |
| 267 | \\ var x: usize = 0; | 256 | \\ var x: usize = 0; |
| 268 | \\ const z = @TypeOf(x, @as(u128, 5)); | 257 | \\ const z = @TypeOf(x, @as(u128, 5)); |
| 269 | \\ assert(z == u128); | 258 | \\ assert(z == u128); |
| 270 | \\ | | |
| 271 | \\ exit(); | | |
| 272 | \\} | 259 | \\} |
| 273 | \\ | 260 | \\ |
| 274 | \\pub fn assert(ok: bool) void { | 261 | \\pub fn assert(ok: bool) void { |
| 275 | \\ if (!ok) unreachable; // assertion failure | 262 | \\ if (!ok) unreachable; // assertion failure |
| 276 | \\} | 263 | \\} |
| 277 | \\ | | |
| 278 | \\fn exit() noreturn { | | |
| 279 | \\ asm volatile ("syscall" | | |
| 280 | \\ : | | |
| 281 | \\ : [number] "{rax}" (231), | | |
| 282 | \\ [arg1] "{rdi}" (0) | | |
| 283 | \\ : "rcx", "r11", "memory" | | |
| 284 | \\ ); | | |
| 285 | \\ unreachable; | | |
| 286 | \\} | | |
| 287 | , | 264 | , |
| 288 | "", | 265 | "", |
| 289 | ); | 266 | ); |
| 290 | case.addCompareOutput( | 267 | case.addCompareOutput( |
| 291 | \\pub export fn _start() noreturn { | 268 | \\pub fn main() void { |
| 292 | \\ const z = @TypeOf(true); | 269 | \\ const z = @TypeOf(true); |
| 293 | \\ assert(z == bool); | 270 | \\ assert(z == bool); |
| 294 | \\ | | |
| 295 | \\ exit(); | | |
| 296 | \\} | 271 | \\} |
| 297 | \\ | 272 | \\ |
| 298 | \\pub fn assert(ok: bool) void { | 273 | \\pub fn assert(ok: bool) void { |
| 299 | \\ if (!ok) unreachable; // assertion failure | 274 | \\ if (!ok) unreachable; // assertion failure |
| 300 | \\} | 275 | \\} |
| 301 | \\ | | |
| 302 | \\fn exit() noreturn { | | |
| 303 | \\ asm volatile ("syscall" | | |
| 304 | \\ : | | |
| 305 | \\ : [number] "{rax}" (231), | | |
| 306 | \\ [arg1] "{rdi}" (0) | | |
| 307 | \\ : "rcx", "r11", "memory" | | |
| 308 | \\ ); | | |
| 309 | \\ unreachable; | | |
| 310 | \\} | | |
| 311 | , | 276 | , |
| 312 | "", | 277 | "", |
| 313 | ); | 278 | ); |
| 314 | case.addError( | 279 | case.addError( |
| 315 | \\pub export fn _start() noreturn { | 280 | \\pub fn main() void { |
| 316 | \\ const z = @TypeOf(true, 1); | 281 | \\ const z = @TypeOf(true, 1); |
| 317 | \\ unreachable; | | |
| 318 | \\} | 282 | \\} |
| 319 | , &[_][]const u8{":2:15: error: incompatible types: 'bool' and 'comptime_int'"}); | 283 | , &[_][]const u8{":2:15: error: incompatible types: 'bool' and 'comptime_int'"}); |
| 320 | } | 284 | } |
| ... | @@ -346,7 +310,7 @@ pub fn addCases(ctx: *TestContext) !void { | ... | @@ -346,7 +310,7 @@ pub fn addCases(ctx: *TestContext) !void { |
| 346 | ); | 310 | ); |
| 347 | // comptime function call | 311 | // comptime function call |
| 348 | case.addCompareOutput( | 312 | case.addCompareOutput( |
| 349 | \\pub export fn _start() noreturn { | 313 | \\pub fn _start() noreturn { |
| 350 | \\ exit(); | 314 | \\ exit(); |
| 351 | \\} | 315 | \\} |
| 352 | \\ | 316 | \\ |
| ... | @@ -397,10 +361,8 @@ pub fn addCases(ctx: *TestContext) !void { | ... | @@ -397,10 +361,8 @@ pub fn addCases(ctx: *TestContext) !void { |
| 397 | { | 361 | { |
| 398 | var case = ctx.exe("assert function", linux_x64); | 362 | var case = ctx.exe("assert function", linux_x64); |
| 399 | case.addCompareOutput( | 363 | case.addCompareOutput( |
| 400 | \\pub export fn _start() noreturn { | 364 | \\pub fn main() void { |
| 401 | \\ add(3, 4); | 365 | \\ add(3, 4); |
| 402 | \\ | | |
| 403 | \\ exit(); | | |
| 404 | \\} | 366 | \\} |
| 405 | \\ | 367 | \\ |
| 406 | \\fn add(a: u32, b: u32) void { | 368 | \\fn add(a: u32, b: u32) void { |
| ... | @@ -427,10 +389,8 @@ pub fn addCases(ctx: *TestContext) !void { | ... | @@ -427,10 +389,8 @@ pub fn addCases(ctx: *TestContext) !void { |
| 427 | // Tests copying a register. For the `c = a + b`, it has to | 389 | // Tests copying a register. For the `c = a + b`, it has to |
| 428 | // preserve both a and b, because they are both used later. | 390 | // preserve both a and b, because they are both used later. |
| 429 | case.addCompareOutput( | 391 | case.addCompareOutput( |
| 430 | \\pub export fn _start() noreturn { | 392 | \\pub fn main() void { |
| 431 | \\ add(3, 4); | 393 | \\ add(3, 4); |
| 432 | \\ | | |
| 433 | \\ exit(); | | |
| 434 | \\} | 394 | \\} |
| 435 | \\ | 395 | \\ |
| 436 | \\fn add(a: u32, b: u32) void { | 396 | \\fn add(a: u32, b: u32) void { |
| ... | @@ -443,26 +403,14 @@ pub fn addCases(ctx: *TestContext) !void { | ... | @@ -443,26 +403,14 @@ pub fn addCases(ctx: *TestContext) !void { |
| 443 | \\pub fn assert(ok: bool) void { | 403 | \\pub fn assert(ok: bool) void { |
| 444 | \\ if (!ok) unreachable; // assertion failure | 404 | \\ if (!ok) unreachable; // assertion failure |
| 445 | \\} | 405 | \\} |
| 446 | \\ | | |
| 447 | \\fn exit() noreturn { | | |
| 448 | \\ asm volatile ("syscall" | | |
| 449 | \\ : | | |
| 450 | \\ : [number] "{rax}" (231), | | |
| 451 | \\ [arg1] "{rdi}" (0) | | |
| 452 | \\ : "rcx", "r11", "memory" | | |
| 453 | \\ ); | | |
| 454 | \\ unreachable; | | |
| 455 | \\} | | |
| 456 | , | 406 | , |
| 457 | "", | 407 | "", |
| 458 | ); | 408 | ); |
| 459 | | 409 | |
| 460 | // More stress on the liveness detection. | 410 | // More stress on the liveness detection. |
| 461 | case.addCompareOutput( | 411 | case.addCompareOutput( |
| 462 | \\pub export fn _start() noreturn { | 412 | \\pub fn main() void { |
| 463 | \\ add(3, 4); | 413 | \\ add(3, 4); |
| 464 | \\ | | |
| 465 | \\ exit(); | | |
| 466 | \\} | 414 | \\} |
| 467 | \\ | 415 | \\ |
| 468 | \\fn add(a: u32, b: u32) void { | 416 | \\fn add(a: u32, b: u32) void { |
| ... | @@ -479,26 +427,14 @@ pub fn addCases(ctx: *TestContext) !void { | ... | @@ -479,26 +427,14 @@ pub fn addCases(ctx: *TestContext) !void { |
| 479 | \\pub fn assert(ok: bool) void { | 427 | \\pub fn assert(ok: bool) void { |
| 480 | \\ if (!ok) unreachable; // assertion failure | 428 | \\ if (!ok) unreachable; // assertion failure |
| 481 | \\} | 429 | \\} |
| 482 | \\ | | |
| 483 | \\fn exit() noreturn { | | |
| 484 | \\ asm volatile ("syscall" | | |
| 485 | \\ : | | |
| 486 | \\ : [number] "{rax}" (231), | | |
| 487 | \\ [arg1] "{rdi}" (0) | | |
| 488 | \\ : "rcx", "r11", "memory" | | |
| 489 | \\ ); | | |
| 490 | \\ unreachable; | | |
| 491 | \\} | | |
| 492 | , | 430 | , |
| 493 | "", | 431 | "", |
| 494 | ); | 432 | ); |
| 495 | | 433 | |
| 496 | // Requires a second move. The register allocator should figure out to re-use rax. | 434 | // Requires a second move. The register allocator should figure out to re-use rax. |
| 497 | case.addCompareOutput( | 435 | case.addCompareOutput( |
| 498 | \\pub export fn _start() noreturn { | 436 | \\pub fn main() void { |
| 499 | \\ add(3, 4); | 437 | \\ add(3, 4); |
| 500 | \\ | | |
| 501 | \\ exit(); | | |
| 502 | \\} | 438 | \\} |
| 503 | \\ | 439 | \\ |
| 504 | \\fn add(a: u32, b: u32) void { | 440 | \\fn add(a: u32, b: u32) void { |
| ... | @@ -516,27 +452,15 @@ pub fn addCases(ctx: *TestContext) !void { | ... | @@ -516,27 +452,15 @@ pub fn addCases(ctx: *TestContext) !void { |
| 516 | \\pub fn assert(ok: bool) void { | 452 | \\pub fn assert(ok: bool) void { |
| 517 | \\ if (!ok) unreachable; // assertion failure | 453 | \\ if (!ok) unreachable; // assertion failure |
| 518 | \\} | 454 | \\} |
| 519 | \\ | | |
| 520 | \\fn exit() noreturn { | | |
| 521 | \\ asm volatile ("syscall" | | |
| 522 | \\ : | | |
| 523 | \\ : [number] "{rax}" (231), | | |
| 524 | \\ [arg1] "{rdi}" (0) | | |
| 525 | \\ : "rcx", "r11", "memory" | | |
| 526 | \\ ); | | |
| 527 | \\ unreachable; | | |
| 528 | \\} | | |
| 529 | , | 455 | , |
| 530 | "", | 456 | "", |
| 531 | ); | 457 | ); |
| 532 | | 458 | |
| 533 | // Now we test integer return values. | 459 | // Now we test integer return values. |
| 534 | case.addCompareOutput( | 460 | case.addCompareOutput( |
| 535 | \\pub export fn _start() noreturn { | 461 | \\pub fn main() void { |
| 536 | \\ assert(add(3, 4) == 7); | 462 | \\ assert(add(3, 4) == 7); |
| 537 | \\ assert(add(20, 10) == 30); | 463 | \\ assert(add(20, 10) == 30); |
| 538 | \\ | | |
| 539 | \\ exit(); | | |
| 540 | \\} | 464 | \\} |
| 541 | \\ | 465 | \\ |
| 542 | \\fn add(a: u32, b: u32) u32 { | 466 | \\fn add(a: u32, b: u32) u32 { |
| ... | @@ -546,27 +470,15 @@ pub fn addCases(ctx: *TestContext) !void { | ... | @@ -546,27 +470,15 @@ pub fn addCases(ctx: *TestContext) !void { |
| 546 | \\pub fn assert(ok: bool) void { | 470 | \\pub fn assert(ok: bool) void { |
| 547 | \\ if (!ok) unreachable; // assertion failure | 471 | \\ if (!ok) unreachable; // assertion failure |
| 548 | \\} | 472 | \\} |
| 549 | \\ | | |
| 550 | \\fn exit() noreturn { | | |
| 551 | \\ asm volatile ("syscall" | | |
| 552 | \\ : | | |
| 553 | \\ : [number] "{rax}" (231), | | |
| 554 | \\ [arg1] "{rdi}" (0) | | |
| 555 | \\ : "rcx", "r11", "memory" | | |
| 556 | \\ ); | | |
| 557 | \\ unreachable; | | |
| 558 | \\} | | |
| 559 | , | 473 | , |
| 560 | "", | 474 | "", |
| 561 | ); | 475 | ); |
| 562 | | 476 | |
| 563 | // Local mutable variables. | 477 | // Local mutable variables. |
| 564 | case.addCompareOutput( | 478 | case.addCompareOutput( |
| 565 | \\pub export fn _start() noreturn { | 479 | \\pub fn main() void { |
| 566 | \\ assert(add(3, 4) == 7); | 480 | \\ assert(add(3, 4) == 7); |
| 567 | \\ assert(add(20, 10) == 30); | 481 | \\ assert(add(20, 10) == 30); |
| 568 | \\ | | |
| 569 | \\ exit(); | | |
| 570 | \\} | 482 | \\} |
| 571 | \\ | 483 | \\ |
| 572 | \\fn add(a: u32, b: u32) u32 { | 484 | \\fn add(a: u32, b: u32) u32 { |
| ... | @@ -580,39 +492,17 @@ pub fn addCases(ctx: *TestContext) !void { | ... | @@ -580,39 +492,17 @@ pub fn addCases(ctx: *TestContext) !void { |
| 580 | \\pub fn assert(ok: bool) void { | 492 | \\pub fn assert(ok: bool) void { |
| 581 | \\ if (!ok) unreachable; // assertion failure | 493 | \\ if (!ok) unreachable; // assertion failure |
| 582 | \\} | 494 | \\} |
| 583 | \\ | | |
| 584 | \\fn exit() noreturn { | | |
| 585 | \\ asm volatile ("syscall" | | |
| 586 | \\ : | | |
| 587 | \\ : [number] "{rax}" (231), | | |
| 588 | \\ [arg1] "{rdi}" (0) | | |
| 589 | \\ : "rcx", "r11", "memory" | | |
| 590 | \\ ); | | |
| 591 | \\ unreachable; | | |
| 592 | \\} | | |
| 593 | , | 495 | , |
| 594 | "", | 496 | "", |
| 595 | ); | 497 | ); |
| 596 | | 498 | |
| 597 | // Optionals | 499 | // Optionals |
| 598 | case.addCompareOutput( | 500 | case.addCompareOutput( |
| 599 | \\pub export fn _start() noreturn { | 501 | \\pub fn main() void { |
| 600 | \\ const a: u32 = 2; | 502 | \\ const a: u32 = 2; |
| 601 | \\ const b: ?u32 = a; | 503 | \\ const b: ?u32 = a; |
| 602 | \\ const c = b.?; | 504 | \\ const c = b.?; |
| 603 | \\ if (c != 2) unreachable; | 505 | \\ if (c != 2) unreachable; |
| 604 | \\ | | |
| 605 | \\ exit(); | | |
| 606 | \\} | | |
| 607 | \\ | | |
| 608 | \\fn exit() noreturn { | | |
| 609 | \\ asm volatile ("syscall" | | |
| 610 | \\ : | | |
| 611 | \\ : [number] "{rax}" (231), | | |
| 612 | \\ [arg1] "{rdi}" (0) | | |
| 613 | \\ : "rcx", "r11", "memory" | | |
| 614 | \\ ); | | |
| 615 | \\ unreachable; | | |
| 616 | \\} | 506 | \\} |
| 617 | , | 507 | , |
| 618 | "", | 508 | "", |
| ... | @@ -620,12 +510,10 @@ pub fn addCases(ctx: *TestContext) !void { | ... | @@ -620,12 +510,10 @@ pub fn addCases(ctx: *TestContext) !void { |
| 620 | | 510 | |
| 621 | // While loops | 511 | // While loops |
| 622 | case.addCompareOutput( | 512 | case.addCompareOutput( |
| 623 | \\pub export fn _start() noreturn { | 513 | \\pub fn main() void { |
| 624 | \\ var i: u32 = 0; | 514 | \\ var i: u32 = 0; |
| 625 | \\ while (i < 4) : (i += 1) print(); | 515 | \\ while (i < 4) : (i += 1) print(); |
| 626 | \\ assert(i == 4); | 516 | \\ assert(i == 4); |
| 627 | \\ | | |
| 628 | \\ exit(); | | |
| 629 | \\} | 517 | \\} |
| 630 | \\ | 518 | \\ |
| 631 | \\fn print() void { | 519 | \\fn print() void { |
| ... | @@ -643,28 +531,16 @@ pub fn addCases(ctx: *TestContext) !void { | ... | @@ -643,28 +531,16 @@ pub fn addCases(ctx: *TestContext) !void { |
| 643 | \\pub fn assert(ok: bool) void { | 531 | \\pub fn assert(ok: bool) void { |
| 644 | \\ if (!ok) unreachable; // assertion failure | 532 | \\ if (!ok) unreachable; // assertion failure |
| 645 | \\} | 533 | \\} |
| 646 | \\ | | |
| 647 | \\fn exit() noreturn { | | |
| 648 | \\ asm volatile ("syscall" | | |
| 649 | \\ : | | |
| 650 | \\ : [number] "{rax}" (231), | | |
| 651 | \\ [arg1] "{rdi}" (0) | | |
| 652 | \\ : "rcx", "r11", "memory" | | |
| 653 | \\ ); | | |
| 654 | \\ unreachable; | | |
| 655 | \\} | | |
| 656 | , | 534 | , |
| 657 | "hello\nhello\nhello\nhello\n", | 535 | "hello\nhello\nhello\nhello\n", |
| 658 | ); | 536 | ); |
| 659 | | 537 | |
| 660 | // inline while requires the condition to be comptime known. | 538 | // inline while requires the condition to be comptime known. |
| 661 | case.addError( | 539 | case.addError( |
| 662 | \\pub export fn _start() noreturn { | 540 | \\pub fn main() void { |
| 663 | \\ var i: u32 = 0; | 541 | \\ var i: u32 = 0; |
| 664 | \\ inline while (i < 4) : (i += 1) print(); | 542 | \\ inline while (i < 4) : (i += 1) print(); |
| 665 | \\ assert(i == 4); | 543 | \\ assert(i == 4); |
| 666 | \\ | | |
| 667 | \\ exit(); | | |
| 668 | \\} | 544 | \\} |
| 669 | \\ | 545 | \\ |
| 670 | \\fn print() void { | 546 | \\fn print() void { |
| ... | @@ -682,24 +558,12 @@ pub fn addCases(ctx: *TestContext) !void { | ... | @@ -682,24 +558,12 @@ pub fn addCases(ctx: *TestContext) !void { |
| 682 | \\pub fn assert(ok: bool) void { | 558 | \\pub fn assert(ok: bool) void { |
| 683 | \\ if (!ok) unreachable; // assertion failure | 559 | \\ if (!ok) unreachable; // assertion failure |
| 684 | \\} | 560 | \\} |
| 685 | \\ | | |
| 686 | \\fn exit() noreturn { | | |
| 687 | \\ asm volatile ("syscall" | | |
| 688 | \\ : | | |
| 689 | \\ : [number] "{rax}" (231), | | |
| 690 | \\ [arg1] "{rdi}" (0) | | |
| 691 | \\ : "rcx", "r11", "memory" | | |
| 692 | \\ ); | | |
| 693 | \\ unreachable; | | |
| 694 | \\} | | |
| 695 | , &[_][]const u8{":3:21: error: unable to resolve comptime value"}); | 561 | , &[_][]const u8{":3:21: error: unable to resolve comptime value"}); |
| 696 | | 562 | |
| 697 | // Labeled blocks (no conditional branch) | 563 | // Labeled blocks (no conditional branch) |
| 698 | case.addCompareOutput( | 564 | case.addCompareOutput( |
| 699 | \\pub export fn _start() noreturn { | 565 | \\pub fn main() void { |
| 700 | \\ assert(add(3, 4) == 20); | 566 | \\ assert(add(3, 4) == 20); |
| 701 | \\ | | |
| 702 | \\ exit(); | | |
| 703 | \\} | 567 | \\} |
| 704 | \\ | 568 | \\ |
| 705 | \\fn add(a: u32, b: u32) u32 { | 569 | \\fn add(a: u32, b: u32) u32 { |
| ... | @@ -717,26 +581,14 @@ pub fn addCases(ctx: *TestContext) !void { | ... | @@ -717,26 +581,14 @@ pub fn addCases(ctx: *TestContext) !void { |
| 717 | \\pub fn assert(ok: bool) void { | 581 | \\pub fn assert(ok: bool) void { |
| 718 | \\ if (!ok) unreachable; // assertion failure | 582 | \\ if (!ok) unreachable; // assertion failure |
| 719 | \\} | 583 | \\} |
| 720 | \\ | | |
| 721 | \\fn exit() noreturn { | | |
| 722 | \\ asm volatile ("syscall" | | |
| 723 | \\ : | | |
| 724 | \\ : [number] "{rax}" (231), | | |
| 725 | \\ [arg1] "{rdi}" (0) | | |
| 726 | \\ : "rcx", "r11", "memory" | | |
| 727 | \\ ); | | |
| 728 | \\ unreachable; | | |
| 729 | \\} | | |
| 730 | , | 584 | , |
| 731 | "", | 585 | "", |
| 732 | ); | 586 | ); |
| 733 | | 587 | |
| 734 | // This catches a possible bug in the logic for re-using dying operands. | 588 | // This catches a possible bug in the logic for re-using dying operands. |
| 735 | case.addCompareOutput( | 589 | case.addCompareOutput( |
| 736 | \\pub export fn _start() noreturn { | 590 | \\pub fn main() void { |
| 737 | \\ assert(add(3, 4) == 116); | 591 | \\ assert(add(3, 4) == 116); |
| 738 | \\ | | |
| 739 | \\ exit(); | | |
| 740 | \\} | 592 | \\} |
| 741 | \\ | 593 | \\ |
| 742 | \\fn add(a: u32, b: u32) u32 { | 594 | \\fn add(a: u32, b: u32) u32 { |
| ... | @@ -759,27 +611,15 @@ pub fn addCases(ctx: *TestContext) !void { | ... | @@ -759,27 +611,15 @@ pub fn addCases(ctx: *TestContext) !void { |
| 759 | \\pub fn assert(ok: bool) void { | 611 | \\pub fn assert(ok: bool) void { |
| 760 | \\ if (!ok) unreachable; // assertion failure | 612 | \\ if (!ok) unreachable; // assertion failure |
| 761 | \\} | 613 | \\} |
| 762 | \\ | | |
| 763 | \\fn exit() noreturn { | | |
| 764 | \\ asm volatile ("syscall" | | |
| 765 | \\ : | | |
| 766 | \\ : [number] "{rax}" (231), | | |
| 767 | \\ [arg1] "{rdi}" (0) | | |
| 768 | \\ : "rcx", "r11", "memory" | | |
| 769 | \\ ); | | |
| 770 | \\ unreachable; | | |
| 771 | \\} | | |
| 772 | , | 614 | , |
| 773 | "", | 615 | "", |
| 774 | ); | 616 | ); |
| 775 | | 617 | |
| 776 | // Spilling registers to the stack. | 618 | // Spilling registers to the stack. |
| 777 | case.addCompareOutput( | 619 | case.addCompareOutput( |
| 778 | \\pub export fn _start() noreturn { | 620 | \\pub fn main() void { |
| 779 | \\ assert(add(3, 4) == 1221); | 621 | \\ assert(add(3, 4) == 1221); |
| 780 | \\ assert(mul(3, 4) == 21609); | 622 | \\ assert(mul(3, 4) == 21609); |
| 781 | \\ | | |
| 782 | \\ exit(); | | |
| 783 | \\} | 623 | \\} |
| 784 | \\ | 624 | \\ |
| 785 | \\fn add(a: u32, b: u32) u32 { | 625 | \\fn add(a: u32, b: u32) u32 { |
| ... | @@ -840,27 +680,15 @@ pub fn addCases(ctx: *TestContext) !void { | ... | @@ -840,27 +680,15 @@ pub fn addCases(ctx: *TestContext) !void { |
| 840 | \\pub fn assert(ok: bool) void { | 680 | \\pub fn assert(ok: bool) void { |
| 841 | \\ if (!ok) unreachable; // assertion failure | 681 | \\ if (!ok) unreachable; // assertion failure |
| 842 | \\} | 682 | \\} |
| 843 | \\ | | |
| 844 | \\fn exit() noreturn { | | |
| 845 | \\ asm volatile ("syscall" | | |
| 846 | \\ : | | |
| 847 | \\ : [number] "{rax}" (231), | | |
| 848 | \\ [arg1] "{rdi}" (0) | | |
| 849 | \\ : "rcx", "r11", "memory" | | |
| 850 | \\ ); | | |
| 851 | \\ unreachable; | | |
| 852 | \\} | | |
| 853 | , | 683 | , |
| 854 | "", | 684 | "", |
| 855 | ); | 685 | ); |
| 856 | | 686 | |
| 857 | // Reusing the registers of dead operands playing nicely with conditional branching. | 687 | // Reusing the registers of dead operands playing nicely with conditional branching. |
| 858 | case.addCompareOutput( | 688 | case.addCompareOutput( |
| 859 | \\pub export fn _start() noreturn { | 689 | \\pub fn main() void { |
| 860 | \\ assert(add(3, 4) == 791); | 690 | \\ assert(add(3, 4) == 791); |
| 861 | \\ assert(add(4, 3) == 79); | 691 | \\ assert(add(4, 3) == 79); |
| 862 | \\ | | |
| 863 | \\ exit(); | | |
| 864 | \\} | 692 | \\} |
| 865 | \\ | 693 | \\ |
| 866 | \\fn add(a: u32, b: u32) u32 { | 694 | \\fn add(a: u32, b: u32) u32 { |
| ... | @@ -902,30 +730,18 @@ pub fn addCases(ctx: *TestContext) !void { | ... | @@ -902,30 +730,18 @@ pub fn addCases(ctx: *TestContext) !void { |
| 902 | \\pub fn assert(ok: bool) void { | 730 | \\pub fn assert(ok: bool) void { |
| 903 | \\ if (!ok) unreachable; // assertion failure | 731 | \\ if (!ok) unreachable; // assertion failure |
| 904 | \\} | 732 | \\} |
| 905 | \\ | | |
| 906 | \\fn exit() noreturn { | | |
| 907 | \\ asm volatile ("syscall" | | |
| 908 | \\ : | | |
| 909 | \\ : [number] "{rax}" (231), | | |
| 910 | \\ [arg1] "{rdi}" (0) | | |
| 911 | \\ : "rcx", "r11", "memory" | | |
| 912 | \\ ); | | |
| 913 | \\ unreachable; | | |
| 914 | \\} | | |
| 915 | , | 733 | , |
| 916 | "", | 734 | "", |
| 917 | ); | 735 | ); |
| 918 | | 736 | |
| 919 | // Character literals and multiline strings. | 737 | // Character literals and multiline strings. |
| 920 | case.addCompareOutput( | 738 | case.addCompareOutput( |
| 921 | \\pub export fn _start() noreturn { | 739 | \\pub fn main() void { |
| 922 | \\ const ignore = | 740 | \\ const ignore = |
| 923 | \\ \\ cool thx | 741 | \\ \\ cool thx |
| 924 | \\ \\ | 742 | \\ \\ |
| 925 | \\ ; | 743 | \\ ; |
| 926 | \\ add('ぁ', '\x03'); | 744 | \\ add('ぁ', '\x03'); |
| 927 | \\ | | |
| 928 | \\ exit(); | | |
| 929 | \\} | 745 | \\} |
| 930 | \\ | 746 | \\ |
| 931 | \\fn add(a: u32, b: u32) void { | 747 | \\fn add(a: u32, b: u32) void { |
| ... | @@ -935,26 +751,14 @@ pub fn addCases(ctx: *TestContext) !void { | ... | @@ -935,26 +751,14 @@ pub fn addCases(ctx: *TestContext) !void { |
| 935 | \\pub fn assert(ok: bool) void { | 751 | \\pub fn assert(ok: bool) void { |
| 936 | \\ if (!ok) unreachable; // assertion failure | 752 | \\ if (!ok) unreachable; // assertion failure |
| 937 | \\} | 753 | \\} |
| 938 | \\ | | |
| 939 | \\fn exit() noreturn { | | |
| 940 | \\ asm volatile ("syscall" | | |
| 941 | \\ : | | |
| 942 | \\ : [number] "{rax}" (231), | | |
| 943 | \\ [arg1] "{rdi}" (0) | | |
| 944 | \\ : "rcx", "r11", "memory" | | |
| 945 | \\ ); | | |
| 946 | \\ unreachable; | | |
| 947 | \\} | | |
| 948 | , | 754 | , |
| 949 | "", | 755 | "", |
| 950 | ); | 756 | ); |
| 951 | | 757 | |
| 952 | // Global const. | 758 | // Global const. |
| 953 | case.addCompareOutput( | 759 | case.addCompareOutput( |
| 954 | \\pub export fn _start() noreturn { | 760 | \\pub fn main() void { |
| 955 | \\ add(aa, bb); | 761 | \\ add(aa, bb); |
| 956 | \\ | | |
| 957 | \\ exit(); | | |
| 958 | \\} | 762 | \\} |
| 959 | \\ | 763 | \\ |
| 960 | \\const aa = 'ぁ'; | 764 | \\const aa = 'ぁ'; |
| ... | @@ -967,41 +771,19 @@ pub fn addCases(ctx: *TestContext) !void { | ... | @@ -967,41 +771,19 @@ pub fn addCases(ctx: *TestContext) !void { |
| 967 | \\pub fn assert(ok: bool) void { | 771 | \\pub fn assert(ok: bool) void { |
| 968 | \\ if (!ok) unreachable; // assertion failure | 772 | \\ if (!ok) unreachable; // assertion failure |
| 969 | \\} | 773 | \\} |
| 970 | \\ | | |
| 971 | \\fn exit() noreturn { | | |
| 972 | \\ asm volatile ("syscall" | | |
| 973 | \\ : | | |
| 974 | \\ : [number] "{rax}" (231), | | |
| 975 | \\ [arg1] "{rdi}" (0) | | |
| 976 | \\ : "rcx", "r11", "memory" | | |
| 977 | \\ ); | | |
| 978 | \\ unreachable; | | |
| 979 | \\} | | |
| 980 | , | 774 | , |
| 981 | "", | 775 | "", |
| 982 | ); | 776 | ); |
| 983 | | 777 | |
| 984 | // Array access. | 778 | // Array access. |
| 985 | case.addCompareOutput( | 779 | case.addCompareOutput( |
| 986 | \\pub export fn _start() noreturn { | 780 | \\pub fn main() void { |
| 987 | \\ assert("hello"[0] == 'h'); | 781 | \\ assert("hello"[0] == 'h'); |
| 988 | \\ | | |
| 989 | \\ exit(); | | |
| 990 | \\} | 782 | \\} |
| 991 | \\ | 783 | \\ |
| 992 | \\pub fn assert(ok: bool) void { | 784 | \\pub fn assert(ok: bool) void { |
| 993 | \\ if (!ok) unreachable; // assertion failure | 785 | \\ if (!ok) unreachable; // assertion failure |
| 994 | \\} | 786 | \\} |
| 995 | \\ | | |
| 996 | \\fn exit() noreturn { | | |
| 997 | \\ asm volatile ("syscall" | | |
| 998 | \\ : | | |
| 999 | \\ : [number] "{rax}" (231), | | |
| 1000 | \\ [arg1] "{rdi}" (0) | | |
| 1001 | \\ : "rcx", "r11", "memory" | | |
| 1002 | \\ ); | | |
| 1003 | \\ unreachable; | | |
| 1004 | \\} | | |
| 1005 | , | 787 | , |
| 1006 | "", | 788 | "", |
| 1007 | ); | 789 | ); |
| ... | @@ -1009,61 +791,35 @@ pub fn addCases(ctx: *TestContext) !void { | ... | @@ -1009,61 +791,35 @@ pub fn addCases(ctx: *TestContext) !void { |
| 1009 | // Array access to a global array. | 791 | // Array access to a global array. |
| 1010 | case.addCompareOutput( | 792 | case.addCompareOutput( |
| 1011 | \\const hello = "hello".*; | 793 | \\const hello = "hello".*; |
| 1012 | \\pub export fn _start() noreturn { | 794 | \\pub fn main() void { |
| 1013 | \\ assert(hello[1] == 'e'); | 795 | \\ assert(hello[1] == 'e'); |
| 1014 | \\ | | |
| 1015 | \\ exit(); | | |
| 1016 | \\} | 796 | \\} |
| 1017 | \\ | 797 | \\ |
| 1018 | \\pub fn assert(ok: bool) void { | 798 | \\pub fn assert(ok: bool) void { |
| 1019 | \\ if (!ok) unreachable; // assertion failure | 799 | \\ if (!ok) unreachable; // assertion failure |
| 1020 | \\} | 800 | \\} |
| 1021 | \\ | | |
| 1022 | \\fn exit() noreturn { | | |
| 1023 | \\ asm volatile ("syscall" | | |
| 1024 | \\ : | | |
| 1025 | \\ : [number] "{rax}" (231), | | |
| 1026 | \\ [arg1] "{rdi}" (0) | | |
| 1027 | \\ : "rcx", "r11", "memory" | | |
| 1028 | \\ ); | | |
| 1029 | \\ unreachable; | | |
| 1030 | \\} | | |
| 1031 | , | 801 | , |
| 1032 | "", | 802 | "", |
| 1033 | ); | 803 | ); |
| 1034 | | 804 | |
| 1035 | // 64bit set stack | 805 | // 64bit set stack |
| 1036 | case.addCompareOutput( | 806 | case.addCompareOutput( |
| 1037 | \\pub export fn _start() noreturn { | 807 | \\pub fn main() void { |
| 1038 | \\ var i: u64 = 0xFFEEDDCCBBAA9988; | 808 | \\ var i: u64 = 0xFFEEDDCCBBAA9988; |
| 1039 | \\ assert(i == 0xFFEEDDCCBBAA9988); | 809 | \\ assert(i == 0xFFEEDDCCBBAA9988); |
| 1040 | \\ | | |
| 1041 | \\ exit(); | | |
| 1042 | \\} | 810 | \\} |
| 1043 | \\ | 811 | \\ |
| 1044 | \\pub fn assert(ok: bool) void { | 812 | \\pub fn assert(ok: bool) void { |
| 1045 | \\ if (!ok) unreachable; // assertion failure | 813 | \\ if (!ok) unreachable; // assertion failure |
| 1046 | \\} | 814 | \\} |
| 1047 | \\ | | |
| 1048 | \\fn exit() noreturn { | | |
| 1049 | \\ asm volatile ("syscall" | | |
| 1050 | \\ : | | |
| 1051 | \\ : [number] "{rax}" (231), | | |
| 1052 | \\ [arg1] "{rdi}" (0) | | |
| 1053 | \\ : "rcx", "r11", "memory" | | |
| 1054 | \\ ); | | |
| 1055 | \\ unreachable; | | |
| 1056 | \\} | | |
| 1057 | , | 815 | , |
| 1058 | "", | 816 | "", |
| 1059 | ); | 817 | ); |
| 1060 | | 818 | |
| 1061 | // Basic for loop | 819 | // Basic for loop |
| 1062 | case.addCompareOutput( | 820 | case.addCompareOutput( |
| 1063 | \\pub export fn _start() noreturn { | 821 | \\pub fn main() void { |
| 1064 | \\ for ("hello") |_| print(); | 822 | \\ for ("hello") |_| print(); |
| 1065 | \\ | | |
| 1066 | \\ exit(); | | |
| 1067 | \\} | 823 | \\} |
| 1068 | \\ | 824 | \\ |
| 1069 | \\fn print() void { | 825 | \\fn print() void { |
| ... | @@ -1077,16 +833,6 @@ pub fn addCases(ctx: *TestContext) !void { | ... | @@ -1077,16 +833,6 @@ pub fn addCases(ctx: *TestContext) !void { |
| 1077 | \\ ); | 833 | \\ ); |
| 1078 | \\ return; | 834 | \\ return; |
| 1079 | \\} | 835 | \\} |
| 1080 | \\ | | |
| 1081 | \\fn exit() noreturn { | | |
| 1082 | \\ asm volatile ("syscall" | | |
| 1083 | \\ : | | |
| 1084 | \\ : [number] "{rax}" (231), | | |
| 1085 | \\ [arg1] "{rdi}" (0) | | |
| 1086 | \\ : "rcx", "r11", "memory" | | |
| 1087 | \\ ); | | |
| 1088 | \\ unreachable; | | |
| 1089 | \\} | | |
| 1090 | , | 836 | , |
| 1091 | "hello\nhello\nhello\nhello\nhello\n", | 837 | "hello\nhello\nhello\nhello\nhello\n", |
| 1092 | ); | 838 | ); |
| ... | @@ -1095,19 +841,8 @@ pub fn addCases(ctx: *TestContext) !void { | ... | @@ -1095,19 +841,8 @@ pub fn addCases(ctx: *TestContext) !void { |
| 1095 | { | 841 | { |
| 1096 | var case = ctx.exe("basic import", linux_x64); | 842 | var case = ctx.exe("basic import", linux_x64); |
| 1097 | case.addCompareOutput( | 843 | case.addCompareOutput( |
| 1098 | \\pub export fn _start() noreturn { | 844 | \\pub fn main() void { |
| 1099 | \\ @import("print.zig").print(); | 845 | \\ @import("print.zig").print(); |
| 1100 | \\ exit(); | | |
| 1101 | \\} | | |
| 1102 | \\ | | |
| 1103 | \\fn exit() noreturn { | | |
| 1104 | \\ asm volatile ("syscall" | | |
| 1105 | \\ : | | |
| 1106 | \\ : [number] "{rax}" (231), | | |
| 1107 | \\ [arg1] "{rdi}" (@as(usize, 0)) | | |
| 1108 | \\ : "rcx", "r11", "memory" | | |
| 1109 | \\ ); | | |
| 1110 | \\ unreachable; | | |
| 1111 | \\} | 846 | \\} |
| 1112 | , | 847 | , |
| 1113 | "Hello, World!\n", | 848 | "Hello, World!\n", |
| ... | @@ -1132,14 +867,14 @@ pub fn addCases(ctx: *TestContext) !void { | ... | @@ -1132,14 +867,14 @@ pub fn addCases(ctx: *TestContext) !void { |
| 1132 | { | 867 | { |
| 1133 | var case = ctx.exe("redundant comptime", linux_x64); | 868 | var case = ctx.exe("redundant comptime", linux_x64); |
| 1134 | case.addError( | 869 | case.addError( |
| 1135 | \\pub export fn _start() void { | 870 | \\pub fn main() void { |
| 1136 | \\ var a: comptime u32 = 0; | 871 | \\ var a: comptime u32 = 0; |
| 1137 | \\} | 872 | \\} |
| 1138 | , | 873 | , |
| 1139 | &.{":2:12: error: redundant comptime keyword in already comptime scope"}, | 874 | &.{":2:12: error: redundant comptime keyword in already comptime scope"}, |
| 1140 | ); | 875 | ); |
| 1141 | case.addError( | 876 | case.addError( |
| 1142 | \\pub export fn _start() void { | 877 | \\pub fn main() void { |
| 1143 | \\ comptime { | 878 | \\ comptime { |
| 1144 | \\ var a: u32 = comptime 0; | 879 | \\ var a: u32 = comptime 0; |
| 1145 | \\ } | 880 | \\ } |
| ... | @@ -1151,19 +886,8 @@ pub fn addCases(ctx: *TestContext) !void { | ... | @@ -1151,19 +886,8 @@ pub fn addCases(ctx: *TestContext) !void { |
| 1151 | { | 886 | { |
| 1152 | var case = ctx.exe("import private", linux_x64); | 887 | var case = ctx.exe("import private", linux_x64); |
| 1153 | case.addError( | 888 | case.addError( |
| 1154 | \\pub export fn _start() noreturn { | 889 | \\pub fn main() void { |
| 1155 | \\ @import("print.zig").print(); | 890 | \\ @import("print.zig").print(); |
| 1156 | \\ exit(); | | |
| 1157 | \\} | | |
| 1158 | \\ | | |
| 1159 | \\fn exit() noreturn { | | |
| 1160 | \\ asm volatile ("syscall" | | |
| 1161 | \\ : | | |
| 1162 | \\ : [number] "{rax}" (231), | | |
| 1163 | \\ [arg1] "{rdi}" (@as(usize, 0)) | | |
| 1164 | \\ : "rcx", "r11", "memory" | | |
| 1165 | \\ ); | | |
| 1166 | \\ unreachable; | | |
| 1167 | \\} | 891 | \\} |
| 1168 | , | 892 | , |
| 1169 | &.{ | 893 | &.{ |
| ... | @@ -1215,19 +939,17 @@ pub fn addCases(ctx: *TestContext) !void { | ... | @@ -1215,19 +939,17 @@ pub fn addCases(ctx: *TestContext) !void { |
| 1215 | }); | 939 | }); |
| 1216 | | 940 | |
| 1217 | ctx.compileError("compileError", linux_x64, | 941 | ctx.compileError("compileError", linux_x64, |
| 1218 | \\pub export fn _start() noreturn { | 942 | \\export fn foo() void { |
| 1219 | \\ @compileError("this is an error"); | 943 | \\ @compileError("this is an error"); |
| 1220 | \\ unreachable; | | |
| 1221 | \\} | 944 | \\} |
| 1222 | , &[_][]const u8{":2:3: error: this is an error"}); | 945 | , &[_][]const u8{":2:3: error: this is an error"}); |
| 1223 | | 946 | |
| 1224 | { | 947 | { |
| 1225 | var case = ctx.obj("variable shadowing", linux_x64); | 948 | var case = ctx.obj("variable shadowing", linux_x64); |
| 1226 | case.addError( | 949 | case.addError( |
| 1227 | \\export fn _start() noreturn { | 950 | \\pub fn main() void { |
| 1228 | \\ var i: u32 = 10; | 951 | \\ var i: u32 = 10; |
| 1229 | \\ var i: u32 = 10; | 952 | \\ var i: u32 = 10; |
| 1230 | \\ unreachable; | | |
| 1231 | \\} | 953 | \\} |
| 1232 | , &[_][]const u8{ | 954 | , &[_][]const u8{ |
| 1233 | ":3:9: error: redeclaration of 'i'", | 955 | ":3:9: error: redeclaration of 'i'", |
| ... | @@ -1235,9 +957,8 @@ pub fn addCases(ctx: *TestContext) !void { | ... | @@ -1235,9 +957,8 @@ pub fn addCases(ctx: *TestContext) !void { |
| 1235 | }); | 957 | }); |
| 1236 | case.addError( | 958 | case.addError( |
| 1237 | \\var testing: i64 = 10; | 959 | \\var testing: i64 = 10; |
| 1238 | \\pub export fn _start() noreturn { | 960 | \\pub fn main() void { |
| 1239 | \\ var testing: i64 = 20; | 961 | \\ var testing: i64 = 20; |
| 1240 | \\ unreachable; | | |
| 1241 | \\} | 962 | \\} |
| 1242 | , &[_][]const u8{ | 963 | , &[_][]const u8{ |
| 1243 | ":3:9: error: local shadows declaration of 'testing'", | 964 | ":3:9: error: local shadows declaration of 'testing'", |
| ... | @@ -1268,7 +989,7 @@ pub fn addCases(ctx: *TestContext) !void { | ... | @@ -1268,7 +989,7 @@ pub fn addCases(ctx: *TestContext) !void { |
| 1268 | | 989 | |
| 1269 | // Now only compile log statements remain. One per Decl. | 990 | // Now only compile log statements remain. One per Decl. |
| 1270 | case.addError( | 991 | case.addError( |
| 1271 | \\pub export fn _start() noreturn { | 992 | \\export fn _start() noreturn { |
| 1272 | \\ const b = true; | 993 | \\ const b = true; |
| 1273 | \\ var f: u32 = 1; | 994 | \\ var f: u32 = 1; |
| 1274 | \\ @compileLog(b, 20, f, x); | 995 | \\ @compileLog(b, 20, f, x); |
| ... | @@ -1306,43 +1027,19 @@ pub fn addCases(ctx: *TestContext) !void { | ... | @@ -1306,43 +1027,19 @@ pub fn addCases(ctx: *TestContext) !void { |
| 1306 | | 1027 | |
| 1307 | // Break out of loop | 1028 | // Break out of loop |
| 1308 | case.addCompareOutput( | 1029 | case.addCompareOutput( |
| 1309 | \\pub export fn _start() noreturn { | 1030 | \\pub fn main() void { |
| 1310 | \\ while (true) { | 1031 | \\ while (true) { |
| 1311 | \\ break; | 1032 | \\ break; |
| 1312 | \\ } | 1033 | \\ } |
| 1313 | \\ | | |
| 1314 | \\ exit(); | | |
| 1315 | \\} | | |
| 1316 | \\ | | |
| 1317 | \\fn exit() noreturn { | | |
| 1318 | \\ asm volatile ("syscall" | | |
| 1319 | \\ : | | |
| 1320 | \\ : [number] "{rax}" (231), | | |
| 1321 | \\ [arg1] "{rdi}" (0) | | |
| 1322 | \\ : "rcx", "r11", "memory" | | |
| 1323 | \\ ); | | |
| 1324 | \\ unreachable; | | |
| 1325 | \\} | 1034 | \\} |
| 1326 | , | 1035 | , |
| 1327 | "", | 1036 | "", |
| 1328 | ); | 1037 | ); |
| 1329 | case.addCompareOutput( | 1038 | case.addCompareOutput( |
| 1330 | \\pub export fn _start() noreturn { | 1039 | \\pub fn main() void { |
| 1331 | \\ foo: while (true) { | 1040 | \\ foo: while (true) { |
| 1332 | \\ break :foo; | 1041 | \\ break :foo; |
| 1333 | \\ } | 1042 | \\ } |
| 1334 | \\ | | |
| 1335 | \\ exit(); | | |
| 1336 | \\} | | |
| 1337 | \\ | | |
| 1338 | \\fn exit() noreturn { | | |
| 1339 | \\ asm volatile ("syscall" | | |
| 1340 | \\ : | | |
| 1341 | \\ : [number] "{rax}" (231), | | |
| 1342 | \\ [arg1] "{rdi}" (0) | | |
| 1343 | \\ : "rcx", "r11", "memory" | | |
| 1344 | \\ ); | | |
| 1345 | \\ unreachable; | | |
| 1346 | \\} | 1043 | \\} |
| 1347 | , | 1044 | , |
| 1348 | "", | 1045 | "", |
| ... | @@ -1534,46 +1231,26 @@ pub fn addCases(ctx: *TestContext) !void { | ... | @@ -1534,46 +1231,26 @@ pub fn addCases(ctx: *TestContext) !void { |
| 1534 | { | 1231 | { |
| 1535 | var case = ctx.exe("orelse at comptime", linux_x64); | 1232 | var case = ctx.exe("orelse at comptime", linux_x64); |
| 1536 | case.addCompareOutput( | 1233 | case.addCompareOutput( |
| 1537 | \\pub export fn _start() noreturn { | 1234 | \\pub fn main() void { |
| 1538 | \\ const i: ?u64 = 0; | 1235 | \\ const i: ?u64 = 0; |
| 1539 | \\ const orelsed = i orelse 5; | 1236 | \\ const result = i orelse 5; |
| 1540 | \\ assert(orelsed == 0); | 1237 | \\ assert(result == 0); |
| 1541 | \\ exit(); | | |
| 1542 | \\} | 1238 | \\} |
| 1543 | \\fn assert(b: bool) void { | 1239 | \\fn assert(b: bool) void { |
| 1544 | \\ if (!b) unreachable; | 1240 | \\ if (!b) unreachable; |
| 1545 | \\} | 1241 | \\} |
| 1546 | \\fn exit() noreturn { | | |
| 1547 | \\ asm volatile ("syscall" | | |
| 1548 | \\ : | | |
| 1549 | \\ : [number] "{rax}" (231), | | |
| 1550 | \\ [arg1] "{rdi}" (0) | | |
| 1551 | \\ : "rcx", "r11", "memory" | | |
| 1552 | \\ ); | | |
| 1553 | \\ unreachable; | | |
| 1554 | \\} | | |
| 1555 | , | 1242 | , |
| 1556 | "", | 1243 | "", |
| 1557 | ); | 1244 | ); |
| 1558 | case.addCompareOutput( | 1245 | case.addCompareOutput( |
| 1559 | \\pub export fn _start() noreturn { | 1246 | \\pub fn main() void { |
| 1560 | \\ const i: ?u64 = null; | 1247 | \\ const i: ?u64 = null; |
| 1561 | \\ const orelsed = i orelse 5; | 1248 | \\ const result = i orelse 5; |
| 1562 | \\ assert(orelsed == 5); | 1249 | \\ assert(result == 5); |
| 1563 | \\ exit(); | | |
| 1564 | \\} | 1250 | \\} |
| 1565 | \\fn assert(b: bool) void { | 1251 | \\fn assert(b: bool) void { |
| 1566 | \\ if (!b) unreachable; | 1252 | \\ if (!b) unreachable; |
| 1567 | \\} | 1253 | \\} |
| 1568 | \\fn exit() noreturn { | | |
| 1569 | \\ asm volatile ("syscall" | | |
| 1570 | \\ : | | |
| 1571 | \\ : [number] "{rax}" (231), | | |
| 1572 | \\ [arg1] "{rdi}" (0) | | |
| 1573 | \\ : "rcx", "r11", "memory" | | |
| 1574 | \\ ); | | |
| 1575 | \\ unreachable; | | |
| 1576 | \\} | | |
| 1577 | , | 1254 | , |
| 1578 | "", | 1255 | "", |
| 1579 | ); | 1256 | ); |
| ... | @@ -1611,20 +1288,10 @@ pub fn addCases(ctx: *TestContext) !void { | ... | @@ -1611,20 +1288,10 @@ pub fn addCases(ctx: *TestContext) !void { |
| 1611 | { | 1288 | { |
| 1612 | var case = ctx.exe("passing u0 to function", linux_x64); | 1289 | var case = ctx.exe("passing u0 to function", linux_x64); |
| 1613 | case.addCompareOutput( | 1290 | case.addCompareOutput( |
| 1614 | \\pub export fn _start() noreturn { | 1291 | \\pub fn main() void { |
| 1615 | \\ doNothing(0); | 1292 | \\ doNothing(0); |
| 1616 | \\ exit(); | | |
| 1617 | \\} | 1293 | \\} |
| 1618 | \\fn doNothing(arg: u0) void {} | 1294 | \\fn doNothing(arg: u0) void {} |
| 1619 | \\fn exit() noreturn { | | |
| 1620 | \\ asm volatile ("syscall" | | |
| 1621 | \\ : | | |
| 1622 | \\ : [number] "{rax}" (231), | | |
| 1623 | \\ [arg1] "{rdi}" (0) | | |
| 1624 | \\ : "rcx", "r11", "memory" | | |
| 1625 | \\ ); | | |
| 1626 | \\ unreachable; | | |
| 1627 | \\} | | |
| 1628 | , | 1295 | , |
| 1629 | "", | 1296 | "", |
| 1630 | ); | 1297 | ); |
| ... | @@ -1632,119 +1299,67 @@ pub fn addCases(ctx: *TestContext) !void { | ... | @@ -1632,119 +1299,67 @@ pub fn addCases(ctx: *TestContext) !void { |
| 1632 | { | 1299 | { |
| 1633 | var case = ctx.exe("catch at comptime", linux_x64); | 1300 | var case = ctx.exe("catch at comptime", linux_x64); |
| 1634 | case.addCompareOutput( | 1301 | case.addCompareOutput( |
| 1635 | \\pub export fn _start() noreturn { | 1302 | \\pub fn main() void { |
| 1636 | \\ const i: anyerror!u64 = 0; | 1303 | \\ const i: anyerror!u64 = 0; |
| 1637 | \\ const caught = i catch 5; | 1304 | \\ const caught = i catch 5; |
| 1638 | \\ assert(caught == 0); | 1305 | \\ assert(caught == 0); |
| 1639 | \\ exit(); | | |
| 1640 | \\} | 1306 | \\} |
| 1641 | \\fn assert(b: bool) void { | 1307 | \\fn assert(b: bool) void { |
| 1642 | \\ if (!b) unreachable; | 1308 | \\ if (!b) unreachable; |
| 1643 | \\} | 1309 | \\} |
| 1644 | \\fn exit() noreturn { | | |
| 1645 | \\ asm volatile ("syscall" | | |
| 1646 | \\ : | | |
| 1647 | \\ : [number] "{rax}" (231), | | |
| 1648 | \\ [arg1] "{rdi}" (0) | | |
| 1649 | \\ : "rcx", "r11", "memory" | | |
| 1650 | \\ ); | | |
| 1651 | \\ unreachable; | | |
| 1652 | \\} | | |
| 1653 | , | 1310 | , |
| 1654 | "", | 1311 | "", |
| 1655 | ); | 1312 | ); |
| 1656 | | 1313 | |
| 1657 | case.addCompareOutput( | 1314 | case.addCompareOutput( |
| 1658 | \\pub export fn _start() noreturn { | 1315 | \\pub fn main() void { |
| 1659 | \\ const i: anyerror!u64 = error.B; | 1316 | \\ const i: anyerror!u64 = error.B; |
| 1660 | \\ const caught = i catch 5; | 1317 | \\ const caught = i catch 5; |
| 1661 | \\ assert(caught == 5); | 1318 | \\ assert(caught == 5); |
| 1662 | \\ exit(); | | |
| 1663 | \\} | 1319 | \\} |
| 1664 | \\fn assert(b: bool) void { | 1320 | \\fn assert(b: bool) void { |
| 1665 | \\ if (!b) unreachable; | 1321 | \\ if (!b) unreachable; |
| 1666 | \\} | 1322 | \\} |
| 1667 | \\fn exit() noreturn { | | |
| 1668 | \\ asm volatile ("syscall" | | |
| 1669 | \\ : | | |
| 1670 | \\ : [number] "{rax}" (231), | | |
| 1671 | \\ [arg1] "{rdi}" (0) | | |
| 1672 | \\ : "rcx", "r11", "memory" | | |
| 1673 | \\ ); | | |
| 1674 | \\ unreachable; | | |
| 1675 | \\} | | |
| 1676 | , | 1323 | , |
| 1677 | "", | 1324 | "", |
| 1678 | ); | 1325 | ); |
| 1679 | | 1326 | |
| 1680 | case.addCompareOutput( | 1327 | case.addCompareOutput( |
| 1681 | \\pub export fn _start() noreturn { | 1328 | \\pub fn main() void { |
| 1682 | \\ const a: anyerror!comptime_int = 42; | 1329 | \\ const a: anyerror!comptime_int = 42; |
| 1683 | \\ const b: *const comptime_int = &(a catch unreachable); | 1330 | \\ const b: *const comptime_int = &(a catch unreachable); |
| 1684 | \\ assert(b.* == 42); | 1331 | \\ assert(b.* == 42); |
| 1685 | \\ | | |
| 1686 | \\ exit(); | | |
| 1687 | \\} | 1332 | \\} |
| 1688 | \\fn assert(b: bool) void { | 1333 | \\fn assert(b: bool) void { |
| 1689 | \\ if (!b) unreachable; // assertion failure | 1334 | \\ if (!b) unreachable; // assertion failure |
| 1690 | \\} | 1335 | \\} |
| 1691 | \\fn exit() noreturn { | | |
| 1692 | \\ asm volatile ("syscall" | | |
| 1693 | \\ : | | |
| 1694 | \\ : [number] "{rax}" (231), | | |
| 1695 | \\ [arg1] "{rdi}" (0) | | |
| 1696 | \\ : "rcx", "r11", "memory" | | |
| 1697 | \\ ); | | |
| 1698 | \\ unreachable; | | |
| 1699 | \\} | | |
| 1700 | , ""); | 1336 | , ""); |
| 1701 | | 1337 | |
| 1702 | case.addCompareOutput( | 1338 | case.addCompareOutput( |
| 1703 | \\pub export fn _start() noreturn { | 1339 | \\pub fn main() void { |
| 1704 | \\ const a: anyerror!u32 = error.B; | 1340 | \\ const a: anyerror!u32 = error.B; |
| 1705 | \\ _ = &(a catch |err| assert(err == error.B)); | 1341 | \\ _ = &(a catch |err| assert(err == error.B)); |
| 1706 | \\ exit(); | | |
| 1707 | \\} | 1342 | \\} |
| 1708 | \\fn assert(b: bool) void { | 1343 | \\fn assert(b: bool) void { |
| 1709 | \\ if (!b) unreachable; | 1344 | \\ if (!b) unreachable; |
| 1710 | \\} | 1345 | \\} |
| 1711 | \\fn exit() noreturn { | | |
| 1712 | \\ asm volatile ("syscall" | | |
| 1713 | \\ : | | |
| 1714 | \\ : [number] "{rax}" (231), | | |
| 1715 | \\ [arg1] "{rdi}" (0) | | |
| 1716 | \\ : "rcx", "r11", "memory" | | |
| 1717 | \\ ); | | |
| 1718 | \\ unreachable; | | |
| 1719 | \\} | | |
| 1720 | , ""); | 1346 | , ""); |
| 1721 | | 1347 | |
| 1722 | case.addCompareOutput( | 1348 | case.addCompareOutput( |
| 1723 | \\pub export fn _start() noreturn { | 1349 | \\pub fn main() void { |
| 1724 | \\ const a: anyerror!u32 = error.Bar; | 1350 | \\ const a: anyerror!u32 = error.Bar; |
| 1725 | \\ a catch |err| assert(err == error.Bar); | 1351 | \\ a catch |err| assert(err == error.Bar); |
| 1726 | \\ | | |
| 1727 | \\ exit(); | | |
| 1728 | \\} | 1352 | \\} |
| 1729 | \\fn assert(b: bool) void { | 1353 | \\fn assert(b: bool) void { |
| 1730 | \\ if (!b) unreachable; | 1354 | \\ if (!b) unreachable; |
| 1731 | \\} | 1355 | \\} |
| 1732 | \\fn exit() noreturn { | | |
| 1733 | \\ asm volatile ("syscall" | | |
| 1734 | \\ : | | |
| 1735 | \\ : [number] "{rax}" (231), | | |
| 1736 | \\ [arg1] "{rdi}" (0) | | |
| 1737 | \\ : "rcx", "r11", "memory" | | |
| 1738 | \\ ); | | |
| 1739 | \\ unreachable; | | |
| 1740 | \\} | | |
| 1741 | , ""); | 1356 | , ""); |
| 1742 | } | 1357 | } |
| 1743 | { | 1358 | { |
| 1744 | var case = ctx.exe("merge error sets", linux_x64); | 1359 | var case = ctx.exe("merge error sets", linux_x64); |
| 1745 | | 1360 | |
| 1746 | case.addCompareOutput( | 1361 | case.addCompareOutput( |
| 1747 | \\pub export fn _start() noreturn { | 1362 | \\pub fn main() void { |
| 1748 | \\ const E = error{ A, B, D } || error { A, B, C }; | 1363 | \\ const E = error{ A, B, D } || error { A, B, C }; |
| 1749 | \\ const a = E.A; | 1364 | \\ const a = E.A; |
| 1750 | \\ const b = E.B; | 1365 | \\ const b = E.B; |
| ... | @@ -1755,20 +1370,10 @@ pub fn addCases(ctx: *TestContext) !void { | ... | @@ -1755,20 +1370,10 @@ pub fn addCases(ctx: *TestContext) !void { |
| 1755 | \\ const y = E2.Y; | 1370 | \\ const y = E2.Y; |
| 1756 | \\ const z = E2.Z; | 1371 | \\ const z = E2.Z; |
| 1757 | \\ assert(anyerror || error { Z } == anyerror); | 1372 | \\ assert(anyerror || error { Z } == anyerror); |
| 1758 | \\ exit(); | | |
| 1759 | \\} | 1373 | \\} |
| 1760 | \\fn assert(b: bool) void { | 1374 | \\fn assert(b: bool) void { |
| 1761 | \\ if (!b) unreachable; | 1375 | \\ if (!b) unreachable; |
| 1762 | \\} | 1376 | \\} |
| 1763 | \\fn exit() noreturn { | | |
| 1764 | \\ asm volatile ("syscall" | | |
| 1765 | \\ : | | |
| 1766 | \\ : [number] "{rax}" (231), | | |
| 1767 | \\ [arg1] "{rdi}" (0) | | |
| 1768 | \\ : "rcx", "r11", "memory" | | |
| 1769 | \\ ); | | |
| 1770 | \\ unreachable; | | |
| 1771 | \\} | | |
| 1772 | , | 1377 | , |
| 1773 | "", | 1378 | "", |
| 1774 | ); | 1379 | ); |