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 / neuralese / host-proposal.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note Host synthetic one-shot CLI: receiver-context-file expected-op expected-operand. |
| 3 | note This harness cannot authorize effects or reserve a production microjob. |
| 4 | om2 debug |
| 5 | note Closed compiled ordinary Omega operations, never dynamically execute vector bytes. |
| 6 | fn nlinc x uint to uint |
| 7 | requires le x 16 |
| 8 | ensures le result 32 |
| 9 | ret add x 1 |
| 10 | end |
| 11 | fn nldouble x uint to uint |
| 12 | requires le x 16 |
| 13 | ensures le result 32 |
| 14 | ret mul x 2 |
| 15 | end |
| 16 | fn nlident x uint to uint |
| 17 | requires le x 16 |
| 18 | ensures le result 32 |
| 19 | ret x |
| 20 | end |
| 21 | text nlrhead "NL4R1 0 " |
| 22 | text nlrtail " 1 1 0 1 0 " |
| 23 | text nlrno "NL4R1 " |
| 24 | text nlzeros " 0 0 0 0 0 0 0 0 0\n" |
| 25 | text nlendl "\n" |
| 26 | text nlspace " " |
| 27 | fn nlout b view uchar * fd int to void |
| 28 | pos = ulong 0 |
| 29 | while lt pos len b bound 8192 |
| 30 | r = write fd b pos sub len b pos |
| 31 | if le r 0 |
| 32 | exit 81 |
| 33 | end |
| 34 | pos = add pos ulong r |
| 35 | end |
| 36 | end |
| 37 | fn nlnumber v uint fd int to void |
| 38 | b = new uchar 10 0 |
| 39 | pos = ulong 10 |
| 40 | x = v |
| 41 | while true bound 10 |
| 42 | pos = sub pos 1 |
| 43 | put b pos uchar add rem x 10 48 |
| 44 | x = div x 10 |
| 45 | if eq x 0 |
| 46 | break |
| 47 | end |
| 48 | end |
| 49 | nlout part b pos sub 10 pos fd |
| 50 | end |
| 51 | fn nlfail code int to int |
| 52 | nlout nlrno 2 |
| 53 | nlnumber uint code 2 |
| 54 | nlout nlzeros 2 |
| 55 | ret code |
| 56 | end |
| 57 | fn nlread fd int b edit uchar * to long |
| 58 | pos = ulong 0 |
| 59 | while lt pos len b bound 5121 |
| 60 | r = read fd b pos sub len b pos |
| 61 | if lt r 0 |
| 62 | ret r |
| 63 | end |
| 64 | if eq r 0 |
| 65 | break |
| 66 | end |
| 67 | pos = add pos ulong r |
| 68 | end |
| 69 | ret long pos |
| 70 | end |
| 71 | fn nlcontext c edit uchar 1025 to int |
| 72 | path = new uchar 4096 0 |
| 73 | n = argread 1 path 0 4096 |
| 74 | if le n 0 |
| 75 | ret 80 |
| 76 | end |
| 77 | fd = fopen path 0 ulong n 0 0 |
| 78 | if lt fd 0 |
| 79 | ret 80 |
| 80 | end |
| 81 | r = nlread int fd c |
| 82 | cl = fclose int fd |
| 83 | if or ne r 1024 ne cl 0 |
| 84 | ret 80 |
| 85 | end |
| 86 | ret 0 |
| 87 | end |
| 88 | fn nlrequest e edit uint 16 to int |
| 89 | argbuf = new uchar 2 0 |
| 90 | r = argread 2 argbuf 0 2 |
| 91 | if ne r 1 |
| 92 | ret 80 |
| 93 | end |
| 94 | v = get argbuf 0 |
| 95 | if or lt v 49 gt v 51 |
| 96 | ret 80 |
| 97 | end |
| 98 | put e 0 uint sub v 48 |
| 99 | r = argread 3 argbuf 0 2 |
| 100 | if ne r 1 |
| 101 | ret 80 |
| 102 | end |
| 103 | v = get argbuf 0 |
| 104 | if or lt v 48 gt v 51 |
| 105 | ret 80 |
| 106 | end |
| 107 | put e 1 uint sub v 48 |
| 108 | if eq get e 0 1 |
| 109 | put e 2 1 |
| 110 | end |
| 111 | if eq get e 0 2 |
| 112 | put e 2 2 |
| 113 | end |
| 114 | put e 3 1 |
| 115 | put e 4 1 |
| 116 | put e 5 1 |
| 117 | put e 6 4 |
| 118 | put e 7 1 |
| 119 | put e 8 0 |
| 120 | put e 9 1 |
| 121 | ret 0 |
| 122 | end |
| 123 | fn nlexec p view uint 16 to void |
| 124 | z = uint 0 |
| 125 | if eq get p 0 1 |
| 126 | z = nlinc get p 1 |
| 127 | end |
| 128 | if eq get p 0 2 |
| 129 | z = nldouble get p 1 |
| 130 | end |
| 131 | if eq get p 0 3 |
| 132 | z = nlident get p 1 |
| 133 | end |
| 134 | nlout nlrhead 1 |
| 135 | for i ulong 3 |
| 136 | if ne i 0 |
| 137 | nlout nlspace 1 |
| 138 | end |
| 139 | nlnumber get p i 1 |
| 140 | end |
| 141 | nlout nlrtail 1 |
| 142 | nlnumber z 1 |
| 143 | nlout nlendl 1 |
| 144 | end |
| 145 | fn main to int |
| 146 | frame = new uchar 5121 0 |
| 147 | ctx = new uchar 1025 0 |
| 148 | p = new uint 16 0 |
| 149 | e = new uint 16 0 |
| 150 | if ne argcnt 4 |
| 151 | ret nlfail 80 |
| 152 | end |
| 153 | r = nlcontext ctx |
| 154 | if ne r 0 |
| 155 | ret nlfail r |
| 156 | end |
| 157 | r = nlrequest e |
| 158 | if ne r 0 |
| 159 | ret nlfail r |
| 160 | end |
| 161 | n = nlread 0 frame |
| 162 | if lt n 0 |
| 163 | ret nlfail 80 |
| 164 | end |
| 165 | note Receiver fixture's issued_at is the trusted synthetic clock, not input now. |
| 166 | now = lpbe64 ctx 64 |
| 167 | r = lpvalid part frame 0 ulong n part ctx 0 1024 now 0 |
| 168 | if ne r 0 |
| 169 | ret nlfail r |
| 170 | end |
| 171 | r = nlproposal part frame 0 ulong n p |
| 172 | if ne r 0 |
| 173 | ret nlfail r |
| 174 | end |
| 175 | if not nlmatch p e |
| 176 | ret nlfail 49 |
| 177 | end |
| 178 | note One-shot pure proposal only; no reservation or external effect occurs. |
| 179 | nlexec p |
| 180 | ret 0 |
| 181 | end |