interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / seed / omc / tests / longnames / long_names.om

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