nx_part_solver.nx source
↩ module page · 41 lines · 1993 B
1// nx_part_solver.nx -- CLI: solve a declarative part-placement constraint file.
2// nx_part_solver <constraints.conf>
3// Prints solved placements + the verdict. Exit 0 SOLVED / 4 INCONSISTENT (worst constraint NAMED) /
4// 3 parse refusal / 1 io / 2 usage. Core in nx_part_solver_lib.nx (the gate imports the same impl).
5// license_tier: ORIGINAL expect_exit: 0
6import "nx_syscalls.nx"
7import "nx_part_solver_lib.nx"
8
9func main(argc: i64, argv: *i64) -> i64 {
10 if argc < 2 {
11 ps_err("usage: nx_part_solver <constraints.conf>\n" as *u8)
12 ps_err(" rows: part <name> <x> <y> <z> <r> | attach <a> <b> <dx> <dy> <dz> | mirror <a> <b>\n" as *u8)
13 ps_err(" station <a> <lo> <hi> | clear <a> <b> <mind> | inside <a> <b> <maxd>\n" as *u8)
14 ps_err(" band <a> <b> <lo> <hi> | ratio <a> <b> <c> <d> <num> <den> [tol_permil]\n" as *u8)
15 ps_err(" rung2: extent <a> <ex> <ey> <ez> | facing <a> <fx> <fy> (snapped to a cardinal)\n" as *u8)
16 ps_err(" noclip <a> <b> [gap] | envelope <a> <b> | face <a> <b>\n" as *u8)
17 sys_exit(2)
18 return 2
19 }
20 let lp: *i64 = sys_mmap(16) as *i64
21 let b: *u8 = sys_read_file(argv[1] as *u8, lp)
22 if (b as i64) == 0 { ps_err("PART-SOLVER-REFUSE cannot read constraint file\n" as *u8); sys_exit(1); return 1 }
23 let rc: i64 = ps_load(b, lp[0])
24 if rc != 0 { sys_exit(0 - rc); return 0 - rc }
25 let ok: i64 = ps_solve()
26 ps_dump()
27 if ok == 1 {
28 ps_out("PART-SOLVER SOLVED parts=" as *u8); ps_outn(ps_np())
29 ps_out(" residual=" as *u8); ps_outn(ps_resid())
30 ps_out("\n" as *u8)
31 sys_exit(0)
32 return 0
33 }
34 ps_out("PART-SOLVER INCONSISTENT worst=" as *u8)
35 ps_out(ps_kindname(ps_ckind(ps_worst())))
36 ps_out(" idx=" as *u8); ps_outn(ps_worst())
37 ps_out(" violation=" as *u8); ps_outn(ps_worstv())
38 ps_out(" -- the set cannot be satisfied; refusing to report a fabricated success\n" as *u8)
39 sys_exit(4)
40 return 4
41}