Unified · Split
| @@ -8,27 +8,30 @@ Hello: module · 7 unmodified lines | |||
| 8 | init: fn(); | 8 | init: fn(); |
| 9 | }; | 9 | }; |
| 10 | 10 | ||
| 11 | sys : Sys; | ||
| 12 | |||
| 11 | init() | 13 | init() |
| 12 | { | 14 | { |
| 13 | a := "foobar!"; | 15 | a := "foobar!"; |
| 14 | sys := load Sys Sys->PATH; | 16 | sys = load Sys Sys->PATH; |
| 15 | sys->print("Hello, %s %o %d %x\n%s%%%% %H", "world!", 8, 10, 16, "------------------\n", a); | 17 | big_val := big 16r12345; |
| 16 | 18 | sys->print("Hello, %s %o %d %x %bd %f\n%s%%%% %H\n\n", "world!", 8, 10, 16, big_val, 0.1, "------------------\n", a); | |
| 17 | #test_function_refs(); | 19 | |
| 18 | #test_alt(); | 20 | test_function_refs(); |
| 19 | #test_channel(); | 21 | test_alt(); |
| 20 | #test_spawn(); | 22 | test_channel(); |
| 21 | #test_exceptions(); | 23 | test_spawn(); |
| 22 | #test_case(); | 24 | test_exceptions(); |
| 23 | #test_discriminated_union(); | 25 | test_case(); |
| 24 | #test_external_module(); | 26 | test_discriminated_union(); |
| 25 | #test_fixed_point(); | 27 | test_external_module(); |
| 26 | #test_exponent(); | 28 | test_fixed_point(); |
| 27 | #test_string(); | 29 | test_exponent(); |
| 28 | #test_array(); | 30 | test_string(); |
| 29 | #test_list(); | 31 | test_array(); |
| 30 | #test_branch(); | 32 | test_list(); |
| 31 | #test_for_loop_function_call(); | 33 | test_branch(); |
| 34 | test_for_loop_function_call(); | ||
| 32 | } | 35 | } |
| 33 | 36 | ||
| 34 | str_cmp(s1: string, s2: string): int | 37 | str_cmp(s1: string, s2: string): int |
| @@ -43,6 +46,7 @@ str_cmp(s1: string, s2: string): int · 8 unmodified lines | |||
| 43 | 46 | ||
| 44 | test_function_refs() | 47 | test_function_refs() |
| 45 | { | 48 | { |
| 49 | sys->print("test_function_refs()\n"); | ||
| 46 | f : ref fn(s1: string, s2: string): int; | 50 | f : ref fn(s1: string, s2: string): int; |
| 47 | f = str_cmp; | 51 | f = str_cmp; |
| 48 | 52 | ||
| @@ -54,6 +58,7 @@ test_function_refs() · 5 unmodified lines | |||
| 54 | 58 | ||
| 55 | test_alt() | 59 | test_alt() |
| 56 | { | 60 | { |
| 61 | sys->print("test_alt()\n"); | ||
| 57 | int_chan_10 := chan of int; | 62 | int_chan_10 := chan of int; |
| 58 | int_chan_20 := chan of int; | 63 | int_chan_20 := chan of int; |
| 59 | int_chan_done := chan of int; | 64 | int_chan_done := chan of int; |
| @@ -144,6 +149,7 @@ alt2(ten : chan of int, twenty : chan of int, done : chan of int) · 84 unmodified lines | |||
| 144 | 149 | ||
| 145 | test_channel() | 150 | test_channel() |
| 146 | { | 151 | { |
| 152 | sys->print("test_channel()\n"); | ||
| 147 | test_channel_int(nil); | 153 | test_channel_int(nil); |
| 148 | test_channel_int_buffered(nil, nil); | 154 | test_channel_int_buffered(nil, nil); |
| 149 | 155 | ||
| @@ -327,6 +333,7 @@ test_channel_ref_adt_buffered(c : chan of ref ChannelAdt, r : chan of ref Channe · 177 unmodified lines | |||
| 327 | 333 | ||
| 328 | test_spawn() | 334 | test_spawn() |
| 329 | { | 335 | { |
| 336 | sys->print("test_spawn()\n"); | ||
| 330 | spawn th1(); | 337 | spawn th1(); |
| 331 | } | 338 | } |
| 332 | 339 | ||
| @@ -342,23 +349,24 @@ TESTEXCEPTION : exception(int, int); · 9 unmodified lines | |||
| 342 | 349 | ||
| 343 | test_exceptions() | 350 | test_exceptions() |
| 344 | { | 351 | { |
| 352 | sys->print("test_exceptions()\n"); | ||
| 345 | { | 353 | { |
| 346 | raise TESTEXCEPTION(5,10); | 354 | raise TESTEXCEPTION(5,10); |
| 347 | } exception e { | 355 | } exception e { |
| 348 | TESTEXCEPTION => | 356 | TESTEXCEPTION => |
| 349 | (a,b) := e; | 357 | (a,b) := e; |
| 350 | if (a != 5 || b != 10) exit; | 358 | if (a != 5 || b != 10) exit; |
| 351 | 359 | ||
| 352 | * => exit; | 360 | * => exit; |
| 353 | } | 361 | } |
| 354 | 362 | ||
| 355 | { | 363 | { |
| 356 | raise "bad time"; | 364 | raise "bad time"; |
| 357 | } exception e { | 365 | } exception e { |
| 358 | "bad time" => ; | 366 | "bad time" => ; |
| 359 | * => exit; | 367 | * => exit; |
| 360 | } | 368 | } |
| 361 | 369 | ||
| 362 | s := 0; | 370 | s := 0; |
| 363 | { | 371 | { |
| 364 | raise_exception_1(0); | 372 | raise_exception_1(0); |
| @@ -421,6 +429,7 @@ raise_exception_n(d : int, s:string) · 56 unmodified lines | |||
| 421 | 429 | ||
| 422 | test_case() | 430 | test_case() |
| 423 | { | 431 | { |
| 432 | sys->print("test_case()\n"); | ||
| 424 | { | 433 | { |
| 425 | s := 0; | 434 | s := 0; |
| 426 | v := 150; | 435 | v := 150; |
| @@ -431,7 +440,7 @@ test_case() · 4 unmodified lines | |||
| 431 | 201 to 300 => s = 0; | 440 | 201 to 300 => s = 0; |
| 432 | * => s = 0; | 441 | * => s = 0; |
| 433 | } | 442 | } |
| 434 | 443 | ||
| 435 | if (s != 1) exit; | 444 | if (s != 1) exit; |
| 436 | } | 445 | } |
| 437 | 446 | ||
| @@ -444,7 +453,7 @@ test_case() · 6 unmodified lines | |||
| 444 | "FOO" or "foo" => s = 1; | 453 | "FOO" or "foo" => s = 1; |
| 445 | * => s = 0; | 454 | * => s = 0; |
| 446 | } | 455 | } |
| 447 | 456 | ||
| 448 | if (s != 1) exit; | 457 | if (s != 1) exit; |
| 449 | } | 458 | } |
| 450 | 459 | ||
| @@ -458,7 +467,7 @@ test_case() · 7 unmodified lines | |||
| 458 | 16r400000000 => s = 0; | 467 | 16r400000000 => s = 0; |
| 459 | * => s = 0; | 468 | * => s = 0; |
| 460 | } | 469 | } |
| 461 | 470 | ||
| 462 | if (s != 1) exit; | 471 | if (s != 1) exit; |
| 463 | } | 472 | } |
| 464 | } | 473 | } |
| @@ -477,6 +486,7 @@ Constant: adt · 12 unmodified lines | |||
| 477 | 486 | ||
| 478 | test_discriminated_union() | 487 | test_discriminated_union() |
| 479 | { | 488 | { |
| 489 | sys->print("test_discriminated_union()\n"); | ||
| 480 | c : ref Constant = ref Constant.Real("pi", 3.14); | 490 | c : ref Constant = ref Constant.Real("pi", 3.14); |
| 481 | pick x := c | 491 | pick x := c |
| 482 | { | 492 | { |
| @@ -491,18 +501,19 @@ test_discriminated_union() · 8 unmodified lines | |||
| 491 | 501 | ||
| 492 | test_external_module() | 502 | test_external_module() |
| 493 | { | 503 | { |
| 504 | sys->print("test_external_module()\n"); | ||
| 494 | ext_mod := load ExtModule ExtModule->PATH; | 505 | ext_mod := load ExtModule ExtModule->PATH; |
| 495 | 506 | ||
| 496 | { | 507 | { |
| 497 | module_int := ext_mod->return_int(); | 508 | module_int := ext_mod->return_int(); |
| 498 | if (module_int != ext_mod->module_constant) exit; | 509 | if (module_int != ext_mod->module_constant) exit; |
| 499 | } | 510 | } |
| 500 | 511 | ||
| 501 | { | 512 | { |
| 502 | thirty_four := ext_mod->double_int(17); | 513 | thirty_four := ext_mod->double_int(17); |
| 503 | if (thirty_four != 34) exit; | 514 | if (thirty_four != 34) exit; |
| 504 | } | 515 | } |
| 505 | 516 | ||
| 506 | { | 517 | { |
| 507 | d := ext_mod->return_datatype(); | 518 | d := ext_mod->return_datatype(); |
| 508 | dr := ext_mod->return_datatype_ref(); | 519 | dr := ext_mod->return_datatype_ref(); |
| @@ -515,6 +526,7 @@ test_external_module() · 6 unmodified lines | |||
| 515 | 526 | ||
| 516 | test_fixed_point() | 527 | test_fixed_point() |
| 517 | { | 528 | { |
| 529 | sys->print("test_fixed_point()\n"); | ||
| 518 | fpt : type fixed(0.125, 512.0); | 530 | fpt : type fixed(0.125, 512.0); |
| 519 | a := fpt(1.1); | 531 | a := fpt(1.1); |
| 520 | b := fpt(2.1); | 532 | b := fpt(2.1); |
| @@ -524,6 +536,7 @@ test_fixed_point() · 3 unmodified lines | |||
| 524 | 536 | ||
| 525 | test_exponent() | 537 | test_exponent() |
| 526 | { | 538 | { |
| 539 | sys->print("test_exponent()\n"); | ||
| 527 | { | 540 | { |
| 528 | base := 2; | 541 | base := 2; |
| 529 | power := 3; | 542 | power := 3; |
| @@ -587,27 +600,28 @@ test_exponent() · 57 unmodified lines | |||
| 587 | 600 | ||
| 588 | test_string() | 601 | test_string() |
| 589 | { | 602 | { |
| 603 | sys->print("test_string()\n"); | ||
| 590 | count4 := "abcd"; | 604 | count4 := "abcd"; |
| 591 | if (len count4 != 4) exit; | 605 | if (len count4 != 4) exit; |
| 592 | 606 | ||
| 593 | array4 := array of byte count4; | 607 | array4 := array of byte count4; |
| 594 | if (len array4 != 4) exit; | 608 | if (len array4 != 4) exit; |
| 595 | 609 | ||
| 596 | count6 := "わがよたれぞ"; | 610 | count6 := "わがよたれぞ"; |
| 597 | if (len count6 != 6) exit; | 611 | if (len count6 != 6) exit; |
| 598 | 612 | ||
| 599 | array18 := array of byte count6; | 613 | array18 := array of byte count6; |
| 600 | if (len array18 != 18) exit; | 614 | if (len array18 != 18) exit; |
| 601 | 615 | ||
| 602 | count6_2 := string array18; | 616 | count6_2 := string array18; |
| 603 | if (count6 != count6_2) exit; | 617 | if (count6 != count6_2) exit; |
| 604 | 618 | ||
| 605 | count7 := "खा सकता"; | 619 | count7 := "खा सकता"; |
| 606 | if (len count7 != 7) exit; | 620 | if (len count7 != 7) exit; |
| 607 | 621 | ||
| 608 | array19 := array of byte count7; | 622 | array19 := array of byte count7; |
| 609 | if (len array19 != 19) exit; | 623 | if (len array19 != 19) exit; |
| 610 | 624 | ||
| 611 | count36 := "abcdefghijklmnopqrstuvwxyz0123456789"; | 625 | count36 := "abcdefghijklmnopqrstuvwxyz0123456789"; |
| 612 | if (len count36 != 36) exit; | 626 | if (len count36 != 36) exit; |
| 613 | 627 | ||
| @@ -622,7 +636,7 @@ test_string() · 8 unmodified lines | |||
| 622 | str[len str] = ch + 4; | 636 | str[len str] = ch + 4; |
| 623 | if (len str != 5) exit; | 637 | if (len str != 5) exit; |
| 624 | if (str[2] != 'c') exit; | 638 | if (str[2] != 'c') exit; |
| 625 | 639 | ||
| 626 | str[2] = 'よ'; | 640 | str[2] = 'よ'; |
| 627 | if (len str != 5) exit; | 641 | if (len str != 5) exit; |
| 628 | if (str[2] != 'よ') exit; | 642 | if (str[2] != 'よ') exit; |
| @@ -633,14 +647,14 @@ test_string() · 4 unmodified lines | |||
| 633 | str_l := "a"; | 647 | str_l := "a"; |
| 634 | str_l2 := "a"; | 648 | str_l2 := "a"; |
| 635 | str_g := "z"; | 649 | str_g := "z"; |
| 636 | 650 | ||
| 637 | if (!(str_l == str_l)) exit; | 651 | if (!(str_l == str_l)) exit; |
| 638 | if (!(str_l == str_l2)) exit; | 652 | if (!(str_l == str_l2)) exit; |
| 639 | if (!(str_l <= str_l2)) exit; | 653 | if (!(str_l <= str_l2)) exit; |
| 640 | if (!(str_l >= str_l2)) exit; | 654 | if (!(str_l >= str_l2)) exit; |
| 641 | if (!(str_l < str_g)) exit; | 655 | if (!(str_l < str_g)) exit; |
| 642 | if (!(str_g > str_l)) exit; | 656 | if (!(str_g > str_l)) exit; |
| 643 | 657 | ||
| 644 | str_e : string; | 658 | str_e : string; |
| 645 | if (str_l == str_e) exit; | 659 | if (str_l == str_e) exit; |
| 646 | if (!(str_l != str_e)) exit; | 660 | if (!(str_l != str_e)) exit; |
| @@ -648,7 +662,7 @@ test_string() · 1 unmodified line | |||
| 648 | if (!(str_l >= str_e)) exit; | 662 | if (!(str_l >= str_e)) exit; |
| 649 | if (str_l < str_e) exit; | 663 | if (str_l < str_e) exit; |
| 650 | if (!(str_g > str_e)) exit; | 664 | if (!(str_g > str_e)) exit; |
| 651 | 665 | ||
| 652 | if (str_e == str_l) exit; | 666 | if (str_e == str_l) exit; |
| 653 | if (!(str_e != str_l)) exit; | 667 | if (!(str_e != str_l)) exit; |
| 654 | if (!(str_e <= str_l)) exit; | 668 | if (!(str_e <= str_l)) exit; |
| @@ -658,18 +672,18 @@ test_string() · 3 unmodified lines | |||
| 658 | } | 672 | } |
| 659 | 673 | ||
| 660 | # Compare (multi-byte) | 674 | # Compare (multi-byte) |
| 661 | { | 675 | { |
| 662 | str_l := "Α"; | 676 | str_l := "Α"; |
| 663 | str_l2 := "Α"; | 677 | str_l2 := "Α"; |
| 664 | str_g := "Ω"; | 678 | str_g := "Ω"; |
| 665 | 679 | ||
| 666 | if (!(str_l == str_l)) exit; | 680 | if (!(str_l == str_l)) exit; |
| 667 | if (!(str_l == str_l2)) exit; | 681 | if (!(str_l == str_l2)) exit; |
| 668 | if (!(str_l <= str_l2)) exit; | 682 | if (!(str_l <= str_l2)) exit; |
| 669 | if (!(str_l >= str_l2)) exit; | 683 | if (!(str_l >= str_l2)) exit; |
| 670 | if (!(str_l < str_g)) exit; | 684 | if (!(str_l < str_g)) exit; |
| 671 | if (!(str_g > str_l)) exit; | 685 | if (!(str_g > str_l)) exit; |
| 672 | 686 | ||
| 673 | str_e : string; | 687 | str_e : string; |
| 674 | if (str_l == str_e) exit; | 688 | if (str_l == str_e) exit; |
| 675 | if (!(str_l != str_e)) exit; | 689 | if (!(str_l != str_e)) exit; |
| @@ -677,7 +691,7 @@ test_string() · 1 unmodified line | |||
| 677 | if (!(str_l >= str_e)) exit; | 691 | if (!(str_l >= str_e)) exit; |
| 678 | if (str_l < str_e) exit; | 692 | if (str_l < str_e) exit; |
| 679 | if (!(str_g > str_e)) exit; | 693 | if (!(str_g > str_e)) exit; |
| 680 | 694 | ||
| 681 | if (str_e == str_l) exit; | 695 | if (str_e == str_l) exit; |
| 682 | if (!(str_e != str_l)) exit; | 696 | if (!(str_e != str_l)) exit; |
| 683 | if (!(str_e <= str_l)) exit; | 697 | if (!(str_e <= str_l)) exit; |
| @@ -687,18 +701,18 @@ test_string() · 3 unmodified lines | |||
| 687 | } | 701 | } |
| 688 | 702 | ||
| 689 | # Compare (multi-byte/ascii mix) | 703 | # Compare (multi-byte/ascii mix) |
| 690 | { | 704 | { |
| 691 | str_l := "a"; | 705 | str_l := "a"; |
| 692 | str_l2 := "a"; | 706 | str_l2 := "a"; |
| 693 | str_g := "Ω"; | 707 | str_g := "Ω"; |
| 694 | 708 | ||
| 695 | if (!(str_l == str_l)) exit; | 709 | if (!(str_l == str_l)) exit; |
| 696 | if (!(str_l == str_l2)) exit; | 710 | if (!(str_l == str_l2)) exit; |
| 697 | if (!(str_l <= str_l2)) exit; | 711 | if (!(str_l <= str_l2)) exit; |
| 698 | if (!(str_l >= str_l2)) exit; | 712 | if (!(str_l >= str_l2)) exit; |
| 699 | if (!(str_l < str_g)) exit; | 713 | if (!(str_l < str_g)) exit; |
| 700 | if (!(str_g > str_l)) exit; | 714 | if (!(str_g > str_l)) exit; |
| 701 | 715 | ||
| 702 | str_e : string; | 716 | str_e : string; |
| 703 | if (str_l == str_e) exit; | 717 | if (str_l == str_e) exit; |
| 704 | if (!(str_l != str_e)) exit; | 718 | if (!(str_l != str_e)) exit; |
| @@ -706,7 +720,7 @@ test_string() · 1 unmodified line | |||
| 706 | if (!(str_l >= str_e)) exit; | 720 | if (!(str_l >= str_e)) exit; |
| 707 | if (str_l < str_e) exit; | 721 | if (str_l < str_e) exit; |
| 708 | if (!(str_g > str_e)) exit; | 722 | if (!(str_g > str_e)) exit; |
| 709 | 723 | ||
| 710 | if (str_e == str_l) exit; | 724 | if (str_e == str_l) exit; |
| 711 | if (!(str_e != str_l)) exit; | 725 | if (!(str_e != str_l)) exit; |
| 712 | if (!(str_e <= str_l)) exit; | 726 | if (!(str_e <= str_l)) exit; |
| @@ -720,17 +734,17 @@ test_string() · 7 unmodified lines | |||
| 720 | s1 := "1"; | 734 | s1 := "1"; |
| 721 | s2 := "2"; | 735 | s2 := "2"; |
| 722 | s3 : string; | 736 | s3 : string; |
| 723 | 737 | ||
| 724 | s4 := s1 + s2; | 738 | s4 := s1 + s2; |
| 725 | if (s4 != "12") exit; | 739 | if (s4 != "12") exit; |
| 726 | 740 | ||
| 727 | s1 += s2; | 741 | s1 += s2; |
| 728 | if (s1 != "12") exit; | 742 | if (s1 != "12") exit; |
| 729 | 743 | ||
| 730 | s5 := s3 + s1; | 744 | s5 := s3 + s1; |
| 731 | s6 := s3 + s3; | 745 | s6 := s3 + s3; |
| 732 | } | 746 | } |
| 733 | 747 | ||
| 734 | # Slice | 748 | # Slice |
| 735 | { | 749 | { |
| 736 | s1 := "01234567"; | 750 | s1 := "01234567"; |
| @@ -747,7 +761,7 @@ test_string() · 10 unmodified lines | |||
| 747 | w_val := 12345; | 761 | w_val := 12345; |
| 748 | s_w := string w_val; | 762 | s_w := string w_val; |
| 749 | if (s_w != "12345") exit; | 763 | if (s_w != "12345") exit; |
| 750 | 764 | ||
| 751 | r_val := 3.14; | 765 | r_val := 3.14; |
| 752 | s_r := string r_val; | 766 | s_r := string r_val; |
| 753 | if (s_r != "3.14") exit; | 767 | if (s_r != "3.14") exit; |
| @@ -762,7 +776,7 @@ test_string() · 8 unmodified lines | |||
| 762 | s_w := "12345"; | 776 | s_w := "12345"; |
| 763 | w_val := int s_w; | 777 | w_val := int s_w; |
| 764 | if (w_val != 12345) exit; | 778 | if (w_val != 12345) exit; |
| 765 | 779 | ||
| 766 | s_r := "3.14"; | 780 | s_r := "3.14"; |
| 767 | r_val := real s_r; | 781 | r_val := real s_r; |
| 768 | if (r_val != 3.14) exit; | 782 | if (r_val != 3.14) exit; |
| @@ -775,10 +789,11 @@ test_string() · 6 unmodified lines | |||
| 775 | 789 | ||
| 776 | test_array() | 790 | test_array() |
| 777 | { | 791 | { |
| 792 | sys->print("test_array()\n"); | ||
| 778 | arr : array of int; | 793 | arr : array of int; |
| 779 | a := len arr; | 794 | a := len arr; |
| 780 | if (a != 0) exit; | 795 | if (a != 0) exit; |
| 781 | 796 | ||
| 782 | test_array_byte(); | 797 | test_array_byte(); |
| 783 | test_array_int(); | 798 | test_array_int(); |
| 784 | test_array_big(); | 799 | test_array_big(); |
| @@ -875,6 +890,7 @@ test_array_real() · 90 unmodified lines | |||
| 875 | 890 | ||
| 876 | test_list() | 891 | test_list() |
| 877 | { | 892 | { |
| 893 | sys->print("test_list()\n"); | ||
| 878 | lst : list of int; | 894 | lst : list of int; |
| 879 | l := len lst; | 895 | l := len lst; |
| 880 | if (l != 0) exit; | 896 | if (l != 0) exit; |
| @@ -892,7 +908,7 @@ test_list_byte() · 11 unmodified lines | |||
| 892 | lst1 := byte 16rff :: lst0; | 908 | lst1 := byte 16rff :: lst0; |
| 893 | lst2 := byte 16rfe :: lst1; | 909 | lst2 := byte 16rfe :: lst1; |
| 894 | lst3 := byte 16rfd :: lst2; | 910 | lst3 := byte 16rfd :: lst2; |
| 895 | 911 | ||
| 896 | if (len lst3 != 3) exit; | 912 | if (len lst3 != 3) exit; |
| 897 | if (hd lst3 != byte 16rfd) exit; | 913 | if (hd lst3 != byte 16rfd) exit; |
| 898 | if (hd tl tl lst3 != byte 16rff) exit; | 914 | if (hd tl tl lst3 != byte 16rff) exit; |
| @@ -904,7 +920,7 @@ test_list_int() · 5 unmodified lines | |||
| 904 | lst1 := 16rff00 :: lst0; | 920 | lst1 := 16rff00 :: lst0; |
| 905 | lst2 := 16rfe00 :: lst1; | 921 | lst2 := 16rfe00 :: lst1; |
| 906 | lst3 := 16rfd00 :: lst2; | 922 | lst3 := 16rfd00 :: lst2; |
| 907 | 923 | ||
| 908 | if (len lst3 != 3) exit; | 924 | if (len lst3 != 3) exit; |
| 909 | if (hd lst3 != 16rfd00) exit; | 925 | if (hd lst3 != 16rfd00) exit; |
| 910 | if (hd tl tl lst3 != 16rff00) exit; | 926 | if (hd tl tl lst3 != 16rff00) exit; |
| @@ -916,7 +932,7 @@ test_list_big() · 5 unmodified lines | |||
| 916 | lst1 := 16rff000000ff000000 :: lst0; | 932 | lst1 := 16rff000000ff000000 :: lst0; |
| 917 | lst2 := 16rfe000000ff000000 :: lst1; | 933 | lst2 := 16rfe000000ff000000 :: lst1; |
| 918 | lst3 := 16rfd000000ff000000 :: lst2; | 934 | lst3 := 16rfd000000ff000000 :: lst2; |
| 919 | 935 | ||
| 920 | if (len lst3 != 3) exit; | 936 | if (len lst3 != 3) exit; |
| 921 | if (hd lst3 != 16rfd000000ff000000) exit; | 937 | if (hd lst3 != 16rfd000000ff000000) exit; |
| 922 | if (hd tl tl lst3 != 16rff000000ff000000) exit; | 938 | if (hd tl tl lst3 != 16rff000000ff000000) exit; |
| @@ -928,7 +944,7 @@ test_list_real() · 5 unmodified lines | |||
| 928 | lst1 := 3.0 :: lst0; | 944 | lst1 := 3.0 :: lst0; |
| 929 | lst2 := 2.0 :: lst1; | 945 | lst2 := 2.0 :: lst1; |
| 930 | lst3 := 1.0 :: lst2; | 946 | lst3 := 1.0 :: lst2; |
| 931 | 947 | ||
| 932 | if (len lst3 != 3) exit; | 948 | if (len lst3 != 3) exit; |
| 933 | if (hd lst3 != 1.0) exit; | 949 | if (hd lst3 != 1.0) exit; |
| 934 | if (hd tl tl lst3 != 3.0) exit; | 950 | if (hd tl tl lst3 != 3.0) exit; |
| @@ -947,7 +963,7 @@ test_list_adt() · 12 unmodified lines | |||
| 947 | lst1 := ( "three", 3.0 ) :: lst0; | 963 | lst1 := ( "three", 3.0 ) :: lst0; |
| 948 | lst2 := ( "two", 2.0 ) :: lst1; | 964 | lst2 := ( "two", 2.0 ) :: lst1; |
| 949 | lst3 := ( "one", 1.0 ) :: lst2; | 965 | lst3 := ( "one", 1.0 ) :: lst2; |
| 950 | 966 | ||
| 951 | if (len lst3 != 3) exit; | 967 | if (len lst3 != 3) exit; |
| 952 | if ((hd lst3).r != 1.0) exit; | 968 | if ((hd lst3).r != 1.0) exit; |
| 953 | if ((hd tl tl lst3).r != 3.0) exit; | 969 | if ((hd tl tl lst3).r != 3.0) exit; |
| @@ -961,7 +977,7 @@ test_list_adt() · 7 unmodified lines | |||
| 961 | lst1 := e3 :: lst0; | 977 | lst1 := e3 :: lst0; |
| 962 | lst2 := e2 :: lst1; | 978 | lst2 := e2 :: lst1; |
| 963 | lst3 := e1 :: lst2; | 979 | lst3 := e1 :: lst2; |
| 964 | 980 | ||
| 965 | if (len lst3 != 3) exit; | 981 | if (len lst3 != 3) exit; |
| 966 | if ((hd lst3).r != 1.0) exit; | 982 | if ((hd lst3).r != 1.0) exit; |
| 967 | if ((hd tl tl lst3).r != 3.0) exit; | 983 | if ((hd tl tl lst3).r != 3.0) exit; |
| @@ -970,12 +986,13 @@ test_list_adt() · 2 unmodified lines | |||
| 970 | 986 | ||
| 971 | test_branch() | 987 | test_branch() |
| 972 | { | 988 | { |
| 989 | sys->print("test_branch()\n"); | ||
| 973 | test_branch_byte(); | 990 | test_branch_byte(); |
| 974 | test_branch_int(); | 991 | test_branch_int(); |
| 975 | test_branch_big(); | 992 | test_branch_big(); |
| 976 | test_branch_real(); | 993 | test_branch_real(); |
| 977 | } | 994 | } |
| 978 | 995 | ||
| 979 | test_branch_byte() | 996 | test_branch_byte() |
| 980 | { | 997 | { |
| 981 | a := byte 16rff; | 998 | a := byte 16rff; |
| @@ -985,7 +1002,7 @@ test_branch_byte() · 3 unmodified lines | |||
| 985 | if (a != b) exit; | 1002 | if (a != b) exit; |
| 986 | if (!(a == b)) exit; | 1003 | if (!(a == b)) exit; |
| 987 | } | 1004 | } |
| 988 | 1005 | ||
| 989 | test_branch_int() | 1006 | test_branch_int() |
| 990 | { | 1007 | { |
| 991 | a := 1024; | 1008 | a := 1024; |
| @@ -995,7 +1012,7 @@ test_branch_int() · 3 unmodified lines | |||
| 995 | if (a != b) exit; | 1012 | if (a != b) exit; |
| 996 | if (!(a == b)) exit; | 1013 | if (!(a == b)) exit; |
| 997 | } | 1014 | } |
| 998 | 1015 | ||
| 999 | test_branch_big() | 1016 | test_branch_big() |
| 1000 | { | 1017 | { |
| 1001 | a := 16r10000000FFFFFFFF; | 1018 | a := 16r10000000FFFFFFFF; |
| @@ -1018,11 +1035,12 @@ test_branch_real() · 16 unmodified lines | |||
| 1018 | 1035 | ||
| 1019 | test_for_loop_function_call() | 1036 | test_for_loop_function_call() |
| 1020 | { | 1037 | { |
| 1021 | for (j := 0; j < 20; j++) | 1038 | sys->print("test_for_loop_function_call()\n"); |
| 1039 | for (j := 0; j < 20; j++) | ||
| 1022 | { | 1040 | { |
| 1023 | is_odd := odd(j); | 1041 | is_odd := odd(j); |
| 1024 | is_even := even(j); | 1042 | is_even := even(j); |
| 1025 | 1043 | ||
| 1026 | if (j % 2 == 0) | 1044 | if (j % 2 == 0) |
| 1027 | { | 1045 | { |
| 1028 | if (is_odd != 0) exit; | 1046 | if (is_odd != 0) exit; |
| @@ -1050,4 +1068,4 @@ even(a: int) : int · 21 unmodified lines | |||
| 1050 | return 1; | 1068 | return 1; |
| 1051 | 1069 | ||
| 1052 | return odd(a - 1); | 1070 | return odd(a - 1); |
| 1053 | } | 1071 | } |
| @@ -134,7 +134,13 @@ namespace disvm · 133 unmodified lines | |||
| 134 | pointer_t gc_reserved; | 134 | pointer_t gc_reserved; |
| 135 | 135 | ||
| 136 | public: | 136 | public: |
| 137 | pointer_t allocation() const; | 137 | pointer_t get_allocation() const; |
| 138 | |||
| 139 | template <typename T> | ||
| 140 | T *get_allocation() const | ||
| 141 | { | ||
| 142 | return reinterpret_cast<T *>(get_allocation()); | ||
| 143 | } | ||
| 138 | 144 | ||
| 139 | private: | 145 | private: |
| 140 | std::atomic<std::size_t> _ref_count; | 146 | std::atomic<std::size_t> _ref_count; |
| @@ -152,7 +152,7 @@ namespace · 151 unmodified lines | |||
| 152 | 152 | ||
| 153 | auto str = at_val<vm_string_t>(r.src); | 153 | auto str = at_val<vm_string_t>(r.src); |
| 154 | auto new_array = new vm_array_t(str); | 154 | auto new_array = new vm_array_t(str); |
| 155 | pt_ref(r.dest) = new_array->allocation(); | 155 | pt_ref(r.dest) = new_array->get_allocation(); |
| 156 | } | 156 | } |
| 157 | 157 | ||
| 158 | EXEC_DECL(cvtac) | 158 | EXEC_DECL(cvtac) |
| @@ -167,7 +167,7 @@ namespace · 8 unmodified lines | |||
| 167 | throw vm_user_exception{ "Invalid array element type for string conversion" }; | 167 | throw vm_user_exception{ "Invalid array element type for string conversion" }; |
| 168 | 168 | ||
| 169 | auto new_string = new vm_string_t(arr->get_length(), reinterpret_cast<uint8_t *>(arr->at(0))); | 169 | auto new_string = new vm_string_t(arr->get_length(), reinterpret_cast<uint8_t *>(arr->at(0))); |
| 170 | str = new_string->allocation(); | 170 | str = new_string->get_allocation(); |
| 171 | } | 171 | } |
| 172 | 172 | ||
| 173 | pt_ref(r.dest) = str; | 173 | pt_ref(r.dest) = str; |
| @@ -196,7 +196,7 @@ namespace · 22 unmodified lines | |||
| 196 | auto str = at_val<vm_string_t>(r.dest); | 196 | auto str = at_val<vm_string_t>(r.dest); |
| 197 | dec_ref_count_and_free(str); | 197 | dec_ref_count_and_free(str); |
| 198 | 198 | ||
| 199 | pt_ref(r.dest) = new_string->allocation(); | 199 | pt_ref(r.dest) = new_string->get_allocation(); |
| 200 | } | 200 | } |
| 201 | 201 | ||
| 202 | EXEC_DECL(cvtcf) | 202 | EXEC_DECL(cvtcf) |
| @@ -221,7 +221,7 @@ namespace · 18 unmodified lines | |||
| 221 | auto new_string = new vm_string_t(len, reinterpret_cast<uint8_t *>(buffer.data())); | 221 | auto new_string = new vm_string_t(len, reinterpret_cast<uint8_t *>(buffer.data())); |
| 222 | 222 | ||
| 223 | auto str = at_val<vm_string_t>(r.dest); | 223 | auto str = at_val<vm_string_t>(r.dest); |
| 224 | pt_ref(r.dest) = new_string->allocation(); | 224 | pt_ref(r.dest) = new_string->get_allocation(); |
| 225 | dec_ref_count_and_free(str); | 225 | dec_ref_count_and_free(str); |
| 226 | } | 226 | } |
| 227 | 227 | ||
| @@ -247,7 +247,7 @@ namespace · 19 unmodified lines | |||
| 247 | auto new_string = new vm_string_t(len, reinterpret_cast<uint8_t *>(buffer.data())); | 247 | auto new_string = new vm_string_t(len, reinterpret_cast<uint8_t *>(buffer.data())); |
| 248 | 248 | ||
| 249 | auto str = at_val<vm_string_t>(r.dest); | 249 | auto str = at_val<vm_string_t>(r.dest); |
| 250 | pt_ref(r.dest) = new_string->allocation(); | 250 | pt_ref(r.dest) = new_string->get_allocation(); |
| 251 | dec_ref_count_and_free(str); | 251 | dec_ref_count_and_free(str); |
| 252 | } | 252 | } |
| 253 | 253 | ||
| @@ -399,7 +399,7 @@ namespace · 145 unmodified lines | |||
| 399 | if (alloc != nullptr) | 399 | if (alloc != nullptr) |
| 400 | { | 400 | { |
| 401 | alloc->add_ref(); | 401 | alloc->add_ref(); |
| 402 | pt_ref(dest) = alloc->allocation(); | 402 | pt_ref(dest) = alloc->get_allocation(); |
| 403 | } | 403 | } |
| 404 | else | 404 | else |
| 405 | { | 405 | { |
| @@ -626,7 +626,7 @@ namespace · 220 unmodified lines | |||
| 626 | auto old_str = at_val<vm_string_t>(r.dest); | 626 | auto old_str = at_val<vm_string_t>(r.dest); |
| 627 | if (str != old_str) | 627 | if (str != old_str) |
| 628 | { | 628 | { |
| 629 | pt_ref(r.dest) = str->allocation(); | 629 | pt_ref(r.dest) = str->get_allocation(); |
| 630 | dec_ref_count_and_free(old_str); | 630 | dec_ref_count_and_free(old_str); |
| 631 | } | 631 | } |
| 632 | } | 632 | } |
| @@ -678,7 +678,7 @@ namespace · 45 unmodified lines | |||
| 678 | 678 | ||
| 679 | if (!append_to_source) | 679 | if (!append_to_source) |
| 680 | { | 680 | { |
| 681 | pt_ref(r.dest) = str->allocation(); | 681 | pt_ref(r.dest) = str->get_allocation(); |
| 682 | dec_ref_count_and_free(dest_maybe); | 682 | dec_ref_count_and_free(dest_maybe); |
| 683 | } | 683 | } |
| 684 | } | 684 | } |
| @@ -692,7 +692,7 @@ namespace · 7 unmodified lines | |||
| 692 | if (str != nullptr) | 692 | if (str != nullptr) |
| 693 | { | 693 | { |
| 694 | auto new_string = new vm_string_t(*str, start, end); | 694 | auto new_string = new vm_string_t(*str, start, end); |
| 695 | pt_ref(r.dest) = new_string->allocation(); | 695 | pt_ref(r.dest) = new_string->get_allocation(); |
| 696 | } | 696 | } |
| 697 | else if (start == 0 && end == 0) | 697 | else if (start == 0 && end == 0) |
| 698 | { | 698 | { |
| @@ -744,7 +744,7 @@ namespace · 45 unmodified lines | |||
| 744 | if (arr->alloc_type->map_in_bytes > 0) | 744 | if (arr->alloc_type->map_in_bytes > 0) |
| 745 | vm.get_garbage_collector().track_allocation(new_array); | 745 | vm.get_garbage_collector().track_allocation(new_array); |
| 746 | 746 | ||
| 747 | pt_ref(r.dest) = new_array->allocation(); | 747 | pt_ref(r.dest) = new_array->get_allocation(); |
| 748 | } | 748 | } |
| 749 | 749 | ||
| 750 | EXEC_DECL(slicela) | 750 | EXEC_DECL(slicela) |
| @@ -810,7 +810,7 @@ namespace · 59 unmodified lines | |||
| 810 | auto value = vt_ref<PrimitiveType>(r.src); | 810 | auto value = vt_ref<PrimitiveType>(r.src); |
| 811 | vt_ref<PrimitiveType>(new_list->value()) = value; | 811 | vt_ref<PrimitiveType>(new_list->value()) = value; |
| 812 | 812 | ||
| 813 | pt_ref(r.dest) = new_list->allocation(); | 813 | pt_ref(r.dest) = new_list->get_allocation(); |
| 814 | } | 814 | } |
| 815 | 815 | ||
| 816 | EXEC_DECL(consb) { _cons<byte_t>(r); } | 816 | EXEC_DECL(consb) { _cons<byte_t>(r); } |
| @@ -830,7 +830,7 @@ namespace · 13 unmodified lines | |||
| 830 | if (alloc != nullptr) | 830 | if (alloc != nullptr) |
| 831 | { | 831 | { |
| 832 | alloc->add_ref(); | 832 | alloc->add_ref(); |
| 833 | pt_ref(new_list->value()) = alloc->allocation(); | 833 | pt_ref(new_list->value()) = alloc->get_allocation(); |
| 834 | 834 | ||
| 835 | vm.get_garbage_collector().track_allocation(new_list); | 835 | vm.get_garbage_collector().track_allocation(new_list); |
| 836 | } | 836 | } |
| @@ -840,7 +840,7 @@ namespace · 3 unmodified lines | |||
| 840 | } | 840 | } |
| 841 | 841 | ||
| 842 | // Return the list | 842 | // Return the list |
| 843 | pt_ref(r.dest) = new_list->allocation(); | 843 | pt_ref(r.dest) = new_list->get_allocation(); |
| 844 | } | 844 | } |
| 845 | 845 | ||
| 846 | EXEC_DECL(consmp) | 846 | EXEC_DECL(consmp) |
| @@ -866,7 +866,7 @@ namespace · 19 unmodified lines | |||
| 866 | vm.get_garbage_collector().track_allocation(new_list); | 866 | vm.get_garbage_collector().track_allocation(new_list); |
| 867 | 867 | ||
| 868 | // Return the list | 868 | // Return the list |
| 869 | pt_ref(r.dest) = new_list->allocation(); | 869 | pt_ref(r.dest) = new_list->get_allocation(); |
| 870 | } | 870 | } |
| 871 | 871 | ||
| 872 | template<typename PrimitiveType> | 872 | template<typename PrimitiveType> |
| @@ -917,7 +917,7 @@ namespace · 44 unmodified lines | |||
| 917 | 917 | ||
| 918 | auto tail_maybe = list->get_tail(); | 918 | auto tail_maybe = list->get_tail(); |
| 919 | if (tail_maybe != nullptr) | 919 | if (tail_maybe != nullptr) |
| 920 | tail = tail_maybe->allocation(); | 920 | tail = tail_maybe->get_allocation(); |
| 921 | 921 | ||
| 922 | // Use the address of the local variable. | 922 | // Use the address of the local variable. |
| 923 | r.src = reinterpret_cast<pointer_t>(&tail); | 923 | r.src = reinterpret_cast<pointer_t>(&tail); |
| @@ -973,7 +973,7 @@ namespace · 49 unmodified lines | |||
| 973 | if (type_desc->map_in_bytes > 0) | 973 | if (type_desc->map_in_bytes > 0) |
| 974 | vm.get_garbage_collector().track_allocation(new_channel); | 974 | vm.get_garbage_collector().track_allocation(new_channel); |
| 975 | 975 | ||
| 976 | pt_ref(r.dest) = new_channel->allocation(); | 976 | pt_ref(r.dest) = new_channel->get_allocation(); |
| 977 | } | 977 | } |
| 978 | } | 978 | } |
| 979 | 979 | ||
| @@ -1061,7 +1061,7 @@ namespace · 81 unmodified lines | |||
| 1061 | 1061 | ||
| 1062 | word_t cancel_outstanding_channel_requests(uint32_t request_thread_id, vm_alt_stack_layout_t *alt, const vm_channel_t &handled_channel) | 1062 | word_t cancel_outstanding_channel_requests(uint32_t request_thread_id, vm_alt_stack_layout_t *alt, const vm_channel_t &handled_channel) |
| 1063 | { | 1063 | { |
| 1064 | auto alloc = handled_channel.allocation(); | 1064 | auto alloc = handled_channel.get_allocation(); |
| 1065 | 1065 | ||
| 1066 | auto handled_index = word_t{ -1 }; | 1066 | auto handled_index = word_t{ -1 }; |
| 1067 | const auto channel_count = (alt->send_count + alt->receive_count); | 1067 | const auto channel_count = (alt->send_count + alt->receive_count); |
| @@ -1216,7 +1216,7 @@ namespace · 148 unmodified lines | |||
| 1216 | if (type_desc->map_in_bytes > 0) | 1216 | if (type_desc->map_in_bytes > 0) |
| 1217 | vm.get_garbage_collector().track_allocation(new_alloc); | 1217 | vm.get_garbage_collector().track_allocation(new_alloc); |
| 1218 | 1218 | ||
| 1219 | pt_ref(r.dest) = new_alloc->allocation(); | 1219 | pt_ref(r.dest) = new_alloc->get_allocation(); |
| 1220 | } | 1220 | } |
| 1221 | } | 1221 | } |
| 1222 | 1222 | ||
| @@ -1248,7 +1248,7 @@ namespace · 25 unmodified lines | |||
| 1248 | if (type_desc->map_in_bytes > 0) | 1248 | if (type_desc->map_in_bytes > 0) |
| 1249 | vm.get_garbage_collector().track_allocation(new_alloc); | 1249 | vm.get_garbage_collector().track_allocation(new_alloc); |
| 1250 | 1250 | ||
| 1251 | pt_ref(r.dest) = new_alloc->allocation(); | 1251 | pt_ref(r.dest) = new_alloc->get_allocation(); |
| 1252 | } | 1252 | } |
| 1253 | 1253 | ||
| 1254 | namespace | 1254 | namespace |
| @@ -1270,7 +1270,7 @@ namespace · 15 unmodified lines | |||
| 1270 | if (type_desc->map_in_bytes > 0) | 1270 | if (type_desc->map_in_bytes > 0) |
| 1271 | vm.get_garbage_collector().track_allocation(new_array); | 1271 | vm.get_garbage_collector().track_allocation(new_array); |
| 1272 | 1272 | ||
| 1273 | pt_ref(r.dest) = new_array->allocation(); | 1273 | pt_ref(r.dest) = new_array->get_allocation(); |
| 1274 | } | 1274 | } |
| 1275 | } | 1275 | } |
| 1276 | 1276 | ||
| @@ -1535,7 +1535,7 @@ namespace · 258 unmodified lines | |||
| 1535 | // The first pointer in the exception is a string type | 1535 | // The first pointer in the exception is a string type |
| 1536 | // that is used to uniquely identify the exception type. | 1536 | // that is used to uniquely identify the exception type. |
| 1537 | // The remainder of the type is user-defined. | 1537 | // The remainder of the type is user-defined. |
| 1538 | auto content = e->allocation(); | 1538 | auto content = e->get_allocation(); |
| 1539 | exception_id = at_val<vm_string_t>(content); | 1539 | exception_id = at_val<vm_string_t>(content); |
| 1540 | 1540 | ||
| 1541 | if (debug::is_component_tracing_enabled<debug::component_trace_t::exception>()) | 1541 | if (debug::is_component_tracing_enabled<debug::component_trace_t::exception>()) |
| @@ -1580,7 +1580,7 @@ namespace · 38 unmodified lines | |||
| 1580 | dec_ref_count_and_free(current_value); | 1580 | dec_ref_count_and_free(current_value); |
| 1581 | 1581 | ||
| 1582 | // Set the exception destination. | 1582 | // Set the exception destination. |
| 1583 | pt_ref(exception_destination) = e->allocation(); | 1583 | pt_ref(exception_destination) = e->get_allocation(); |
| 1584 | 1584 | ||
| 1585 | r.pc = handler_pc; | 1585 | r.pc = handler_pc; |
| 1586 | } | 1586 | } |
| @@ -1630,7 +1630,7 @@ namespace · 43 unmodified lines | |||
| 1630 | const auto &function_imports = imports[module_import_index]; | 1630 | const auto &function_imports = imports[module_import_index]; |
| 1631 | 1631 | ||
| 1632 | auto entry_module_ref = new vm_module_ref_t{ imported_module, function_imports }; | 1632 | auto entry_module_ref = new vm_module_ref_t{ imported_module, function_imports }; |
| 1633 | pt_ref(r.dest) = entry_module_ref->allocation(); | 1633 | pt_ref(r.dest) = entry_module_ref->get_allocation(); |
| 1634 | } | 1634 | } |
| 1635 | } | 1635 | } |
| 1636 | 1636 | ||
| @@ -151,7 +151,7 @@ namespace · 150 unmodified lines | |||
| 151 | debug::log_msg(debug::component_trace_t::garbage_collector, debug::log_level_t::debug, "gc: mark: alloc: %#" PRIxPTR "\n", curr); | 151 | debug::log_msg(debug::component_trace_t::garbage_collector, debug::log_level_t::debug, "gc: mark: alloc: %#" PRIxPTR "\n", curr); |
| 152 | 152 | ||
| 153 | if (curr->alloc_type->map_in_bytes > 0) | 153 | if (curr->alloc_type->map_in_bytes > 0) |
| 154 | enum_pointer_fields(*curr->alloc_type, curr->allocation(), add_pointer_to_queue); | 154 | enum_pointer_fields(*curr->alloc_type, curr->get_allocation(), add_pointer_to_queue); |
| 155 | 155 | ||
| 156 | set_gc_colour(curr, curr_colour); | 156 | set_gc_colour(curr, curr_colour); |
| 157 | } | 157 | } |
| @@ -389,7 +389,7 @@ namespace · 388 unmodified lines | |||
| 389 | auto array_stack_pointer = std::size_t{ 0 }; | 389 | auto array_stack_pointer = std::size_t{ 0 }; |
| 390 | auto success = bool{}; | 390 | auto success = bool{}; |
| 391 | auto code = byte_t{}; | 391 | auto code = byte_t{}; |
| 392 | auto base = reinterpret_cast<byte_t *>(modobj.original_mp->allocation()); | 392 | auto base = reinterpret_cast<byte_t *>(modobj.original_mp->get_allocation()); |
| 393 | for (;;) | 393 | for (;;) |
| 394 | { | 394 | { |
| 395 | auto bytesRead = reader.get_next_bytes(sizeof(code), &code); | 395 | auto bytesRead = reader.get_next_bytes(sizeof(code), &code); |
| @@ -449,7 +449,7 @@ namespace · 53 unmodified lines | |||
| 449 | throw module_reader_exception{ "Failed to read string data" }; | 449 | throw module_reader_exception{ "Failed to read string data" }; |
| 450 | 450 | ||
| 451 | auto new_string = new vm_string_t(str_buffer.size(), str_buffer.data()); | 451 | auto new_string = new vm_string_t(str_buffer.size(), str_buffer.data()); |
| 452 | *reinterpret_cast<pointer_t *>(data_dest) = new_string->allocation(); | 452 | *reinterpret_cast<pointer_t *>(data_dest) = new_string->get_allocation(); |
| 453 | break; | 453 | break; |
| 454 | } | 454 | } |
| 455 | case datum_type_t::value_real64: | 455 | case datum_type_t::value_real64: |
| @@ -469,7 +469,7 @@ namespace · 13 unmodified lines | |||
| 469 | if (!success) throw module_reader_exception{ "Failed to read word" }; | 469 | if (!success) throw module_reader_exception{ "Failed to read word" }; |
| 470 | 470 | ||
| 471 | auto new_array = new vm_array_t(modobj.type_section[element_type], element_count); | 471 | auto new_array = new vm_array_t(modobj.type_section[element_type], element_count); |
| 472 | *reinterpret_cast<pointer_t *>(data_dest) = new_array->allocation(); | 472 | *reinterpret_cast<pointer_t *>(data_dest) = new_array->get_allocation(); |
| 473 | break; | 473 | break; |
| 474 | } | 474 | } |
| 475 | case datum_type_t::set_array: | 475 | case datum_type_t::set_array: |
| @@ -7,7 +7,11 @@ · 6 unmodified lines | |||
| 7 | #include <array> | 7 | #include <array> |
| 8 | #include <chrono> | 8 | #include <chrono> |
| 9 | #include <thread> | 9 | #include <thread> |
| 10 | #include <iostream> | ||
| 11 | #include <fstream> | ||
| 12 | #include <streambuf> | ||
| 10 | #include <exceptions.h> | 13 | #include <exceptions.h> |
| 14 | #include <debug.h> | ||
| 11 | #include <utf8.h> | 15 | #include <utf8.h> |
| 12 | #include "Sysmod.h" | 16 | #include "Sysmod.h" |
| 13 | #include "sys_utils.h" | 17 | #include "sys_utils.h" |
| @@ -73,15 +77,113 @@ std::shared_ptr<const type_descriptor_t> T_FD; · 59 unmodified lines | |||
| 73 | std::shared_ptr<const type_descriptor_t> T_Connection; | 77 | std::shared_ptr<const type_descriptor_t> T_Connection; |
| 74 | std::shared_ptr<const type_descriptor_t> T_FileIO; | 78 | std::shared_ptr<const type_descriptor_t> T_FileIO; |
| 75 | 79 | ||
| 80 | struct vm_fd_t final : public Sys_FD | ||
| 81 | { | ||
| 82 | static void finalizer(vm_alloc_t *fileHandle) | ||
| 83 | { | ||
| 84 | auto fd = fileHandle->get_allocation<vm_fd_t>(); | ||
| 85 | fd->~vm_fd_t(); | ||
| 86 | } | ||
| 87 | |||
| 88 | vm_fd_t(word_t fd, std::unique_ptr<std::iostream> s) | ||
| 89 | : Sys_FD{ fd } | ||
| 90 | , _istream{ s.get() } | ||
| 91 | , _ostream{ s.get() } | ||
| 92 | { | ||
| 93 | assert(s != nullptr); | ||
| 94 | _stream = std::move(s); | ||
| 95 | } | ||
| 96 | |||
| 97 | vm_fd_t(word_t fd, std::unique_ptr<std::istream> s) | ||
| 98 | : Sys_FD{ fd } | ||
| 99 | , _istream{ s.get() } | ||
| 100 | , _ostream{ nullptr } | ||
| 101 | { | ||
| 102 | assert(s != nullptr); | ||
| 103 | _stream = std::move(s); | ||
| 104 | } | ||
| 105 | |||
| 106 | vm_fd_t(word_t fd, std::unique_ptr<std::ostream> s) | ||
| 107 | : Sys_FD{ fd } | ||
| 108 | , _istream{ nullptr } | ||
| 109 | , _ostream{ s.get() } | ||
| 110 | { | ||
| 111 | assert(s != nullptr); | ||
| 112 | _stream = std::move(s); | ||
| 113 | } | ||
| 114 | |||
| 115 | vm_fd_t(word_t fd, std::istream &s) | ||
| 116 | : Sys_FD{ fd } | ||
| 117 | , _istream{ &s } | ||
| 118 | , _ostream{ nullptr } | ||
| 119 | { | ||
| 120 | } | ||
| 121 | |||
| 122 | vm_fd_t(word_t fd, std::ostream &s) | ||
| 123 | : Sys_FD{ fd } | ||
| 124 | , _istream{ nullptr } | ||
| 125 | , _ostream{ &s } | ||
| 126 | { | ||
| 127 | } | ||
| 128 | |||
| 129 | ~vm_fd_t() | ||
| 130 | { | ||
| 131 | debug::assign_debug_pointer(&_istream); | ||
| 132 | debug::assign_debug_pointer(&_ostream); | ||
| 133 | |||
| 134 | if (debug::is_component_tracing_enabled<debug::component_trace_t::memory>()) | ||
| 135 | debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "destroy: file descriptor: %d", fd); | ||
| 136 | } | ||
| 137 | |||
| 138 | std::istream& input() const | ||
| 139 | { | ||
| 140 | if (_istream == nullptr) | ||
| 141 | throw vm_user_exception{ "File descriptor not open for write" }; | ||
| 142 | |||
| 143 | return *_istream; | ||
| 144 | } | ||
| 145 | |||
| 146 | std::ostream& output() const | ||
| 147 | { | ||
| 148 | if (_ostream == nullptr) | ||
| 149 | throw vm_user_exception{ "File descriptor not open for read" }; | ||
| 150 | |||
| 151 | return *_ostream; | ||
| 152 | } | ||
| 153 | |||
| 154 | private: | ||
| 155 | std::istream *_istream; | ||
| 156 | std::ostream *_ostream; | ||
| 157 | std::unique_ptr<std::ios> _stream; | ||
| 158 | }; | ||
| 159 | |||
| 160 | namespace | ||
| 161 | { | ||
| 162 | vm_alloc_t *vm_stdin = nullptr; | ||
| 163 | vm_alloc_t *vm_stdout = nullptr; | ||
| 164 | vm_alloc_t *vm_stderr = nullptr; | ||
| 165 | } | ||
| 166 | |||
| 76 | void | 167 | void |
| 77 | Sysmodinit(void) | 168 | Sysmodinit(void) |
| 78 | { | 169 | { |
| 79 | builtin::register_module_exports(Sys_PATH, Sysmodlen, Sysmodtab); | 170 | builtin::register_module_exports(Sys_PATH, Sysmodlen, Sysmodtab); |
| 80 | T_Qid = type_descriptor_t::create(sizeof(Sys_Qid), sizeof(Sys_Qid_map), Sys_Qid_map); | 171 | T_Qid = type_descriptor_t::create(sizeof(Sys_Qid), sizeof(Sys_Qid_map), Sys_Qid_map); |
| 81 | T_Dir = type_descriptor_t::create(sizeof(Sys_Dir), sizeof(Sys_Dir_map), Sys_Dir_map); | 172 | T_Dir = type_descriptor_t::create(sizeof(Sys_Dir), sizeof(Sys_Dir_map), Sys_Dir_map); |
| 82 | T_FD = type_descriptor_t::create(sizeof(Sys_FD), sizeof(Sys_FD_map), Sys_FD_map); | 173 | T_FD = type_descriptor_t::create(sizeof(vm_fd_t), sizeof(Sys_FD_map), Sys_FD_map, vm_fd_t::finalizer); |
| 83 | T_Connection = type_descriptor_t::create(sizeof(Sys_Connection), sizeof(Sys_Connection_map), Sys_Connection_map); | 174 | T_Connection = type_descriptor_t::create(sizeof(Sys_Connection), sizeof(Sys_Connection_map), Sys_Connection_map); |
| 84 | T_FileIO = type_descriptor_t::create(sizeof(Sys_FileIO), sizeof(Sys_FileIO_map), Sys_FileIO_map); | 175 | T_FileIO = type_descriptor_t::create(sizeof(Sys_FileIO), sizeof(Sys_FileIO_map), Sys_FileIO_map); |
| 176 | |||
| 177 | // Initialize default file descriptors | ||
| 178 | |||
| 179 | vm_stdin = vm_alloc_t::allocate(T_FD); | ||
| 180 | ::new(vm_stdin->get_allocation()) vm_fd_t{ 0, std::cin }; | ||
| 181 | |||
| 182 | vm_stdout = vm_alloc_t::allocate(T_FD); | ||
| 183 | ::new(vm_stdout->get_allocation()) vm_fd_t{ 1, std::cout }; | ||
| 184 | |||
| 185 | vm_stderr = vm_alloc_t::allocate(T_FD); | ||
| 186 | ::new(vm_stderr->get_allocation()) vm_fd_t{ 2, std::cerr }; | ||
| 85 | } | 187 | } |
| 86 | 188 | ||
| 87 | void | 189 | void |
| @@ -354,13 +456,13 @@ Sys_print(vm_registers_t &r, vm_t &vm) · 266 unmodified lines | |||
| 354 | auto written = printf_to_buffer(*str, msg_args, fp_base, static_buffer.size(), static_buffer.data()); | 456 | auto written = printf_to_buffer(*str, msg_args, fp_base, static_buffer.size(), static_buffer.data()); |
| 355 | if (written >= 0) | 457 | if (written >= 0) |
| 356 | { | 458 | { |
| 357 | std::printf(static_buffer.data()); | 459 | vm_stdout->get_allocation<vm_fd_t>()->output() << static_buffer.data(); |
| 358 | } | 460 | } |
| 359 | else | 461 | else |
| 360 | { | 462 | { |
| 361 | auto dynamic_buffer = std::vector<char>(static_buffer.size() * 2); | 463 | auto dynamic_buffer = std::vector<char>(static_buffer.size() * 2); |
| 362 | written = printf_to_dynamic_buffer(*str, msg_args, fp_base, dynamic_buffer); | 464 | written = printf_to_dynamic_buffer(*str, msg_args, fp_base, dynamic_buffer); |
| 363 | std::printf(dynamic_buffer.data()); | 465 | vm_stdout->get_allocation<vm_fd_t>()->output() << static_buffer.data(); |
| 364 | } | 466 | } |
| 365 | 467 | ||
| 366 | *fp.ret = written; | 468 | *fp.ret = written; |
| @@ -4,8 +4,8 @@ · 3 unmodified lines | |||
| 4 | // Author: arr | 4 | // Author: arr |
| 5 | // | 5 | // |
| 6 | 6 | ||
| 7 | #include <array> | ||
| 8 | #include <cinttypes> | 7 | #include <cinttypes> |
| 8 | #include <array> | ||
| 9 | #include <utf8.h> | 9 | #include <utf8.h> |
| 10 | #include "sys_utils.h" | 10 | #include "sys_utils.h" |
| 11 | 11 | ||
| @@ -28,7 +28,7 @@ namespace · 27 unmodified lines | |||
| 28 | reg.src = reinterpret_cast<pointer_t>(reinterpret_cast<uint8_t *>(reg.stack.peek_frame()->base()) + inst.source.register1); | 28 | reg.src = reinterpret_cast<pointer_t>(reinterpret_cast<uint8_t *>(reg.stack.peek_frame()->base()) + inst.source.register1); |
| 29 | break; | 29 | break; |
| 30 | case address_mode_t::offset_indirect_mp: | 30 | case address_mode_t::offset_indirect_mp: |
| 31 | reg.src = reinterpret_cast<pointer_t>(reinterpret_cast<uint8_t *>(reg.mp_base->allocation()) + inst.source.register1); | 31 | reg.src = reinterpret_cast<pointer_t>(reinterpret_cast<uint8_t *>(reg.mp_base->get_allocation()) + inst.source.register1); |
| 32 | break; | 32 | break; |
| 33 | case address_mode_t::offset_double_indirect_fp: | 33 | case address_mode_t::offset_double_indirect_fp: |
| 34 | { | 34 | { |
| @@ -38,7 +38,7 @@ namespace · 3 unmodified lines | |||
| 38 | } | 38 | } |
| 39 | case address_mode_t::offset_double_indirect_mp: | 39 | case address_mode_t::offset_double_indirect_mp: |
| 40 | { | 40 | { |
| 41 | const auto mp_offset = *reinterpret_cast<std::size_t *>(reinterpret_cast<uint8_t *>(reg.mp_base->allocation()) + inst.source.register1); | 41 | const auto mp_offset = *reinterpret_cast<std::size_t *>(reinterpret_cast<uint8_t *>(reg.mp_base->get_allocation()) + inst.source.register1); |
| 42 | reg.src = reinterpret_cast<pointer_t>(mp_offset + inst.source.register2); | 42 | reg.src = reinterpret_cast<pointer_t>(mp_offset + inst.source.register2); |
| 43 | break; | 43 | break; |
| 44 | } | 44 | } |
| @@ -58,7 +58,7 @@ namespace · 13 unmodified lines | |||
| 58 | reg.dest = reinterpret_cast<pointer_t>(reinterpret_cast<uint8_t *>(reg.stack.peek_frame()->base()) + inst.destination.register1); | 58 | reg.dest = reinterpret_cast<pointer_t>(reinterpret_cast<uint8_t *>(reg.stack.peek_frame()->base()) + inst.destination.register1); |
| 59 | break; | 59 | break; |
| 60 | case address_mode_t::offset_indirect_mp: | 60 | case address_mode_t::offset_indirect_mp: |
| 61 | reg.dest = reinterpret_cast<pointer_t>(reinterpret_cast<uint8_t *>(reg.mp_base->allocation()) + inst.destination.register1); | 61 | reg.dest = reinterpret_cast<pointer_t>(reinterpret_cast<uint8_t *>(reg.mp_base->get_allocation()) + inst.destination.register1); |
| 62 | break; | 62 | break; |
| 63 | case address_mode_t::offset_double_indirect_fp: | 63 | case address_mode_t::offset_double_indirect_fp: |
| 64 | { | 64 | { |
| @@ -68,7 +68,7 @@ namespace · 3 unmodified lines | |||
| 68 | } | 68 | } |
| 69 | case address_mode_t::offset_double_indirect_mp: | 69 | case address_mode_t::offset_double_indirect_mp: |
| 70 | { | 70 | { |
| 71 | const auto mp_offset = *reinterpret_cast<std::size_t *>(reinterpret_cast<uint8_t *>(reg.mp_base->allocation()) + inst.destination.register1); | 71 | const auto mp_offset = *reinterpret_cast<std::size_t *>(reinterpret_cast<uint8_t *>(reg.mp_base->get_allocation()) + inst.destination.register1); |
| 72 | reg.dest = reinterpret_cast<pointer_t>(mp_offset + inst.destination.register2); | 72 | reg.dest = reinterpret_cast<pointer_t>(mp_offset + inst.destination.register2); |
| 73 | break; | 73 | break; |
| 74 | } | 74 | } |
| @@ -88,7 +88,7 @@ namespace · 13 unmodified lines | |||
| 88 | reg.mid = reinterpret_cast<pointer_t>(reinterpret_cast<uint8_t *>(reg.stack.peek_frame()->base()) + inst.middle.register1); | 88 | reg.mid = reinterpret_cast<pointer_t>(reinterpret_cast<uint8_t *>(reg.stack.peek_frame()->base()) + inst.middle.register1); |
| 89 | break; | 89 | break; |
| 90 | case address_mode_middle_t::small_offset_indirect_mp: | 90 | case address_mode_middle_t::small_offset_indirect_mp: |
| 91 | reg.mid = reinterpret_cast<pointer_t>(reinterpret_cast<uint8_t *>(reg.mp_base->allocation()) + inst.middle.register1); | 91 | reg.mid = reinterpret_cast<pointer_t>(reinterpret_cast<uint8_t *>(reg.mp_base->get_allocation()) + inst.middle.register1); |
| 92 | break; | 92 | break; |
| 93 | case address_mode_middle_t::small_immediate: | 93 | case address_mode_middle_t::small_immediate: |
| 94 | reg.mid = reinterpret_cast<pointer_t>(const_cast<word_t *>(&inst.middle.register1)); | 94 | reg.mid = reinterpret_cast<pointer_t>(const_cast<word_t *>(&inst.middle.register1)); |
| @@ -230,7 +230,7 @@ vm_alloc_t *vm_alloc_t::allocate(std::shared_ptr<const type_descriptor_t> td) · 229 unmodified lines | |||
| 230 | auto alloc = ::new(mem)vm_alloc_t{ td }; | 230 | auto alloc = ::new(mem)vm_alloc_t{ td }; |
| 231 | 231 | ||
| 232 | // Initialize pointer types | 232 | // Initialize pointer types |
| 233 | init_memory(*td, alloc->allocation()); | 233 | init_memory(*td, alloc->get_allocation()); |
| 234 | 234 | ||
| 235 | debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "init: vm alloc: %d\n", td->size_in_bytes); | 235 | debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "init: vm alloc: %d\n", td->size_in_bytes); |
| 236 | return alloc; | 236 | return alloc; |
| @@ -255,10 +255,10 @@ vm_alloc_t *vm_alloc_t::copy(const vm_alloc_t &other) · 18 unmodified lines | |||
| 255 | auto alloc_copy = vm_alloc_t::allocate(other.alloc_type); | 255 | auto alloc_copy = vm_alloc_t::allocate(other.alloc_type); |
| 256 | 256 | ||
| 257 | // Copy the current memory contents of the allocation | 257 | // Copy the current memory contents of the allocation |
| 258 | std::memcpy(alloc_copy->allocation(), other.allocation(), alloc_copy->alloc_type->size_in_bytes); | 258 | std::memcpy(alloc_copy->get_allocation(), other.get_allocation(), alloc_copy->alloc_type->size_in_bytes); |
| 259 | 259 | ||
| 260 | // Ref count all dynamic allocations | 260 | // Ref count all dynamic allocations |
| 261 | inc_ref_count_in_memory(*alloc_copy->alloc_type, alloc_copy->allocation()); | 261 | inc_ref_count_in_memory(*alloc_copy->alloc_type, alloc_copy->get_allocation()); |
| 262 | 262 | ||
| 263 | debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "copy: vm alloc: %#" PRIxPTR " %#" PRIxPTR "\n", &other, alloc_copy); | 263 | debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "copy: vm alloc: %#" PRIxPTR " %#" PRIxPTR "\n", &other, alloc_copy); |
| 264 | return alloc_copy; | 264 | return alloc_copy; |
| @@ -289,7 +289,7 @@ vm_alloc_t::~vm_alloc_t() · 24 unmodified lines | |||
| 289 | finalizer(this); | 289 | finalizer(this); |
| 290 | 290 | ||
| 291 | // Free pointer types | 291 | // Free pointer types |
| 292 | destroy_memory(*alloc_type, allocation()); | 292 | destroy_memory(*alloc_type, get_allocation()); |
| 293 | debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "destroy: vm alloc\n"); | 293 | debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "destroy: vm alloc\n"); |
| 294 | } | 294 | } |
| 295 | 295 | ||
| @@ -314,7 +314,7 @@ std::size_t vm_alloc_t::get_ref_count() const · 18 unmodified lines | |||
| 314 | return _ref_count; | 314 | return _ref_count; |
| 315 | } | 315 | } |
| 316 | 316 | ||
| 317 | pointer_t vm_alloc_t::allocation() const | 317 | pointer_t vm_alloc_t::get_allocation() const |
| 318 | { | 318 | { |
| 319 | // Remove const on the this pointer so the offset can be computed. | 319 | // Remove const on the this pointer so the offset can be computed. |
| 320 | auto non_const_this = const_cast<vm_alloc_t *>(this); | 320 | auto non_const_this = const_cast<vm_alloc_t *>(this); |