Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/si/architecture/tools/zero-legacy/expect.om # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / si / architecture / tools / zero-legacy / expect.om` 175 lines ยท 2880 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note expect: judge a closure report against an expected row file (#316 gate). 3 note usage: expect OUTPUT EXPECTED 4 note Every line of EXPECTED must occur as a whole line of OUTPUT (order free, 5 note because directory enumeration order is filesystem dependent), and the two 6 note files must hold the same number of row lines (lines not starting with #). 7 note Exit 0 when both hold; 1 and the missing line on stderr otherwise; 2 when 8 note the row counts differ; 64 for usage; 65 when a file cannot be read. 9 10 text tuse "usage: expect OUTPUT EXPECTED\n" 11 text terr "expect: cannot read a file\n" 12 text tmiss "expect: missing line: " 13 text tcnt "expect: row count differs\n" 14 text tnl "\n" 15 16 global out uchar 65536 17 global outn ulong 1 18 global exp uchar 65536 19 global expn ulong 1 20 global name uchar 256 21 22 fn load1 to bool 23 n = argread 1 name 0 255 24 if lt n 1 25 ret false 26 end 27 fd = fopen name 0 ulong n 0 0 28 if lt fd 0 29 ret false 30 end 31 r = read int fd out 0 65535 32 if gt r 0 33 put outn 0 ulong r 34 end 35 r = fclose int fd 36 ret true 37 end 38 39 fn load2 to bool 40 n = argread 2 name 0 255 41 if lt n 1 42 ret false 43 end 44 fd = fopen name 0 ulong n 0 0 45 if lt fd 0 46 ret false 47 end 48 r = read int fd exp 0 65535 49 if gt r 0 50 put expn 0 ulong r 51 end 52 r = fclose int fd 53 ret true 54 end 55 56 note end of the line that starts at s in out 57 fn oend s ulong to ulong 58 e = s 59 n = get outn 0 60 while lt e n bound 65536 61 if eq get out e 10 62 ret e 63 end 64 e = add e 1 65 end 66 ret e 67 end 68 69 fn eend s ulong to ulong 70 e = s 71 n = get expn 0 72 while lt e n bound 65536 73 if eq get exp e 10 74 ret e 75 end 76 e = add e 1 77 end 78 ret e 79 end 80 81 note does exp[s..s+m) equal out[t..t+m) 82 fn same s ulong t ulong m ulong to bool 83 for i ulong m 84 if ne get exp add s i get out add t i 85 ret false 86 end 87 end 88 ret true 89 end 90 91 note is the expected line exp[s..s+m) a whole, not yet used line of out; the match is consumed 92 note (its first byte becomes 1, which no text line starts with) so repeated rows must each occur 93 fn has s ulong m ulong to bool 94 n = get outn 0 95 t = ulong 0 96 while lt t n bound 65536 97 e = oend t 98 if eq sub e t m 99 if same s t m 100 put out t 1 101 ret true 102 end 103 end 104 t = add e 1 105 end 106 ret false 107 end 108 109 fn rows1 to ulong 110 n = get outn 0 111 c = ulong 0 112 t = ulong 0 113 while lt t n bound 65536 114 e = oend t 115 if gt e t 116 if ne get out t 35 117 c = add c 1 118 end 119 end 120 t = add e 1 121 end 122 ret c 123 end 124 125 fn rows2 to ulong 126 n = get expn 0 127 c = ulong 0 128 t = ulong 0 129 while lt t n bound 65536 130 e = eend t 131 if gt e t 132 if ne get exp t 35 133 c = add c 1 134 end 135 end 136 t = add e 1 137 end 138 ret c 139 end 140 141 fn main to int 142 if lt argcnt 3 143 r = write 2 tuse 0 len tuse 144 ret 64 145 end 146 if not load1 147 r = write 2 terr 0 len terr 148 ret 65 149 end 150 if not load2 151 r = write 2 terr 0 len terr 152 ret 65 153 end 154 c1 = rows1 155 n = get expn 0 156 s = ulong 0 157 while lt s n bound 65536 158 e = eend s 159 m = sub e s 160 if gt m 0 161 if not has s m 162 r = write 2 tmiss 0 len tmiss 163 r = write 2 exp s m 164 r = write 2 tnl 0 1 165 ret 1 166 end 167 end 168 s = add e 1 169 end 170 if ne c1 rows2 171 r = write 2 tcnt 0 len tcnt 172 ret 2 173 end 174 ret 0 175 end