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 / seed / node / probe / check.om

174 lines · 2830 bytes Raw Blame History
1note Native independent wire client. Argument is the disposable server PID.
2text label "omega-node-n0."
3text ok "PASS N0 control; maximum snapshot latency in nanoseconds follows\n"
4text nl "\n"
5global serverid ulong 1
6global addr uchar 110
7global wire uchar 4
8global reply uchar 12
9global peer uchar 12
10global held int 6
11
12fn write_number v ulong to void
13d = new uchar 20 0
14x = v
15k = ulong 20
16for i ulong 20
17k = sub k 1
18put d k uchar add rem x 10 48
19x = div x 10
20if eq x 0
21break
22end
23end
24r = write 1 d k sub 20 k
25end
26
27note Write "/proc/<pid>/stat" into p; returns its length.
28fn ck test bool code int to void
29if not test
30exit code
31end
32end
33
34fn init_addr to void
35a = new uchar 12 0
36n = argread 1 a 0 len a
37ck and gt n 0 le n 8 2
38v = ulong 0
39for i ulong ulong n bound 8
40b = get a i
41ck and ge b 48 le b 57 2
42v = add mul v 10 ulong sub b 48
43end
44ck gt v 0 2
45put serverid 0 v
46put addr 0 1
47for i ulong len label
48put addr add i 3 get label i
49end
50for i ulong 4
51b = uchar and shr v mul i 8 255
52put addr add add len label 3 i b
53end
54end
55
56fn dial to int
57for i ulong 40
58s = socknew 1 524289 0
59ck ge s 0 3
60r = connect int s addr 0 add len label 7
61if eq r 0
62ck eq peercred int s peer 0 12 0 4
63id = ulong 0
64for j ulong 4
65id = or id shl ulong get peer j mul j 8
66end
67ck eq id get serverid 0 4
68ret int s
69end
70r = fclose int s
71r = sleepns 5000000
72end
73exit 5
74end
75
76fn exchange op uchar ver uchar count ulong size uchar to void
77s = dial
78put wire 0 size
79put wire 1 ver
80put wire 2 op
81put wire 3 123
82for i ulong count bound 4
83ck eq sendmsg s wire i 1 16384 1 6
84end
85ck eq shutdown s 1 0 6
86off = ulong 0
87for k ulong 12
88ck gt waitio s 1 1000000000 0 7
89r = recv s reply off sub 12 off 0
90ck gt r 0 7
91off = add off ulong r
92if eq off 12
93break
94end
95end
96ck eq off 12 7
97ck eq get reply 0 11 8
98ck eq get reply 1 1 8
99if ge count 3
100ck eq get reply 2 op 8
101end
102id = ulong 0
103for j ulong 4
104id = or id shl ulong get reply add j 8 mul j 8
105end
106ck eq id get serverid 0 8
107r = fclose s
108end
109
110fn cmd op uchar to void
111exchange op 1 3 2
112ck eq get reply 3 0 9
113end
114
115fn bad op uchar ver uchar count ulong size uchar to void
116exchange op ver count size
117ck eq get reply 3 1 10
118end
119
120fn latency to long
121for k ulong 6
122s = dial
123put held k s
124ck eq sendmsg s wire 0 1 16384 1 11
125end
126mx = long 0
127for j ulong 32
128t = monons
129cmd 2
130dt = sub monons t
131ck lt dt 200000000 12
132if gt dt mx
133mx = dt
134end
135ck eq get reply 6 0 12
136end
137for k ulong 6
138r = fclose get held k
139end
140ret mx
141end
142
143fn main to int
144init_addr
145cmd 1
146bad 5 2 3 2
147bad 3 1 2 2
148bad 3 1 4 2
149bad 3 1 3 255
150bad 77 1 3 2
151cmd 2
152ck eq get reply 4 0 13
153mx = latency
154ck eq get reply 7 1 14
155cmd 3
156ck eq get reply 4 1 15
157cmd 4
158ck eq get reply 4 0 16
159cmd 6
160ck eq get reply 6 1 17
161for i ulong 100
162cmd 2
163if eq get reply 6 2
164break
165end
166r = sleepns 2000000
167end
168ck eq get reply 6 2 18
169cmd 5
170r = write 1 ok 0 len ok
171write_number ulong mx
172r = write 1 nl 0 len nl
173ret 0
174end