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