Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/src/train/generation.om # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / src / train / generation.om` 212 lines ยท 5384 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note M22 OMTRGEN1 snapshots. The first 120 bytes and the payloads are hashed. 3 note The digest is filled by the caller after transfer of the payloads. 4 om2 5 6 const gen_magic ulong `3552853328668151119` 7 const cur_magic ulong `3553996803581168975` 8 const rec_magic ulong `826558292` 9 const payload_limit ulong `1099511627776` 10 11 fn gen_word bytes view uchar * first ulong to ulong 12 value = ulong 0 13 for j ulong 8 14 value = or value shl ulong get bytes add first j mul j 8 15 end 16 ret value 17 end 18 19 fn gen_word32 bytes view uchar * first ulong to ulong 20 value = ulong 0 21 for j ulong 4 22 value = or value shl ulong get bytes add first j mul j 8 23 end 24 ret value 25 end 26 27 fn put_gen_word bytes edit uchar * first ulong value ulong to void 28 for j ulong 8 29 put bytes add first j uchar and shr value mul j 8 255 30 end 31 end 32 33 fn put_gen_word32 bytes edit uchar * first ulong value ulong to void 34 for j ulong 4 35 put bytes add first j uchar and shr value mul j 8 255 36 end 37 end 38 39 fn hex_nibble v ulong to uchar 40 if lt v 10 41 ret uchar add 48 v 42 end 43 ret uchar add 87 v 44 end 45 46 fn unhex_char c ulong to long 47 if and ge c 48 le c 57 48 ret long sub c 48 49 end 50 if and ge c 97 le c 102 51 ret long add sub c 97 10 52 end 53 ret -1 54 end 55 56 export fn tg_encode_hex digest view uchar 32 out_hex out uchar 64 to void 57 for i ulong 32 58 b = ulong get digest i 59 put out_hex mul i 2 hex_nibble shr b 4 60 put out_hex add mul i 2 1 hex_nibble and b 15 61 end 62 end 63 64 export fn tg_encode_pointer gen ulong digest view uchar 32 out_buf out uchar 95 to void 65 put_gen_word out_buf 0 cur_magic 66 put out_buf 8 32 67 rem_gen = gen 68 for i ulong 20 69 pos = sub 28 i 70 put out_buf pos uchar add 48 rem rem_gen 10 71 rem_gen = div rem_gen 10 72 end 73 put out_buf 29 32 74 for i ulong 32 75 b = ulong get digest i 76 put out_buf add 30 mul i 2 hex_nibble shr b 4 77 put out_buf add 31 mul i 2 hex_nibble and b 15 78 end 79 put out_buf 94 10 80 end 81 82 export fn tg_decode_pointer buf view uchar 95 gen_out edit ulong 1 digest_out out uchar 32 to ulong 83 if ne gen_word buf 0 cur_magic 84 ret 0 85 end 86 if or ne get buf 8 32 ne get buf 29 32 87 ret 0 88 end 89 if ne get buf 94 10 90 ret 0 91 end 92 g = ulong 0 93 for i ulong 20 94 c = ulong get buf add 9 i 95 if or lt c 48 gt c 57 96 ret 0 97 end 98 d = sub c 48 99 if or gt g `1844674407370955161` and eq g `1844674407370955161` gt d 5 100 ret 0 101 end 102 g = add mul g 10 d 103 end 104 for i ulong 32 105 hi = unhex_char ulong get buf add 30 mul i 2 106 lo = unhex_char ulong get buf add 31 mul i 2 107 if or lt hi 0 lt lo 0 108 ret 0 109 end 110 put digest_out i uchar or shl ulong hi 4 ulong lo 111 end 112 put gen_out 0 g 113 ret 1 114 end 115 116 export fn tg_encode_dispatch fields view ulong 6 refs view ulong 9 base_digest view uchar 32 rec out uchar 192 to void 117 for i ulong 192 118 put rec i 0 119 end 120 put_gen_word32 rec 0 rec_magic 121 put_gen_word32 rec 4 get fields 0 122 put_gen_word rec 16 get fields 1 123 put_gen_word rec 24 get fields 2 124 put_gen_word rec 32 get fields 3 125 put_gen_word rec 40 get fields 4 126 n_refs = get fields 5 127 if gt n_refs 3 128 n_refs = 3 129 end 130 put_gen_word32 rec 48 n_refs 131 for i ulong n_refs 132 base = add 56 mul i 24 133 put_gen_word32 rec base get refs mul i 3 134 put_gen_word rec add base 8 get refs add mul i 3 1 135 put_gen_word rec add base 16 get refs add mul i 3 2 136 end 137 for i ulong 32 138 put rec add 128 i get base_digest i 139 end 140 end 141 142 export fn tg_set_dispatch_seq rec edit uchar 192 seq ulong to void 143 put_gen_word rec 8 seq 144 end 145 146 export fn tg_check_dispatch_header rec view uchar 192 expect_seq ulong to ulong 147 if or ne gen_word32 rec 0 rec_magic ne gen_word rec 8 expect_seq 148 ret 0 149 end 150 ret 1 151 end 152 153 export fn tg_decode_dispatch rec view uchar 192 fields edit ulong 7 refs edit ulong 9 to ulong 154 n_refs = gen_word32 rec 48 155 if gt n_refs 3 156 ret 0 157 end 158 put fields 0 gen_word32 rec 4 159 put fields 1 gen_word rec 8 160 put fields 2 gen_word rec 16 161 put fields 3 gen_word rec 24 162 put fields 4 gen_word rec 32 163 put fields 5 gen_word rec 40 164 put fields 6 n_refs 165 for i ulong 9 166 put refs i 0 167 end 168 for i ulong n_refs 169 base = add 56 mul i 24 170 put refs mul i 3 gen_word32 rec base 171 put refs add mul i 3 1 gen_word rec add base 8 172 put refs add mul i 3 2 gen_word rec add base 16 173 end 174 ret 1 175 end 176 177 export fn tg_encode_generation fields view ulong 5 dispatch view uchar 32 previous view uchar 32 header out uchar 152 to void 178 put_gen_word header 0 gen_magic 179 put_gen_word header 8 1 180 for i ulong 5 181 put_gen_word header add 16 mul i 8 get fields i 182 end 183 for i ulong 32 184 put header add 56 i get dispatch i 185 put header add 88 i get previous i 186 put header add 120 i 0 187 end 188 end 189 190 note Return 1 for a verified header, 2 for a truncated file and 0 for a 191 note format error. Preserve the historical order of these refusals. 192 export fn tg_decode_generation header view uchar 152 size ulong expected ulong fields edit ulong 5 to ulong 193 if or ne gen_word header 0 gen_magic ne gen_word header 8 1 194 ret 0 195 end 196 params = gen_word header 32 197 opt = gen_word header 40 198 if or gt params payload_limit gt opt payload_limit 199 ret 0 200 end 201 total = add 152 add params opt 202 if lt size total 203 ret 2 204 end 205 if or ne size total ne gen_word header 16 expected 206 ret 0 207 end 208 for i ulong 5 209 put fields i gen_word header add 16 mul i 8 210 end 211 ret 1 212 end