omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / seed / omc / tests / longnames / long_names.om
| 1 | note long_names: a name of 9 to 63 bytes (local, parameter, for counter, global, text, const, struct, |
| 2 | note field) is its own name, compared in full. counter_a and counter_b share their first 8 bytes and |
| 3 | note stay two names, distinct from the 8-byte counter_; a name that begins with an 8-byte keyword |
| 4 | note (continue_count, execpure_value) is a name; a local that shares its first 8 bytes with a long |
| 5 | note function (add_three_total, add_three_values) is a local. Each failing check exits with its own |
| 6 | note status 1..10; when all pass it prints the total and exits 0. |
| 7 | struct point_pair left_value uint right_value long end |
| 8 | const table_length ulong 4 |
| 9 | global shared_counter ulong 1 |
| 10 | text greeting_text "long_names ok total " |
| 11 | text newline_text "\n" |
| 12 | |
| 13 | note add_three_values: three long parameter names |
| 14 | fn add_three_values first_value long second_value long third_value long to long |
| 15 | ret add add first_value second_value third_value |
| 16 | end |
| 17 | |
| 18 | note sum_of_pair: a struct parameter with a long name, its long fields read with get |
| 19 | fn sum_of_pair pair_argument view point_pair to long |
| 20 | ret add long get pair_argument left_value get pair_argument right_value |
| 21 | end |
| 22 | |
| 23 | note sum_of_bytes: a sized view whose length is a long const, walked by a long for counter |
| 24 | fn sum_of_bytes byte_values view uchar table_length to ulong |
| 25 | running_total = ulong 0 |
| 26 | for byte_index ulong table_length |
| 27 | running_total = add running_total ulong get byte_values byte_index |
| 28 | end |
| 29 | ret running_total |
| 30 | end |
| 31 | |
| 32 | note bump_shared_counter: a void function with a long name and parameter, called as a statement |
| 33 | fn bump_shared_counter amount_to_add ulong to void |
| 34 | put shared_counter 0 add get shared_counter 0 amount_to_add |
| 35 | end |
| 36 | |
| 37 | note write_decimal: print the value in decimal |
| 38 | fn write_decimal value_to_print ulong to void |
| 39 | digit_buffer = new uchar 20 0 |
| 40 | output_buffer = new uchar 20 0 |
| 41 | digit_count = ulong 0 |
| 42 | remaining_value = value_to_print |
| 43 | keep_going = true |
| 44 | while keep_going bound 21 |
| 45 | put digit_buffer digit_count uchar add rem remaining_value 10 48 |
| 46 | digit_count = add digit_count 1 |
| 47 | remaining_value = div remaining_value 10 |
| 48 | if eq remaining_value 0 |
| 49 | keep_going = false |
| 50 | end |
| 51 | end |
| 52 | output_index = ulong 0 |
| 53 | while gt digit_count 0 bound 21 |
| 54 | digit_count = sub digit_count 1 |
| 55 | put output_buffer output_index get digit_buffer digit_count |
| 56 | output_index = add output_index 1 |
| 57 | end |
| 58 | written_bytes = write 1 output_buffer 0 output_index |
| 59 | end |
| 60 | |
| 61 | note checks: the names that share prefixes, then every kind of long name; 0 when all hold |
| 62 | fn checks to int |
| 63 | counter_a = long 20 |
| 64 | counter_b = long 1 |
| 65 | counter_ = long 100 |
| 66 | if ne add add counter_a counter_b counter_ 121 |
| 67 | ret 1 |
| 68 | end |
| 69 | continue_count = long 3 |
| 70 | execpure_value = long 4 |
| 71 | if ne add continue_count execpure_value 7 |
| 72 | ret 2 |
| 73 | end |
| 74 | add_three_total = add_three_values counter_a counter_b counter_ |
| 75 | if ne add_three_total 121 |
| 76 | ret 3 |
| 77 | end |
| 78 | a_name_that_is_exactly_sixty_three_bytes_long_for_the_omc_gate_ = long 5 |
| 79 | if ne a_name_that_is_exactly_sixty_three_bytes_long_for_the_omc_gate_ 5 |
| 80 | ret 4 |
| 81 | end |
| 82 | point_value = new point_pair 5 -2 |
| 83 | put point_value right_value 10 |
| 84 | if ne sum_of_pair point_value 15 |
| 85 | ret 5 |
| 86 | end |
| 87 | if ne offsetof point_pair right_value 8 |
| 88 | ret 6 |
| 89 | end |
| 90 | if ne sizeof point_pair 16 |
| 91 | ret 7 |
| 92 | end |
| 93 | byte_array = new uchar table_length 3 |
| 94 | if ne sum_of_bytes byte_array 12 |
| 95 | ret 8 |
| 96 | end |
| 97 | bump_shared_counter 40 |
| 98 | bump_shared_counter 2 |
| 99 | if ne get shared_counter 0 42 |
| 100 | ret 9 |
| 101 | end |
| 102 | if ne len greeting_text 20 |
| 103 | ret 10 |
| 104 | end |
| 105 | ret 0 |
| 106 | end |
| 107 | |
| 108 | fn main to int |
| 109 | check_status = checks |
| 110 | if ne check_status 0 |
| 111 | ret check_status |
| 112 | end |
| 113 | written_bytes = write 1 greeting_text 0 len greeting_text |
| 114 | write_decimal add get shared_counter 0 121 |
| 115 | written_bytes = write 1 newline_text 0 len newline_text |
| 116 | ret 0 |
| 117 | end |