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/seed/omc/diaggen.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 / seed / omc / diaggen.om` 465 lines ยท 7138 bytes Raw Blame History 1 note Diagnostic source generator. Compose after the core of seed/trace/sha256.om; compile in OM-2. 2 note Usage: diaggen OMC_SOURCE ERROR_REG SHA_SOURCE RUNTIME_SOURCE [sites] 3 note Or: diaggen OMC_SOURCE OMC_BINARY, a derived append-only size-history row. 4 note stdout is canonical compiler source, or the documented site catalog when argc is 6. 5 global buf uchar * 6 global bn ulong 1 7 global src uchar * 8 global sn ulong 1 9 global obuf uchar * 10 global on ulong 1 11 global path uchar 4096 12 text beginmark "note D2-GENERATED-BEGIN" 13 text endmark "note D2-GENERATED-END" 14 text pinhead "text d2pin \"" 15 text sitehead "note d2site " 16 text reghead "omc|" 17 text fnhead "fn " 18 text shastop "fn sha256 " 19 text names "h w k nr blk kset mask ror ch maj bs0 bs1 ss0 ss1 kinit hinit compress" 20 text dsp "ds_" 21 text premeans "text d2means \"" 22 text presites "text d2sites \"" 23 text tail "\"\n" 24 text header "\nnote D2-GENERATED-BEGIN\n" 25 text footer "\nnote D2-GENERATED-END\n" 26 27 fn load arg ulong to void 28 p = argread arg path 0 len path 29 if or le p 0 ge p long len path 30 exit 61 31 end 32 fd = fopen path 0 ulong p 0 0 33 if lt fd 0 34 exit 62 35 end 36 n = ulong 0 37 while true bound `9223372036854775807` 38 if gt n sub ulong `9223372036854775807` 4096 39 exit 63 40 end 41 if lt len buf add n 4096 42 z = enlarge buf add n 4096 43 if ne z 0 44 exit 63 45 end 46 end 47 nr = read int fd buf n 4096 48 if lt nr 0 49 exit 64 50 end 51 if eq nr 0 52 break 53 end 54 n = add n ulong nr 55 end 56 z = fclose int fd 57 put bn 0 n 58 end 59 60 fn ob c uchar to void 61 n = get on 0 62 if eq n len obuf 63 cap = ulong `9223372036854775807` 64 if le n div sub cap 4096 2 65 cap = add mul n 2 4096 66 end 67 if eq n cap 68 exit 63 69 end 70 z = enlarge obuf cap 71 if ne z 0 72 exit 63 73 end 74 end 75 put obuf n c 76 put on 0 add n 1 77 end 78 79 fn ot t view uchar * to void 80 for i ulong len t bound `9223372036854775807` 81 ob get t i 82 end 83 end 84 85 fn esc c uchar to void 86 if eq c 10 87 ob 92 88 ob 110 89 else 90 if or eq c 92 eq c 34 91 ob 92 92 end 93 ob c 94 end 95 end 96 97 fn match p ulong t view uchar * to bool 98 if gt add p len t get bn 0 99 ret false 100 end 101 for i ulong len t bound `9223372036854775807` 102 if ne get buf add p i get t i 103 ret false 104 end 105 end 106 ret true 107 end 108 109 fn nl p ulong to ulong 110 i = p 111 while lt i get bn 0 bound `9223372036854775807` 112 if eq get buf i 10 113 ret i 114 end 115 i = add i 1 116 end 117 ret i 118 end 119 120 fn rename a ulong b ulong to bool 121 p = ulong 0 122 while lt p len names bound `9223372036854775807` 123 q = p 124 while lt q len names bound `9223372036854775807` 125 if eq get names q 32 126 break 127 end 128 q = add q 1 129 end 130 if eq sub b a sub q p 131 same = true 132 for i ulong sub b a bound `9223372036854775807` 133 if ne get buf add a i get names add p i 134 same = false 135 end 136 end 137 if same 138 ret true 139 end 140 end 141 p = add q 1 142 end 143 ret false 144 end 145 146 fn hashout pos ulong to void 147 hinit 148 i = ulong 0 149 while ge sub get on 0 i 64 bound `9223372036854775807` 150 for j ulong 64 bound `9223372036854775807` 151 put blk j get obuf add i j 152 end 153 compress 154 i = add i 64 155 end 156 n = sub get on 0 i 157 for j ulong 64 bound `9223372036854775807` 158 put blk j 0 159 end 160 for j ulong n bound `9223372036854775807` 161 put blk j get obuf add i j 162 end 163 put blk n 128 164 if ge n 56 165 compress 166 for j ulong 64 bound `9223372036854775807` 167 put blk j 0 168 end 169 end 170 bits = mul get on 0 8 171 for j ulong 8 bound `9223372036854775807` 172 put blk add 56 j uchar and shr bits mul sub 7 j 8 255 173 end 174 compress 175 hexout pos 176 end 177 178 fn hexout pos ulong to void 179 for j ulong 32 bound `9223372036854775807` 180 v = and shr get h div j 4 mul sub 3 rem j 4 8 255 181 hi = shr v 4 182 lo = and v 15 183 if lt hi 10 184 put obuf add pos mul j 2 uchar add hi 48 185 else 186 put obuf add pos mul j 2 uchar add hi 87 187 end 188 if lt lo 10 189 put obuf add add pos mul j 2 1 uchar add lo 48 190 else 191 put obuf add add pos mul j 2 1 uchar add lo 87 192 end 193 end 194 end 195 196 fn flush to void 197 i = ulong 0 198 while lt i get on 0 bound `9223372036854775807` 199 nr = write 1 obuf i sub get on 0 i 200 if le nr 0 201 exit 65 202 end 203 i = add i ulong nr 204 end 205 end 206 207 global marks ulong 2 208 fn scan to void 209 i = ulong 0 210 nb = ulong 0 211 ends = ulong 0 212 while lt i get bn 0 bound `9223372036854775807` 213 j = nl i 214 if match i beginmark 215 put marks 0 i 216 nb = add nb 1 217 end 218 if match i endmark 219 put marks 1 add j 1 220 ends = add ends 1 221 end 222 i = add j 1 223 end 224 if or or ne nb 1 ne ends 1 le get marks 1 get marks 0 225 exit 66 226 end 227 end 228 fn sites escaped bool to void 229 i = ulong 0 230 while lt i get bn 0 bound `9223372036854775807` 231 j = nl i 232 if match i sitehead 233 p = add i len sitehead 234 while lt p j bound `9223372036854775807` 235 if escaped 236 esc get buf p 237 else 238 ob get buf p 239 end 240 p = add p 1 241 end 242 if escaped 243 esc 10 244 else 245 ob 10 246 end 247 end 248 i = add j 1 249 end 250 end 251 fn means to void 252 i = ulong 0 253 while lt i get bn 0 bound `9223372036854775807` 254 j = nl i 255 if match i reghead 256 p = add i len reghead 257 bars = ulong 0 258 while lt p j bound `9223372036854775807` 259 c = get buf p 260 if eq c 124 261 bars = add bars 1 262 if eq bars 1 263 esc 124 264 end 265 else 266 if or eq bars 0 eq bars 3 267 esc c 268 end 269 end 270 p = add p 1 271 end 272 esc 10 273 end 274 i = add j 1 275 end 276 end 277 fn runtimehead to void 278 i = ulong 0 279 while lt i get bn 0 bound `9223372036854775807` 280 if match i fnhead 281 ret 282 end 283 ob get buf i 284 i = add i 1 285 end 286 end 287 fn runtimebody to void 288 i = ulong 0 289 while lt i get bn 0 bound `9223372036854775807` 290 if match i fnhead 291 break 292 end 293 i = add i 1 294 end 295 while lt i get bn 0 bound `9223372036854775807` 296 ob get buf i 297 i = add i 1 298 end 299 end 300 fn shacore to void 301 i = ulong 0 302 while lt i get bn 0 bound `9223372036854775807` 303 if match i shastop 304 ret 305 end 306 c = get buf i 307 if or or eq c 32 eq c 10 eq c 13 308 ob c 309 i = add i 1 310 else 311 j = i 312 while lt j get bn 0 bound `9223372036854775807` 313 c = get buf j 314 if or or eq c 32 eq c 10 eq c 13 315 break 316 end 317 j = add j 1 318 end 319 if rename i j 320 ot dsp 321 end 322 while lt i j bound `9223372036854775807` 323 ob get buf i 324 i = add i 1 325 end 326 end 327 end 328 end 329 text sizetag "seeded-" 330 text sizedesc "\tGenerated from seeded source and executable\t" 331 332 fn decimal n ulong to void 333 if ge n 10 334 decimal div n 10 335 end 336 ob uchar add 48 rem n 10 337 end 338 339 fn sizerecord to void 340 load 1 341 lines = ulong 0 342 functions = ulong 0 343 for i ulong get bn 0 bound `9223372036854775807` 344 start = eq i 0 345 if gt i 0 346 start = eq get buf sub i 1 10 347 end 348 if start 349 if match i fnhead 350 functions = add functions 1 351 end 352 end 353 if eq get buf i 10 354 lines = add lines 1 355 end 356 end 357 load 2 358 n = get bn 0 359 if lt n 176 360 exit 67 361 end 362 if ne rem sub n 176 4 0 363 exit 67 364 end 365 if ne get buf 0 127 366 exit 67 367 end 368 if ne get buf 1 69 369 exit 67 370 end 371 if ne get buf 2 76 372 exit 67 373 end 374 if ne get buf 3 70 375 exit 67 376 end 377 for i ulong n bound `9223372036854775807` 378 ob get buf i 379 end 380 hashout 0 381 z = enlarge src 64 382 if ne z 0 383 exit 63 384 end 385 for i ulong 64 386 put src i get obuf i 387 end 388 put on 0 0 389 ot sizetag 390 for i ulong 12 391 ob get src i 392 end 393 ot sizedesc 394 decimal lines 395 ob 9 396 decimal functions 397 ob 9 398 decimal div sub n 176 4 399 ob 9 400 for i ulong 64 401 ob get src i 402 end 403 ob 10 404 flush 405 end 406 407 fn main to int 408 if eq argcnt 3 409 sizerecord 410 ret 0 411 end 412 if or lt argcnt 5 gt argcnt 6 413 ret 60 414 end 415 load 1 416 scan 417 if eq argcnt 6 418 sites false 419 flush 420 ret 0 421 end 422 z = enlarge src get bn 0 423 if ne z 0 424 ret 63 425 end 426 put sn 0 get bn 0 427 for i ulong get bn 0 bound `9223372036854775807` 428 put src i get buf i 429 end 430 for i ulong get marks 0 bound `9223372036854775807` 431 ob get src i 432 end 433 ot beginmark 434 ob 10 435 ot pinhead 436 pinpos = get on 0 437 for i ulong 64 bound `9223372036854775807` 438 ob 48 439 end 440 ot tail 441 load 2 442 ot premeans 443 means 444 ot tail 445 load 1 446 ot presites 447 sites true 448 ot tail 449 load 4 450 runtimehead 451 load 3 452 shacore 453 load 4 454 runtimebody 455 ot footer 456 finish = get marks 1 457 if lt finish get sn 0 458 for i ulong sub get sn 0 finish bound `9223372036854775807` 459 ob get src add finish i 460 end 461 end 462 hashout pinpos 463 flush 464 ret 0 465 end