interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / src / physics0 / pd0_chan.om

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