| ... | ... | @@ -390,168 +390,6 @@ export fn main(argc: c_int, argv: &&u8) -> c_int { |
| 390 | 390 | 0o10700.00010e0: 0x1.1c0001p+12 |
| 391 | 391 | )OUTPUT"); |
| 392 | 392 | |
| 393 | | |
| 394 | | |
| 395 | | add_simple_case("continue and break", R"SOURCE( |
| 396 | | const io = @import("std").io; |
| 397 | | pub fn main(args: [][]u8) -> %void { |
| 398 | | var i : i32 = 0; |
| 399 | | while (true) { |
| 400 | | %%io.stdout.printf("loop\n"); |
| 401 | | i += 1; |
| 402 | | if (i < 4) { |
| 403 | | continue; |
| 404 | | } |
| 405 | | break; |
| 406 | | } |
| 407 | | } |
| 408 | | )SOURCE", "loop\nloop\nloop\nloop\n"); |
| 409 | | |
| 410 | | add_simple_case("@sizeof() and @typeof()", R"SOURCE( |
| 411 | | const io = @import("std").io; |
| 412 | | const x: u16 = 13; |
| 413 | | const z: @typeof(x) = 19; |
| 414 | | pub fn main(args: [][]u8) -> %void { |
| 415 | | const y: @typeof(x) = 120; |
| 416 | | %%io.stdout.print_u64(@sizeof(@typeof(y))); |
| 417 | | %%io.stdout.printf("\n"); |
| 418 | | } |
| 419 | | )SOURCE", "2\n"); |
| 420 | | |
| 421 | | add_simple_case("pointer dereferencing", R"SOURCE( |
| 422 | | const io = @import("std").io; |
| 423 | | |
| 424 | | pub fn main(args: [][]u8) -> %void { |
| 425 | | var x = i32(3); |
| 426 | | const y = &x; |
| 427 | | |
| 428 | | *y += 1; |
| 429 | | |
| 430 | | if (x != 4) { |
| 431 | | %%io.stdout.printf("BAD\n"); |
| 432 | | } |
| 433 | | if (*y != 4) { |
| 434 | | %%io.stdout.printf("BAD\n"); |
| 435 | | } |
| 436 | | %%io.stdout.printf("OK\n"); |
| 437 | | } |
| 438 | | )SOURCE", "OK\n"); |
| 439 | | |
| 440 | | add_simple_case("constant expressions", R"SOURCE( |
| 441 | | const io = @import("std").io; |
| 442 | | |
| 443 | | const ARRAY_SIZE : i8 = 20; |
| 444 | | |
| 445 | | pub fn main(args: [][]u8) -> %void { |
| 446 | | var array : [ARRAY_SIZE]u8 = undefined; |
| 447 | | %%io.stdout.print_u64(@sizeof(@typeof(array))); |
| 448 | | %%io.stdout.printf("\n"); |
| 449 | | } |
| 450 | | )SOURCE", "20\n"); |
| 451 | | |
| 452 | | add_simple_case("@min_value() and @max_value()", R"SOURCE( |
| 453 | | const io = @import("std").io; |
| 454 | | pub fn main(args: [][]u8) -> %void { |
| 455 | | %%io.stdout.printf("max u8: "); |
| 456 | | %%io.stdout.print_u64(@max_value(u8)); |
| 457 | | %%io.stdout.printf("\n"); |
| 458 | | |
| 459 | | %%io.stdout.printf("max u16: "); |
| 460 | | %%io.stdout.print_u64(@max_value(u16)); |
| 461 | | %%io.stdout.printf("\n"); |
| 462 | | |
| 463 | | %%io.stdout.printf("max u32: "); |
| 464 | | %%io.stdout.print_u64(@max_value(u32)); |
| 465 | | %%io.stdout.printf("\n"); |
| 466 | | |
| 467 | | %%io.stdout.printf("max u64: "); |
| 468 | | %%io.stdout.print_u64(@max_value(u64)); |
| 469 | | %%io.stdout.printf("\n"); |
| 470 | | |
| 471 | | %%io.stdout.printf("max i8: "); |
| 472 | | %%io.stdout.print_i64(@max_value(i8)); |
| 473 | | %%io.stdout.printf("\n"); |
| 474 | | |
| 475 | | %%io.stdout.printf("max i16: "); |
| 476 | | %%io.stdout.print_i64(@max_value(i16)); |
| 477 | | %%io.stdout.printf("\n"); |
| 478 | | |
| 479 | | %%io.stdout.printf("max i32: "); |
| 480 | | %%io.stdout.print_i64(@max_value(i32)); |
| 481 | | %%io.stdout.printf("\n"); |
| 482 | | |
| 483 | | %%io.stdout.printf("max i64: "); |
| 484 | | %%io.stdout.print_i64(@max_value(i64)); |
| 485 | | %%io.stdout.printf("\n"); |
| 486 | | |
| 487 | | %%io.stdout.printf("min u8: "); |
| 488 | | %%io.stdout.print_u64(@min_value(u8)); |
| 489 | | %%io.stdout.printf("\n"); |
| 490 | | |
| 491 | | %%io.stdout.printf("min u16: "); |
| 492 | | %%io.stdout.print_u64(@min_value(u16)); |
| 493 | | %%io.stdout.printf("\n"); |
| 494 | | |
| 495 | | %%io.stdout.printf("min u32: "); |
| 496 | | %%io.stdout.print_u64(@min_value(u32)); |
| 497 | | %%io.stdout.printf("\n"); |
| 498 | | |
| 499 | | %%io.stdout.printf("min u64: "); |
| 500 | | %%io.stdout.print_u64(@min_value(u64)); |
| 501 | | %%io.stdout.printf("\n"); |
| 502 | | |
| 503 | | %%io.stdout.printf("min i8: "); |
| 504 | | %%io.stdout.print_i64(@min_value(i8)); |
| 505 | | %%io.stdout.printf("\n"); |
| 506 | | |
| 507 | | %%io.stdout.printf("min i16: "); |
| 508 | | %%io.stdout.print_i64(@min_value(i16)); |
| 509 | | %%io.stdout.printf("\n"); |
| 510 | | |
| 511 | | %%io.stdout.printf("min i32: "); |
| 512 | | %%io.stdout.print_i64(@min_value(i32)); |
| 513 | | %%io.stdout.printf("\n"); |
| 514 | | |
| 515 | | %%io.stdout.printf("min i64: "); |
| 516 | | %%io.stdout.print_i64(@min_value(i64)); |
| 517 | | %%io.stdout.printf("\n"); |
| 518 | | } |
| 519 | | )SOURCE", |
| 520 | | "max u8: 255\n" |
| 521 | | "max u16: 65535\n" |
| 522 | | "max u32: 4294967295\n" |
| 523 | | "max u64: 18446744073709551615\n" |
| 524 | | "max i8: 127\n" |
| 525 | | "max i16: 32767\n" |
| 526 | | "max i32: 2147483647\n" |
| 527 | | "max i64: 9223372036854775807\n" |
| 528 | | "min u8: 0\n" |
| 529 | | "min u16: 0\n" |
| 530 | | "min u32: 0\n" |
| 531 | | "min u64: 0\n" |
| 532 | | "min i8: -128\n" |
| 533 | | "min i16: -32768\n" |
| 534 | | "min i32: -2147483648\n" |
| 535 | | "min i64: -9223372036854775808\n"); |
| 536 | | |
| 537 | | |
| 538 | | add_simple_case("overflow intrinsics", R"SOURCE( |
| 539 | | const io = @import("std").io; |
| 540 | | pub fn main(args: [][]u8) -> %void { |
| 541 | | var result: u8 = undefined; |
| 542 | | if (!@add_with_overflow(u8, 250, 100, &result)) { |
| 543 | | %%io.stdout.printf("BAD\n"); |
| 544 | | } |
| 545 | | if (@add_with_overflow(u8, 100, 150, &result)) { |
| 546 | | %%io.stdout.printf("BAD\n"); |
| 547 | | } |
| 548 | | if (result != 250) { |
| 549 | | %%io.stdout.printf("BAD\n"); |
| 550 | | } |
| 551 | | %%io.stdout.printf("OK\n"); |
| 552 | | } |
| 553 | | )SOURCE", "OK\n"); |
| 554 | | |
| 555 | 393 | add_simple_case("order-independent declarations", R"SOURCE( |
| 556 | 394 | const io = @import("std").io; |
| 557 | 395 | const z = io.stdin_fileno; |
| ... | ... | @@ -567,18 +405,6 @@ fn print_ok(val: @typeof(x)) -> @typeof(foo) { |
| 567 | 405 | const foo : i32 = 0; |
| 568 | 406 | )SOURCE", "OK\n"); |
| 569 | 407 | |
| 570 | | add_simple_case("nested arrays", R"SOURCE( |
| 571 | | const io = @import("std").io; |
| 572 | | |
| 573 | | pub fn main(args: [][]u8) -> %void { |
| 574 | | const array_of_strings = [][]u8 {"hello", "this", "is", "my", "thing"}; |
| 575 | | for (array_of_strings) |str| { |
| 576 | | %%io.stdout.printf(str); |
| 577 | | %%io.stdout.printf("\n"); |
| 578 | | } |
| 579 | | } |
| 580 | | )SOURCE", "hello\nthis\nis\nmy\nthing\n"); |
| 581 | | |
| 582 | 408 | add_simple_case("for loops", R"SOURCE( |
| 583 | 409 | const io = @import("std").io; |
| 584 | 410 | |
| ... | ... | @@ -604,126 +430,6 @@ pub fn main(args: [][]u8) -> %void { |
| 604 | 430 | } |
| 605 | 431 | )SOURCE", "9\n8\n7\n6\n0\n1\n2\n3\n9\n8\n7\n6\n0\n1\n2\n3\n"); |
| 606 | 432 | |
| 607 | | add_simple_case("function pointers", R"SOURCE( |
| 608 | | const io = @import("std").io; |
| 609 | | |
| 610 | | pub fn main(args: [][]u8) -> %void { |
| 611 | | const fns = []@typeof(fn1) { fn1, fn2, fn3, fn4, }; |
| 612 | | for (fns) |f| { |
| 613 | | %%io.stdout.print_u64(f()); |
| 614 | | %%io.stdout.printf("\n"); |
| 615 | | } |
| 616 | | } |
| 617 | | |
| 618 | | fn fn1() -> u32 {5} |
| 619 | | fn fn2() -> u32 {6} |
| 620 | | fn fn3() -> u32 {7} |
| 621 | | fn fn4() -> u32 {8} |
| 622 | | )SOURCE", "5\n6\n7\n8\n"); |
| 623 | | |
| 624 | | add_simple_case("statically initialized struct", R"SOURCE( |
| 625 | | const io = @import("std").io; |
| 626 | | struct Foo { |
| 627 | | x: i32, |
| 628 | | y: bool, |
| 629 | | } |
| 630 | | var foo = Foo { .x = 13, .y = true, }; |
| 631 | | pub fn main(args: [][]u8) -> %void { |
| 632 | | foo.x += 1; |
| 633 | | if (foo.x != 14) { |
| 634 | | %%io.stdout.printf("BAD\n"); |
| 635 | | } |
| 636 | | |
| 637 | | %%io.stdout.printf("OK\n"); |
| 638 | | } |
| 639 | | )SOURCE", "OK\n"); |
| 640 | | |
| 641 | | add_simple_case("statically initialized array literal", R"SOURCE( |
| 642 | | const io = @import("std").io; |
| 643 | | const x = []u8{1,2,3,4}; |
| 644 | | pub fn main(args: [][]u8) -> %void { |
| 645 | | const y : [4]u8 = x; |
| 646 | | if (y[3] != 4) { |
| 647 | | %%io.stdout.printf("BAD\n"); |
| 648 | | } |
| 649 | | |
| 650 | | %%io.stdout.printf("OK\n"); |
| 651 | | } |
| 652 | | )SOURCE", "OK\n"); |
| 653 | | |
| 654 | | add_simple_case("return with implicit cast from while loop", R"SOURCE( |
| 655 | | const io = @import("std").io; |
| 656 | | pub fn main(args: [][]u8) -> %void { |
| 657 | | while (true) { |
| 658 | | %%io.stdout.printf("OK\n"); |
| 659 | | return; |
| 660 | | } |
| 661 | | } |
| 662 | | )SOURCE", "OK\n"); |
| 663 | | |
| 664 | | add_simple_case("return struct byval from function", R"SOURCE( |
| 665 | | const io = @import("std").io; |
| 666 | | struct Foo { |
| 667 | | x: i32, |
| 668 | | y: i32, |
| 669 | | } |
| 670 | | fn make_foo(x: i32, y: i32) -> Foo { |
| 671 | | Foo { |
| 672 | | .x = x, |
| 673 | | .y = y, |
| 674 | | } |
| 675 | | } |
| 676 | | pub fn main(args: [][]u8) -> %void { |
| 677 | | const foo = make_foo(1234, 5678); |
| 678 | | if (foo.y != 5678) { |
| 679 | | %%io.stdout.printf("BAD\n"); |
| 680 | | } |
| 681 | | %%io.stdout.printf("OK\n"); |
| 682 | | } |
| 683 | | )SOURCE", "OK\n"); |
| 684 | | |
| 685 | | add_simple_case("string concatenation", R"SOURCE( |
| 686 | | const io = @import("std").io; |
| 687 | | pub fn main(args: [][]u8) -> %void { |
| 688 | | %%io.stdout.printf("OK" ++ " IT " ++ "WORKED\n"); |
| 689 | | } |
| 690 | | )SOURCE", "OK IT WORKED\n"); |
| 691 | | |
| 692 | | add_simple_case("constant struct with negation", R"SOURCE( |
| 693 | | const io = @import("std").io; |
| 694 | | struct Vertex { |
| 695 | | x: f32, |
| 696 | | y: f32, |
| 697 | | r: f32, |
| 698 | | g: f32, |
| 699 | | b: f32, |
| 700 | | } |
| 701 | | const vertices = []Vertex { |
| 702 | | Vertex { .x = -0.6, .y = -0.4, .r = 1.0, .g = 0.0, .b = 0.0 }, |
| 703 | | Vertex { .x = 0.6, .y = -0.4, .r = 0.0, .g = 1.0, .b = 0.0 }, |
| 704 | | Vertex { .x = 0.0, .y = 0.6, .r = 0.0, .g = 0.0, .b = 1.0 }, |
| 705 | | }; |
| 706 | | pub fn main(args: [][]u8) -> %void { |
| 707 | | if (vertices[0].x != -0.6) { |
| 708 | | %%io.stdout.printf("BAD\n"); |
| 709 | | } |
| 710 | | %%io.stdout.printf("OK\n"); |
| 711 | | } |
| 712 | | )SOURCE", "OK\n"); |
| 713 | | |
| 714 | | add_simple_case("int to ptr cast", R"SOURCE( |
| 715 | | const io = @import("std").io; |
| 716 | | pub fn main(args: [][]u8) -> %void { |
| 717 | | const x = isize(13); |
| 718 | | const y = (&u8)(x); |
| 719 | | const z = usize(y); |
| 720 | | if (z != 13) { |
| 721 | | %%io.stdout.printf("BAD\n"); |
| 722 | | } |
| 723 | | %%io.stdout.printf("OK\n"); |
| 724 | | } |
| 725 | | )SOURCE", "OK\n"); |
| 726 | | |
| 727 | 433 | add_simple_case("pointer to void return type", R"SOURCE( |
| 728 | 434 | const io = @import("std").io; |
| 729 | 435 | const x = void{}; |