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 / physics0 / pd0_chan.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note src/physics0/pd0_chan.om: Learner-side framed pipe channel to PD-0 world. |
| 3 | note Learner-side safe: no generator, no world, no file I/O. |
| 4 | |
| 5 | fn pd0_read_full fd int buf edit uchar * n ulong to int |
| 6 | got = ulong 0 |
| 7 | while lt got n bound 1048576 |
| 8 | k = read fd buf got sub n got |
| 9 | if le k long 0 |
| 10 | ret -1 |
| 11 | end |
| 12 | got = add got ulong k |
| 13 | end |
| 14 | ret 0 |
| 15 | end |
| 16 | |
| 17 | fn pd0_write_full fd int buf view uchar * n ulong to int |
| 18 | putn = ulong 0 |
| 19 | while lt putn n bound 1048576 |
| 20 | k = write fd buf putn sub n putn |
| 21 | if le k long 0 |
| 22 | ret -1 |
| 23 | end |
| 24 | putn = add putn ulong k |
| 25 | end |
| 26 | ret 0 |
| 27 | end |
| 28 | |
| 29 | fn pd0_chan_call_fd in_fd int out_fd int req view uchar * resp edit uchar * to ulong |
| 30 | rlen = len req |
| 31 | len4 = new uchar 4 0 |
| 32 | pd0_put_u32 edit len4 ulong 0 uint rlen |
| 33 | if ne pd0_write_full out_fd view len4 ulong 4 0 |
| 34 | ret ulong 0 |
| 35 | end |
| 36 | if ne pd0_write_full out_fd req rlen 0 |
| 37 | ret ulong 0 |
| 38 | end |
| 39 | if ne pd0_read_full in_fd edit len4 ulong 4 0 |
| 40 | ret ulong 0 |
| 41 | end |
| 42 | n = ulong pd0_get_u32 view len4 ulong 0 |
| 43 | if or eq n ulong 0 gt n len resp |
| 44 | ret ulong 0 |
| 45 | end |
| 46 | if ne pd0_read_full in_fd resp n 0 |
| 47 | ret ulong 0 |
| 48 | end |
| 49 | ret n |
| 50 | end |
| 51 | |
| 52 | fn pd0_chan_describe_fd in_fd int out_fd int d edit Pd0Desc to int |
| 53 | req = new uchar 64 0 |
| 54 | resp = new uchar 256 0 |
| 55 | rlen = pd0_req_describe edit req |
| 56 | n = pd0_chan_call_fd in_fd out_fd part req 0 rlen edit resp |
| 57 | if eq n ulong 0 |
| 58 | ret -1 |
| 59 | end |
| 60 | ret pd0_desc_decode part resp 0 n d |
| 61 | end |
| 62 | |
| 63 | fn pd0_chan_reset_fd in_fd int out_fd int n_obs uchar vals view long 4 r edit Pd0Rec to int |
| 64 | req = new uchar 64 0 |
| 65 | resp = new uchar 256 0 |
| 66 | rlen = pd0_req_reset n_obs vals edit req |
| 67 | if eq rlen ulong 0 |
| 68 | ret -1 |
| 69 | end |
| 70 | n = pd0_chan_call_fd in_fd out_fd part req 0 rlen edit resp |
| 71 | if eq n ulong 0 |
| 72 | ret -1 |
| 73 | end |
| 74 | ret pd0_rec_decode part resp 0 n r |
| 75 | end |
| 76 | |
| 77 | fn pd0_chan_step_fd in_fd int out_fd int ch uchar val long r edit Pd0Rec to int |
| 78 | req = new uchar 64 0 |
| 79 | resp = new uchar 256 0 |
| 80 | rlen = pd0_req_step ch val edit req |
| 81 | n = pd0_chan_call_fd in_fd out_fd part req 0 rlen edit resp |
| 82 | if eq n ulong 0 |
| 83 | ret -1 |
| 84 | end |
| 85 | ret pd0_rec_decode part resp 0 n r |
| 86 | end |