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/ng/tests/ir/host-oracle.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 / ng / tests / ir / host-oracle.om` 432 lines ยท 10686 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note Build with src/ir.om. host-oracle UNIT.ir NEW-NATIVE-DIR emits IR and executes equivalent native host operations. 3 note The gate passes the same two program arguments and a controlled environment to ngrun. 4 note Every native expected success is checked before an expected IR value is recorded. 5 global hc_s uint 16 6 global hc_a uint 16 7 global hc_seen uchar 256 8 global hc_count ulong 2 9 global hc_dig uchar 24 10 text hc_st0 "HC_NATIVE operations=" 11 text hc_st1 " words=" 12 text hc_st2 "\n" 13 text hc_bad0 "HC_FAIL operation=" 14 text hc_bad1 " actual-bits=" 15 text hc_bad2 " expected-bits=" 16 global hc_buf uchar 512 17 global hc_out uchar 8192 18 global hc_root uchar 4096 19 global hc_arg uchar 4096 20 global hc_pkt uchar 64 21 text hc_name "probe" 22 text hc_new "renamed" 23 text hc_link "linked" 24 text hc_dir "child" 25 text hc_empty "empty" 26 text hc_data "hello" 27 text hc_one "X" 28 text hc_env "NG_ORACLE=present" 29 text hc_msg "HOSTORACLE\n" 30 fn hc_c t uint v ulong to uint 31 ret ir_res ir_op get hc_s 0 1 t v 0 32 end 33 34 fn hc_true c uint to void 35 o = ir_op get hc_s 0 82 0 14 2 36 ir_set o 0 get hc_s 1 37 ir_set o 1 c 38 put hc_s 1 ir_otok o 39 end 40 fn hc_cmp op uint a uint b uint to uint 41 o = ir_op get hc_s 0 op 1 0 2 42 ir_set o 0 a 43 ir_set o 1 b 44 ret ir_res o 45 end 46 fn hc_ok v uint actual long expected long to void 47 if ne actual expected 48 hc_diag actual expected 49 exit 2 50 end 51 hc_true hc_cmp 30 v hc_c 9 bitcast ulong actual 52 end 53 fn hc_pos v uint actual long to void 54 if le actual 0 55 hc_diag actual 1 56 exit 2 57 end 58 hc_true hc_cmp 34 v hc_c 9 0 59 end 60 fn hc_host w ulong ty uint n uint to uint 61 put hc_count 0 add get hc_count 0 1 62 if eq get hc_seen w 0 63 put hc_count 1 add get hc_count 1 1 64 put hc_seen w 1 65 end 66 o = ir_op get hc_s 0 110 ty w add n 1 67 ir_set o 0 get hc_s 1 68 for j uint n bound 16 69 ir_set o add j 1 get hc_a j 70 end 71 put hc_s 1 ir_otok o 72 ret ir_res o 73 end 74 fn hc_slice slot ulong ref uint off ulong n ulong to void 75 z = hc_c 5 off 76 sz = hc_c 5 n 77 o = ir_op get hc_s 0 80 0 3 4 78 ir_set o 0 get hc_s 1 79 ir_set o 1 ref 80 ir_set o 2 z 81 ir_set o 3 sz 82 put hc_s 1 ir_otok o 83 put hc_a slot ref 84 put hc_a add slot 1 z 85 put hc_a add slot 2 sz 86 end 87 fn hc_text txt view uchar * to uint 88 t = ir_tarr 2 uint len txt 89 r = ir_tref t 0 0 90 g = ir_glob t 1 91 for j ulong len txt bound 4096 92 ir_gbyt g uint get txt j 93 end 94 ret ir_res ir_op get hc_s 0 52 r ulong g 0 95 end 96 fn hc_memory to uint 97 t = ir_tarr 2 512 98 r = ir_tref t 1 0 99 g = ir_glob t 0 100 ret ir_res ir_op get hc_s 0 52 r ulong g 0 101 end 102 fn hc_byte idx ulong actual uchar expected uchar to void 103 if ne actual expected 104 hc_diag long actual long expected 105 exit 2 106 end 107 r = get hc_s 2 108 i = hc_c 5 idx 109 e = hc_c 5 1 110 o = ir_op get hc_s 0 79 0 3 4 111 ir_set o 0 get hc_s 1 112 ir_set o 1 r 113 ir_set o 2 i 114 ir_set o 3 e 115 put hc_s 1 ir_otok o 116 o = ir_op get hc_s 0 42 2 0 3 117 ir_set o 0 get hc_s 1 118 ir_set o 1 r 119 ir_set o 2 i 120 v = ir_res o 121 hc_true hc_cmp 30 v hc_c 2 ulong actual 122 end 123 124 fn hc_fdword w ulong actual long expected long to void 125 put hc_a 0 hc_c 8 3 126 hc_ok hc_host w 9 1 actual expected 127 end 128 fn hc_args to void 129 hc_ok hc_host 121 9 0 argcnt 3 130 put hc_a 0 hc_c 5 1 131 hc_slice 1 get hc_s 2 0 1 132 hc_ok hc_host 122 9 4 argread 1 hc_buf 0 1 -105 133 hc_byte 0 get hc_buf 0 0 134 put hc_a 0 hc_c 5 1 135 hc_slice 1 get hc_s 2 0 len hc_buf 136 n = argread 1 hc_buf 0 len hc_buf 137 hc_pos hc_host 122 9 4 n 138 hc_ok hc_host 136 9 0 envcnt 1 139 put hc_a 0 hc_c 5 0 140 hc_slice 1 get hc_s 2 0 0 141 hc_ok hc_host 137 9 4 envread 0 hc_buf 0 0 -105 142 put hc_a 0 hc_c 5 0 143 hc_slice 1 get hc_s 2 0 len hc_buf 144 hc_ok hc_host 137 9 4 envread 0 hc_buf 0 len hc_buf long len hc_env 145 hc_byte 0 get hc_buf 0 78 146 hc_pos hc_host 109 9 0 monons 147 hc_pos hc_host 130 9 0 realns 148 put hc_a 0 hc_c 9 0 149 hc_ok hc_host 120 9 1 sleepns 0 0 150 uid = getuid 151 hc_ok hc_host 145 9 0 uid uid 152 gid = getgid 153 hc_ok hc_host 147 9 0 gid gid 154 hc_ok hc_host 146 9 0 geteuid uid 155 hc_ok hc_host 148 9 0 getegid gid 156 v = hc_host 199 0 0 157 cpufence 158 v = hc_host 200 0 0 159 cpurelax 160 end 161 fn hc_files1 to void 162 hc_slice 0 get hc_s 3 0 len hc_name 163 put hc_a 3 hc_c 8 194 164 put hc_a 4 hc_c 8 384 165 fd = fopen hc_name 0 len hc_name 194 384 166 hc_ok hc_host 110 9 5 fd 3 167 put hc_a 0 hc_c 8 3 168 hc_slice 1 get hc_s 4 0 len hc_data 169 hc_ok hc_host 54 9 4 write int fd hc_data 0 len hc_data long len hc_data 170 put hc_a 0 hc_c 8 3 171 hc_slice 1 get hc_s 5 0 len hc_one 172 put hc_a 4 hc_c 9 2 173 hc_ok hc_host 162 9 5 pwrite int fd hc_one 0 len hc_one 2 1 174 put hc_a 0 hc_c 8 3 175 put hc_a 1 hc_c 9 0 176 put hc_a 2 hc_c 8 0 177 hc_ok hc_host 103 9 3 fseek int fd 0 0 0 178 put hc_a 0 hc_c 8 3 179 hc_slice 1 get hc_s 2 0 5 180 hc_ok hc_host 53 9 4 read int fd hc_buf 0 5 5 181 hc_byte 0 get hc_buf 0 104 182 hc_byte 1 get hc_buf 1 101 183 hc_byte 2 get hc_buf 2 88 184 hc_byte 3 get hc_buf 3 108 185 hc_byte 4 get hc_buf 4 111 186 put hc_a 0 hc_c 8 3 187 hc_slice 1 get hc_s 2 0 3 188 put hc_a 4 hc_c 9 1 189 hc_ok hc_host 161 9 5 pread int fd hc_buf 0 3 1 3 190 hc_byte 0 get hc_buf 0 101 191 hc_byte 1 get hc_buf 1 88 192 hc_byte 2 get hc_buf 2 108 193 put hc_a 0 hc_c 8 3 194 hc_slice 1 get hc_s 2 0 128 195 hc_ok hc_host 117 9 4 fstat int fd hc_buf 0 128 0 196 hc_byte 48 get hc_buf 48 5 197 put hc_a 0 hc_c 8 3 198 put hc_a 1 hc_c 9 4 199 hc_ok hc_host 139 9 2 ftrunc int fd 4 0 200 hc_fdword 101 fsync int fd 0 201 hc_fdword 156 fdsync int fd 0 202 put hc_a 0 hc_c 8 3 203 put hc_a 1 hc_c 8 384 204 hc_ok hc_host 102 9 2 fchmod int fd 384 0 205 put hc_a 0 hc_c 8 3 206 put hc_a 1 hc_c 8 6 207 hc_ok hc_host 197 9 2 flock int fd 6 0 208 put hc_a 0 hc_c 8 3 209 put hc_a 1 hc_c 8 8 210 hc_ok hc_host 197 9 2 flock int fd 8 0 211 hc_fdword 100 fclose int fd 0 212 end 213 fn hc_files2 to void 214 hc_slice 0 get hc_s 3 0 len hc_name 215 put hc_a 3 hc_c 8 0 216 hc_ok hc_host 144 9 4 faccess hc_name 0 len hc_name 0 0 217 hc_slice 0 get hc_s 3 0 len hc_name 218 put hc_a 3 hc_c 8 384 219 hc_ok hc_host 143 9 4 chmod hc_name 0 len hc_name 384 0 220 hc_slice 0 get hc_s 3 0 len hc_name 221 put hc_a 3 hc_c 8 bitcast ulong getuid 222 put hc_a 4 hc_c 8 bitcast ulong getgid 223 hc_ok hc_host 151 9 5 chown hc_name 0 len hc_name int getuid int getgid 0 224 hc_slice 0 get hc_s 3 0 len hc_name 225 hc_slice 3 get hc_s 2 0 128 226 hc_ok hc_host 140 9 6 stat hc_name 0 len hc_name hc_buf 0 128 0 227 hc_byte 48 get hc_buf 48 4 228 hc_slice 0 get hc_s 3 0 len hc_name 229 hc_slice 3 get hc_s 2 0 128 230 hc_ok hc_host 149 9 6 lstat hc_name 0 len hc_name hc_buf 0 128 0 231 hc_slice 0 get hc_s 3 0 len hc_name 232 hc_slice 3 get hc_s 2 0 128 233 hc_ok hc_host 133 9 6 readlnk hc_name 0 len hc_name hc_buf 0 128 -22 234 hc_slice 0 get hc_s 3 0 len hc_name 235 put hc_a 3 hc_c 9 3 236 hc_ok hc_host 150 9 4 truncate hc_name 0 len hc_name 3 0 237 hc_slice 0 get hc_s 3 0 len hc_name 238 put hc_a 3 hc_c 8 0 239 put hc_a 4 hc_c 8 0 240 fd = fopen hc_name 0 len hc_name 0 0 241 hc_ok hc_host 110 9 5 fd 3 242 put hc_a 0 hc_c 8 3 243 hc_slice 1 get hc_s 2 0 8 244 hc_ok hc_host 53 9 4 read int fd hc_buf 0 8 3 245 hc_byte 2 get hc_buf 2 88 246 hc_fdword 100 fclose int fd 0 247 end 248 fn hc_packet a view uchar * b view uchar * to uint 249 put hc_pkt 0 2 250 put hc_pkt 1 0 251 put hc_pkt 2 uchar len a 252 put hc_pkt 3 0 253 for j ulong len a bound 32 254 put hc_pkt add 4 j get a j 255 end 256 p = add 4 len a 257 put hc_pkt p uchar len b 258 put hc_pkt add p 1 0 259 for j ulong len b bound 32 260 put hc_pkt add add p 2 j get b j 261 end 262 n = add add p 2 len b 263 t = ir_tarr 2 uint n 264 r = ir_tref t 0 0 265 g = ir_glob t 1 266 for j ulong n bound 64 267 ir_gbyt g uint get hc_pkt j 268 end 269 put hc_s 15 uint n 270 ret ir_res ir_op get hc_s 0 52 r ulong g 0 271 end 272 fn hc_files3 to void 273 r = hc_packet hc_name hc_new 274 hc_slice 0 r 0 ulong get hc_s 15 275 put hc_a 3 hc_c 8 1 276 hc_ok hc_host 125 9 4 renames hc_pkt 0 ulong get hc_s 15 1 0 277 r = hc_packet hc_new hc_link 278 hc_slice 0 r 0 ulong get hc_s 15 279 hc_ok hc_host 141 9 3 link hc_pkt 0 ulong get hc_s 15 0 280 r = hc_text hc_link 281 hc_slice 0 r 0 len hc_link 282 hc_ok hc_host 111 9 3 unlink hc_link 0 len hc_link 0 283 r = hc_text hc_new 284 hc_slice 0 r 0 len hc_new 285 hc_ok hc_host 111 9 3 unlink hc_new 0 len hc_new 0 286 r = hc_text hc_empty 287 hc_slice 0 r 0 len hc_empty 288 put hc_a 3 hc_c 8 448 289 hc_ok hc_host 112 9 4 makedir hc_empty 0 len hc_empty 448 0 290 hc_slice 0 r 0 len hc_empty 291 hc_ok hc_host 126 9 3 rmdir hc_empty 0 len hc_empty 0 292 hc_slice 0 get hc_s 3 0 len hc_name 293 put hc_a 3 hc_c 8 0 294 fd = memfd hc_name 0 len hc_name 0 295 hc_ok hc_host 157 9 4 fd 3 296 put hc_a 0 hc_c 8 3 297 hc_slice 1 get hc_s 4 0 len hc_data 298 hc_ok hc_host 54 9 4 write int fd hc_data 0 len hc_data long len hc_data 299 hc_fdword 100 fclose int fd 0 300 end 301 fn hc_dirs to void 302 r = hc_text hc_dir 303 hc_slice 0 r 0 len hc_dir 304 put hc_a 3 hc_c 8 448 305 hc_ok hc_host 112 9 4 makedir hc_dir 0 len hc_dir 448 0 306 hc_slice 0 r 0 len hc_dir 307 put hc_a 3 hc_c 8 16384 308 put hc_a 4 hc_c 8 0 309 fd = fopen hc_dir 0 len hc_dir 16384 0 310 hc_ok hc_host 110 9 5 fd 3 311 put hc_a 0 hc_c 8 3 312 hc_slice 1 get hc_s 2 0 len hc_buf 313 hc_pos hc_host 113 9 4 getdnts int fd hc_buf 0 len hc_buf 314 hc_slice 0 r 0 len hc_dir 315 hc_ok hc_host 138 9 3 chdir hc_dir 0 len hc_dir 0 316 put hc_a 0 hc_c 8 3 317 hc_ok hc_host 153 9 1 fchdir int fd 0 318 hc_fdword 100 fclose int fd 0 319 hc_slice 0 get hc_s 2 0 len hc_buf 320 hc_pos hc_host 132 9 3 cwd hc_buf 0 len hc_buf 321 hc_byte 0 get hc_buf 0 47 322 end 323 fn hc_paths to void 324 n = argread 1 hc_arg 0 len hc_arg 325 if or le n 0 ge n 4096 326 exit 2 327 end 328 base = ulong 0 329 if ne get hc_arg 0 47 330 k = cwd hc_out 0 len hc_out 331 if le k 0 332 exit 2 333 end 334 base = sub ulong k 1 335 put hc_out base 47 336 base = add base 1 337 end 338 if gt add base ulong n 4095 339 exit 2 340 end 341 for j ulong ulong n bound 4096 342 put hc_out add base j get hc_arg j 343 end 344 put hc_s 14 uint add base ulong n 345 n = argread 2 hc_root 0 len hc_root 346 if or le n 0 ge n 4096 347 exit 2 348 end 349 k = makedir hc_root 0 ulong n 448 350 if ne k 0 351 exit 2 352 end 353 k = chdir hc_root 0 ulong n 354 if ne k 0 355 exit 2 356 end 357 end 358 fn hc_print v ulong to void 359 x = v 360 i = ulong 24 361 while true bound 24 362 i = sub i 1 363 put hc_dig i uchar add 48 rem x 10 364 x = div x 10 365 if eq x 0 366 k = write 2 hc_dig i sub 24 i 367 ret 368 end 369 end 370 end 371 fn hc_diag actual long expected long to void 372 k = write 2 hc_bad0 0 len hc_bad0 373 hc_print get hc_count 0 374 k = write 2 hc_bad1 0 len hc_bad1 375 hc_print bitcast ulong actual 376 k = write 2 hc_bad2 0 len hc_bad2 377 hc_print bitcast ulong expected 378 k = write 2 hc_st2 0 len hc_st2 379 end 380 fn main to int 381 if ne argcnt 3 382 ret 2 383 end 384 ir_init 385 f = ir_fnew 2 0 8 386 put hc_s 0 ir_blk f 387 put hc_s 1 ir_ftok f 388 put hc_s 2 hc_memory 389 put hc_s 3 hc_text hc_name 390 put hc_s 4 hc_text hc_data 391 put hc_s 5 hc_text hc_one 392 hc_paths 393 mask = umask 0 394 put hc_a 0 hc_c 8 0 395 hc_ok hc_host 155 9 1 mask mask 396 hc_args 397 hc_files1 398 hc_files2 399 hc_files3 400 hc_dirs 401 r = hc_text hc_msg 402 put hc_a 0 hc_c 8 1 403 hc_slice 1 r 0 len hc_msg 404 v = hc_host 54 9 4 405 hc_true hc_cmp 30 v hc_c 9 len hc_msg 406 status = hc_c 8 7 407 o = ir_op get hc_s 0 66 0 0 2 408 ir_set o 0 get hc_s 1 409 ir_set o 1 status 410 n = ir_wr 411 fd = fopen hc_out 0 ulong get hc_s 14 577 384 412 if lt fd 0 413 hc_diag fd 0 414 ret 2 415 end 416 written = ar_out ulong fd 1 0 n 417 cl = fclose int fd 418 if eq written 0 419 hc_diag 0 long n 420 ret 2 421 end 422 k = write 2 hc_st0 0 len hc_st0 423 hc_print get hc_count 0 424 k = write 2 hc_st1 0 len hc_st1 425 hc_print get hc_count 1 426 k = write 2 hc_st2 0 len hc_st2 427 k = write 1 hc_msg 0 len hc_msg 428 if ne k long len hc_msg 429 ret 2 430 end 431 exit 7 432 end