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 / adapters / upper-lower.om
| 1 | note SPDX-License-Identifier: AGPL-3.0-or-later |
| 2 | note Handwritten S1 upper -> restricted Omegese lowering (translation-v1 section 5). No host compute. |
| 3 | note Build prepends the unchanged pinned vendor sha256.om and the #621 core.om; `decode` is the full |
| 4 | note source-aware v1 validation. One envelope per process: the core's globals are not reentrant. |
| 5 | global One uchar 1 |
| 6 | global Nm uchar 64 |
| 7 | global Nl ulong 1 |
| 8 | global Lo uchar 8192 |
| 9 | global Ln ulong 1 |
| 10 | global Dg uchar 20 |
| 11 | text Words "cwd random envcnt envread chdir ftrunc stat link symlnk chmod faccess getuid geteuid getgid getegid lstat truncate chown const fchdir getppid umask fdsync memfd setsid getpgid setpgid pread pwrite getsid syncfs shutdown devctl mapnew mapdrop mapread mapwrite devcall uvmctl mapaddr mapget mapset maphold mapbind bool uchar u8 ushort u16 uint u32 ulong u64 byte i8 short i16 int i32 long i64 add sub mul div rem and or xor shl shr eq ne lt le gt ge neg not get len read write true false view edit fn to end if else while bound for ret void global text put free exit note new break trap own sockname realns execprog renames rmdir killpid pipefds getpid waitio getdnts connect bind waitpid fstat recv send sleepns argcnt argread fclose fsync fchmod fseek socknew listen accept fork dupfd monons fopen unlink makedir struct f32 f64 bitcast fsqrt fabs fmin fmax sizeof offsetof continue v i0 i1 i2 i3 i4 i5 main" |
| 12 | text Tnote "note omega.universal.lower.v1 semantic " |
| 13 | text Tfn "fn " |
| 14 | text Tpar " ulong" |
| 15 | text Tto " to ulong\n" |
| 16 | text Tnew "v = new ulong " |
| 17 | text Tput "put v " |
| 18 | text Tget " get v " |
| 19 | text Tadd "add" |
| 20 | text Tsub "sub" |
| 21 | text Tmul "mul" |
| 22 | text Tret "ret get v " |
| 23 | text Tend "end\n" |
| 24 | text Hexd "0123456789abcdef" |
| 25 | text Dflt "calc" |
| 26 | text E64 "LOWER_BAD_COMMAND\n" |
| 27 | text E65 "LOWER_MALFORMED\n" |
| 28 | text E68 "LOWER_PROFILE_MISMATCH\n" |
| 29 | text E77 "LOWER_IO\n" |
| 30 | |
| 31 | fn die code ulong to void |
| 32 | if eq code 64 |
| 33 | w = write 2 E64 0 len E64 |
| 34 | end |
| 35 | if eq code 65 |
| 36 | w = write 2 E65 0 len E65 |
| 37 | end |
| 38 | if eq code 68 |
| 39 | w = write 2 E68 0 len E68 |
| 40 | end |
| 41 | if eq code 77 |
| 42 | w = write 2 E77 0 len E77 |
| 43 | end |
| 44 | exit int code |
| 45 | end |
| 46 | |
| 47 | fn oc c ulong to void |
| 48 | p = get Ln 0 |
| 49 | if ge p 8192 |
| 50 | die 65 |
| 51 | end |
| 52 | put Lo p uchar c |
| 53 | put Ln 0 add p 1 |
| 54 | end |
| 55 | |
| 56 | fn olinestart k ulong to void |
| 57 | for i ulong len Tput |
| 58 | oc ulong get Tput i |
| 59 | end |
| 60 | odec k |
| 61 | oc 32 |
| 62 | end |
| 63 | |
| 64 | fn odec v ulong to void |
| 65 | n = ulong 0 |
| 66 | x = v |
| 67 | put Dg 0 48 |
| 68 | if eq x 0 |
| 69 | n = 1 |
| 70 | end |
| 71 | while ne x 0 |
| 72 | put Dg n uchar add rem x 10 48 |
| 73 | n = add n 1 |
| 74 | x = div x 10 |
| 75 | end |
| 76 | while gt n 0 |
| 77 | n = sub n 1 |
| 78 | oc ulong get Dg n |
| 79 | end |
| 80 | end |
| 81 | |
| 82 | fn alnum c ulong to bool |
| 83 | if and ge c 65 le c 90 |
| 84 | ret true |
| 85 | end |
| 86 | if and ge c 97 le c 122 |
| 87 | ret true |
| 88 | end |
| 89 | if and ge c 48 le c 57 |
| 90 | ret true |
| 91 | end |
| 92 | ret eq c 95 |
| 93 | end |
| 94 | |
| 95 | fn wrdchar p ulong to bool |
| 96 | if ge p len Words |
| 97 | ret false |
| 98 | end |
| 99 | ret ne get Words p 32 |
| 100 | end |
| 101 | |
| 102 | fn sameword b ulong e ulong to bool |
| 103 | if ne sub e b get Nl 0 |
| 104 | ret false |
| 105 | end |
| 106 | for i ulong get Nl 0 |
| 107 | if ne get Words add b i get Nm i |
| 108 | ret false |
| 109 | end |
| 110 | end |
| 111 | ret true |
| 112 | end |
| 113 | |
| 114 | fn reserved to bool |
| 115 | p = ulong 0 |
| 116 | while lt p len Words |
| 117 | b = p |
| 118 | while wrdchar p |
| 119 | p = add p 1 |
| 120 | end |
| 121 | if sameword b p |
| 122 | ret true |
| 123 | end |
| 124 | p = add p 1 |
| 125 | end |
| 126 | ret false |
| 127 | end |
| 128 | |
| 129 | fn takename to void |
| 130 | c = argcnt |
| 131 | if eq c 1 |
| 132 | for i ulong len Dflt |
| 133 | put Nm i get Dflt i |
| 134 | end |
| 135 | put Nl 0 len Dflt |
| 136 | ret |
| 137 | end |
| 138 | if ne c 2 |
| 139 | die 64 |
| 140 | end |
| 141 | r = argread 1 Nm 0 64 |
| 142 | if lt r 1 |
| 143 | die 64 |
| 144 | end |
| 145 | n = ulong r |
| 146 | if gt n 63 |
| 147 | die 64 |
| 148 | end |
| 149 | put Nl 0 n |
| 150 | f = ulong get Nm 0 |
| 151 | if and ge f 48 le f 57 |
| 152 | die 64 |
| 153 | end |
| 154 | for i ulong n |
| 155 | if not alnum ulong get Nm i |
| 156 | die 64 |
| 157 | end |
| 158 | end |
| 159 | if reserved |
| 160 | die 64 |
| 161 | end |
| 162 | end |
| 163 | |
| 164 | fn s1op i ulong to bool |
| 165 | code = get Oc i |
| 166 | if or ne get Ot i 1 ne get Oef i 0 |
| 167 | ret false |
| 168 | end |
| 169 | if ne get Oal i 0 |
| 170 | ret false |
| 171 | end |
| 172 | if eq code 9 |
| 173 | ret and eq get Oat i 0 eq get Oob i 1 |
| 174 | end |
| 175 | if eq code 1 |
| 176 | ret and eq get Oat i 1 eq get Oob i 0 |
| 177 | end |
| 178 | if or lt code 2 gt code 4 |
| 179 | ret false |
| 180 | end |
| 181 | ret and eq get Oat i 1 eq get Oob i 1 |
| 182 | end |
| 183 | |
| 184 | fn s1 to ulong |
| 185 | if or ne get M 0 1 ne get M 1 1 |
| 186 | die 68 |
| 187 | end |
| 188 | if or ne get M 2 0 ne get M 3 1 |
| 189 | die 68 |
| 190 | end |
| 191 | n = ulong 0 |
| 192 | for i ulong get M 4 |
| 193 | if not s1op i |
| 194 | die 68 |
| 195 | end |
| 196 | if eq get Oc i 9 |
| 197 | n = add n 1 |
| 198 | end |
| 199 | end |
| 200 | for i ulong get M 4 |
| 201 | if eq get Oc i 9 |
| 202 | if ge get Oi i n |
| 203 | die 68 |
| 204 | end |
| 205 | end |
| 206 | end |
| 207 | ret n |
| 208 | end |
| 209 | |
| 210 | fn oheader to void |
| 211 | for i ulong len Tnote |
| 212 | oc ulong get Tnote i |
| 213 | end |
| 214 | hinit |
| 215 | for i ulong len Semdom |
| 216 | hbyte get Semdom i |
| 217 | end |
| 218 | part 13 get M 5 |
| 219 | finish |
| 220 | for i ulong 32 |
| 221 | b = ulong get Hash i |
| 222 | oc ulong get Hexd shr b 4 |
| 223 | oc ulong get Hexd and b 15 |
| 224 | end |
| 225 | oc 10 |
| 226 | end |
| 227 | |
| 228 | fn osig n ulong to void |
| 229 | for i ulong len Tfn |
| 230 | oc ulong get Tfn i |
| 231 | end |
| 232 | for i ulong get Nl 0 |
| 233 | oc ulong get Nm i |
| 234 | end |
| 235 | for s ulong n |
| 236 | oc 32 |
| 237 | oc 105 |
| 238 | odec s |
| 239 | for i ulong len Tpar |
| 240 | oc ulong get Tpar i |
| 241 | end |
| 242 | end |
| 243 | for i ulong len Tto |
| 244 | oc ulong get Tto i |
| 245 | end |
| 246 | for i ulong len Tnew |
| 247 | oc ulong get Tnew i |
| 248 | end |
| 249 | odec get M 4 |
| 250 | oc 32 |
| 251 | oc 48 |
| 252 | oc 10 |
| 253 | end |
| 254 | |
| 255 | fn oref a ulong to void |
| 256 | for i ulong len Tget |
| 257 | oc ulong get Tget i |
| 258 | end |
| 259 | odec a |
| 260 | end |
| 261 | |
| 262 | fn oarith code ulong to void |
| 263 | for i ulong 3 |
| 264 | if eq code 2 |
| 265 | oc ulong get Tadd i |
| 266 | end |
| 267 | if eq code 3 |
| 268 | oc ulong get Tsub i |
| 269 | end |
| 270 | if eq code 4 |
| 271 | oc ulong get Tmul i |
| 272 | end |
| 273 | end |
| 274 | end |
| 275 | |
| 276 | fn obody to void |
| 277 | for k ulong get M 4 |
| 278 | olinestart k |
| 279 | code = get Oc k |
| 280 | if eq code 9 |
| 281 | oc 105 |
| 282 | odec get Oi k |
| 283 | end |
| 284 | if eq code 1 |
| 285 | odec get Oi k |
| 286 | end |
| 287 | if and ge code 2 le code 4 |
| 288 | oarith code |
| 289 | oref get Oa k |
| 290 | oref get Ob k |
| 291 | end |
| 292 | oc 10 |
| 293 | end |
| 294 | for i ulong len Tret |
| 295 | oc ulong get Tret i |
| 296 | end |
| 297 | odec sub get M 4 1 |
| 298 | oc 10 |
| 299 | for i ulong len Tend |
| 300 | oc ulong get Tend i |
| 301 | end |
| 302 | end |
| 303 | |
| 304 | fn main to int |
| 305 | n = ulong 0 |
| 306 | more = ulong 1 |
| 307 | while and eq more 1 lt n 8192 |
| 308 | r = read 0 Ib n sub 8192 n |
| 309 | if lt r 0 |
| 310 | die 77 |
| 311 | end |
| 312 | if eq r 0 |
| 313 | more = 0 |
| 314 | else |
| 315 | n = add n ulong r |
| 316 | end |
| 317 | end |
| 318 | big = ulong 0 |
| 319 | if eq n 8192 |
| 320 | r = read 0 One 0 1 |
| 321 | if lt r 0 |
| 322 | die 77 |
| 323 | end |
| 324 | if gt r 0 |
| 325 | big = 1 |
| 326 | end |
| 327 | end |
| 328 | takename |
| 329 | if eq big 1 |
| 330 | die 65 |
| 331 | end |
| 332 | constants |
| 333 | code = decode n |
| 334 | if eq code 68 |
| 335 | die 68 |
| 336 | end |
| 337 | if ne code 0 |
| 338 | die 65 |
| 339 | end |
| 340 | k = s1 |
| 341 | put Ln 0 0 |
| 342 | oheader |
| 343 | osig k |
| 344 | obody |
| 345 | sent = ulong 0 |
| 346 | m = get Ln 0 |
| 347 | while lt sent m |
| 348 | r = write 1 Lo sent sub m sent |
| 349 | if le r 0 |
| 350 | die 77 |
| 351 | end |
| 352 | sent = add sent ulong r |
| 353 | end |
| 354 | ret 0 |
| 355 | end |