| ... | ... | @@ -65,6 +65,7 @@ pub fn addCases(ctx: *TestContext) !void { |
| 65 | 65 | , |
| 66 | 66 | "Hello, World!\n", |
| 67 | 67 | ); |
| 68 | |
| 68 | 69 | // Now change the message only |
| 69 | 70 | case.addCompareOutput( |
| 70 | 71 | \\pub export fn _start() noreturn { |
| ... | ... | @@ -237,25 +238,13 @@ pub fn addCases(ctx: *TestContext) !void { |
| 237 | 238 | { |
| 238 | 239 | var case = ctx.exe("subtracting numbers at runtime", linux_x64); |
| 239 | 240 | case.addCompareOutput( |
| 240 | | \\pub export fn _start() noreturn { |
| 241 | \\pub fn main() void { |
| 241 | 242 | \\ sub(7, 4); |
| 242 | | \\ |
| 243 | | \\ exit(); |
| 244 | 243 | \\} |
| 245 | 244 | \\ |
| 246 | 245 | \\fn sub(a: u32, b: u32) void { |
| 247 | 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 | 252 | { |
| 264 | 253 | var case = ctx.exe("@TypeOf", linux_x64); |
| 265 | 254 | case.addCompareOutput( |
| 266 | | \\pub export fn _start() noreturn { |
| 255 | \\pub fn main() void { |
| 267 | 256 | \\ var x: usize = 0; |
| 268 | 257 | \\ const z = @TypeOf(x, @as(u128, 5)); |
| 269 | 258 | \\ assert(z == u128); |
| 270 | | \\ |
| 271 | | \\ exit(); |
| 272 | 259 | \\} |
| 273 | 260 | \\ |
| 274 | 261 | \\pub fn assert(ok: bool) void { |
| 275 | 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 | 267 | case.addCompareOutput( |
| 291 | | \\pub export fn _start() noreturn { |
| 268 | \\pub fn main() void { |
| 292 | 269 | \\ const z = @TypeOf(true); |
| 293 | 270 | \\ assert(z == bool); |
| 294 | | \\ |
| 295 | | \\ exit(); |
| 296 | 271 | \\} |
| 297 | 272 | \\ |
| 298 | 273 | \\pub fn assert(ok: bool) void { |
| 299 | 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 | 279 | case.addError( |
| 315 | | \\pub export fn _start() noreturn { |
| 280 | \\pub fn main() void { |
| 316 | 281 | \\ const z = @TypeOf(true, 1); |
| 317 | | \\ unreachable; |
| 318 | 282 | \\} |
| 319 | 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 | 310 | ); |
| 347 | 311 | // comptime function call |
| 348 | 312 | case.addCompareOutput( |
| 349 | | \\pub export fn _start() noreturn { |
| 313 | \\pub fn _start() noreturn { |
| 350 | 314 | \\ exit(); |
| 351 | 315 | \\} |
| 352 | 316 | \\ |
| ... | ... | @@ -397,10 +361,8 @@ pub fn addCases(ctx: *TestContext) !void { |
| 397 | 361 | { |
| 398 | 362 | var case = ctx.exe("assert function", linux_x64); |
| 399 | 363 | case.addCompareOutput( |
| 400 | | \\pub export fn _start() noreturn { |
| 364 | \\pub fn main() void { |
| 401 | 365 | \\ add(3, 4); |
| 402 | | \\ |
| 403 | | \\ exit(); |
| 404 | 366 | \\} |
| 405 | 367 | \\ |
| 406 | 368 | \\fn add(a: u32, b: u32) void { |
| ... | ... | @@ -427,10 +389,8 @@ pub fn addCases(ctx: *TestContext) !void { |
| 427 | 389 | // Tests copying a register. For the `c = a + b`, it has to |
| 428 | 390 | // preserve both a and b, because they are both used later. |
| 429 | 391 | case.addCompareOutput( |
| 430 | | \\pub export fn _start() noreturn { |
| 392 | \\pub fn main() void { |
| 431 | 393 | \\ add(3, 4); |
| 432 | | \\ |
| 433 | | \\ exit(); |
| 434 | 394 | \\} |
| 435 | 395 | \\ |
| 436 | 396 | \\fn add(a: u32, b: u32) void { |
| ... | ... | @@ -443,26 +403,14 @@ pub fn addCases(ctx: *TestContext) !void { |
| 443 | 403 | \\pub fn assert(ok: bool) void { |
| 444 | 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 | 410 | // More stress on the liveness detection. |
| 461 | 411 | case.addCompareOutput( |
| 462 | | \\pub export fn _start() noreturn { |
| 412 | \\pub fn main() void { |
| 463 | 413 | \\ add(3, 4); |
| 464 | | \\ |
| 465 | | \\ exit(); |
| 466 | 414 | \\} |
| 467 | 415 | \\ |
| 468 | 416 | \\fn add(a: u32, b: u32) void { |
| ... | ... | @@ -479,26 +427,14 @@ pub fn addCases(ctx: *TestContext) !void { |
| 479 | 427 | \\pub fn assert(ok: bool) void { |
| 480 | 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 | 434 | // Requires a second move. The register allocator should figure out to re-use rax. |
| 497 | 435 | case.addCompareOutput( |
| 498 | | \\pub export fn _start() noreturn { |
| 436 | \\pub fn main() void { |
| 499 | 437 | \\ add(3, 4); |
| 500 | | \\ |
| 501 | | \\ exit(); |
| 502 | 438 | \\} |
| 503 | 439 | \\ |
| 504 | 440 | \\fn add(a: u32, b: u32) void { |
| ... | ... | @@ -516,27 +452,15 @@ pub fn addCases(ctx: *TestContext) !void { |
| 516 | 452 | \\pub fn assert(ok: bool) void { |
| 517 | 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 | 459 | // Now we test integer return values. |
| 534 | 460 | case.addCompareOutput( |
| 535 | | \\pub export fn _start() noreturn { |
| 461 | \\pub fn main() void { |
| 536 | 462 | \\ assert(add(3, 4) == 7); |
| 537 | 463 | \\ assert(add(20, 10) == 30); |
| 538 | | \\ |
| 539 | | \\ exit(); |
| 540 | 464 | \\} |
| 541 | 465 | \\ |
| 542 | 466 | \\fn add(a: u32, b: u32) u32 { |
| ... | ... | @@ -546,27 +470,15 @@ pub fn addCases(ctx: *TestContext) !void { |
| 546 | 470 | \\pub fn assert(ok: bool) void { |
| 547 | 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 | 477 | // Local mutable variables. |
| 564 | 478 | case.addCompareOutput( |
| 565 | | \\pub export fn _start() noreturn { |
| 479 | \\pub fn main() void { |
| 566 | 480 | \\ assert(add(3, 4) == 7); |
| 567 | 481 | \\ assert(add(20, 10) == 30); |
| 568 | | \\ |
| 569 | | \\ exit(); |
| 570 | 482 | \\} |
| 571 | 483 | \\ |
| 572 | 484 | \\fn add(a: u32, b: u32) u32 { |
| ... | ... | @@ -580,39 +492,17 @@ pub fn addCases(ctx: *TestContext) !void { |
| 580 | 492 | \\pub fn assert(ok: bool) void { |
| 581 | 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 | 499 | // Optionals |
| 598 | 500 | case.addCompareOutput( |
| 599 | | \\pub export fn _start() noreturn { |
| 501 | \\pub fn main() void { |
| 600 | 502 | \\ const a: u32 = 2; |
| 601 | 503 | \\ const b: ?u32 = a; |
| 602 | 504 | \\ const c = b.?; |
| 603 | 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 | 510 | |
| 621 | 511 | // While loops |
| 622 | 512 | case.addCompareOutput( |
| 623 | | \\pub export fn _start() noreturn { |
| 513 | \\pub fn main() void { |
| 624 | 514 | \\ var i: u32 = 0; |
| 625 | 515 | \\ while (i < 4) : (i += 1) print(); |
| 626 | 516 | \\ assert(i == 4); |
| 627 | | \\ |
| 628 | | \\ exit(); |
| 629 | 517 | \\} |
| 630 | 518 | \\ |
| 631 | 519 | \\fn print() void { |
| ... | ... | @@ -643,28 +531,16 @@ pub fn addCases(ctx: *TestContext) !void { |
| 643 | 531 | \\pub fn assert(ok: bool) void { |
| 644 | 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 | 535 | "hello\nhello\nhello\nhello\n", |
| 658 | 536 | ); |
| 659 | 537 | |
| 660 | 538 | // inline while requires the condition to be comptime known. |
| 661 | 539 | case.addError( |
| 662 | | \\pub export fn _start() noreturn { |
| 540 | \\pub fn main() void { |
| 663 | 541 | \\ var i: u32 = 0; |
| 664 | 542 | \\ inline while (i < 4) : (i += 1) print(); |
| 665 | 543 | \\ assert(i == 4); |
| 666 | | \\ |
| 667 | | \\ exit(); |
| 668 | 544 | \\} |
| 669 | 545 | \\ |
| 670 | 546 | \\fn print() void { |
| ... | ... | @@ -682,24 +558,12 @@ pub fn addCases(ctx: *TestContext) !void { |
| 682 | 558 | \\pub fn assert(ok: bool) void { |
| 683 | 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 | 561 | , &[_][]const u8{":3:21: error: unable to resolve comptime value"}); |
| 696 | 562 | |
| 697 | 563 | // Labeled blocks (no conditional branch) |
| 698 | 564 | case.addCompareOutput( |
| 699 | | \\pub export fn _start() noreturn { |
| 565 | \\pub fn main() void { |
| 700 | 566 | \\ assert(add(3, 4) == 20); |
| 701 | | \\ |
| 702 | | \\ exit(); |
| 703 | 567 | \\} |
| 704 | 568 | \\ |
| 705 | 569 | \\fn add(a: u32, b: u32) u32 { |
| ... | ... | @@ -717,26 +581,14 @@ pub fn addCases(ctx: *TestContext) !void { |
| 717 | 581 | \\pub fn assert(ok: bool) void { |
| 718 | 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 | 588 | // This catches a possible bug in the logic for re-using dying operands. |
| 735 | 589 | case.addCompareOutput( |
| 736 | | \\pub export fn _start() noreturn { |
| 590 | \\pub fn main() void { |
| 737 | 591 | \\ assert(add(3, 4) == 116); |
| 738 | | \\ |
| 739 | | \\ exit(); |
| 740 | 592 | \\} |
| 741 | 593 | \\ |
| 742 | 594 | \\fn add(a: u32, b: u32) u32 { |
| ... | ... | @@ -759,27 +611,15 @@ pub fn addCases(ctx: *TestContext) !void { |
| 759 | 611 | \\pub fn assert(ok: bool) void { |
| 760 | 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 | 618 | // Spilling registers to the stack. |
| 777 | 619 | case.addCompareOutput( |
| 778 | | \\pub export fn _start() noreturn { |
| 620 | \\pub fn main() void { |
| 779 | 621 | \\ assert(add(3, 4) == 1221); |
| 780 | 622 | \\ assert(mul(3, 4) == 21609); |
| 781 | | \\ |
| 782 | | \\ exit(); |
| 783 | 623 | \\} |
| 784 | 624 | \\ |
| 785 | 625 | \\fn add(a: u32, b: u32) u32 { |
| ... | ... | @@ -840,27 +680,15 @@ pub fn addCases(ctx: *TestContext) !void { |
| 840 | 680 | \\pub fn assert(ok: bool) void { |
| 841 | 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 | 687 | // Reusing the registers of dead operands playing nicely with conditional branching. |
| 858 | 688 | case.addCompareOutput( |
| 859 | | \\pub export fn _start() noreturn { |
| 689 | \\pub fn main() void { |
| 860 | 690 | \\ assert(add(3, 4) == 791); |
| 861 | 691 | \\ assert(add(4, 3) == 79); |
| 862 | | \\ |
| 863 | | \\ exit(); |
| 864 | 692 | \\} |
| 865 | 693 | \\ |
| 866 | 694 | \\fn add(a: u32, b: u32) u32 { |
| ... | ... | @@ -902,30 +730,18 @@ pub fn addCases(ctx: *TestContext) !void { |
| 902 | 730 | \\pub fn assert(ok: bool) void { |
| 903 | 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 | 737 | // Character literals and multiline strings. |
| 920 | 738 | case.addCompareOutput( |
| 921 | | \\pub export fn _start() noreturn { |
| 739 | \\pub fn main() void { |
| 922 | 740 | \\ const ignore = |
| 923 | 741 | \\ \\ cool thx |
| 924 | 742 | \\ \\ |
| 925 | 743 | \\ ; |
| 926 | 744 | \\ add('ぁ', '\x03'); |
| 927 | | \\ |
| 928 | | \\ exit(); |
| 929 | 745 | \\} |
| 930 | 746 | \\ |
| 931 | 747 | \\fn add(a: u32, b: u32) void { |
| ... | ... | @@ -935,26 +751,14 @@ pub fn addCases(ctx: *TestContext) !void { |
| 935 | 751 | \\pub fn assert(ok: bool) void { |
| 936 | 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 | 758 | // Global const. |
| 953 | 759 | case.addCompareOutput( |
| 954 | | \\pub export fn _start() noreturn { |
| 760 | \\pub fn main() void { |
| 955 | 761 | \\ add(aa, bb); |
| 956 | | \\ |
| 957 | | \\ exit(); |
| 958 | 762 | \\} |
| 959 | 763 | \\ |
| 960 | 764 | \\const aa = 'ぁ'; |
| ... | ... | @@ -967,41 +771,19 @@ pub fn addCases(ctx: *TestContext) !void { |
| 967 | 771 | \\pub fn assert(ok: bool) void { |
| 968 | 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 | 778 | // Array access. |
| 985 | 779 | case.addCompareOutput( |
| 986 | | \\pub export fn _start() noreturn { |
| 780 | \\pub fn main() void { |
| 987 | 781 | \\ assert("hello"[0] == 'h'); |
| 988 | | \\ |
| 989 | | \\ exit(); |
| 990 | 782 | \\} |
| 991 | 783 | \\ |
| 992 | 784 | \\pub fn assert(ok: bool) void { |
| 993 | 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 | 791 | // Array access to a global array. |
| 1010 | 792 | case.addCompareOutput( |
| 1011 | 793 | \\const hello = "hello".*; |
| 1012 | | \\pub export fn _start() noreturn { |
| 794 | \\pub fn main() void { |
| 1013 | 795 | \\ assert(hello[1] == 'e'); |
| 1014 | | \\ |
| 1015 | | \\ exit(); |
| 1016 | 796 | \\} |
| 1017 | 797 | \\ |
| 1018 | 798 | \\pub fn assert(ok: bool) void { |
| 1019 | 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 | 805 | // 64bit set stack |
| 1036 | 806 | case.addCompareOutput( |
| 1037 | | \\pub export fn _start() noreturn { |
| 807 | \\pub fn main() void { |
| 1038 | 808 | \\ var i: u64 = 0xFFEEDDCCBBAA9988; |
| 1039 | 809 | \\ assert(i == 0xFFEEDDCCBBAA9988); |
| 1040 | | \\ |
| 1041 | | \\ exit(); |
| 1042 | 810 | \\} |
| 1043 | 811 | \\ |
| 1044 | 812 | \\pub fn assert(ok: bool) void { |
| 1045 | 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 | 819 | // Basic for loop |
| 1062 | 820 | case.addCompareOutput( |
| 1063 | | \\pub export fn _start() noreturn { |
| 821 | \\pub fn main() void { |
| 1064 | 822 | \\ for ("hello") |_| print(); |
| 1065 | | \\ |
| 1066 | | \\ exit(); |
| 1067 | 823 | \\} |
| 1068 | 824 | \\ |
| 1069 | 825 | \\fn print() void { |
| ... | ... | @@ -1077,16 +833,6 @@ pub fn addCases(ctx: *TestContext) !void { |
| 1077 | 833 | \\ ); |
| 1078 | 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 | 837 | "hello\nhello\nhello\nhello\nhello\n", |
| 1092 | 838 | ); |
| ... | ... | @@ -1095,19 +841,8 @@ pub fn addCases(ctx: *TestContext) !void { |
| 1095 | 841 | { |
| 1096 | 842 | var case = ctx.exe("basic import", linux_x64); |
| 1097 | 843 | case.addCompareOutput( |
| 1098 | | \\pub export fn _start() noreturn { |
| 844 | \\pub fn main() void { |
| 1099 | 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 | 848 | "Hello, World!\n", |
| ... | ... | @@ -1132,14 +867,14 @@ pub fn addCases(ctx: *TestContext) !void { |
| 1132 | 867 | { |
| 1133 | 868 | var case = ctx.exe("redundant comptime", linux_x64); |
| 1134 | 869 | case.addError( |
| 1135 | | \\pub export fn _start() void { |
| 870 | \\pub fn main() void { |
| 1136 | 871 | \\ var a: comptime u32 = 0; |
| 1137 | 872 | \\} |
| 1138 | 873 | , |
| 1139 | 874 | &.{":2:12: error: redundant comptime keyword in already comptime scope"}, |
| 1140 | 875 | ); |
| 1141 | 876 | case.addError( |
| 1142 | | \\pub export fn _start() void { |
| 877 | \\pub fn main() void { |
| 1143 | 878 | \\ comptime { |
| 1144 | 879 | \\ var a: u32 = comptime 0; |
| 1145 | 880 | \\ } |
| ... | ... | @@ -1151,19 +886,8 @@ pub fn addCases(ctx: *TestContext) !void { |
| 1151 | 886 | { |
| 1152 | 887 | var case = ctx.exe("import private", linux_x64); |
| 1153 | 888 | case.addError( |
| 1154 | | \\pub export fn _start() noreturn { |
| 889 | \\pub fn main() void { |
| 1155 | 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 | 939 | }); |
| 1216 | 940 | |
| 1217 | 941 | ctx.compileError("compileError", linux_x64, |
| 1218 | | \\pub export fn _start() noreturn { |
| 942 | \\export fn foo() void { |
| 1219 | 943 | \\ @compileError("this is an error"); |
| 1220 | | \\ unreachable; |
| 1221 | 944 | \\} |
| 1222 | 945 | , &[_][]const u8{":2:3: error: this is an error"}); |
| 1223 | 946 | |
| 1224 | 947 | { |
| 1225 | 948 | var case = ctx.obj("variable shadowing", linux_x64); |
| 1226 | 949 | case.addError( |
| 1227 | | \\export fn _start() noreturn { |
| 950 | \\pub fn main() void { |
| 1228 | 951 | \\ var i: u32 = 10; |
| 1229 | 952 | \\ var i: u32 = 10; |
| 1230 | | \\ unreachable; |
| 1231 | 953 | \\} |
| 1232 | 954 | , &[_][]const u8{ |
| 1233 | 955 | ":3:9: error: redeclaration of 'i'", |
| ... | ... | @@ -1235,9 +957,8 @@ pub fn addCases(ctx: *TestContext) !void { |
| 1235 | 957 | }); |
| 1236 | 958 | case.addError( |
| 1237 | 959 | \\var testing: i64 = 10; |
| 1238 | | \\pub export fn _start() noreturn { |
| 960 | \\pub fn main() void { |
| 1239 | 961 | \\ var testing: i64 = 20; |
| 1240 | | \\ unreachable; |
| 1241 | 962 | \\} |
| 1242 | 963 | , &[_][]const u8{ |
| 1243 | 964 | ":3:9: error: local shadows declaration of 'testing'", |
| ... | ... | @@ -1268,7 +989,7 @@ pub fn addCases(ctx: *TestContext) !void { |
| 1268 | 989 | |
| 1269 | 990 | // Now only compile log statements remain. One per Decl. |
| 1270 | 991 | case.addError( |
| 1271 | | \\pub export fn _start() noreturn { |
| 992 | \\export fn _start() noreturn { |
| 1272 | 993 | \\ const b = true; |
| 1273 | 994 | \\ var f: u32 = 1; |
| 1274 | 995 | \\ @compileLog(b, 20, f, x); |
| ... | ... | @@ -1306,43 +1027,19 @@ pub fn addCases(ctx: *TestContext) !void { |
| 1306 | 1027 | |
| 1307 | 1028 | // Break out of loop |
| 1308 | 1029 | case.addCompareOutput( |
| 1309 | | \\pub export fn _start() noreturn { |
| 1030 | \\pub fn main() void { |
| 1310 | 1031 | \\ while (true) { |
| 1311 | 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 | 1038 | case.addCompareOutput( |
| 1330 | | \\pub export fn _start() noreturn { |
| 1039 | \\pub fn main() void { |
| 1331 | 1040 | \\ foo: while (true) { |
| 1332 | 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 | 1231 | { |
| 1535 | 1232 | var case = ctx.exe("orelse at comptime", linux_x64); |
| 1536 | 1233 | case.addCompareOutput( |
| 1537 | | \\pub export fn _start() noreturn { |
| 1234 | \\pub fn main() void { |
| 1538 | 1235 | \\ const i: ?u64 = 0; |
| 1539 | | \\ const orelsed = i orelse 5; |
| 1540 | | \\ assert(orelsed == 0); |
| 1541 | | \\ exit(); |
| 1236 | \\ const result = i orelse 5; |
| 1237 | \\ assert(result == 0); |
| 1542 | 1238 | \\} |
| 1543 | 1239 | \\fn assert(b: bool) void { |
| 1544 | 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 | 1245 | case.addCompareOutput( |
| 1559 | | \\pub export fn _start() noreturn { |
| 1246 | \\pub fn main() void { |
| 1560 | 1247 | \\ const i: ?u64 = null; |
| 1561 | | \\ const orelsed = i orelse 5; |
| 1562 | | \\ assert(orelsed == 5); |
| 1563 | | \\ exit(); |
| 1248 | \\ const result = i orelse 5; |
| 1249 | \\ assert(result == 5); |
| 1564 | 1250 | \\} |
| 1565 | 1251 | \\fn assert(b: bool) void { |
| 1566 | 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 | 1288 | { |
| 1612 | 1289 | var case = ctx.exe("passing u0 to function", linux_x64); |
| 1613 | 1290 | case.addCompareOutput( |
| 1614 | | \\pub export fn _start() noreturn { |
| 1291 | \\pub fn main() void { |
| 1615 | 1292 | \\ doNothing(0); |
| 1616 | | \\ exit(); |
| 1617 | 1293 | \\} |
| 1618 | 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 | 1299 | { |
| 1633 | 1300 | var case = ctx.exe("catch at comptime", linux_x64); |
| 1634 | 1301 | case.addCompareOutput( |
| 1635 | | \\pub export fn _start() noreturn { |
| 1302 | \\pub fn main() void { |
| 1636 | 1303 | \\ const i: anyerror!u64 = 0; |
| 1637 | 1304 | \\ const caught = i catch 5; |
| 1638 | 1305 | \\ assert(caught == 0); |
| 1639 | | \\ exit(); |
| 1640 | 1306 | \\} |
| 1641 | 1307 | \\fn assert(b: bool) void { |
| 1642 | 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 | 1314 | case.addCompareOutput( |
| 1658 | | \\pub export fn _start() noreturn { |
| 1315 | \\pub fn main() void { |
| 1659 | 1316 | \\ const i: anyerror!u64 = error.B; |
| 1660 | 1317 | \\ const caught = i catch 5; |
| 1661 | 1318 | \\ assert(caught == 5); |
| 1662 | | \\ exit(); |
| 1663 | 1319 | \\} |
| 1664 | 1320 | \\fn assert(b: bool) void { |
| 1665 | 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 | 1327 | case.addCompareOutput( |
| 1681 | | \\pub export fn _start() noreturn { |
| 1328 | \\pub fn main() void { |
| 1682 | 1329 | \\ const a: anyerror!comptime_int = 42; |
| 1683 | 1330 | \\ const b: *const comptime_int = &(a catch unreachable); |
| 1684 | 1331 | \\ assert(b.* == 42); |
| 1685 | | \\ |
| 1686 | | \\ exit(); |
| 1687 | 1332 | \\} |
| 1688 | 1333 | \\fn assert(b: bool) void { |
| 1689 | 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 | 1338 | case.addCompareOutput( |
| 1703 | | \\pub export fn _start() noreturn { |
| 1339 | \\pub fn main() void { |
| 1704 | 1340 | \\ const a: anyerror!u32 = error.B; |
| 1705 | 1341 | \\ _ = &(a catch |err| assert(err == error.B)); |
| 1706 | | \\ exit(); |
| 1707 | 1342 | \\} |
| 1708 | 1343 | \\fn assert(b: bool) void { |
| 1709 | 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 | 1348 | case.addCompareOutput( |
| 1723 | | \\pub export fn _start() noreturn { |
| 1349 | \\pub fn main() void { |
| 1724 | 1350 | \\ const a: anyerror!u32 = error.Bar; |
| 1725 | 1351 | \\ a catch |err| assert(err == error.Bar); |
| 1726 | | \\ |
| 1727 | | \\ exit(); |
| 1728 | 1352 | \\} |
| 1729 | 1353 | \\fn assert(b: bool) void { |
| 1730 | 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 | 1359 | var case = ctx.exe("merge error sets", linux_x64); |
| 1745 | 1360 | |
| 1746 | 1361 | case.addCompareOutput( |
| 1747 | | \\pub export fn _start() noreturn { |
| 1362 | \\pub fn main() void { |
| 1748 | 1363 | \\ const E = error{ A, B, D } || error { A, B, C }; |
| 1749 | 1364 | \\ const a = E.A; |
| 1750 | 1365 | \\ const b = E.B; |
| ... | ... | @@ -1755,20 +1370,10 @@ pub fn addCases(ctx: *TestContext) !void { |
| 1755 | 1370 | \\ const y = E2.Y; |
| 1756 | 1371 | \\ const z = E2.Z; |
| 1757 | 1372 | \\ assert(anyerror || error { Z } == anyerror); |
| 1758 | | \\ exit(); |
| 1759 | 1373 | \\} |
| 1760 | 1374 | \\fn assert(b: bool) void { |
| 1761 | 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 | ); |