shrub/j/6/ut_seek.c

280 lines
5.8 KiB
C
Raw Normal View History

2013-09-29 00:21:18 +04:00
/* j/6/seek.c
**
** This file is in the public domain.
*/
#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
_seek_flat(
2014-09-06 00:13:24 +04:00
u3_noun wob)
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
if ( u3_nul == wob ) {
return u3_nul;
2013-09-29 00:21:18 +04:00
} else {
2014-09-06 00:13:24 +04:00
u3_noun i_wob = u3h(wob);
u3_noun t_wob = u3t(wob);
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04:00
return u3nc
(u3nc(u3k(u3h(i_wob)),
u3nt(c3__ash, u3_nul, 1)),
2014-08-21 01:18:34 +04:00
_seek_flat(t_wob));
2013-09-29 00:21:18 +04:00
}
}
2013-11-12 11:09:11 +04:00
#if 0
2014-09-06 00:13:24 +04:00
static u3_noun
2014-08-21 01:18:34 +04:00
_seek_silk_yew(
2014-09-06 00:13:24 +04:00
u3_noun van,
u3_noun syx,
u3_noun qq_tor)
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
if ( u3_nul == qq_tor ) {
return u3_nul;
2013-09-29 00:21:18 +04:00
}
else {
2014-09-06 00:13:24 +04:00
u3_noun iqq_tor = u3h(qq_tor);
u3_noun qiqq_tor = u3t(iqq_tor);
u3_noun yon = _seek_silk_yew(van, syx, u3t(qq_tor));
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04:00
if ( c3__yew != u3h(qiqq_tor) ) {
2013-09-29 00:21:18 +04:00
return yon;
} else {
2014-09-06 00:13:24 +04:00
u3_noun nuy = u3_cqf_look(syx, u3t(qiqq_tor));
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04:00
if ( u3_nul == nuy ) {
return u3_cm_error("silk");
2013-09-29 00:21:18 +04:00
}
else {
2014-09-06 00:13:24 +04:00
yon = u3nc(u3k(u3t(nuy)), yon);
u3z(nuy);
2013-09-29 00:21:18 +04:00
return yon;
}
}
}
2013-09-29 00:21:18 +04:00
}
2014-09-06 00:13:24 +04:00
static u3_noun
_seek_silk_yaw(u3_noun
u3_noun hey)
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
u3_atom axe = 0;
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04:00
while ( u3_nul != hey ) {
2013-09-29 00:21:18 +04:00
if ( axe == 0 ) {
2014-09-06 00:13:24 +04:00
axe = u3h(u3h(hey));
} else if ( axe != u3h(u3h(hey)) ) {
return u3_cm_error("silk");
2013-09-29 00:21:18 +04:00
}
2014-09-06 00:13:24 +04:00
hey = u3t(hey);
2013-09-29 00:21:18 +04:00
}
}
2014-09-06 00:13:24 +04:00
static u3_noun
_seek_silk_fum(u3_noun
u3_noun hey,
u3_noun qq_tor)
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
if ( u3_nul == qq_tor ) {
return u3_nul;
2013-09-29 00:21:18 +04:00
}
2014-09-06 00:13:24 +04:00
c3_assert(u3_nul != hey);
return u3nc
(u3nc(u3k(u3h(u3h(qq_tor))),
u3k(u3t(u3h(hey)))),
_seek_silk_fum(u3t(hey), u3t(qq_tor)));
2013-09-29 00:21:18 +04:00
}
2014-09-06 00:13:24 +04:00
static u3_noun
2014-08-21 01:18:34 +04:00
_seek_silk(
2014-09-06 00:13:24 +04:00
u3_noun van,
u3_noun syx,
u3_noun tor)
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
u3_noun p_tor, q_tor, pq_tor, qq_tor;
u3_noun hey, ret;
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04:00
u3_cr_cell(tor, &p_tor, &q_tor);
if ( u3_yes == u3h(q_tor) ) {
return u3_nul;
2013-09-29 00:21:18 +04:00
}
2014-09-06 00:13:24 +04:00
u3_cr_cell(u3t(q_tor), &pq_tor, &qq_tor);
2014-08-21 01:18:34 +04:00
hey = _seek_silk_yew(van, syx, qq_tor);
2014-09-06 00:13:24 +04:00
if ( u3_nul == hey ) {
return u3_nul;
2013-09-29 00:21:18 +04:00
}
2014-09-06 00:13:24 +04:00
if ( u3_ckb_lent(u3k(hey)) !=
u3_ckb_lent(u3k(qq_tor)) )
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
return u3_cm_error("silk");
2013-09-29 00:21:18 +04:00
}
2014-09-06 00:13:24 +04:00
ret = u3nq
(u3_nul,
u3_no,
u3_cqc_peg(pq_tor, _seek_silk_yaw(hey)),
2014-08-21 01:18:34 +04:00
_seek_silk_fum(hey, qq_tor));
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04:00
u3z(hey);
2013-09-29 00:21:18 +04:00
return ret;
}
#endif
2014-09-06 00:13:24 +04:00
u3_noun
2014-09-03 09:46:55 +04:00
_cqfu_seek(
2014-09-06 00:13:24 +04:00
u3_noun van,
u3_noun sut,
u3_noun way,
u3_noun hyp)
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
if ( u3_nul == hyp ) {
return u3nt
(1, u3_yes, u3k(sut));
2013-09-29 00:21:18 +04:00
}
2014-09-06 00:13:24 +04:00
else if ( u3_no == u3du(hyp) ) {
return u3_cm_bail(c3__fail);
2013-09-29 00:21:18 +04:00
}
else {
2014-09-06 00:13:24 +04:00
u3_noun i_hyp = u3h(hyp);
u3_noun t_hyp = u3t(hyp);
u3_noun zar;
u3_noun p_zar, q_zar;
u3_noun yip, syp, ret;
if ( u3_yes == u3du(i_hyp) ) {
yip = u3k(i_hyp);
2013-09-29 00:21:18 +04:00
} else {
2014-09-06 00:13:24 +04:00
yip = u3nt(u3_no, 0, u3k(i_hyp));
2013-09-29 00:21:18 +04:00
}
2014-09-03 09:46:55 +04:00
zar = _cqfu_seek(van, sut, way, t_hyp);
2014-09-06 00:13:24 +04:00
u3_cr_cell(zar, &p_zar, &q_zar);
2013-09-29 00:21:18 +04:00
2013-12-26 21:12:07 +04:00
#if 0
2014-09-06 00:13:24 +04:00
if ( u3_yes == u3h(yip) ) {
sic = u3_nul;
2013-09-29 00:21:18 +04:00
} else {
2014-09-06 00:13:24 +04:00
// sic = _seek_silk(van, u3h(u3t(yip)), zar);
sic = u3_nul;
2013-09-29 00:21:18 +04:00
}
2014-09-06 00:13:24 +04:00
if ( u3_nul != sic ) {
u3z(yip);
u3z(zar);
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04:00
return u3t(sic);
2013-09-29 00:21:18 +04:00
}
2013-12-26 21:12:07 +04:00
#endif
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04:00
if ( u3_yes == u3h(q_zar) ) {
syp = u3k(u3t(q_zar));
2013-09-29 00:21:18 +04:00
} else {
2014-09-06 00:13:24 +04:00
u3_noun pq_zar, qq_zar;
u3_noun wip;
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04:00
u3_cr_cell(u3t(q_zar), &pq_zar, &qq_zar);
2014-08-21 01:18:34 +04:00
wip = _seek_flat(qq_zar);
2014-09-06 00:13:24 +04:00
syp = u3_cqfu_fire(van, sut, wip);
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04:00
u3z(wip);
2013-09-29 00:21:18 +04:00
}
2014-09-06 00:13:24 +04:00
if ( u3_no == u3h(yip) ) {
u3_noun p_yip, q_yip, hud;
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04:00
if ( u3_no == u3_cr_cell(u3t(yip), &p_yip, &q_yip) ) {
return u3_cm_bail(c3__fail);
2013-09-29 00:21:18 +04:00
}
2014-09-06 00:13:24 +04:00
hud = u3_cqfu_fink(van, syp, p_yip, way, q_yip);
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
u3_noun p_hud, q_hud;
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04:00
u3_cr_cell(hud, &p_hud, &q_hud);
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04:00
ret = u3nc(u3_cqc_peg(p_zar, p_hud),
u3k(q_hud));
u3z(hud);
2013-09-29 00:21:18 +04:00
}
}
2013-09-29 00:21:18 +04:00
else {
2014-09-06 00:13:24 +04:00
u3_noun p_yip = u3t(yip);
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04:00
if ( u3_no == u3ud(p_yip) ) {
return u3_cm_bail(c3__fail);
2013-09-29 00:21:18 +04:00
}
else {
2014-09-06 00:13:24 +04:00
ret = u3nt
(u3_cqc_peg(p_zar, p_yip),
u3_yes,
u3_cqfu_peek(van, syp, way, p_yip));
2013-09-29 00:21:18 +04:00
}
}
2014-09-06 00:13:24 +04:00
u3z(yip);
u3z(syp);
u3z(zar);
2013-09-29 00:21:18 +04:00
return ret;
}
}
/* boilerplate
*/
2014-09-06 00:13:24 +04:00
u3_noun
u3_cwfu_seek(
u3_noun cor)
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
u3_noun sut, way, hyp, van;
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04:00
if ( (u3_no == u3_cr_mean(cor, u3_cv_sam_2, &way,
u3_cv_sam_3, &hyp,
u3_cv_con, &van,
2013-09-29 00:21:18 +04:00
0)) ||
2014-09-06 00:13:24 +04:00
(u3_none == (sut = u3_cr_at(u3_cv_sam, van))) )
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
return u3_cm_bail(c3__fail);
2013-09-29 00:21:18 +04:00
} else {
2014-09-03 09:46:55 +04:00
return _cqfu_seek(van, sut, way, hyp);
2013-09-29 00:21:18 +04:00
}
}
2014-09-06 00:13:24 +04:00
u3_noun
u3_cqfu_seek(u3_noun van,
u3_noun sut,
u3_noun way,
u3_noun hyp)
2013-09-29 00:21:18 +04:00
{
2014-08-28 23:40:40 +04:00
c3_m fun_m = c3__seek;
2014-09-06 00:13:24 +04:00
u3_noun pro = u3_cz_find_3(fun_m, sut, way, hyp);
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04: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_seek(van, sut, way, hyp);
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04:00
return u3_cz_save_3(fun_m, sut, way, hyp, pro);
2013-09-29 00:21:18 +04:00
}
}
2014-09-06 00:13:24 +04:00
u3_noun
u3_cqfu_seep(u3_noun van,
u3_noun sut,
u3_noun way,
u3_noun hyp)
2013-12-26 21:12:07 +04:00
{
2014-09-06 00:13:24 +04:00
u3_noun zar = u3_cqfu_seek(van, sut, way, hyp);
u3_noun p_zar = u3h(zar);
u3_noun q_zar = u3t(zar);
2014-01-05 00:19:59 +04:00
2014-09-06 00:13:24 +04:00
if ( u3_yes != u3h(q_zar) ) {
return u3_cm_bail(c3__exit);
2013-12-26 21:12:07 +04:00
}
else {
2014-09-06 00:13:24 +04:00
u3_noun ret = u3nc(u3k(p_zar),
u3k(u3t(q_zar)));
2013-12-26 21:12:07 +04:00
2014-09-06 00:13:24 +04:00
u3z(zar);
2013-12-26 21:12:07 +04:00
return ret;
}
}