urbit/j/f/ut_find.c

776 lines
22 KiB
C
Raw Normal View History

2013-09-29 00:21:18 +04:00
/* j/6/find.c
**
*/
#include "all.h"
2014-09-04 07:10:43 +04:00
2013-09-29 00:21:18 +04:00
/* logic
*/
2014-09-06 00:13:24 +04:00
static u3_noun
2014-08-21 01:18:34 +04:00
_fino_in(
2014-09-06 00:13:24 +04:00
u3_noun van,
u3_noun sut,
u3_noun dep,
u3_noun way,
u3_noun cog,
u3_noun gil)
2013-12-31 23:30:37 +04:00
{
2014-09-06 00:13:24 +04:00
u3_noun p_sut, q_sut;
2013-12-31 23:30:37 +04:00
2014-11-05 04:18:47 +03:00
if ( c3y == u3ud(sut) ) {
2014-09-06 00:13:24 +04:00
return u3nc(u3k(dep), u3_nul);
2013-12-31 23:30:37 +04:00
}
2014-09-06 00:13:24 +04:00
else switch ( u3h(sut) ) {
default: return u3nc(u3k(dep), u3_nul);
2013-12-31 23:30:37 +04:00
case c3__bull: {
2014-11-06 03:20:01 +03:00
if ( (c3n == u3r_trel(sut, 0, &p_sut, &q_sut)) ) {
return u3m_bail(c3__fail);
}
else {
2014-11-06 03:20:01 +03:00
if ( c3n == u3r_sing(cog, u3h(p_sut)) ) {
2014-01-02 00:47:18 +04:00
return _fino_in
2014-08-21 01:18:34 +04:00
(van, q_sut, dep, way, cog, gil);
}
2013-12-31 23:30:37 +04:00
else {
if ( 0 == dep ) {
2014-09-06 00:13:24 +04:00
return u3nc
2014-08-21 01:18:34 +04:00
(0,
2014-09-06 00:13:24 +04:00
u3nt(
u3_nul,
2013-12-31 23:30:37 +04:00
1,
2014-09-06 00:13:24 +04:00
u3nt(2, u3k(p_sut),
u3k(q_sut))));
2013-12-31 23:30:37 +04:00
} else {
2014-01-02 00:47:18 +04:00
return _fino_in
2014-08-21 01:18:34 +04:00
(
2014-11-06 22:13:57 +03:00
van, q_sut, u3qa_dec(dep), way, cog, gil);
2013-12-31 23:30:37 +04:00
}
}
}
}
case c3__cell: {
2014-11-06 03:20:01 +03:00
if ( (c3n == u3r_trel(sut, 0, &p_sut, &q_sut)) ) {
return u3m_bail(c3__fail);
2013-12-31 23:30:37 +04:00
} else {
2014-09-06 00:13:24 +04:00
u3_noun taf = _fino_in(van, p_sut, dep, way, cog, gil);
u3_noun p_taf = u3h(taf);
u3_noun q_taf = u3t(taf);
u3_noun ret;
if ( u3_nul == q_taf ) {
u3_noun bov = _fino_in(van, q_sut, p_taf, way, cog, gil);
u3_noun p_bov = u3h(bov);
u3_noun q_bov = u3t(bov);
if ( u3_nul == q_bov ) {
ret = u3k(bov);
}
2013-12-31 23:30:37 +04:00
else {
2014-09-06 00:13:24 +04:00
u3_noun puq_bov, quq_bov;
2014-11-06 03:20:01 +03:00
u3r_mean(q_bov, 6, &puq_bov, 7, &quq_bov, 0);
2014-09-06 00:13:24 +04:00
ret = u3nq
(u3k(p_bov),
u3_nul,
2014-11-06 22:13:57 +03:00
u3qc_peg(3, puq_bov),
2014-09-06 00:13:24 +04:00
u3k(quq_bov));
2013-12-31 23:30:37 +04:00
}
2014-09-06 00:13:24 +04:00
u3z(bov);
}
2013-12-31 23:30:37 +04:00
else {
2014-09-06 00:13:24 +04:00
u3_noun puq_taf, quq_taf;
2014-11-06 03:20:01 +03:00
u3r_mean(q_taf, 6, &puq_taf, 7, &quq_taf, 0);
2014-09-06 00:13:24 +04:00
ret = u3nq
(u3k(p_taf),
u3_nul,
2014-11-06 22:13:57 +03:00
u3qc_peg(2, puq_taf),
2014-09-06 00:13:24 +04:00
u3k(quq_taf));
2013-12-31 23:30:37 +04:00
}
2014-09-06 00:13:24 +04:00
u3z(taf);
2013-12-31 23:30:37 +04:00
return ret;
}
}
case c3__core: {
2014-09-06 00:13:24 +04:00
u3_noun pq_sut, qq_sut, rq_sut;
u3_noun prq_sut, qrq_sut;
2013-12-31 23:30:37 +04:00
2014-11-06 03:20:01 +03:00
if ( (c3n == u3r_trel(sut, 0, &p_sut, &q_sut)) ||
(c3n == u3r_trel(q_sut, &pq_sut, &qq_sut, &rq_sut)) ||
(c3n == u3r_cell(rq_sut, &prq_sut, &qrq_sut)) )
2013-12-31 23:30:37 +04:00
{
2014-11-06 03:20:01 +03:00
return u3m_bail(c3__fail);
2013-12-31 23:30:37 +04:00
} else {
2014-11-06 22:13:57 +03:00
u3_noun zem = u3qf_look(cog, qrq_sut);
2013-12-31 23:30:37 +04:00
2014-09-06 00:13:24 +04:00
if ( (u3_nul != zem) && (0 != dep) ) {
u3_noun ped;
2013-12-31 23:30:37 +04:00
2014-11-06 22:13:57 +03:00
ped = u3qa_dec(dep);
2014-09-06 00:13:24 +04:00
u3z(dep); dep = ped;
2013-12-31 23:30:37 +04:00
2014-09-06 00:13:24 +04:00
u3z(zem);
zem = u3_nul;
2013-12-31 23:30:37 +04:00
}
2014-09-06 00:13:24 +04:00
if ( u3_nul == zem ) {
u3_noun taf = _fino_in(van, p_sut, dep, way, cog, gil);
u3_noun p_taf = u3h(taf);
u3_noun q_taf = u3t(taf);
2013-12-31 23:30:37 +04:00
2014-09-06 00:13:24 +04:00
if ( u3_nul == q_taf ) {
u3z(taf);
return u3nc(u3k(dep), u3_nul);
}
2013-12-31 23:30:37 +04:00
else {
2014-09-06 00:13:24 +04:00
u3_noun puq_taf, quq_taf;
u3_noun pro;
2013-12-31 23:30:37 +04:00
2014-11-06 03:20:01 +03:00
u3r_mean(q_taf, 6, &puq_taf, 7, &quq_taf, 0);
2013-12-31 23:30:37 +04:00
2014-11-06 22:13:57 +03:00
if ( c3n == u3qfu_park
2014-08-21 01:18:34 +04:00
(van, sut, way, puq_taf) )
2013-12-31 23:30:37 +04:00
{
2014-11-06 22:13:57 +03:00
u3_noun weh = u3qfu_shep
2014-09-06 00:13:24 +04:00
(van, "way", 'a', u3k(way));
2014-11-06 22:13:57 +03:00
u3_noun waz = u3qfu_shep
2014-09-06 00:13:24 +04:00
(van, "axis", 'd', u3k(puq_taf));
2014-11-06 03:20:01 +03:00
u3t_push(u3nc(c3__mean, weh));
u3t_push(u3nc(c3__mean, waz));
return u3m_error("find-park");
2013-12-31 23:30:37 +04:00
}
else {
2014-09-06 00:13:24 +04:00
pro = u3nq
(u3k(p_taf),
u3_nul,
2014-11-06 22:13:57 +03:00
u3qc_peg(3, puq_taf),
2014-09-06 00:13:24 +04:00
u3k(quq_taf));
2013-12-31 23:30:37 +04:00
2014-09-06 00:13:24 +04:00
u3z(taf);
2013-12-31 23:30:37 +04:00
return pro;
}
}
}
else {
2014-09-06 00:13:24 +04:00
u3_noun u_zem = u3t(zem);
u3_noun pu_zem = u3h(u_zem);
u3_noun qu_zem = u3t(u_zem);
u3_noun mut;
u3_noun pro;
mut = u3nt(c3__core,
u3k(p_sut),
u3nt(c3__gold,
u3k(qq_sut),
u3k(rq_sut)));
pro = u3nc
2014-08-21 01:18:34 +04:00
(
2013-12-31 23:30:37 +04:00
0,
2014-09-06 00:13:24 +04:00
u3nq(
u3_nul,
2014-08-21 01:18:34 +04:00
1,
1,
2014-09-06 00:13:24 +04:00
u3nc
2014-11-06 22:13:57 +03:00
(u3qc_peg(2, pu_zem),
2014-09-06 00:13:24 +04:00
u3nc(
u3nc(mut, u3k(qu_zem)),
u3_nul))));
u3z(zem);
2013-12-31 23:30:37 +04:00
return pro;
}
}
}
case c3__face: {
2014-11-06 03:20:01 +03:00
if ( (c3n == u3r_trel(sut, 0, &p_sut, &q_sut)) ) {
return u3m_bail(c3__fail);
} else {
2014-11-06 03:20:01 +03:00
if ( c3n == u3r_sing(cog, p_sut) ) {
2014-09-06 00:13:24 +04:00
return u3nc(u3k(dep), u3_nul);
2013-12-31 23:30:37 +04:00
} else {
if ( 0 == dep ) {
2014-09-06 00:13:24 +04:00
return u3nc
2014-08-21 01:18:34 +04:00
(0,
2014-09-06 00:13:24 +04:00
u3nq(u3_nul, 1, 0, u3k(q_sut)));
2013-12-31 23:30:37 +04:00
} else {
2014-09-06 00:13:24 +04:00
return u3nc
2014-11-06 22:13:57 +03:00
(u3qa_dec(dep), u3_nul);
2013-12-31 23:30:37 +04:00
}
}
}
}
case c3__cube: {
2014-11-06 22:13:57 +03:00
u3_noun fop = u3qfu_repo(van, sut);
2014-09-06 00:13:24 +04:00
u3_noun pro = _fino_in(van, fop, dep, way, cog, gil);
2013-12-31 23:30:37 +04:00
2014-09-06 00:13:24 +04:00
u3z(fop);
2013-12-31 23:30:37 +04:00
return pro;
}
case c3__fork: {
2014-11-06 03:20:01 +03:00
if ( (c3n == u3r_trel(sut, 0, &p_sut, &q_sut)) ) {
return u3m_bail(c3__fail);
2013-12-31 23:30:37 +04:00
}
2014-11-06 22:13:57 +03:00
if ( (c3y == u3qdi_has(gil, q_sut)) ) {
2014-08-21 01:18:34 +04:00
return _fino_in(van, p_sut, dep, way, cog, gil);
}
2014-11-06 22:13:57 +03:00
else if ( (c3y == u3qdi_has(gil, p_sut)) ) {
2014-08-21 01:18:34 +04:00
return _fino_in(van, q_sut, dep, way, cog, gil);
}
2013-12-31 23:30:37 +04:00
else {
2014-09-06 00:13:24 +04:00
u3_noun hax = _fino_in(van, p_sut, dep, way, cog, gil);
u3_noun yor = _fino_in(van, q_sut, dep, way, cog, gil);
u3_noun p_hax = u3h(hax);
u3_noun p_yor = u3h(yor);
u3_noun q_hax = u3t(hax);
u3_noun q_yor = u3t(yor);
u3_noun puq_hax, quq_hax;
u3_noun puq_yor, quq_yor;
2014-12-19 22:14:19 +03:00
u3_noun ret = 0;
2014-09-06 00:13:24 +04:00
if ( u3_nul != q_hax ) {
2014-11-06 03:20:01 +03:00
u3r_mean(q_hax, 6, &puq_hax, 7, &quq_hax, 0);
2013-12-31 23:30:37 +04:00
}
2014-09-06 00:13:24 +04:00
if ( u3_nul != q_yor ) {
2014-11-06 03:20:01 +03:00
u3r_mean(q_yor, 6, &puq_yor, 7, &quq_yor, 0);
2013-12-31 23:30:37 +04:00
}
2014-11-06 03:20:01 +03:00
if ( c3y == u3r_sing(hax, yor) ) {
2014-09-06 00:13:24 +04:00
ret = u3k(hax);
2013-12-31 23:30:37 +04:00
}
else {
2014-11-06 03:20:01 +03:00
if ( (c3n == u3r_sing(p_hax, p_yor)) ||
2014-09-06 00:13:24 +04:00
((u3_nul == q_hax) || (u3_nul == q_yor)) ||
2014-11-06 03:20:01 +03:00
(c3n == u3r_sing(puq_hax, puq_yor)) ||
(c3n == u3r_sing(u3h(quq_hax), u3h(quq_yor))) )
2013-12-31 23:30:37 +04:00
{
2014-11-06 03:20:01 +03:00
return u3m_error("find-fork");
2013-12-31 23:30:37 +04:00
}
2014-09-06 00:13:24 +04:00
switch ( u3h(quq_hax) ) {
2013-12-31 23:30:37 +04:00
case 0: {
2014-09-06 00:13:24 +04:00
u3_noun pquq_hax = u3t(quq_hax);
u3_noun pquq_yor = u3t(quq_yor);
2014-08-21 01:18:34 +04:00
2014-09-06 00:13:24 +04:00
ret = u3nc
2014-08-21 01:18:34 +04:00
(
2014-09-06 00:13:24 +04:00
u3k(p_hax),
u3nq
2014-08-21 01:18:34 +04:00
(
2014-09-06 00:13:24 +04:00
u3_nul,
u3k(puq_hax),
2013-12-31 23:30:37 +04:00
0,
2014-11-06 22:13:57 +03:00
u3qf_fork(pquq_hax, pquq_yor)));
2013-12-31 23:30:37 +04:00
break;
}
case 1: {
2014-09-06 00:13:24 +04:00
u3_noun pquq_hax, qquq_hax, pquq_yor, qquq_yor;
2013-12-31 23:30:37 +04:00
2014-11-06 03:20:01 +03:00
u3x_cell(u3t(quq_hax), &pquq_hax, &qquq_hax);
u3x_cell(u3t(quq_yor), &pquq_yor, &qquq_yor);
2013-12-31 23:30:37 +04:00
2014-11-06 03:20:01 +03:00
if ( c3n == u3r_sing(pquq_hax, pquq_yor) ) {
return u3m_error("find-fork");
2013-12-31 23:30:37 +04:00
} else {
2014-09-06 00:13:24 +04:00
ret = u3nc
2014-08-21 01:18:34 +04:00
(
2014-09-06 00:13:24 +04:00
u3k(p_hax),
u3nq
(u3_nul,
u3k(puq_hax),
2013-12-31 23:30:37 +04:00
1,
2014-09-06 00:13:24 +04:00
u3nc
(u3k(pquq_hax),
2014-11-06 22:13:57 +03:00
u3qb_weld
2014-08-21 01:18:34 +04:00
(qquq_hax, qquq_yor))));
2013-12-31 23:30:37 +04:00
break;
}
}
case 2: {
2014-09-06 00:13:24 +04:00
u3_noun pquq_hax, qquq_hax, pquq_yor, qquq_yor;
u3_noun ppquq_hax, qpquq_hax, rpquq_hax, spquq_hax;
u3_noun ppquq_yor, qpquq_yor, rpquq_yor, spquq_yor;
2013-12-31 23:30:37 +04:00
2014-11-06 03:20:01 +03:00
u3x_cell(u3t(quq_hax), &pquq_hax, &qquq_hax);
u3x_cell(u3t(quq_yor), &pquq_yor, &qquq_yor);
u3x_qual(
pquq_hax,
2014-01-02 00:47:18 +04:00
&ppquq_hax, &qpquq_hax, &rpquq_hax, &spquq_hax);
2014-11-06 03:20:01 +03:00
u3x_qual(
pquq_yor,
2014-01-02 00:47:18 +04:00
&ppquq_yor, &qpquq_yor, &rpquq_yor, &spquq_yor);
2013-12-31 23:30:37 +04:00
2014-11-06 03:20:01 +03:00
if ( (c3n == u3r_sing(ppquq_hax, ppquq_yor)) ||
(c3n == u3r_sing(qpquq_hax, qpquq_yor)) ||
(c3n == u3r_sing(rpquq_hax, rpquq_yor)) )
2014-01-02 00:47:18 +04:00
{
2014-11-06 03:20:01 +03:00
return u3m_error("find-fork");
2013-12-31 23:30:37 +04:00
}
else {
2014-09-06 00:13:24 +04:00
ret = u3nc
2014-08-21 01:18:34 +04:00
(
2014-09-06 00:13:24 +04:00
u3k(p_hax),
u3nq
2014-08-21 01:18:34 +04:00
(
2014-09-06 00:13:24 +04:00
u3_nul,
u3k(puq_hax),
2013-12-31 23:30:37 +04:00
2,
2014-09-06 00:13:24 +04:00
u3nc(
u3nq(
u3k(ppquq_hax),
u3k(qpquq_hax),
u3k(rpquq_hax),
2014-11-06 22:13:57 +03:00
u3qf_fork(
spquq_hax,
2014-01-02 00:47:18 +04:00
spquq_yor)),
2014-11-06 22:13:57 +03:00
u3qf_fork(qquq_hax, qquq_yor))));
2013-12-31 23:30:37 +04:00
break;
}
}
}
}
2014-09-06 00:13:24 +04:00
u3z(yor);
u3z(hax);
2013-12-31 23:30:37 +04:00
return ret;
}
}
2014-09-06 00:13:24 +04:00
case c3__hold: p_sut = u3t(sut);
2013-12-31 23:30:37 +04:00
{
2014-11-06 22:13:57 +03:00
if ( (c3y == u3qdi_has(gil, sut)) ) {
2014-09-06 00:13:24 +04:00
return u3nc(u3k(dep), u3_nul);
}
2013-12-31 23:30:37 +04:00
else {
2014-11-06 22:13:57 +03:00
u3_noun zoc = u3qdi_put(gil, sut);
u3_noun fop = u3qfu_repo(van, sut);
2014-09-06 00:13:24 +04:00
u3_noun pro = _fino_in(van, fop, dep, way, cog, zoc);
2013-12-31 23:30:37 +04:00
2014-09-06 00:13:24 +04:00
u3z(fop);
u3z(zoc);
2013-12-31 23:30:37 +04:00
return pro;
}
}
}
}
2014-09-06 00:13:24 +04:00
static u3_noun
2014-08-21 01:18:34 +04:00
_find_in(
2014-09-06 00:13:24 +04:00
u3_noun van,
u3_noun sut,
u3_noun dep,
u3_noun way,
u3_noun cog,
u3_noun gil)
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
u3_noun p_sut, q_sut, pp_sut, qp_sut, rp_sut, sp_sut;
2013-09-29 00:21:18 +04:00
2014-11-05 04:18:47 +03:00
if ( c3y == u3ud(sut) ) {
2014-09-06 00:13:24 +04:00
return u3nc(u3k(dep), u3_nul);
2013-09-29 00:21:18 +04:00
}
2014-09-06 00:13:24 +04:00
else switch ( u3h(sut) ) {
default: return u3nc(u3k(dep), u3_nul);
2013-09-29 00:21:18 +04:00
2013-12-26 21:12:07 +04:00
case c3__bull: {
2014-11-06 03:20:01 +03:00
if ( (c3n == u3r_trel(sut, 0, &p_sut, &q_sut)) ||
(c3n == u3r_qual(p_sut, &pp_sut, &qp_sut, &rp_sut, &sp_sut)) )
2013-12-26 21:12:07 +04:00
{
2014-11-06 03:20:01 +03:00
return u3m_bail(c3__fail);
}
else {
2014-11-06 03:20:01 +03:00
if ( c3n == u3r_sing(cog, pp_sut) ) {
2014-01-02 00:47:18 +04:00
return _find_in
2014-08-21 01:18:34 +04:00
(van, q_sut, dep, way, cog, gil);
}
2013-12-26 21:12:07 +04:00
else {
if ( 0 == dep ) {
2014-09-06 00:13:24 +04:00
return u3nc
2014-08-21 01:18:34 +04:00
(0,
2014-09-06 00:13:24 +04:00
u3nq(
u3_nul,
u3k(rp_sut),
2014-11-05 04:18:47 +03:00
c3y,
2014-09-06 00:13:24 +04:00
u3k(sp_sut)));
2013-12-26 21:12:07 +04:00
} else {
2014-01-02 00:47:18 +04:00
return _find_in
2014-08-21 01:18:34 +04:00
(
2014-11-06 22:13:57 +03:00
van, q_sut, u3qa_dec(dep), way, cog, gil);
2014-09-06 00:13:24 +04:00
return u3nc
2014-11-06 22:13:57 +03:00
(u3qa_dec(dep), u3_nul);
2013-12-26 21:12:07 +04:00
}
}
}
}
2013-09-29 00:21:18 +04:00
case c3__cell: {
2014-11-06 03:20:01 +03:00
if ( (c3n == u3r_trel(sut, 0, &p_sut, &q_sut)) ) {
return u3m_bail(c3__fail);
2013-09-29 00:21:18 +04:00
} else {
2014-09-06 00:13:24 +04:00
u3_noun taf = _find_in(van, p_sut, dep, way, cog, gil);
u3_noun p_taf = u3h(taf);
u3_noun q_taf = u3t(taf);
u3_noun ret;
if ( u3_nul == q_taf ) {
u3_noun bov = _find_in(van, q_sut, p_taf, way, cog, gil);
u3_noun p_bov = u3h(bov);
u3_noun q_bov = u3t(bov);
if ( u3_nul == q_bov ) {
ret = u3k(bov);
}
2013-09-29 00:21:18 +04:00
else {
2014-09-06 00:13:24 +04:00
u3_noun puq_bov, quq_bov;
2014-11-06 03:20:01 +03:00
u3r_mean(q_bov, 6, &puq_bov, 7, &quq_bov, 0);
2014-09-06 00:13:24 +04:00
ret = u3nq
(u3k(p_bov),
u3_nul,
2014-11-06 22:13:57 +03:00
u3qc_peg(3, puq_bov),
2014-09-06 00:13:24 +04:00
u3k(quq_bov));
2013-09-29 00:21:18 +04:00
}
2014-09-06 00:13:24 +04:00
u3z(bov);
}
2013-09-29 00:21:18 +04:00
else {
2014-09-06 00:13:24 +04:00
u3_noun puq_taf, quq_taf;
2014-11-06 03:20:01 +03:00
u3r_mean(q_taf, 6, &puq_taf, 7, &quq_taf, 0);
2014-09-06 00:13:24 +04:00
ret = u3nq
(u3k(p_taf),
u3_nul,
2014-11-06 22:13:57 +03:00
u3qc_peg(2, puq_taf),
2014-09-06 00:13:24 +04:00
u3k(quq_taf));
2013-09-29 00:21:18 +04:00
}
2014-09-06 00:13:24 +04:00
u3z(taf);
2013-09-29 00:21:18 +04:00
return ret;
}
}
case c3__core: {
2014-09-06 00:13:24 +04:00
u3_noun pq_sut, qq_sut, rq_sut;
u3_noun prq_sut, qrq_sut;
2013-09-29 00:21:18 +04:00
2014-11-06 03:20:01 +03:00
if ( (c3n == u3r_trel(sut, 0, &p_sut, &q_sut)) ||
(c3n == u3r_trel(q_sut, &pq_sut, &qq_sut, &rq_sut)) ||
(c3n == u3r_cell(rq_sut, &prq_sut, &qrq_sut)) )
2013-09-29 00:21:18 +04:00
{
2014-11-06 03:20:01 +03:00
return u3m_bail(c3__fail);
2013-09-29 00:21:18 +04:00
} else {
2014-11-06 22:13:57 +03:00
u3_noun zem = u3qf_look(cog, qrq_sut);
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04:00
if ( (u3_nul != zem) && (0 != dep) ) {
u3_noun ped;
2013-09-29 00:21:18 +04:00
2014-11-06 22:13:57 +03:00
ped = u3qa_dec(dep);
2014-09-06 00:13:24 +04:00
u3z(dep); dep = ped;
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04:00
u3z(zem);
zem = u3_nul;
2013-09-29 00:21:18 +04:00
}
2014-09-06 00:13:24 +04:00
if ( u3_nul == zem ) {
u3_noun taf = _find_in(van, p_sut, dep, way, cog, gil);
u3_noun p_taf = u3h(taf);
u3_noun q_taf = u3t(taf);
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04:00
if ( u3_nul == q_taf ) {
u3z(taf);
return u3nc(u3k(dep), u3_nul);
}
2013-09-29 00:21:18 +04:00
else {
2014-09-06 00:13:24 +04:00
u3_noun puq_taf, quq_taf;
u3_noun pro;
2013-09-29 00:21:18 +04:00
2014-11-06 03:20:01 +03:00
u3r_mean(q_taf, 6, &puq_taf, 7, &quq_taf, 0);
2013-09-29 00:21:18 +04:00
2014-11-06 22:13:57 +03:00
if ( c3n == u3qfu_park
2014-08-21 01:18:34 +04:00
(van, sut, way, puq_taf) )
2013-09-29 00:21:18 +04:00
{
2014-11-06 22:13:57 +03:00
u3_noun weh = u3qfu_shep
2014-09-06 00:13:24 +04:00
(van, "way", 'a', u3k(way));
2014-11-06 22:13:57 +03:00
u3_noun waz = u3qfu_shep
2014-09-06 00:13:24 +04:00
(van, "axis", 'd', u3k(puq_taf));
2014-11-06 03:20:01 +03:00
u3t_push(u3nc(c3__mean, weh));
u3t_push(u3nc(c3__mean, waz));
return u3m_error("find-park");
2013-09-29 00:21:18 +04:00
}
else {
2014-09-06 00:13:24 +04:00
pro = u3nq
(u3k(p_taf),
u3_nul,
2014-11-06 22:13:57 +03:00
u3qc_peg(3, puq_taf),
2014-09-06 00:13:24 +04:00
u3k(quq_taf));
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04:00
u3z(taf);
2013-09-29 00:21:18 +04:00
return pro;
}
}
}
else {
2014-09-06 00:13:24 +04:00
u3_noun u_zem = u3t(zem);
u3_noun pu_zem = u3h(u_zem);
u3_noun qu_zem = u3t(u_zem);
u3_noun mut;
u3_noun pro;
mut = u3nt(c3__core,
u3k(p_sut),
u3nt(c3__gold,
u3k(qq_sut),
u3k(rq_sut)));
pro = u3nc
2014-08-21 01:18:34 +04:00
(
2013-09-29 00:21:18 +04:00
0,
2014-09-06 00:13:24 +04:00
u3nq(
u3_nul,
2014-08-21 01:18:34 +04:00
1,
2014-11-05 04:18:47 +03:00
c3n,
2014-09-06 00:13:24 +04:00
u3nc
2014-11-06 22:13:57 +03:00
(u3qc_peg(2, pu_zem),
2014-09-06 00:13:24 +04:00
u3nc(
u3nc(mut, u3k(qu_zem)),
u3_nul))));
u3z(zem);
2013-09-29 00:21:18 +04:00
return pro;
}
}
}
case c3__face: {
2014-11-06 03:20:01 +03:00
if ( (c3n == u3r_trel(sut, 0, &p_sut, &q_sut)) ) {
return u3m_bail(c3__fail);
} else {
2014-11-06 03:20:01 +03:00
if ( c3n == u3r_sing(cog, p_sut) ) {
2014-09-06 00:13:24 +04:00
return u3nc(u3k(dep), u3_nul);
2013-09-29 00:21:18 +04:00
} else {
if ( 0 == dep ) {
2014-09-06 00:13:24 +04:00
return u3nc
2014-08-21 01:18:34 +04:00
(0,
2014-11-05 04:18:47 +03:00
u3nq(u3_nul, 1, c3y, u3k(q_sut)));
2013-09-29 00:21:18 +04:00
} else {
2014-09-06 00:13:24 +04:00
return u3nc
2014-11-06 22:13:57 +03:00
(u3qa_dec(dep), u3_nul);
2013-09-29 00:21:18 +04:00
}
}
}
}
case c3__cube: {
2014-11-06 22:13:57 +03:00
u3_noun fop = u3qfu_repo(van, sut);
2014-09-06 00:13:24 +04:00
u3_noun pro = _find_in(van, fop, dep, way, cog, gil);
2014-09-06 00:13:24 +04:00
u3z(fop);
return pro;
}
2013-09-29 00:21:18 +04:00
case c3__fork: {
2014-11-06 03:20:01 +03:00
if ( (c3n == u3r_trel(sut, 0, &p_sut, &q_sut)) ) {
return u3m_bail(c3__fail);
2013-09-29 00:21:18 +04:00
}
2014-11-06 22:13:57 +03:00
if ( (c3y == u3qdi_has(gil, q_sut)) ) {
2014-08-21 01:18:34 +04:00
return _find_in(van, p_sut, dep, way, cog, gil);
}
2014-11-06 22:13:57 +03:00
else if ( (c3y == u3qdi_has(gil, p_sut)) ) {
2014-08-21 01:18:34 +04:00
return _find_in(van, q_sut, dep, way, cog, gil);
}
2013-09-29 00:21:18 +04:00
else {
2014-09-06 00:13:24 +04:00
u3_noun hax = _find_in(van, p_sut, dep, way, cog, gil);
u3_noun yor = _find_in(van, q_sut, dep, way, cog, gil);
u3_noun p_hax = u3h(hax);
u3_noun p_yor = u3h(yor);
u3_noun q_hax = u3t(hax);
u3_noun q_yor = u3t(yor);
u3_noun puq_hax, quq_hax;
u3_noun puq_yor, quq_yor;
2014-12-19 22:14:19 +03:00
u3_noun ret = 0;
2014-09-06 00:13:24 +04:00
if ( u3_nul != q_hax ) {
2014-11-06 03:20:01 +03:00
u3r_mean(q_hax, 6, &puq_hax, 7, &quq_hax, 0);
2013-09-29 00:21:18 +04:00
}
2014-09-06 00:13:24 +04:00
if ( u3_nul != q_yor ) {
2014-11-06 03:20:01 +03:00
u3r_mean(q_yor, 6, &puq_yor, 7, &quq_yor, 0);
2013-09-29 00:21:18 +04:00
}
2014-11-06 03:20:01 +03:00
if ( c3y == u3r_sing(hax, yor) ) {
2014-09-06 00:13:24 +04:00
ret = u3k(hax);
2013-12-31 23:30:37 +04:00
}
else {
2014-11-06 03:20:01 +03:00
if ( (c3n == u3r_sing(p_hax, p_yor)) ||
2014-09-06 00:13:24 +04:00
((u3_nul == q_hax) || (u3_nul == q_yor)) ||
2014-11-06 03:20:01 +03:00
(c3n == u3r_sing(puq_hax, puq_yor)) ||
(c3n == u3r_sing(u3h(quq_hax), u3h(quq_yor))) )
2013-12-31 23:30:37 +04:00
{
2014-11-06 03:20:01 +03:00
return u3m_error("find-fork");
2013-09-29 00:21:18 +04:00
}
2014-09-06 00:13:24 +04:00
switch ( u3h(quq_hax) ) {
2014-11-05 04:18:47 +03:00
case c3y: {
2014-09-06 00:13:24 +04:00
u3_noun pquq_hax = u3t(quq_hax);
u3_noun pquq_yor = u3t(quq_yor);
2014-08-21 01:18:34 +04:00
2014-09-06 00:13:24 +04:00
ret = u3nc
2014-08-21 01:18:34 +04:00
(
2014-09-06 00:13:24 +04:00
u3k(p_hax),
u3nq
2014-08-21 01:18:34 +04:00
(
2014-09-06 00:13:24 +04:00
u3_nul,
u3k(puq_hax),
2014-11-05 04:18:47 +03:00
c3y,
2014-11-06 22:13:57 +03:00
u3qf_fork(pquq_hax, pquq_yor)));
2013-12-31 23:30:37 +04:00
break;
2013-09-29 00:21:18 +04:00
}
2014-11-05 04:18:47 +03:00
case c3n: {
2014-09-06 00:13:24 +04:00
u3_noun pquq_hax, qquq_hax, pquq_yor, qquq_yor;
2013-09-29 00:21:18 +04:00
2014-11-06 03:20:01 +03:00
u3x_cell(u3t(quq_hax), &pquq_hax, &qquq_hax);
u3x_cell(u3t(quq_yor), &pquq_yor, &qquq_yor);
2013-09-29 00:21:18 +04:00
2014-11-06 03:20:01 +03:00
if ( c3n == u3r_sing(pquq_hax, pquq_yor) ) {
return u3m_error("find-fork");
2013-12-31 23:30:37 +04:00
} else {
2014-09-06 00:13:24 +04:00
ret = u3nc
2014-08-21 01:18:34 +04:00
(
2014-09-06 00:13:24 +04:00
u3k(p_hax),
u3nq
(u3_nul,
u3k(puq_hax),
2014-11-05 04:18:47 +03:00
c3n,
2014-09-06 00:13:24 +04:00
u3nc
(u3k(pquq_hax),
2014-11-06 22:13:57 +03:00
u3qb_weld
2014-08-21 01:18:34 +04:00
(qquq_hax, qquq_yor))));
2013-12-31 23:30:37 +04:00
break;
2013-09-29 00:21:18 +04:00
}
}
}
}
2014-09-06 00:13:24 +04:00
u3z(yor);
u3z(hax);
2013-09-29 00:21:18 +04:00
return ret;
}
}
2014-09-06 00:13:24 +04:00
case c3__hold: p_sut = u3t(sut);
2013-09-29 00:21:18 +04:00
{
2014-11-06 22:13:57 +03:00
if ( (c3y == u3qdi_has(gil, sut)) ) {
2014-09-06 00:13:24 +04:00
return u3nc(u3k(dep), u3_nul);
}
2013-09-29 00:21:18 +04:00
else {
2014-11-06 22:13:57 +03:00
u3_noun zoc = u3qdi_put(gil, sut);
u3_noun fop = u3qfu_repo(van, sut);
2014-09-06 00:13:24 +04:00
u3_noun pro = _find_in(van, fop, dep, way, cog, zoc);
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04:00
u3z(fop);
u3z(zoc);
2013-09-29 00:21:18 +04:00
return pro;
}
}
}
}
2014-09-06 00:13:24 +04:00
u3_noun
2014-09-03 09:46:55 +04:00
_cqfu_find(
2014-09-06 00:13:24 +04:00
u3_noun van,
u3_noun sut,
u3_noun dep,
u3_noun way,
u3_noun cog)
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
return _find_in(van, sut, dep, way, cog, u3_nul);
2013-09-29 00:21:18 +04:00
}
2014-09-06 00:13:24 +04:00
u3_noun
2014-09-04 01:33:18 +04:00
_cqfu_fino(
2014-09-06 00:13:24 +04:00
u3_noun van,
u3_noun sut,
u3_noun dep,
u3_noun way,
u3_noun cog)
2013-12-31 23:30:37 +04:00
{
2014-09-06 00:13:24 +04:00
return _fino_in(van, sut, dep, way, cog, u3_nul);
2013-12-31 23:30:37 +04:00
}
/* boilerplate
*/
2014-09-06 00:13:24 +04:00
u3_noun
2014-11-06 22:13:57 +03:00
u3wfu_fino(
2014-09-06 00:13:24 +04:00
u3_noun cor)
2013-12-31 23:30:37 +04:00
{
2014-09-06 00:13:24 +04:00
u3_noun sut, dep, way, cog, van;
2013-12-31 23:30:37 +04:00
2014-11-18 00:56:51 +03:00
if ( (c3n == u3r_mean(cor, u3x_sam_2, &dep,
u3x_sam_6, &way,
u3x_sam_7, &cog,
u3x_con, &van,
2013-12-31 23:30:37 +04:00
0)) ||
2014-11-18 00:56:51 +03:00
(u3_none == (sut = u3r_at(u3x_sam, van))) )
2013-12-31 23:30:37 +04:00
{
2014-11-06 03:20:01 +03:00
return u3m_bail(c3__fail);
2013-12-31 23:30:37 +04:00
} else {
2014-09-04 01:33:18 +04:00
return _cqfu_fino(van, sut, dep, way, cog);
2013-12-31 23:30:37 +04:00
}
}
2014-09-06 00:13:24 +04:00
u3_noun
2014-11-06 22:13:57 +03:00
u3qfu_fino(
2014-09-06 00:13:24 +04:00
u3_noun van,
u3_noun sut,
u3_noun dep,
u3_noun way,
u3_noun cog)
2013-12-31 23:30:37 +04:00
{
2014-08-28 23:40:40 +04:00
c3_m fun_m = c3__fino;
2014-11-06 03:20:01 +03:00
u3_noun pro = u3z_find_4(fun_m, sut, dep, way, cog);
2013-12-31 23:30:37 +04:00
2014-11-06 02:36:30 +03:00
if ( u3_none != pro ) {
2014-08-28 23:40:40 +04:00
return pro;
2013-12-31 23:30:37 +04:00
}
else {
2014-09-04 01:33:18 +04:00
pro = _cqfu_fino(van, sut, dep, way, cog);
2013-12-31 23:30:37 +04:00
2014-11-06 03:20:01 +03:00
return u3z_save_4(fun_m, sut, dep, way, cog, pro);
2013-12-31 23:30:37 +04:00
}
}
2013-09-29 00:21:18 +04:00
/* boilerplate
*/
2014-09-06 00:13:24 +04:00
u3_noun
2014-11-06 22:13:57 +03:00
u3wfu_find(
2014-09-06 00:13:24 +04:00
u3_noun cor)
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
u3_noun sut, dep, way, cog, van;
2013-09-29 00:21:18 +04:00
2014-11-18 00:56:51 +03:00
if ( (c3n == u3r_mean(cor, u3x_sam_2, &dep,
u3x_sam_6, &way,
u3x_sam_7, &cog,
u3x_con, &van,
2013-09-29 00:21:18 +04:00
0)) ||
2014-11-18 00:56:51 +03:00
(u3_none == (sut = u3r_at(u3x_sam, van))) )
2013-09-29 00:21:18 +04:00
{
2014-11-06 03:20:01 +03:00
return u3m_bail(c3__fail);
2013-09-29 00:21:18 +04:00
} else {
2014-09-03 09:46:55 +04:00
return _cqfu_find(van, sut, dep, way, cog);
2013-09-29 00:21:18 +04:00
}
}
2014-09-06 00:13:24 +04:00
u3_noun
2014-11-06 22:13:57 +03:00
u3qfu_find(
2014-09-06 00:13:24 +04:00
u3_noun van,
u3_noun sut,
u3_noun dep,
u3_noun way,
u3_noun cog)
2013-09-29 00:21:18 +04:00
{
2014-08-28 23:40:40 +04:00
c3_m fun_m = c3__find;
2014-11-06 03:20:01 +03:00
u3_noun pro = u3z_find_4(fun_m, sut, dep, way, cog);
2013-09-29 00:21:18 +04:00
2014-11-06 02:36:30 +03:00
if ( u3_none != pro ) {
2014-08-28 23:40:40 +04:00
return pro;
2013-09-29 00:21:18 +04:00
}
else {
2014-09-03 09:46:55 +04:00
pro = _cqfu_find(van, sut, dep, way, cog);
2013-09-29 00:21:18 +04:00
2014-11-06 03:20:01 +03:00
return u3z_save_4(fun_m, sut, dep, way, cog, pro);
2013-09-29 00:21:18 +04:00
}
}