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 / omc / tests / pools / srv.om

136 lines · 2468 bytes Raw Blame History
1note gate-pools S (design section 11): 2000 requests of growing and shrinking sizes (a fixed 64-bit LCG,
2note 1 byte .. 64 MiB; the first 8 ramp to the 64 MiB high-water mark) served from one pool that is enlarged
3note only past its high-water mark and reused. Prints the high-water mark, enlarge calls, new marks, VmRSS (kB)
4note after the high-water point (request 8) and at the end, and a checksum of the bytes served.
5note Control: with the byte L on stdin, requests 8..23 are served from fresh memory past the old end (a
6note server that enlarges per request); its VmRSS must rise past the high-water mark.
7global P uchar *
8global sb uchar 4096
9global mb uchar 1
10global ob uchar 24
11text pth "/proc/self/status"
12fn pnum v ulong to void
13put ob 23 10
14i = ulong 23
15x = v
16go = true
17while go bound 21
18i = sub i 1
19put ob i uchar add rem x 10 48
20x = div x 10
21go = ne x 0
22end
23k = write 1 ob i sub 24 i
24end
25fn plong v long to void
26if lt v 0
27put ob 0 uchar 45
28k = write 1 ob 0 1
29pnum ulong neg v
30else
31pnum ulong v
32end
33end
34fn hit i ulong to bool
35a = and eq get sb i 86 eq get sb add i 1 109
36b = and eq get sb add i 2 82 eq get sb add i 5 58
37ret and a b
38end
39fn rss to ulong
40fd = fopen pth 0 len pth 0 0
41if lt fd 0
42ret 0
43end
44n = read int fd sb 0 4096
45fd = fclose int fd
46if le n 0
47ret 0
48end
49lim = ulong n
50i = ulong 0
51while lt add i 6 lim bound 4096
52if hit i
53break
54end
55i = add i 1
56end
57i = add i 6
58v = ulong 0
59while lt i lim bound 4096
60ch = get sb i
61if and ge ch 48 le ch 57
62v = add mul v 10 ulong sub ch 48
63else
64if and ne ch 32 ne ch 9
65break
66end
67end
68i = add i 1
69end
70ret v
71end
72fn serve q ulong b ulong sz ulong to ulong
73cs = ulong 0
74o = ulong 0
75while lt o sz bound 20000
76put P add b o uchar and add q o 255
77cs = add cs ulong get P add b o
78o = add o 4096
79end
80ret cs
81end
82fn main to int
83leak = false
84k = read 0 mb 0 1
85if gt k 0
86leak = eq get mb 0 76
87end
88x = ulong 12345
89hw = ulong 0
90calls = ulong 0
91marks = ulong 0
92rhw = ulong 0
93cs = ulong 0
94q = ulong 0
95while lt q 2000
96x = add mul x 6364136223846793005 1442695040888963407
97sz = add rem shr x 33 67108864 1
98if lt q 8
99sz = mul add q 1 8388608
100end
101b = ulong 0
102if and leak ge q 8
103if eq q 24
104break
105end
106sz = add rem sz 4194304 1
107b = len P
108r = enlarge P add b sz
109calls = add calls 1
110if ne r 0
111ret 4
112end
113end
114if gt sz hw
115r = enlarge P sz
116calls = add calls 1
117if ne r 0
118ret 3
119end
120hw = sz
121marks = add marks 1
122end
123cs = add cs serve q b sz
124if eq q 8
125rhw = rss
126end
127q = add q 1
128end
129pnum hw
130pnum calls
131pnum marks
132pnum rhw
133pnum rss
134pnum cs
135ret 0
136end