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 / ng / bench / ngbench-sha.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note seed/ng/bench/ngbench-sha.om: the last unit of ngbench (D1b). Build, in this order: |
| 3 | note cat seed/ng/ngbench.om seed/ng/sha256.om seed/ng/bench/ngbench-sha.om | seed/out/omc > ngbench |
| 4 | note ngbench.om comes first because its om2 line must be the unit's first line; this part comes after |
| 5 | note seed/ng/sha256.om because it names sha256.om's globals (sh_dat, sh_dig), and a global must be |
| 6 | note declared before use (functions may be called before their definition). Owner: ng-bench lane. |
| 7 | note hashpb: SHA-256 (sha256.om sh_all over sh_dat) of the file named by gpb into gdg and ghx; returns |
| 8 | note its size; 2^63 only when it is absent (open fails with ENOENT, errno 2); 2^63 + 1 when it is |
| 9 | note present but cannot be used: open fails with any other errno (EACCES, ENOTDIR, ELOOP, ...), a read |
| 10 | note fails (a directory: EISDIR), or it holds len sh_dat (16 MiB) bytes or more. Callers that only need |
| 11 | note "no hash" test ge 2^63; callers that treat "absent" as allowed must refuse 2^63 + 1. |
| 12 | fn hashpb to ulong |
| 13 | fd = fopen gpb 0 get gpbn 0 0 0 |
| 14 | if lt fd 0 |
| 15 | if eq fd -2 |
| 16 | ret 9223372036854775808 |
| 17 | end |
| 18 | ret 9223372036854775809 |
| 19 | end |
| 20 | n = ulong 0 |
| 21 | bad = false |
| 22 | going = true |
| 23 | while going bound 16777217 |
| 24 | r = read int fd sh_dat n sub len sh_dat n |
| 25 | if lt r 0 |
| 26 | bad = true |
| 27 | going = false |
| 28 | else |
| 29 | if eq r 0 |
| 30 | going = false |
| 31 | else |
| 32 | n = add n ulong r |
| 33 | if eq n len sh_dat |
| 34 | bad = true |
| 35 | going = false |
| 36 | end |
| 37 | end |
| 38 | end |
| 39 | end |
| 40 | x = fclose int fd |
| 41 | if bad |
| 42 | ret 9223372036854775809 |
| 43 | end |
| 44 | sh_all n |
| 45 | for i ulong 32 |
| 46 | put gdg i get sh_dig i |
| 47 | end |
| 48 | tohex |
| 49 | ret n |
| 50 | end |