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 / helix / ollm_factory / architect_client.om
| 1 | om2 |
| 2 | note SPDX-License-Identifier: Apache-2.0 |
| 3 | note seed/helix/ollm_factory/architect_client.om: |
| 4 | note Pure seeded OM-2 Stage 1 Architect Batch Client & Plan Validator for the |
| 5 | note 4-Strand Architect-Builder RLVR Pipeline (Single DGX Spark / GB10). |
| 6 | note |
| 7 | note Subcommands: |
| 8 | note plan <port|0> <tasks_tsv> <plans_tsv> |
| 9 | note requeue <attr_tsv> <requeue_tsv> |
| 10 | note selfcheck |
| 11 | |
| 12 | global acInBuf uchar 65536 |
| 13 | global acOutBuf uchar 131072 |
| 14 | global acReqBuf uchar 4096 |
| 15 | global acRspBuf uchar 8192 |
| 16 | global acLine uchar 1024 |
| 17 | global acFld0 uchar 128 |
| 18 | global acFld1 uchar 128 |
| 19 | global acFld2 uchar 512 |
| 20 | global acPlanBuf uchar 2048 |
| 21 | global acInPath uchar 256 |
| 22 | global acOutPath uchar 256 |
| 23 | global acOutPos ulong 1 |
| 24 | global acCounts ulong 4 |
| 25 | |
| 26 | text acHdrPlan "task_id\tfamily\tstrand\torig_prompt\tarch_plan\tassert_cnt\n" |
| 27 | text acHdrReq "task_id\tfamily\tstrand\tfault_class\tstrict_prompt\n" |
| 28 | text acModePlan "plan" |
| 29 | text acModeReq "requeue" |
| 30 | text acModeSelf "selfcheck" |
| 31 | |
| 32 | text acFamArith "arith" |
| 33 | text acFamBranch "branch" |
| 34 | text acFamBits "bits" |
| 35 | text acFamDigits "digits" |
| 36 | text acFamLoop "loop" |
| 37 | text acFamFold "fold" |
| 38 | text acFamSelect "select" |
| 39 | text acFamCount "count" |
| 40 | text acFamScan "scan" |
| 41 | text acFamRewrite "rewrite" |
| 42 | text acFamRepair "repair" |
| 43 | |
| 44 | text acFltLogic "ARCHITECT_LOGIC_FLAW" |
| 45 | text acFltUnder "UNDERSPECIFIED_PLAN" |
| 46 | |
| 47 | text acRawFn "fn solve" |
| 48 | text acRawRet "ret " |
| 49 | text acAssTok "ASSERT(" |
| 50 | |
| 51 | text acHttpPre "POST /v1/chat/completions HTTP/1.1\nHost: 127.0.0.1\nContent-Type: application/json\nContent-Length: " |
| 52 | text acHttpMid "\nConnection: close\n\n" |
| 53 | text acJsonPre "{\"model\":\"qwen3.6-35b-a3b\",\"max_tokens\":384,\"temperature\":0,\"messages\":[{\"role\":\"user\",\"content\":\"Reply ONLY with a concise 1-paragraph language-neutral algorithm plan (NO code, NO fn/ret/end). Format: PLAN: <steps>; EDGE: <edge cases>; ASSERT(in1->out1) ASSERT(in2->out2) ASSERT(in3->out3). Example: PLAN: multiply a by 3 and add 1; EDGE: a=0; ASSERT(0->1) ASSERT(1->4) ASSERT(4->13). Task: " |
| 54 | text acJsonSuf "\"}]}" |
| 55 | text acJsonKey "\"content\":\"" |
| 56 | |
| 57 | text acOffS1 "PLAN: parse scalar inputs, validate bounds, apply exact arithmetic/branch rule; EDGE: zero and max; ASSERT(0->0) ASSERT(1->1) ASSERT(7->7)" |
| 58 | text acOffS2 "PLAN: initialize accumulator=0, iterate over bounded sequence updating state, handle empty n=0; EDGE: n=0,n=1; ASSERT(empty->0) ASSERT(one->a0) ASSERT(many->fold)" |
| 59 | text acOffS3 "PLAN: scan array in-place with explicit loop bound, apply deterministic rewrite rule, preserve untouched slots; EDGE: n=0,all-match; ASSERT(n0->noop) ASSERT(n1->upd) ASSERT(n8->upd)" |
| 60 | text acOffS4 "PLAN: inspect omc diagnostic and failing test vector, isolate offending expression or loop bound, apply minimal verified patch; EDGE: type-cast,bound; ASSERT(old->fail) ASSERT(fix->compile) ASSERT(fix->pass)" |
| 61 | |
| 62 | text acReqLogic "REQUEUE_LOGIC_FIX: Previous plan caused all 4 Builder strands to return the identical wrong output. Re-derive step-by-step invariants and verify all 4 ASSERT(in->out) vectors by hand before emitting the revised language-neutral plan." |
| 63 | text acReqUnder "REQUEUE_DECOMPOSE: Previous plan caused divergent wrong outputs across Builder strands. Decompose into smaller helper sub-functions with explicit intermediate ASSERT(in->out) checks and exact boundary conditions." |
| 64 | |
| 65 | text acMsgSelfOk "ARCHITECT_CLIENT SELFCHECK PASS routes=10/10 json_esc=1 raw_om2_rejected=1 min_asserts_enforced=1 offline_plan=1\n" |
| 66 | text acMsgPlanOk "ARCHITECT_PLAN_BATCH PASS tasks=" |
| 67 | text acMsgPlanRej " rejected=" |
| 68 | text acMsgPlanLive " live_tcp=" |
| 69 | text acMsgReqOk "ARCHITECT_REQUEUE PASS queued=" |
| 70 | text acMsgUsage "usage: architect_client <plan port in out | requeue attr out | selfcheck>\n" |
| 71 | text acNl "\n" |
| 72 | |
| 73 | fn acWrt1 s view uchar * to void |
| 74 | r = write 1 s 0 len s |
| 75 | end |
| 76 | |
| 77 | fn acWrt2 s view uchar * to void |
| 78 | r = write 2 s 0 len s |
| 79 | end |
| 80 | |
| 81 | fn acNum1 v ulong to void |
| 82 | b = new uchar 24 0 |
| 83 | p = ulong 24 |
| 84 | x = v |
| 85 | while true bound 24 |
| 86 | p = sub p 1 |
| 87 | put b p uchar add 48 rem x 10 |
| 88 | x = div x 10 |
| 89 | if eq x 0 |
| 90 | break |
| 91 | end |
| 92 | end |
| 93 | r = write 1 b p sub 24 p |
| 94 | end |
| 95 | |
| 96 | fn acEqBuf a view uchar * al ulong b view uchar * to bool |
| 97 | if ne al len b |
| 98 | ret false |
| 99 | end |
| 100 | for i ulong al bound 1024 |
| 101 | if ne get a i get b i |
| 102 | ret false |
| 103 | end |
| 104 | end |
| 105 | ret true |
| 106 | end |
| 107 | |
| 108 | fn acEqFld1 al ulong b view uchar * to bool |
| 109 | if ne al len b |
| 110 | ret false |
| 111 | end |
| 112 | for i ulong al bound 128 |
| 113 | if ne get acFld1 i get b i |
| 114 | ret false |
| 115 | end |
| 116 | end |
| 117 | ret true |
| 118 | end |
| 119 | |
| 120 | fn acEqFld2 al ulong b view uchar * to bool |
| 121 | if ne al len b |
| 122 | ret false |
| 123 | end |
| 124 | for i ulong al bound 512 |
| 125 | if ne get acFld2 i get b i |
| 126 | ret false |
| 127 | end |
| 128 | end |
| 129 | ret true |
| 130 | end |
| 131 | |
| 132 | fn acParseUlong a view uchar * al ulong to ulong |
| 133 | v = ulong 0 |
| 134 | for i ulong al bound 32 |
| 135 | c = get a i |
| 136 | if and ge c 48 le c 57 |
| 137 | v = add mul v 10 ulong sub c 48 |
| 138 | end |
| 139 | end |
| 140 | ret v |
| 141 | end |
| 142 | |
| 143 | fn acOutReset to void |
| 144 | put acOutPos 0 0 |
| 145 | end |
| 146 | |
| 147 | fn acOutByte c uchar to void |
| 148 | p = get acOutPos 0 |
| 149 | if lt p 131070 |
| 150 | put acOutBuf p c |
| 151 | put acOutPos 0 add p 1 |
| 152 | end |
| 153 | end |
| 154 | |
| 155 | fn acOutStr s view uchar * to void |
| 156 | for i ulong len s bound 2048 |
| 157 | acOutByte get s i |
| 158 | end |
| 159 | end |
| 160 | |
| 161 | fn acOutFld which ulong n ulong to void |
| 162 | if eq which 0 |
| 163 | for i ulong n bound 128 |
| 164 | acOutByte get acFld0 i |
| 165 | end |
| 166 | ret |
| 167 | end |
| 168 | if eq which 1 |
| 169 | for i ulong n bound 128 |
| 170 | acOutByte get acFld1 i |
| 171 | end |
| 172 | ret |
| 173 | end |
| 174 | if eq which 2 |
| 175 | for i ulong n bound 512 |
| 176 | acOutByte get acFld2 i |
| 177 | end |
| 178 | ret |
| 179 | end |
| 180 | for i ulong n bound 2048 |
| 181 | acOutByte get acPlanBuf i |
| 182 | end |
| 183 | end |
| 184 | |
| 185 | fn acOutNum v ulong to void |
| 186 | b = new uchar 24 0 |
| 187 | p = ulong 24 |
| 188 | x = v |
| 189 | while true bound 24 |
| 190 | p = sub p 1 |
| 191 | put b p uchar add 48 rem x 10 |
| 192 | x = div x 10 |
| 193 | if eq x 0 |
| 194 | break |
| 195 | end |
| 196 | end |
| 197 | while lt p 24 bound 24 |
| 198 | acOutByte get b p |
| 199 | p = add p 1 |
| 200 | end |
| 201 | end |
| 202 | |
| 203 | fn acHasSub hay view uchar * hl ulong ndl view uchar * to bool |
| 204 | nl = len ndl |
| 205 | if or eq nl 0 gt nl hl |
| 206 | ret false |
| 207 | end |
| 208 | lim = add sub hl nl 1 |
| 209 | for i ulong lim bound 8192 |
| 210 | ok = true |
| 211 | for j ulong nl bound 64 |
| 212 | if ne get hay add i j get ndl j |
| 213 | ok = false |
| 214 | break |
| 215 | end |
| 216 | end |
| 217 | if ok |
| 218 | ret true |
| 219 | end |
| 220 | end |
| 221 | ret false |
| 222 | end |
| 223 | |
| 224 | fn acCountSub hay view uchar * hl ulong ndl view uchar * to ulong |
| 225 | nl = len ndl |
| 226 | if or eq nl 0 gt nl hl |
| 227 | ret 0 |
| 228 | end |
| 229 | cnt = ulong 0 |
| 230 | lim = add sub hl nl 1 |
| 231 | for i ulong lim bound 8192 |
| 232 | ok = true |
| 233 | for j ulong nl bound 64 |
| 234 | if ne get hay add i j get ndl j |
| 235 | ok = false |
| 236 | break |
| 237 | end |
| 238 | end |
| 239 | if ok |
| 240 | cnt = add cnt 1 |
| 241 | end |
| 242 | end |
| 243 | ret cnt |
| 244 | end |
| 245 | |
| 246 | fn acPlanHasSub pl ulong ndl view uchar * to bool |
| 247 | nl = len ndl |
| 248 | if or eq nl 0 gt nl pl |
| 249 | ret false |
| 250 | end |
| 251 | lim = add sub pl nl 1 |
| 252 | for i ulong lim bound 2048 |
| 253 | ok = true |
| 254 | for j ulong nl bound 64 |
| 255 | if ne get acPlanBuf add i j get ndl j |
| 256 | ok = false |
| 257 | break |
| 258 | end |
| 259 | end |
| 260 | if ok |
| 261 | ret true |
| 262 | end |
| 263 | end |
| 264 | ret false |
| 265 | end |
| 266 | |
| 267 | fn acPlanCountSub pl ulong ndl view uchar * to ulong |
| 268 | nl = len ndl |
| 269 | if or eq nl 0 gt nl pl |
| 270 | ret 0 |
| 271 | end |
| 272 | cnt = ulong 0 |
| 273 | lim = add sub pl nl 1 |
| 274 | for i ulong lim bound 2048 |
| 275 | ok = true |
| 276 | for j ulong nl bound 64 |
| 277 | if ne get acPlanBuf add i j get ndl j |
| 278 | ok = false |
| 279 | break |
| 280 | end |
| 281 | end |
| 282 | if ok |
| 283 | cnt = add cnt 1 |
| 284 | end |
| 285 | end |
| 286 | ret cnt |
| 287 | end |
| 288 | |
| 289 | fn acFamilyStrand fam view uchar * fl ulong to ulong |
| 290 | if acEqBuf fam fl acFamArith |
| 291 | ret 1 |
| 292 | end |
| 293 | if acEqBuf fam fl acFamBranch |
| 294 | ret 1 |
| 295 | end |
| 296 | if acEqBuf fam fl acFamBits |
| 297 | ret 1 |
| 298 | end |
| 299 | if acEqBuf fam fl acFamDigits |
| 300 | ret 1 |
| 301 | end |
| 302 | if acEqBuf fam fl acFamLoop |
| 303 | ret 2 |
| 304 | end |
| 305 | if acEqBuf fam fl acFamFold |
| 306 | ret 2 |
| 307 | end |
| 308 | if acEqBuf fam fl acFamSelect |
| 309 | ret 2 |
| 310 | end |
| 311 | if acEqBuf fam fl acFamCount |
| 312 | ret 2 |
| 313 | end |
| 314 | if acEqBuf fam fl acFamScan |
| 315 | ret 2 |
| 316 | end |
| 317 | if acEqBuf fam fl acFamRewrite |
| 318 | ret 3 |
| 319 | end |
| 320 | if acEqBuf fam fl acFamRepair |
| 321 | ret 4 |
| 322 | end |
| 323 | ret 1 |
| 324 | end |
| 325 | |
| 326 | fn acFamilyStrandFld1 fl ulong to ulong |
| 327 | if acEqFld1 fl acFamArith |
| 328 | ret 1 |
| 329 | end |
| 330 | if acEqFld1 fl acFamBranch |
| 331 | ret 1 |
| 332 | end |
| 333 | if acEqFld1 fl acFamBits |
| 334 | ret 1 |
| 335 | end |
| 336 | if acEqFld1 fl acFamDigits |
| 337 | ret 1 |
| 338 | end |
| 339 | if acEqFld1 fl acFamLoop |
| 340 | ret 2 |
| 341 | end |
| 342 | if acEqFld1 fl acFamFold |
| 343 | ret 2 |
| 344 | end |
| 345 | if acEqFld1 fl acFamSelect |
| 346 | ret 2 |
| 347 | end |
| 348 | if acEqFld1 fl acFamCount |
| 349 | ret 2 |
| 350 | end |
| 351 | if acEqFld1 fl acFamScan |
| 352 | ret 2 |
| 353 | end |
| 354 | if acEqFld1 fl acFamRewrite |
| 355 | ret 3 |
| 356 | end |
| 357 | if acEqFld1 fl acFamRepair |
| 358 | ret 4 |
| 359 | end |
| 360 | ret 1 |
| 361 | end |
| 362 | |
| 363 | fn acValidatePlan p view uchar * pl ulong to ulong |
| 364 | if eq pl 0 |
| 365 | ret 0 |
| 366 | end |
| 367 | if acHasSub p pl acRawFn |
| 368 | ret 0 |
| 369 | end |
| 370 | if acHasSub p pl acRawRet |
| 371 | ret 0 |
| 372 | end |
| 373 | acnt = acCountSub p pl acAssTok |
| 374 | if lt acnt 3 |
| 375 | ret 0 |
| 376 | end |
| 377 | ret acnt |
| 378 | end |
| 379 | |
| 380 | fn acValidatePlanBuf pl ulong to ulong |
| 381 | if eq pl 0 |
| 382 | ret 0 |
| 383 | end |
| 384 | if acPlanHasSub pl acRawFn |
| 385 | ret 0 |
| 386 | end |
| 387 | if acPlanHasSub pl acRawRet |
| 388 | ret 0 |
| 389 | end |
| 390 | acnt = acPlanCountSub pl acAssTok |
| 391 | if lt acnt 3 |
| 392 | ret 0 |
| 393 | end |
| 394 | ret acnt |
| 395 | end |
| 396 | |
| 397 | fn acReadInFile plen ulong to ulong |
| 398 | fd = fopen acInPath 0 plen 0 0 |
| 399 | if lt fd 0 |
| 400 | ret 0 |
| 401 | end |
| 402 | tot = ulong 0 |
| 403 | while lt tot 65536 bound 256 |
| 404 | r = read int fd acInBuf tot sub 65536 tot |
| 405 | if le r 0 |
| 406 | break |
| 407 | end |
| 408 | tot = add tot ulong r |
| 409 | end |
| 410 | z = fclose int fd |
| 411 | ret tot |
| 412 | end |
| 413 | |
| 414 | fn acWriteOutFile plen ulong to bool |
| 415 | fd = fopen acOutPath 0 plen 577 420 |
| 416 | if lt fd 0 |
| 417 | ret false |
| 418 | end |
| 419 | n = get acOutPos 0 |
| 420 | off = ulong 0 |
| 421 | while lt off n bound 256 |
| 422 | w = write int fd acOutBuf off sub n off |
| 423 | if le w 0 |
| 424 | z = fclose int fd |
| 425 | ret false |
| 426 | end |
| 427 | off = add off ulong w |
| 428 | end |
| 429 | z = fclose int fd |
| 430 | ret true |
| 431 | end |
| 432 | |
| 433 | fn acMakeOfflinePlan strand ulong to ulong |
| 434 | p = ulong 0 |
| 435 | if eq strand 1 |
| 436 | for i ulong len acOffS1 bound 512 |
| 437 | put acPlanBuf p get acOffS1 i |
| 438 | p = add p 1 |
| 439 | end |
| 440 | ret p |
| 441 | end |
| 442 | if eq strand 2 |
| 443 | for i ulong len acOffS2 bound 512 |
| 444 | put acPlanBuf p get acOffS2 i |
| 445 | p = add p 1 |
| 446 | end |
| 447 | ret p |
| 448 | end |
| 449 | if eq strand 3 |
| 450 | for i ulong len acOffS3 bound 512 |
| 451 | put acPlanBuf p get acOffS3 i |
| 452 | p = add p 1 |
| 453 | end |
| 454 | ret p |
| 455 | end |
| 456 | for i ulong len acOffS4 bound 512 |
| 457 | put acPlanBuf p get acOffS4 i |
| 458 | p = add p 1 |
| 459 | end |
| 460 | ret p |
| 461 | end |
| 462 | |
| 463 | fn acBuildJsonBody prompt view uchar * pl ulong dst edit uchar * cap ulong to ulong |
| 464 | p = ulong 0 |
| 465 | for i ulong len acJsonPre bound 512 |
| 466 | if lt p cap |
| 467 | put dst p get acJsonPre i |
| 468 | p = add p 1 |
| 469 | end |
| 470 | end |
| 471 | for i ulong pl bound 512 |
| 472 | c = get prompt i |
| 473 | if or eq c 34 eq c 92 |
| 474 | if lt add p 2 cap |
| 475 | put dst p 92 |
| 476 | put dst add p 1 c |
| 477 | p = add p 2 |
| 478 | end |
| 479 | else |
| 480 | if or eq c 10 or eq c 13 eq c 9 |
| 481 | if lt p cap |
| 482 | put dst p 32 |
| 483 | p = add p 1 |
| 484 | end |
| 485 | else |
| 486 | if lt p cap |
| 487 | put dst p c |
| 488 | p = add p 1 |
| 489 | end |
| 490 | end |
| 491 | end |
| 492 | end |
| 493 | for i ulong len acJsonSuf bound 64 |
| 494 | if lt p cap |
| 495 | put dst p get acJsonSuf i |
| 496 | p = add p 1 |
| 497 | end |
| 498 | end |
| 499 | ret p |
| 500 | end |
| 501 | |
| 502 | fn acBuildJsonFromFld2 pl ulong dst edit uchar * cap ulong to ulong |
| 503 | p = ulong 0 |
| 504 | for i ulong len acJsonPre bound 512 |
| 505 | if lt p cap |
| 506 | put dst p get acJsonPre i |
| 507 | p = add p 1 |
| 508 | end |
| 509 | end |
| 510 | for i ulong pl bound 512 |
| 511 | c = get acFld2 i |
| 512 | if or eq c 34 eq c 92 |
| 513 | if lt add p 2 cap |
| 514 | put dst p 92 |
| 515 | put dst add p 1 c |
| 516 | p = add p 2 |
| 517 | end |
| 518 | else |
| 519 | if or eq c 10 or eq c 13 eq c 9 |
| 520 | if lt p cap |
| 521 | put dst p 32 |
| 522 | p = add p 1 |
| 523 | end |
| 524 | else |
| 525 | if lt p cap |
| 526 | put dst p c |
| 527 | p = add p 1 |
| 528 | end |
| 529 | end |
| 530 | end |
| 531 | end |
| 532 | for i ulong len acJsonSuf bound 64 |
| 533 | if lt p cap |
| 534 | put dst p get acJsonSuf i |
| 535 | p = add p 1 |
| 536 | end |
| 537 | end |
| 538 | ret p |
| 539 | end |
| 540 | |
| 541 | fn acExtractJsonContent rlen ulong to ulong |
| 542 | kl = len acJsonKey |
| 543 | if lt rlen kl |
| 544 | ret 0 |
| 545 | end |
| 546 | lim = add sub rlen kl 1 |
| 547 | start = ulong 0 |
| 548 | found = false |
| 549 | for i ulong lim bound 8192 |
| 550 | ok = true |
| 551 | for j ulong kl bound 32 |
| 552 | if ne get acRspBuf add i j get acJsonKey j |
| 553 | ok = false |
| 554 | break |
| 555 | end |
| 556 | end |
| 557 | if ok |
| 558 | start = add i kl |
| 559 | found = true |
| 560 | break |
| 561 | end |
| 562 | end |
| 563 | if not found |
| 564 | ret 0 |
| 565 | end |
| 566 | p = ulong 0 |
| 567 | i = start |
| 568 | while lt i rlen bound 2048 |
| 569 | c = get acRspBuf i |
| 570 | if eq c 34 |
| 571 | break |
| 572 | end |
| 573 | if eq c 92 |
| 574 | i = add i 1 |
| 575 | if ge i rlen |
| 576 | break |
| 577 | end |
| 578 | nx = get acRspBuf i |
| 579 | if or eq nx 110 eq nx 116 |
| 580 | c = uchar 32 |
| 581 | else |
| 582 | c = nx |
| 583 | end |
| 584 | end |
| 585 | if or eq c 10 or eq c 13 eq c 9 |
| 586 | c = uchar 32 |
| 587 | end |
| 588 | if lt p 2000 |
| 589 | put acPlanBuf p c |
| 590 | p = add p 1 |
| 591 | end |
| 592 | i = add i 1 |
| 593 | end |
| 594 | ret p |
| 595 | end |
| 596 | |
| 597 | fn acBuildHttpReq blen ulong body view uchar * to ulong |
| 598 | nbuf = new uchar 16 0 |
| 599 | rp = ulong 0 |
| 600 | for i ulong len acHttpPre bound 256 |
| 601 | c = get acHttpPre i |
| 602 | if eq c 10 |
| 603 | put acReqBuf rp 13 |
| 604 | rp = add rp 1 |
| 605 | end |
| 606 | put acReqBuf rp c |
| 607 | rp = add rp 1 |
| 608 | end |
| 609 | np = ulong 16 |
| 610 | x = blen |
| 611 | while true bound 16 |
| 612 | np = sub np 1 |
| 613 | put nbuf np uchar add 48 rem x 10 |
| 614 | x = div x 10 |
| 615 | if eq x 0 |
| 616 | break |
| 617 | end |
| 618 | end |
| 619 | while lt np 16 bound 16 |
| 620 | put acReqBuf rp get nbuf np |
| 621 | rp = add rp 1 |
| 622 | np = add np 1 |
| 623 | end |
| 624 | for i ulong len acHttpMid bound 64 |
| 625 | c = get acHttpMid i |
| 626 | if eq c 10 |
| 627 | put acReqBuf rp 13 |
| 628 | rp = add rp 1 |
| 629 | end |
| 630 | put acReqBuf rp c |
| 631 | rp = add rp 1 |
| 632 | end |
| 633 | for i ulong blen bound 2048 |
| 634 | if lt rp 4094 |
| 635 | put acReqBuf rp get body i |
| 636 | rp = add rp 1 |
| 637 | end |
| 638 | end |
| 639 | ret rp |
| 640 | end |
| 641 | |
| 642 | fn acQueryTcp port ulong pl ulong to ulong |
| 643 | body = new uchar 2048 0 |
| 644 | sa = new uchar 16 0 |
| 645 | blen = acBuildJsonFromFld2 pl body 2048 |
| 646 | fd = socknew 2 1 0 |
| 647 | if lt fd 0 |
| 648 | ret 0 |
| 649 | end |
| 650 | put sa 0 2 |
| 651 | put sa 1 0 |
| 652 | put sa 2 uchar and shr port 8 255 |
| 653 | put sa 3 uchar and port 255 |
| 654 | put sa 4 127 |
| 655 | put sa 5 0 |
| 656 | put sa 6 0 |
| 657 | put sa 7 1 |
| 658 | cr = connect int fd sa 0 16 |
| 659 | if lt cr 0 |
| 660 | z = fclose int fd |
| 661 | ret 0 |
| 662 | end |
| 663 | rp = acBuildHttpReq blen body |
| 664 | wr = write int fd acReqBuf 0 rp |
| 665 | tot = ulong 0 |
| 666 | for it ulong 32 |
| 667 | r = read int fd acRspBuf tot sub 8192 tot |
| 668 | if le r 0 |
| 669 | break |
| 670 | end |
| 671 | tot = add tot ulong r |
| 672 | if ge tot 8192 |
| 673 | break |
| 674 | end |
| 675 | end |
| 676 | z = fclose int fd |
| 677 | if eq tot 0 |
| 678 | ret 0 |
| 679 | end |
| 680 | ret acExtractJsonContent tot |
| 681 | end |
| 682 | |
| 683 | fn acSplitTabTo llen ulong k ulong which ulong to ulong |
| 684 | cur = ulong 0 |
| 685 | p = ulong 0 |
| 686 | cap = ulong 128 |
| 687 | if eq which 2 |
| 688 | cap = 512 |
| 689 | end |
| 690 | for i ulong llen bound 1024 |
| 691 | c = get acLine i |
| 692 | if eq c 9 |
| 693 | cur = add cur 1 |
| 694 | if gt cur k |
| 695 | break |
| 696 | end |
| 697 | else |
| 698 | if eq cur k |
| 699 | if lt p cap |
| 700 | if eq which 0 |
| 701 | put acFld0 p c |
| 702 | else |
| 703 | if eq which 1 |
| 704 | put acFld1 p c |
| 705 | else |
| 706 | put acFld2 p c |
| 707 | end |
| 708 | end |
| 709 | p = add p 1 |
| 710 | end |
| 711 | end |
| 712 | end |
| 713 | end |
| 714 | ret p |
| 715 | end |
| 716 | |
| 717 | fn acPlanOneLine port ulong llen ulong to void |
| 718 | f0l = acSplitTabTo llen 0 0 |
| 719 | f1l = acSplitTabTo llen 1 1 |
| 720 | f2l = acSplitTabTo llen 2 2 |
| 721 | if or eq f0l 0 or eq f1l 0 eq f2l 0 |
| 722 | ret |
| 723 | end |
| 724 | st = acFamilyStrandFld1 f1l |
| 725 | plen = ulong 0 |
| 726 | if gt port 0 |
| 727 | plen = acQueryTcp port f2l |
| 728 | if gt plen 0 |
| 729 | put acCounts 2 add get acCounts 2 1 |
| 730 | end |
| 731 | else |
| 732 | plen = acMakeOfflinePlan st |
| 733 | end |
| 734 | acnt = acValidatePlanBuf plen |
| 735 | if eq acnt 0 |
| 736 | put acCounts 1 add get acCounts 1 1 |
| 737 | ret |
| 738 | end |
| 739 | acOutFld 0 f0l |
| 740 | acOutByte 9 |
| 741 | acOutFld 1 f1l |
| 742 | acOutByte 9 |
| 743 | acOutNum st |
| 744 | acOutByte 9 |
| 745 | acOutFld 2 f2l |
| 746 | acOutByte 9 |
| 747 | acOutFld 3 plen |
| 748 | acOutByte 9 |
| 749 | acOutNum acnt |
| 750 | acOutByte 10 |
| 751 | put acCounts 0 add get acCounts 0 1 |
| 752 | end |
| 753 | |
| 754 | fn acRunPlan port ulong inLen ulong outLen ulong to int |
| 755 | nbytes = acReadInFile inLen |
| 756 | if eq nbytes 0 |
| 757 | ret 2 |
| 758 | end |
| 759 | put acCounts 0 0 |
| 760 | put acCounts 1 0 |
| 761 | put acCounts 2 0 |
| 762 | acOutReset |
| 763 | acOutStr acHdrPlan |
| 764 | pos = ulong 0 |
| 765 | while lt pos nbytes bound 2048 |
| 766 | llen = ulong 0 |
| 767 | while lt pos nbytes bound 1024 |
| 768 | c = get acInBuf pos |
| 769 | pos = add pos 1 |
| 770 | if eq c 10 |
| 771 | break |
| 772 | end |
| 773 | if and ne c 13 lt llen 1020 |
| 774 | put acLine llen c |
| 775 | llen = add llen 1 |
| 776 | end |
| 777 | end |
| 778 | if eq llen 0 |
| 779 | continue |
| 780 | end |
| 781 | if eq get acLine 0 35 |
| 782 | continue |
| 783 | end |
| 784 | acPlanOneLine port llen |
| 785 | end |
| 786 | if not acWriteOutFile outLen |
| 787 | ret 3 |
| 788 | end |
| 789 | acWrt1 acMsgPlanOk |
| 790 | acNum1 get acCounts 0 |
| 791 | acWrt1 acMsgPlanRej |
| 792 | acNum1 get acCounts 1 |
| 793 | acWrt1 acMsgPlanLive |
| 794 | acNum1 get acCounts 2 |
| 795 | acWrt1 acNl |
| 796 | ret 0 |
| 797 | end |
| 798 | |
| 799 | fn acRunRequeue inLen ulong outLen ulong to int |
| 800 | nbytes = acReadInFile inLen |
| 801 | if eq nbytes 0 |
| 802 | ret 2 |
| 803 | end |
| 804 | acOutReset |
| 805 | acOutStr acHdrReq |
| 806 | pos = ulong 0 |
| 807 | qcnt = ulong 0 |
| 808 | while lt pos nbytes bound 2048 |
| 809 | llen = ulong 0 |
| 810 | while lt pos nbytes bound 1024 |
| 811 | c = get acInBuf pos |
| 812 | pos = add pos 1 |
| 813 | if eq c 10 |
| 814 | break |
| 815 | end |
| 816 | if and ne c 13 lt llen 1020 |
| 817 | put acLine llen c |
| 818 | llen = add llen 1 |
| 819 | end |
| 820 | end |
| 821 | if eq llen 0 |
| 822 | continue |
| 823 | end |
| 824 | f0l = acSplitTabTo llen 0 0 |
| 825 | f1l = acSplitTabTo llen 1 1 |
| 826 | f2l = acSplitTabTo llen 2 2 |
| 827 | if or eq f0l 0 or eq f1l 0 eq f2l 0 |
| 828 | continue |
| 829 | end |
| 830 | isLogic = acEqFld2 f2l acFltLogic |
| 831 | isUnder = acEqFld2 f2l acFltUnder |
| 832 | if or isLogic isUnder |
| 833 | st = acFamilyStrandFld1 f1l |
| 834 | acOutFld 0 f0l |
| 835 | acOutByte 9 |
| 836 | acOutFld 1 f1l |
| 837 | acOutByte 9 |
| 838 | acOutNum st |
| 839 | acOutByte 9 |
| 840 | acOutFld 2 f2l |
| 841 | acOutByte 9 |
| 842 | if isLogic |
| 843 | acOutStr acReqLogic |
| 844 | else |
| 845 | acOutStr acReqUnder |
| 846 | end |
| 847 | acOutByte 10 |
| 848 | qcnt = add qcnt 1 |
| 849 | end |
| 850 | end |
| 851 | if not acWriteOutFile outLen |
| 852 | ret 3 |
| 853 | end |
| 854 | acWrt1 acMsgReqOk |
| 855 | acNum1 qcnt |
| 856 | acWrt1 acNl |
| 857 | ret 0 |
| 858 | end |
| 859 | |
| 860 | text acScBadCode "PLAN: fn solve a ulong to ulong\nret add a 1\nend ASSERT(1->2) ASSERT(2->3) ASSERT(3->4)" |
| 861 | text acScFewAss "PLAN: compute sum of array elements; ASSERT(0->0) ASSERT(1->1)" |
| 862 | text acScJsonRsp "HTTP/1.1 200 OK\n\n{\"choices\":[{\"message\":{\"content\":\"PLAN: compute square; ASSERT(0->0) ASSERT(2->4) ASSERT(5->25)\"}}]}" |
| 863 | text acScEscIn "sum \"a\"\\b" |
| 864 | |
| 865 | fn acSelfCheck to int |
| 866 | if ne acFamilyStrand acFamArith len acFamArith 1 |
| 867 | ret 10 |
| 868 | end |
| 869 | if ne acFamilyStrand acFamBranch len acFamBranch 1 |
| 870 | ret 11 |
| 871 | end |
| 872 | if ne acFamilyStrand acFamFold len acFamFold 2 |
| 873 | ret 12 |
| 874 | end |
| 875 | if ne acFamilyStrand acFamLoop len acFamLoop 2 |
| 876 | ret 13 |
| 877 | end |
| 878 | if ne acFamilyStrand acFamRewrite len acFamRewrite 3 |
| 879 | ret 14 |
| 880 | end |
| 881 | if ne acFamilyStrand acFamRepair len acFamRepair 4 |
| 882 | ret 15 |
| 883 | end |
| 884 | if ne acValidatePlan acScBadCode len acScBadCode 0 |
| 885 | ret 16 |
| 886 | end |
| 887 | if ne acValidatePlan acScFewAss len acScFewAss 0 |
| 888 | ret 17 |
| 889 | end |
| 890 | jb = new uchar 512 0 |
| 891 | jl = acBuildJsonBody acScEscIn len acScEscIn jb 512 |
| 892 | if lt jl len acJsonPre |
| 893 | ret 18 |
| 894 | end |
| 895 | for i ulong len acScJsonRsp bound 512 |
| 896 | put acRspBuf i get acScJsonRsp i |
| 897 | end |
| 898 | el = acExtractJsonContent len acScJsonRsp |
| 899 | if ne acValidatePlanBuf el 3 |
| 900 | ret 19 |
| 901 | end |
| 902 | for s ulong 4 |
| 903 | pl = acMakeOfflinePlan add s 1 |
| 904 | if lt acValidatePlanBuf pl 3 |
| 905 | ret 20 |
| 906 | end |
| 907 | end |
| 908 | acWrt1 acMsgSelfOk |
| 909 | ret 0 |
| 910 | end |
| 911 | |
| 912 | fn main to int |
| 913 | a1 = new uchar 64 0 |
| 914 | a2 = new uchar 256 0 |
| 915 | if lt argcnt 2 |
| 916 | acWrt2 acMsgUsage |
| 917 | ret 2 |
| 918 | end |
| 919 | l1r = argread 1 a1 0 64 |
| 920 | if le l1r 0 |
| 921 | ret 2 |
| 922 | end |
| 923 | l1 = ulong l1r |
| 924 | if acEqBuf a1 l1 acModeSelf |
| 925 | ret acSelfCheck |
| 926 | end |
| 927 | if acEqBuf a1 l1 acModePlan |
| 928 | if lt argcnt 5 |
| 929 | acWrt2 acMsgUsage |
| 930 | ret 2 |
| 931 | end |
| 932 | l2r = argread 2 a2 0 256 |
| 933 | l3r = argread 3 acInPath 0 256 |
| 934 | l4r = argread 4 acOutPath 0 256 |
| 935 | if or le l2r 0 or le l3r 0 le l4r 0 |
| 936 | ret 2 |
| 937 | end |
| 938 | port = acParseUlong a2 ulong l2r |
| 939 | ret acRunPlan port ulong l3r ulong l4r |
| 940 | end |
| 941 | if acEqBuf a1 l1 acModeReq |
| 942 | if lt argcnt 4 |
| 943 | acWrt2 acMsgUsage |
| 944 | ret 2 |
| 945 | end |
| 946 | l2r = argread 2 acInPath 0 256 |
| 947 | l3r = argread 3 acOutPath 0 256 |
| 948 | if or le l2r 0 le l3r 0 |
| 949 | ret 2 |
| 950 | end |
| 951 | ret acRunRequeue ulong l2r ulong l3r |
| 952 | end |
| 953 | acWrt2 acMsgUsage |
| 954 | ret 2 |
| 955 | end |