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 / seed / node / code-test.om
| 1 | note seed/node/code-test.om -- checks of the coding workflow (DRA-290). |
| 2 | note omnode-code-test unit JDIR: the creator's decisions on crafted model |
| 3 | note and tool records, no child process; prints "code checks=N fail=F" and |
| 4 | note exits 0, or 150 + the number of the first failing check. |
| 5 | note omnode-code-test cancel MS INFER TOOL OMC ROOT WORK JDIR PORT VIEW OBJ...: |
| 6 | note omnode-code with objective 0's first inference cancelled through |
| 7 | note auth_cancel once it has run MS milliseconds. |
| 8 | note omnode-code-test overload LIMIT INFER ... OBJ...: omnode-code admitting |
| 9 | note at most LIMIT jobs (DRA-291: the view shows the refusals). |
| 10 | note omnode-code-test uncertain INFER ... OBJ...: omnode-code whose first |
| 11 | note granted replace has its worker killed once its START is durable |
| 12 | note (DRA-291, DRA-292: an unknown effect). |
| 13 | text ctunit "unit" |
| 14 | text ctcanc "cancel" |
| 15 | text ctover "overload" |
| 16 | text ctunc "uncertain" |
| 17 | text ctobj "loop,4,3,70,jobs/item76666.om,Fix the error in this file and confirm its goal." |
| 18 | text ctpath "jobs/item76666.om" |
| 19 | text ctbadp "jobs/item76667.om" |
| 20 | text ctsrc "fn calc x int to int\ns = x\nfor i ulong 2\ns = add s int 4\nend\nret s\nend\nfn main to int\nret calc int 70\nend\n" |
| 21 | text ctfix "fn calc x int to int\ns = x\nfor i ulong 3\ns = add s int 4\nend\nret s\nend\nfn main to int\nret calc int 70\nend\n" |
| 22 | text ctold "ulong 2" |
| 23 | text ctnew "ulong 3" |
| 24 | text ctnone "ulong 9" |
| 25 | text ctdup "int 4" |
| 26 | text ctdup2 "s" |
| 27 | text ctgar "ulong 3 x" |
| 28 | text ctrs "Read succeeded." |
| 29 | text ctfnf "File not found." |
| 30 | text cttf "Test failed: calc(70) expected 82, got 78." |
| 31 | text ctes "Edit saved." |
| 32 | text cttp "Tests passed." |
| 33 | text ctp0 "Task: Fix the error in this file and confirm its goal.\nFile: jobs/item76666.om\nGoal: calc starts with x and adds 4 exactly 3 times in a for loop. main calls calc with 70.\nState: unread\nAnswer:\n" |
| 34 | text ctp2 "Task: Fix the error in this file and confirm its goal.\nFile: jobs/item76666.om\nGoal: calc starts with x and adds 4 exactly 3 times in a for loop. main calls calc with 70.\nState: failed\nSource:\nfn calc x int to int\ns = x\nfor i ulong 2\ns = add s int 4\nend\nret s\nend\nfn main to int\nret calc int 70\nend\nTool result: Test failed: calc(70) expected 82, got 78.\nAnswer:\n" |
| 35 | text ctfl "code-test check " |
| 36 | text ctfl2 " FAIL\n" |
| 37 | text ctsum "code checks=" |
| 38 | text ctsum2 " fail=" |
| 39 | text ctomni "OMNI1 " |
| 40 | text ctomnt "OMNT1 " |
| 41 | global ctcases ulong 1 |
| 42 | global ctn ulong 3 |
| 43 | global ctc ulong 1 |
| 44 | |
| 45 | note The creator's pool handle, kept for the record helpers. |
| 46 | fn ct_c to long |
| 47 | ret long get ctc 0 |
| 48 | end |
| 49 | |
| 50 | fn ct_ok b bool to void |
| 51 | put ctn 0 add get ctn 0 1 |
| 52 | if b |
| 53 | ret |
| 54 | end |
| 55 | put ctn 1 add get ctn 1 1 |
| 56 | if eq get ctn 2 0 |
| 57 | put ctn 2 get ctn 0 |
| 58 | end |
| 59 | o = new uchar 4096 0 |
| 60 | p = cw_cat o 0 ctfl |
| 61 | p = cw_dec o p get ctn 0 |
| 62 | p = cw_cat o p ctfl2 |
| 63 | cw_out o p |
| 64 | end |
| 65 | |
| 66 | note Objective 0 in state st (verified vf), its source sel (0 none, 1 the |
| 67 | note broken source, 2 the fixed one), no job, running. |
| 68 | note Independent scenarios each need a fresh durable objective after the previous one ended. |
| 69 | fn ct_newjournal to void |
| 70 | b = new uchar 4096 0 |
| 71 | tag = get ctcases 0 |
| 72 | put ctcases 0 add tag 1 |
| 73 | n = cw_dec b 0 ulong getpid |
| 74 | put b n 45 |
| 75 | n = cw_dec b add n 1 tag |
| 76 | r = makedir b 0 n 448 |
| 77 | if ne r 0 |
| 78 | exit 59 |
| 79 | end |
| 80 | for i ulong n bound 100 |
| 81 | put cwcf add 5120 i get b i |
| 82 | end |
| 83 | put cwcl 5 n |
| 84 | if ne cw_jopen 1 1 0 |
| 85 | exit 59 |
| 86 | end |
| 87 | end |
| 88 | |
| 89 | fn ct_set st ulong vf ulong sel ulong to void |
| 90 | if ne jn_res 0 0 |
| 91 | jn_close |
| 92 | ct_newjournal |
| 93 | end |
| 94 | cw_s 0 6 st |
| 95 | cw_s 0 8 vf |
| 96 | cw_s 0 9 0 |
| 97 | cw_s 0 10 0 |
| 98 | cw_s 0 12 0 |
| 99 | cw_s 0 13 0 |
| 100 | cw_s 0 14 0 |
| 101 | put cwinf 0 0 |
| 102 | if eq sel 1 |
| 103 | cw_setsrc 0 ctsrc |
| 104 | end |
| 105 | if eq sel 2 |
| 106 | cw_setsrc 0 ctfix |
| 107 | end |
| 108 | end |
| 109 | |
| 110 | note The objective's state: result r and, when r is 0, a job of kind k in |
| 111 | note flight (k 0: none). |
| 112 | fn ct_is r ulong k ulong to bool |
| 113 | if ne cw_g 0 12 r |
| 114 | ret false |
| 115 | end |
| 116 | if ne r 0 |
| 117 | ret true |
| 118 | end |
| 119 | if eq k 0 |
| 120 | ret eq cw_g 0 10 0 |
| 121 | end |
| 122 | id = cw_g 0 10 |
| 123 | ret and gt id 0 and eq rem id 10 k jn_known id |
| 124 | end |
| 125 | |
| 126 | note Record texts by index: 0 path, 1 another path, 2 old, 3 new, 4 old |
| 127 | note text not in the source, 5 old text twice in it, 6 old text many times, |
| 128 | note 7 new text outside the grammar. Appended to b at p; the new length. |
| 129 | fn ct_cat b edit uchar 4096 p ulong s ulong to ulong |
| 130 | if eq s 0 |
| 131 | ret cw_cat b p ctpath |
| 132 | end |
| 133 | if eq s 1 |
| 134 | ret cw_cat b p ctbadp |
| 135 | end |
| 136 | if eq s 2 |
| 137 | ret cw_cat b p ctold |
| 138 | end |
| 139 | if eq s 3 |
| 140 | ret cw_cat b p ctnew |
| 141 | end |
| 142 | if eq s 4 |
| 143 | ret cw_cat b p ctnone |
| 144 | end |
| 145 | if eq s 5 |
| 146 | ret cw_cat b p ctdup |
| 147 | end |
| 148 | if eq s 6 |
| 149 | ret cw_cat b p ctdup2 |
| 150 | end |
| 151 | ret cw_cat b p ctgar |
| 152 | end |
| 153 | |
| 154 | fn ct_len s ulong to ulong |
| 155 | b = new uchar 4096 0 |
| 156 | ret ct_cat b 0 s |
| 157 | end |
| 158 | |
| 159 | fn ct_nums b edit uchar 4096 p ulong a ulong o ulong to ulong |
| 160 | q = cw_cat b p cwsp |
| 161 | q = cw_dec b q 1 |
| 162 | q = cw_cat b q cwsp |
| 163 | q = cw_dec b q 100 |
| 164 | q = cw_cat b q cwsp |
| 165 | q = cw_dec b q 12 |
| 166 | q = cw_cat b q cwsp |
| 167 | q = cw_dec b q a |
| 168 | q = cw_cat b q cwsp |
| 169 | q = cw_dec b q o |
| 170 | ret q |
| 171 | end |
| 172 | |
| 173 | fn ct_tail b edit uchar 4096 p ulong nl ulong tl ulong to ulong |
| 174 | q = cw_cat b p cwsp |
| 175 | q = cw_dec b q nl |
| 176 | q = cw_cat b q cwsp |
| 177 | q = cw_dec b q tl |
| 178 | ret cw_cat b q cwnl |
| 179 | end |
| 180 | |
| 181 | note The model's action k on path text pa, replacing text ol by text nw |
| 182 | note (indices for ct_cat); the raw text is two newlines. |
| 183 | fn ct_act k ulong pa ulong ol ulong nw ulong to void |
| 184 | b = new uchar 4096 0 |
| 185 | p = cw_cat b 0 ctomni |
| 186 | p = cw_dec b p k |
| 187 | p = ct_nums b p ct_len pa ct_len ol |
| 188 | p = ct_tail b p ct_len nw 2 |
| 189 | p = ct_cat b p pa |
| 190 | p = ct_cat b p ol |
| 191 | p = ct_cat b p nw |
| 192 | p = cw_cat b p cwnl |
| 193 | p = cw_cat b p cwnl |
| 194 | cw_ires ct_c 0 b |
| 195 | end |
| 196 | |
| 197 | note A plain answer (Tests passed., File not found.) of kind k. |
| 198 | fn ct_ans k ulong a view uchar * to void |
| 199 | b = new uchar 4096 0 |
| 200 | p = cw_cat b 0 ctomni |
| 201 | p = cw_dec b p k |
| 202 | p = ct_nums b p 0 0 |
| 203 | p = ct_tail b p 0 len a |
| 204 | p = cw_cat b p a |
| 205 | cw_ires ct_c 0 b |
| 206 | end |
| 207 | |
| 208 | note A tool record of job kind k: status st, observation ob, content ct. |
| 209 | fn ct_tool k ulong st ulong ob view uchar * ct view uchar * to void |
| 210 | b = new uchar 4096 0 |
| 211 | p = cw_cat b 0 ctomnt |
| 212 | p = cw_dec b p st |
| 213 | p = cw_cat b p cwsp |
| 214 | p = cw_dec b p len ob |
| 215 | p = cw_cat b p cwsp |
| 216 | p = cw_dec b p len ct |
| 217 | p = cw_cat b p cwnl |
| 218 | p = cw_cat b p ob |
| 219 | p = cw_cat b p ct |
| 220 | cw_tres ct_c 0 k b |
| 221 | end |
| 222 | |
| 223 | fn ct_prompt to void |
| 224 | o = new uchar 4096 0 |
| 225 | ct_set 0 0 0 |
| 226 | n = cw_prmt o 0 |
| 227 | ct_ok cw_eq view part o 0 n ctp0 |
| 228 | ct_set 2 0 1 |
| 229 | cw_seto 0 cttf |
| 230 | n = cw_prmt o 0 |
| 231 | ct_ok cw_eq view part o 0 n ctp2 |
| 232 | end |
| 233 | |
| 234 | note Model actions against the policy. |
| 235 | fn ct_model to void |
| 236 | ct_set 0 0 0 |
| 237 | ct_act 1 0 2 3 |
| 238 | ct_ok ct_is 0 2 |
| 239 | ct_set 0 0 0 |
| 240 | ct_act 1 1 2 3 |
| 241 | ct_ok ct_is 11 0 |
| 242 | ct_set 0 0 0 |
| 243 | ct_act 2 0 2 3 |
| 244 | ct_ok ct_is 10 0 |
| 245 | ct_set 0 0 0 |
| 246 | ct_act 9 0 2 3 |
| 247 | ct_ok ct_is 10 0 |
| 248 | ct_set 1 0 1 |
| 249 | ct_act 3 0 2 3 |
| 250 | ct_ok ct_is 10 0 |
| 251 | ct_set 1 0 1 |
| 252 | ct_act 2 0 2 3 |
| 253 | ct_ok ct_is 0 3 |
| 254 | ct_set 3 0 2 |
| 255 | ct_act 2 0 2 3 |
| 256 | ct_ok ct_is 0 3 |
| 257 | ct_set 4 1 2 |
| 258 | ct_act 2 0 2 3 |
| 259 | ct_ok ct_is 10 0 |
| 260 | ct_edits |
| 261 | ct_answers |
| 262 | end |
| 263 | |
| 264 | fn ct_edits to void |
| 265 | u = new uchar 4096 0 |
| 266 | ct_set 2 0 1 |
| 267 | ct_act 3 0 4 3 |
| 268 | ct_ok ct_is 13 0 |
| 269 | ct_set 2 0 1 |
| 270 | ct_act 3 0 5 3 |
| 271 | ct_ok ct_is 13 0 |
| 272 | ct_set 2 0 1 |
| 273 | ct_act 3 0 6 3 |
| 274 | ct_ok ct_is 13 0 |
| 275 | ct_set 2 0 1 |
| 276 | ct_act 3 0 2 7 |
| 277 | ct_ok ct_is 13 0 |
| 278 | ct_set 2 0 1 |
| 279 | ct_act 3 1 2 3 |
| 280 | ct_ok ct_is 11 0 |
| 281 | ct_set 2 0 1 |
| 282 | ct_act 3 0 2 3 |
| 283 | ct_ok ct_is 0 4 |
| 284 | n = cw_ld u 4 0 |
| 285 | ct_ok cw_eq view part u 0 n ctfix |
| 286 | end |
| 287 | |
| 288 | fn ct_answers to void |
| 289 | ct_set 4 0 1 |
| 290 | ct_ans 4 cttp |
| 291 | ct_ok ct_is 14 0 |
| 292 | ct_set 3 0 2 |
| 293 | ct_ans 4 cttp |
| 294 | ct_ok ct_is 14 0 |
| 295 | ct_set 4 1 2 |
| 296 | ct_ans 4 cttp |
| 297 | ct_ok ct_is 0 5 |
| 298 | ct_set 0 0 0 |
| 299 | ct_ans 5 ctfnf |
| 300 | ct_ok ct_is 10 0 |
| 301 | ct_set 5 0 0 |
| 302 | ct_ans 5 ctfnf |
| 303 | ct_ok ct_is 1 0 |
| 304 | end |
| 305 | |
| 306 | note Malformed model records. |
| 307 | fn ct_bad to void |
| 308 | b = new uchar 4096 0 |
| 309 | ct_set 0 0 0 |
| 310 | p = cw_cat b 0 ctomnt |
| 311 | cw_ires ct_c 0 b |
| 312 | ct_ok ct_is 18 0 |
| 313 | ct_set 0 0 0 |
| 314 | p = cw_cat b 0 ctomni |
| 315 | p = cw_dec b p 4 |
| 316 | p = ct_nums b p 0 0 |
| 317 | p = ct_tail b p 0 3969 |
| 318 | cw_ires ct_c 0 b |
| 319 | ct_ok ct_is 18 0 |
| 320 | ct_set 0 0 0 |
| 321 | p = cw_cat b 0 ctomni |
| 322 | p = cw_dec b p 4 |
| 323 | p = cw_cat b p cwnl |
| 324 | cw_ires ct_c 0 b |
| 325 | ct_ok ct_is 18 0 |
| 326 | end |
| 327 | |
| 328 | note Tool records. |
| 329 | fn ct_tools to void |
| 330 | u = new uchar 4096 0 |
| 331 | ct_set 0 0 0 |
| 332 | ct_tool 2 0 ctrs ctsrc |
| 333 | ct_ok and ct_is 0 0 eq cw_g 0 6 1 |
| 334 | n = cw_ld u 2 0 |
| 335 | ct_ok cw_eq view part u 0 n ctsrc |
| 336 | ct_set 0 0 0 |
| 337 | ct_tool 2 1 ctfnf ctes |
| 338 | ct_ok and ct_is 0 0 eq cw_g 0 6 5 |
| 339 | ct_set 0 0 0 |
| 340 | ct_tool 2 2 ctfnf ctes |
| 341 | ct_ok ct_is 17 0 |
| 342 | ct_set 1 0 1 |
| 343 | ct_tool 3 6 cttf ctsrc |
| 344 | ct_ok and ct_is 0 0 and eq cw_g 0 6 2 eq cw_g 0 8 0 |
| 345 | ct_set 1 0 1 |
| 346 | ct_tool 3 6 cttf ctfix |
| 347 | ct_ok ct_is 15 0 |
| 348 | ct_set 3 0 2 |
| 349 | ct_tool 3 0 cttp ctfix |
| 350 | ct_ok and ct_is 0 0 and eq cw_g 0 6 4 eq cw_g 0 8 1 |
| 351 | ct_set 3 0 2 |
| 352 | ct_tool 3 4 cttp ctfix |
| 353 | ct_ok ct_is 17 0 |
| 354 | ct_saves |
| 355 | end |
| 356 | |
| 357 | fn ct_saves to void |
| 358 | ct_set 2 0 1 |
| 359 | ct_act 3 0 2 3 |
| 360 | ct_ok ct_is 0 4 |
| 361 | cw_s 0 10 0 |
| 362 | ct_tool 4 0 ctes ctfix |
| 363 | ct_ok and ct_is 0 0 eq cw_g 0 6 3 |
| 364 | ct_set 2 0 1 |
| 365 | cw_s 0 15 0 |
| 366 | ct_tool 4 0 ctes ctfix |
| 367 | ct_ok ct_is 15 0 |
| 368 | ct_set 2 0 1 |
| 369 | ct_tool 4 5 ctes ctsrc |
| 370 | ct_ok ct_is 13 0 |
| 371 | ct_set 4 1 2 |
| 372 | ct_tool 5 0 cttp ctfix |
| 373 | ct_ok ct_is 1 0 |
| 374 | ct_set 4 1 2 |
| 375 | ct_tool 5 6 cttf ctfix |
| 376 | ct_ok ct_is 15 0 |
| 377 | ct_set 4 1 2 |
| 378 | ct_tool 5 0 cttp ctsrc |
| 379 | ct_ok ct_is 15 0 |
| 380 | end |
| 381 | |
| 382 | note Job outcome words. |
| 383 | fn ct_fates to void |
| 384 | ct_ok eq cw_fate 2 1 0 |
| 385 | ct_ok eq cw_fate or ulong 2 shl ulong 1024 8 1 16 |
| 386 | ct_ok eq cw_fate or ulong 2 shl ulong 1280 8 1 16 |
| 387 | ct_ok eq cw_fate or ulong 2 shl ulong 2048 8 1 16 |
| 388 | ct_ok eq cw_fate or ulong 2 shl ulong 256 8 3 17 |
| 389 | ct_ok eq cw_fate or ulong 2 shl ulong 9 8 1 21 |
| 390 | ct_ok eq cw_fate or ulong 1 shl ulong 9 8 1 19 |
| 391 | ct_ok eq cw_fate 22 1 19 |
| 392 | ct_ok eq cw_fate 0 4 21 |
| 393 | ct_ok eq cw_fate 90 2 22 |
| 394 | ct_ok eq cw_fate 18 2 23 |
| 395 | end |
| 396 | |
| 397 | note Turn limit and prompt length. |
| 398 | fn ct_limits c long to void |
| 399 | sp = new uchar 4096 0 |
| 400 | ct_set 1 0 0 |
| 401 | cw_s 0 7 7 |
| 402 | cw_plan c |
| 403 | ct_ok ct_is 12 0 |
| 404 | for j ulong 3790 |
| 405 | put sp j 32 |
| 406 | end |
| 407 | ct_set 1 0 0 |
| 408 | cw_setsrc 0 view part sp 0 3790 |
| 409 | cw_s 0 7 0 |
| 410 | cw_plan c |
| 411 | ct_ok ct_is 20 0 |
| 412 | ct_set 0 0 0 |
| 413 | cw_plan c |
| 414 | ct_ok and ct_is 0 1 eq cw_g 0 7 1 |
| 415 | end |
| 416 | |
| 417 | note The cancel hook with a journal that refuses (DRA-398 review r2): a |
| 418 | note job running in a free slot as objective 0's inference, the hook armed |
| 419 | note and due. auth_cancel refuses (-5): nothing traps, the job keeps |
| 420 | note running and the hook stays armed. Everything is restored after. |
| 421 | fn ct_hook c long to void |
| 422 | s = ulong 64 |
| 423 | for j ulong 64 |
| 424 | if eq get sjst j 0 |
| 425 | s = j |
| 426 | end |
| 427 | end |
| 428 | ct_ok lt s 64 |
| 429 | if ge s 64 |
| 430 | ret |
| 431 | end |
| 432 | ct_set 1 0 0 |
| 433 | cw_s 0 9 1 |
| 434 | cw_s 0 10 4242 |
| 435 | put cwt0 0 0 |
| 436 | put sjid s 4242 |
| 437 | put sjst s 3 |
| 438 | put cwtk 0 1 |
| 439 | put cwtk 1 0 |
| 440 | put jbad 0 1 |
| 441 | cw_hook c |
| 442 | ct_ok and eq get cwtk 0 1 eq get sjst s 3 |
| 443 | put jbad 0 0 |
| 444 | put cwtk 0 0 |
| 445 | put sjst s 0 |
| 446 | put sjid s 0 |
| 447 | ct_set 0 0 0 |
| 448 | end |
| 449 | |
| 450 | note A full queue: a refused inference is asked for again (the objective |
| 451 | note keeps waiting for a turn); a refused tool job ends the objective with |
| 452 | note 23; both refusals are counted for the view. |
| 453 | fn ct_full c long to void |
| 454 | for k ulong 64 |
| 455 | if lt jn_admit add 9001 k 0 1 0 |
| 456 | break |
| 457 | end |
| 458 | end |
| 459 | r0 = vw_cget 0 |
| 460 | ct_set 0 0 0 |
| 461 | cw_plan c |
| 462 | ct_ok and ct_is 0 0 eq cw_g 0 9 0 |
| 463 | ct_set 1 0 1 |
| 464 | cw_tool c 0 3 |
| 465 | ct_ok ct_is 23 0 |
| 466 | ct_ok eq vw_cget 0 add r0 2 |
| 467 | end |
| 468 | |
| 469 | fn ct_unit to int |
| 470 | if lt argcnt 3 |
| 471 | ret 2 |
| 472 | end |
| 473 | d = new uchar 1024 0 |
| 474 | n = argread 2 d 0 1000 |
| 475 | if lt n 1 |
| 476 | ret 2 |
| 477 | end |
| 478 | for k ulong 7 |
| 479 | put cwcl k 1 |
| 480 | put cwcf mul k 1024 47 |
| 481 | end |
| 482 | r = makedir d 0 ulong n 448 |
| 483 | if and lt r 0 ne r neg long 17 |
| 484 | ret 59 |
| 485 | end |
| 486 | if ne chdir d 0 ulong n 0 |
| 487 | ret 59 |
| 488 | end |
| 489 | put cwno 0 1 |
| 490 | if not cw_parse 0 ctobj |
| 491 | ret 3 |
| 492 | end |
| 493 | c = pool_new 4 2 |
| 494 | if le c 0 |
| 495 | ret 50 |
| 496 | end |
| 497 | put ctc 0 ulong c |
| 498 | if ne sup_init c 0 |
| 499 | ret 51 |
| 500 | end |
| 501 | if ne sched_new c 8 8 0 |
| 502 | ret 52 |
| 503 | end |
| 504 | if ne auth_new c 0 |
| 505 | ret 53 |
| 506 | end |
| 507 | ct_newjournal |
| 508 | ct_prompt |
| 509 | ct_model |
| 510 | ct_bad |
| 511 | ct_tools |
| 512 | ct_fates |
| 513 | ct_limits c |
| 514 | ct_hook c |
| 515 | ct_full c |
| 516 | ct_set 0 0 0 |
| 517 | put jbad 0 1 |
| 518 | cw_end 0 1 |
| 519 | ct_ok and ne get cwresultbad 0 0 and eq cw_g 0 12 0 eq jn_res 0 0 |
| 520 | put jbad 0 0 |
| 521 | jn_close |
| 522 | ret ct_end |
| 523 | end |
| 524 | |
| 525 | fn ct_end to int |
| 526 | o = new uchar 4096 0 |
| 527 | p = cw_cat o 0 ctsum |
| 528 | p = cw_dec o p get ctn 0 |
| 529 | p = cw_cat o p ctsum2 |
| 530 | p = cw_dec o p get ctn 1 |
| 531 | p = cw_cat o p cwnl |
| 532 | cw_out o p |
| 533 | if eq get ctn 1 0 |
| 534 | ret 0 |
| 535 | end |
| 536 | ret int add 150 get ctn 2 |
| 537 | end |
| 538 | |
| 539 | fn ct_mode to ulong |
| 540 | b = new uchar 16 0 |
| 541 | n = argread 1 b 0 16 |
| 542 | if lt n 1 |
| 543 | ret 0 |
| 544 | end |
| 545 | if cw_eq view part b 0 ulong n ctunit |
| 546 | ret 1 |
| 547 | end |
| 548 | if cw_eq view part b 0 ulong n ctcanc |
| 549 | ret 2 |
| 550 | end |
| 551 | if cw_eq view part b 0 ulong n ctover |
| 552 | ret 3 |
| 553 | end |
| 554 | if cw_eq view part b 0 ulong n ctunc |
| 555 | ret 4 |
| 556 | end |
| 557 | ret 0 |
| 558 | end |
| 559 | |
| 560 | fn main to int |
| 561 | m = ct_mode |
| 562 | if eq m 1 |
| 563 | ret ct_unit |
| 564 | end |
| 565 | if eq m 2 |
| 566 | ms = ct_num 2 |
| 567 | put cwtk 0 1 |
| 568 | put cwtk 1 ms |
| 569 | ret cw_main 3 3600 |
| 570 | end |
| 571 | if eq m 3 |
| 572 | q = ct_num 2 |
| 573 | if eq q 0 |
| 574 | ret 2 |
| 575 | end |
| 576 | put cwql 0 q |
| 577 | ret cw_main 3 3600 |
| 578 | end |
| 579 | if eq m 4 |
| 580 | put cwtu 0 1 |
| 581 | ret cw_main 2 3600 |
| 582 | end |
| 583 | ret 2 |
| 584 | end |
| 585 | |
| 586 | note Argument i as a decimal of at most 7 digits; 0 when malformed. |
| 587 | fn ct_num i ulong to ulong |
| 588 | b = new uchar 16 0 |
| 589 | n = argread i b 0 16 |
| 590 | if or lt n 1 gt n 7 |
| 591 | ret 0 |
| 592 | end |
| 593 | v = ulong 0 |
| 594 | for j ulong ulong n |
| 595 | c = ulong get b j |
| 596 | if or lt c 48 gt c 57 |
| 597 | ret 0 |
| 598 | end |
| 599 | v = add mul v 10 sub c 48 |
| 600 | end |
| 601 | ret v |
| 602 | end |