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 / aienux / allen / look-stat.om
| 1 | note SPDX-License-Identifier: MIT |
| 2 | note Allen's look, the stopwatch: what a second of frames costs on the machine that runs the show. |
| 3 | note look-show.om stamps three clocks a frame (before the decision, after compose and conversion, |
| 4 | note after the blit); once a second the sums become one line |
| 5 | note STAT net=<network ready> e=<last firmware error> h=<SNP handles> l=<locate status> |
| 6 | note c=<efi 8 scans> p=<probe step per handle, hex> m=<adapter MAC, hex> s=<second> |
| 7 | note t=<ms into the show> f=<frames> cc=<compose+convert ms> bl=<blit ms> |
| 8 | note r=<rectangles> px=<pixels composed> full=<full redraws> max=<slowest frame ms> |
| 9 | note lens=<w>x<h> rip=<ripple radius> kb=<KiB blitted> |
| 10 | note The network fields come first so the 159-byte answer view never cuts them off. |
| 11 | note sent as one datagram to the courier's port (the relay drops anything that is not courier |
| 12 | note wire; tcpdump on the Spark reads it) and kept as Allen's answer to the typed line `stats`. |
| 13 | note Stw: 0 second start ms, 1 frames, 2 compose+convert ms, 3 blit ms, 4 rectangles, 5 pixels, |
| 14 | note 6 full redraws, 7 slowest frame ms, 8 seconds counted, 9 a line waits in Stt for the wire, |
| 15 | note 10 bytes blitted. |
| 16 | global Stw ulong 16 |
| 17 | global Stv ulong 16 |
| 18 | global Stt uchar 256 |
| 19 | global Sttn ulong 1 |
| 20 | global Stdig uchar 24 |
| 21 | global Stn ulong 8 |
| 22 | text Stfmt "STAT % s=# t=# f=# cc=# bl=# r=# px=# full=# max=# lens=#x# rip=# kb=#" |
| 23 | text Stnetf "net=# e=# h=# l=# c=# p=% m=%" |
| 24 | text Stkey "stats" |
| 25 | fn stput c uchar to void |
| 26 | n = get Sttn 0 |
| 27 | if lt n len Stt |
| 28 | put Stt n c |
| 29 | put Sttn 0 add n 1 |
| 30 | end |
| 31 | end |
| 32 | fn stnum v ulong to void |
| 33 | n = ulong 0 |
| 34 | while gt v 9 bound 24 |
| 35 | put Stdig n uchar rem v 10 |
| 36 | v = div v 10 |
| 37 | n = add n 1 |
| 38 | end |
| 39 | put Stdig n uchar v |
| 40 | n = add n 1 |
| 41 | for i ulong n |
| 42 | stput add uchar 48 get Stdig sub sub n 1 i |
| 43 | end |
| 44 | end |
| 45 | fn stdiff a ulong b ulong to ulong |
| 46 | note b - a, 0 when the clock failed or went backwards. |
| 47 | if or lt b a eq b 18446744073709551615 |
| 48 | ret 0 |
| 49 | end |
| 50 | ret sub b a |
| 51 | end |
| 52 | fn sthex v ulong to void |
| 53 | note One lowercase hex digit of v (0..15). |
| 54 | if lt v 10 |
| 55 | stput add uchar 48 uchar v |
| 56 | else |
| 57 | stput add uchar 87 uchar v |
| 58 | end |
| 59 | end |
| 60 | fn stprobe h ulong to void |
| 61 | note One efi 8 probe step per SNP handle (Es 15), handle 0 first; at most 16, at least one digit. |
| 62 | note 0 not reached, 1 no Mode, 2 MAC size, 3 IfType, 4 Start, 5 Initialize, 6 GetStatus, 7 state, |
| 63 | note 8 no link (kept initialized), 9 filter mask, a ReceiveFilters, b not opened, e chosen without |
| 64 | note link detection, f chosen with a link. |
| 65 | n = h |
| 66 | if gt n 16 |
| 67 | n = ulong 16 |
| 68 | end |
| 69 | if eq n 0 |
| 70 | n = ulong 1 |
| 71 | end |
| 72 | v = get Es 15 |
| 73 | for i ulong n |
| 74 | sthex and shr v mul i 4 15 |
| 75 | end |
| 76 | end |
| 77 | fn stnet to void |
| 78 | note Stnetf from Es (efi-main.om efnetup): network ready, last firmware error, then efi 8's |
| 79 | note handles, LocateHandleBuffer status, scans, probe steps and the adapter's MAC (Nmac). |
| 80 | d = get Es 14 |
| 81 | put Stn 0 get Es 6 |
| 82 | put Stn 1 get Es 12 |
| 83 | put Stn 2 and d 255 |
| 84 | put Stn 3 and shr d 8 255 |
| 85 | put Stn 4 and shr d 16 65535 |
| 86 | k = ulong 0 |
| 87 | for i ulong len Stnetf |
| 88 | c = get Stnetf i |
| 89 | if eq c 35 |
| 90 | stnum get Stn k |
| 91 | k = add k 1 |
| 92 | else |
| 93 | if eq c 37 |
| 94 | if eq k 5 |
| 95 | stprobe get Stn 2 |
| 96 | else |
| 97 | for j ulong 6 |
| 98 | b = ulong get Nmac j |
| 99 | sthex shr b 4 |
| 100 | sthex and b 15 |
| 101 | end |
| 102 | end |
| 103 | k = add k 1 |
| 104 | else |
| 105 | stput c |
| 106 | end |
| 107 | end |
| 108 | end |
| 109 | end |
| 110 | fn stline to void |
| 111 | note Stfmt with every # replaced by the next value of Stv and % by the network fields. |
| 112 | put Sttn 0 0 |
| 113 | k = ulong 0 |
| 114 | for i ulong len Stfmt |
| 115 | c = get Stfmt i |
| 116 | if eq c 35 |
| 117 | stnum get Stv k |
| 118 | k = add k 1 |
| 119 | else |
| 120 | if eq c 37 |
| 121 | stnet |
| 122 | else |
| 123 | stput c |
| 124 | end |
| 125 | end |
| 126 | end |
| 127 | end |
| 128 | fn stsecond now ulong t ulong to void |
| 129 | put Stw 8 add get Stw 8 1 |
| 130 | put Stv 0 get Stw 8 |
| 131 | put Stv 1 t |
| 132 | put Stv 2 get Stw 1 |
| 133 | put Stv 3 get Stw 2 |
| 134 | put Stv 4 get Stw 3 |
| 135 | put Stv 5 get Stw 4 |
| 136 | put Stv 6 get Stw 5 |
| 137 | put Stv 7 get Stw 6 |
| 138 | put Stv 8 get Stw 7 |
| 139 | put Stv 9 ulong pkmax get Ntlens 2 0 |
| 140 | put Stv 10 ulong pkmax get Ntlens 3 0 |
| 141 | put Stv 11 ulong pkmax get Ntrip 0 0 |
| 142 | put Stv 12 div get Stw 10 1024 |
| 143 | stline |
| 144 | put Stw 9 1 |
| 145 | for i ulong 8 |
| 146 | put Stw i 0 |
| 147 | end |
| 148 | put Stw 0 now |
| 149 | put Stw 10 0 |
| 150 | end |
| 151 | fn stframe t0 ulong t1 ulong t2 ulong t ulong px ulong rf ulong to void |
| 152 | note One frame: t0 before the decision, t1 after compose and conversion, t2 after the blit; |
| 153 | note t is the show's clock, px the pixels composed, rf twice the rectangles plus 1 for a |
| 154 | note whole-screen redraw (six parameters is the language's limit). |
| 155 | if eq get Stw 0 0 |
| 156 | put Stw 0 t0 |
| 157 | end |
| 158 | put Stw 1 add get Stw 1 1 |
| 159 | put Stw 2 add get Stw 2 stdiff t0 t1 |
| 160 | put Stw 3 add get Stw 3 stdiff t1 t2 |
| 161 | put Stw 4 add get Stw 4 shr rf 1 |
| 162 | put Stw 5 add get Stw 5 px |
| 163 | put Stw 6 add get Stw 6 and rf 1 |
| 164 | d = stdiff t0 t2 |
| 165 | if gt d get Stw 7 |
| 166 | put Stw 7 d |
| 167 | end |
| 168 | if ge t2 add get Stw 0 1000 |
| 169 | stsecond t2 t |
| 170 | end |
| 171 | end |
| 172 | fn ststep up bool to void |
| 173 | note Offer the waiting line to the wire when the network is up and nothing is in flight; the |
| 174 | note courier's own datagrams are offered again on their clock, so one frame of delay is harmless. |
| 175 | if or eq get Stw 9 0 not up |
| 176 | ret |
| 177 | end |
| 178 | if ne get Ntxlen 0 0 |
| 179 | ret |
| 180 | end |
| 181 | n = get Sttn 0 |
| 182 | if or eq n 0 gt n 1472 |
| 183 | put Stw 9 0 |
| 184 | ret |
| 185 | end |
| 186 | ntxzero |
| 187 | for i ulong n |
| 188 | put Ntx add 42 i get Stt i |
| 189 | end |
| 190 | nudp 4294967295 47033 47033 n true |
| 191 | nqueue 7 add 42 n |
| 192 | put Stw 9 0 |
| 193 | end |
| 194 | fn stasked to bool |
| 195 | note True when the typed line is `stats`: the last line becomes what Allen says. |
| 196 | n = get Hminn 0 |
| 197 | if ne n len Stkey |
| 198 | ret false |
| 199 | end |
| 200 | for i ulong n |
| 201 | if ne get Hmin i get Stkey i |
| 202 | ret false |
| 203 | end |
| 204 | end |
| 205 | n = get Sttn 0 |
| 206 | if gt n len Hmsay |
| 207 | n = len Hmsay |
| 208 | end |
| 209 | for i ulong n |
| 210 | put Hmsay i get Stt i |
| 211 | end |
| 212 | put Hmsayn 0 n |
| 213 | hmsaid |
| 214 | ret true |
| 215 | end |