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 / scene-input.om
| 1 | note Bounded model scene input. Existing scene stays the strict canonical parser. |
| 2 | note Nm thinking,normalized bytes,tidying count,hidden lines,line bytes,mood seen, |
| 3 | note invalid/overflow,plain candidate bytes,canonical line count. Input restored. |
| 4 | global Nm ulong 9 |
| 5 | global Nraw uchar 2048 |
| 6 | global Nline uchar 2048 |
| 7 | global Nnorm uchar 2048 |
| 8 | global Nplain uchar 160 |
| 9 | text Ntags "<think></think>" |
| 10 | fn nlow c uchar to uchar |
| 11 | if and ge c 65 le c 90 |
| 12 | ret add sub c 65 97 |
| 13 | end |
| 14 | ret c |
| 15 | end |
| 16 | fn nalpha c uchar to bool |
| 17 | v = nlow c |
| 18 | ret and ge v 97 le v 122 |
| 19 | end |
| 20 | fn nmatch at ulong off ulong size ulong to bool |
| 21 | if gt add at size get Nm 4 |
| 22 | ret false |
| 23 | end |
| 24 | for i ulong size |
| 25 | if ne nlow get Nline add at i get Ntags add off i |
| 26 | ret false |
| 27 | end |
| 28 | end |
| 29 | ret true |
| 30 | end |
| 31 | fn nemit c uchar to void |
| 32 | n = get Nm 1 |
| 33 | if ge n 2048 |
| 34 | put Nm 6 1 |
| 35 | ret |
| 36 | end |
| 37 | put Nnorm n c |
| 38 | put Nm 1 add n 1 |
| 39 | end |
| 40 | fn nmark c uchar to bool |
| 41 | if or eq c 45 eq c 42 |
| 42 | ret true |
| 43 | end |
| 44 | if or eq c 35 eq c 62 |
| 45 | ret true |
| 46 | end |
| 47 | ret eq c 34 |
| 48 | end |
| 49 | fn nlead c uchar to bool |
| 50 | if or eq c 32 eq c 42 |
| 51 | ret true |
| 52 | end |
| 53 | if eq c 35 |
| 54 | ret true |
| 55 | end |
| 56 | ret nalpha c |
| 57 | end |
| 58 | fn ndigits p ulong to ulong |
| 59 | while lt p get Nm 4 |
| 60 | if not isdigit get Nline p |
| 61 | ret p |
| 62 | end |
| 63 | p = add p 1 |
| 64 | end |
| 65 | ret p |
| 66 | end |
| 67 | fn nspaces p ulong to ulong |
| 68 | while lt p get Nm 4 |
| 69 | if ne get Nline p 32 |
| 70 | ret p |
| 71 | end |
| 72 | p = add p 1 |
| 73 | end |
| 74 | ret p |
| 75 | end |
| 76 | fn npstep s ulong to ulong |
| 77 | n = get Nm 4 |
| 78 | c = get Nline s |
| 79 | if nmark c |
| 80 | if eq add s 1 n |
| 81 | ret n |
| 82 | end |
| 83 | if nlead get Nline add s 1 |
| 84 | ret add s 1 |
| 85 | end |
| 86 | ret s |
| 87 | end |
| 88 | if not isdigit c |
| 89 | ret s |
| 90 | end |
| 91 | p = ndigits s |
| 92 | if ge add p 1 n |
| 93 | ret s |
| 94 | end |
| 95 | if not or eq get Nline p 46 eq get Nline p 41 |
| 96 | ret s |
| 97 | end |
| 98 | if ne get Nline add p 1 32 |
| 99 | ret s |
| 100 | end |
| 101 | ret add p 2 |
| 102 | end |
| 103 | fn nprefix to ulong |
| 104 | s = ulong 0 |
| 105 | while lt s get Nm 4 |
| 106 | next = npstep s |
| 107 | if eq next s |
| 108 | ret s |
| 109 | end |
| 110 | put Nm 2 add get Nm 2 1 |
| 111 | s = nspaces next |
| 112 | end |
| 113 | ret s |
| 114 | end |
| 115 | fn nfinish to void |
| 116 | n = get Nm 4 |
| 117 | while gt n 0 |
| 118 | if eq get Nline sub n 1 32 |
| 119 | n = sub n 1 |
| 120 | else |
| 121 | nprocess n |
| 122 | ret |
| 123 | end |
| 124 | end |
| 125 | end |
| 126 | fn nprocess n ulong to void |
| 127 | put Nm 4 n |
| 128 | hide = ne get Nm 0 0 |
| 129 | for i ulong n |
| 130 | if nmatch i 0 7 |
| 131 | put Nm 0 1 |
| 132 | hide = true |
| 133 | end |
| 134 | if nmatch i 7 8 |
| 135 | put Nm 0 0 |
| 136 | hide = true |
| 137 | end |
| 138 | end |
| 139 | if hide |
| 140 | put Nm 3 add get Nm 3 1 |
| 141 | ret |
| 142 | end |
| 143 | if ge n 3 |
| 144 | if and eq get Nline 0 96 eq get Nline 1 96 |
| 145 | if eq get Nline 2 96 |
| 146 | put Nm 2 add get Nm 2 1 |
| 147 | ret |
| 148 | end |
| 149 | end |
| 150 | end |
| 151 | s = nprefix |
| 152 | if ge s n |
| 153 | ret |
| 154 | end |
| 155 | w = s |
| 156 | while lt w n |
| 157 | if nalpha get Nline w |
| 158 | w = add w 1 |
| 159 | else |
| 160 | nword s w n |
| 161 | ret |
| 162 | end |
| 163 | end |
| 164 | nword s w n |
| 165 | end |
| 166 | fn nword s ulong w ulong n ulong to void |
| 167 | for i ulong sub w s |
| 168 | put In add s i nlow get Nline add s i |
| 169 | end |
| 170 | word = scword s sub w s |
| 171 | if gt word 10 |
| 172 | word = 0 |
| 173 | end |
| 174 | r = w |
| 175 | while lt r n |
| 176 | c = get Nline r |
| 177 | if or eq c 42 eq c 34 |
| 178 | r = add r 1 |
| 179 | put Nm 2 add get Nm 2 1 |
| 180 | else |
| 181 | nappend s w r n word |
| 182 | ret |
| 183 | end |
| 184 | end |
| 185 | nappend s w r n word |
| 186 | end |
| 187 | fn nappend s ulong w ulong r ulong n ulong word ulong to void |
| 188 | if lt r n |
| 189 | if not or eq get Nline r 32 eq get Nline r 58 |
| 190 | word = 0 |
| 191 | end |
| 192 | end |
| 193 | if eq word 0 |
| 194 | size = sub n s |
| 195 | if and eq get Nm 7 0 le size 159 |
| 196 | if lt get Nm 8 12 |
| 197 | for i ulong size |
| 198 | put Nplain i get Nline add s i |
| 199 | end |
| 200 | put Nm 7 size |
| 201 | end |
| 202 | end |
| 203 | for i ulong size |
| 204 | nemit get Nline add s i |
| 205 | end |
| 206 | else |
| 207 | if eq word 1 |
| 208 | if lt get Nm 8 12 |
| 209 | put Nm 5 1 |
| 210 | end |
| 211 | end |
| 212 | for i ulong sub w s |
| 213 | nemit nlow get Nline add s i |
| 214 | end |
| 215 | head = ne word 2 |
| 216 | for i ulong sub n r |
| 217 | c = get Nline add r i |
| 218 | if eq c 58 |
| 219 | if ne word 1 |
| 220 | head = false |
| 221 | end |
| 222 | end |
| 223 | if head |
| 224 | c = nlow c |
| 225 | end |
| 226 | nemit c |
| 227 | end |
| 228 | end |
| 229 | nemit 10 |
| 230 | put Nm 8 add get Nm 8 1 |
| 231 | end |
| 232 | fn nclear to void |
| 233 | for i ulong 8 |
| 234 | put Sc i 0 |
| 235 | end |
| 236 | for i ulong 64 |
| 237 | put Things i 0 |
| 238 | end |
| 239 | put Sw 3 0 |
| 240 | end |
| 241 | fn scdecode to bool |
| 242 | for i ulong 9 |
| 243 | put Nm i 0 |
| 244 | end |
| 245 | nclear |
| 246 | n = get Inlen 0 |
| 247 | if gt n 2048 |
| 248 | put Nm 6 1 |
| 249 | ret false |
| 250 | end |
| 251 | for i ulong n |
| 252 | if eq get In i 0 |
| 253 | put Nm 6 1 |
| 254 | ret false |
| 255 | end |
| 256 | put Nraw i get In i |
| 257 | end |
| 258 | for i ulong n |
| 259 | c = get Nraw i |
| 260 | if eq c 10 |
| 261 | nfinish |
| 262 | put Nm 4 0 |
| 263 | else |
| 264 | if eq c 9 |
| 265 | c = uchar 32 |
| 266 | put Nm 2 add get Nm 2 1 |
| 267 | end |
| 268 | if and ge c 32 le c 126 |
| 269 | p = get Nm 4 |
| 270 | keep = true |
| 271 | if eq c 32 |
| 272 | if eq p 0 |
| 273 | keep = false |
| 274 | else |
| 275 | if eq get Nline sub p 1 32 |
| 276 | keep = false |
| 277 | end |
| 278 | end |
| 279 | end |
| 280 | if keep |
| 281 | put Nline p c |
| 282 | put Nm 4 add p 1 |
| 283 | else |
| 284 | put Nm 2 add get Nm 2 1 |
| 285 | end |
| 286 | else |
| 287 | put Nm 2 add get Nm 2 1 |
| 288 | end |
| 289 | end |
| 290 | end |
| 291 | nfinish |
| 292 | ok = false |
| 293 | if eq get Nm 6 0 |
| 294 | for i ulong get Nm 1 |
| 295 | put In i get Nnorm i |
| 296 | end |
| 297 | put Inlen 0 get Nm 1 |
| 298 | ok = scene |
| 299 | if ne get Nm 5 0 |
| 300 | ok = true |
| 301 | end |
| 302 | if not ok |
| 303 | if gt get Nm 7 0 |
| 304 | for i ulong get Nm 7 |
| 305 | put In i get Nplain i |
| 306 | end |
| 307 | put Inlen 0 get Nm 7 |
| 308 | ok = scsay 0 get Nm 7 |
| 309 | end |
| 310 | end |
| 311 | else |
| 312 | nclear |
| 313 | end |
| 314 | for i ulong n |
| 315 | put In i get Nraw i |
| 316 | end |
| 317 | put Inlen 0 n |
| 318 | ret ok |
| 319 | end |