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 / src / source-aware / main.om
| 1 | note Direct stdin interface. First byte command, then bounded complete request to EOF. |
| 2 | global One uchar 1 |
| 3 | text D64 "BAD_COMMAND\n" |
| 4 | text D65 "MALFORMED\n" |
| 5 | text D66 "UNKNOWN_VERSION\n" |
| 6 | text D67 "LIMIT\n" |
| 7 | text D68 "PROFILE_MISMATCH\n" |
| 8 | text D69 "UNKNOWN_OPERATION\n" |
| 9 | text D70 "TYPE_MISMATCH\n" |
| 10 | text D71 "EFFECT_ALIAS_MISMATCH\n" |
| 11 | text D72 "OBLIGATION_MISMATCH\n" |
| 12 | text D73 "PROVENANCE_MISSING\n" |
| 13 | text D74 "PROVENANCE_MISMATCH\n" |
| 14 | text D75 "SOURCE_SPAN\n" |
| 15 | text D76 "SOURCE_ENCODING\n" |
| 16 | text D77 "IO\n" |
| 17 | text D78 "CONTRACT_MISMATCH\n" |
| 18 | |
| 19 | fn diagnose code ulong to void |
| 20 | if eq code 64 |
| 21 | w = write 2 D64 0 len D64 |
| 22 | end |
| 23 | if eq code 65 |
| 24 | w = write 2 D65 0 len D65 |
| 25 | end |
| 26 | if eq code 66 |
| 27 | w = write 2 D66 0 len D66 |
| 28 | end |
| 29 | if eq code 67 |
| 30 | w = write 2 D67 0 len D67 |
| 31 | end |
| 32 | if eq code 68 |
| 33 | w = write 2 D68 0 len D68 |
| 34 | end |
| 35 | if eq code 69 |
| 36 | w = write 2 D69 0 len D69 |
| 37 | end |
| 38 | if eq code 70 |
| 39 | w = write 2 D70 0 len D70 |
| 40 | end |
| 41 | if eq code 71 |
| 42 | w = write 2 D71 0 len D71 |
| 43 | end |
| 44 | if eq code 72 |
| 45 | w = write 2 D72 0 len D72 |
| 46 | end |
| 47 | if eq code 73 |
| 48 | w = write 2 D73 0 len D73 |
| 49 | end |
| 50 | if eq code 74 |
| 51 | w = write 2 D74 0 len D74 |
| 52 | end |
| 53 | if eq code 75 |
| 54 | w = write 2 D75 0 len D75 |
| 55 | end |
| 56 | if eq code 76 |
| 57 | w = write 2 D76 0 len D76 |
| 58 | end |
| 59 | if eq code 77 |
| 60 | w = write 2 D77 0 len D77 |
| 61 | end |
| 62 | if eq code 78 |
| 63 | w = write 2 D78 0 len D78 |
| 64 | end |
| 65 | end |
| 66 | |
| 67 | fn main to int |
| 68 | constants |
| 69 | r = read 0 One 0 1 |
| 70 | if ne r 1 |
| 71 | diagnose 64 |
| 72 | ret 64 |
| 73 | end |
| 74 | mode = ulong get One 0 |
| 75 | n = ulong 0 |
| 76 | while lt n 8192 |
| 77 | r = read 0 Ib n sub ulong 8192 n |
| 78 | if lt r 0 |
| 79 | diagnose 77 |
| 80 | ret 77 |
| 81 | end |
| 82 | if eq r 0 |
| 83 | code = perform mode n |
| 84 | if ne code 0 |
| 85 | diagnose code |
| 86 | ret int code |
| 87 | end |
| 88 | sent = ulong 0 |
| 89 | while lt sent get El 0 |
| 90 | r = write 1 Eb sent sub get El 0 sent |
| 91 | if le r 0 |
| 92 | diagnose 77 |
| 93 | ret 77 |
| 94 | end |
| 95 | sent = add sent ulong r |
| 96 | end |
| 97 | ret 0 |
| 98 | end |
| 99 | n = add n ulong r |
| 100 | end |
| 101 | diagnose 67 |
| 102 | ret 67 |
| 103 | end |