shrub/jets/f/ut_seek.c

161 lines
3.4 KiB
C
Raw Normal View History

2013-09-29 00:21:18 +04:00
/* j/6/seek.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
2015-08-28 19:34:36 +03:00
_seek_flat(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
2015-08-28 19:34:36 +03:00
return u3nc(u3nc(u3k(u3h(i_wob)),
u3nt(c3__ash, u3_nul, 1)),
_seek_flat(t_wob));
2013-09-29 00:21:18 +04:00
}
}
2014-09-06 00:13:24 +04:00
u3_noun
2015-08-28 19:34:36 +03:00
_cqfu_seek(u3_noun van,
u3_noun sut,
u3_noun way,
u3_noun hyp)
2013-09-29 00:21:18 +04:00
{
2015-12-23 07:12:56 +03:00
c3_assert(0);
2014-09-06 00:13:24 +04:00
if ( u3_nul == hyp ) {
return u3nt
2014-11-05 04:18:47 +03:00
(1, c3y, u3k(sut));
2013-09-29 00:21:18 +04:00
}
2014-11-05 04:18:47 +03:00
else if ( c3n == u3du(hyp) ) {
2014-11-06 03:20:01 +03:00
return u3m_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;
2014-11-05 04:18:47 +03:00
if ( c3y == u3du(i_hyp) ) {
2014-09-06 00:13:24 +04:00
yip = u3k(i_hyp);
2013-09-29 00:21:18 +04:00
} else {
yip = u3nt(c3n, 0, u3nc(u3_nul, 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-11-06 03:20:01 +03:00
u3r_cell(zar, &p_zar, &q_zar);
2013-09-29 00:21:18 +04:00
2014-11-05 04:18:47 +03:00
if ( c3y == u3h(q_zar) ) {
2014-09-06 00:13:24 +04:00
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-11-06 03:20:01 +03:00
u3r_cell(u3t(q_zar), &pq_zar, &qq_zar);
2014-08-21 01:18:34 +04:00
wip = _seek_flat(qq_zar);
2014-11-06 22:13:57 +03:00
syp = u3qfu_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-11-05 04:18:47 +03:00
if ( c3n == u3h(yip) ) {
2014-09-06 00:13:24 +04:00
u3_noun p_yip, q_yip, hud;
2013-09-29 00:21:18 +04:00
if ( c3n == u3r_cell(u3t(yip), &p_yip, &q_yip) ) {
return u3m_bail(c3__fail);
}
2015-11-29 00:08:52 +03:00
hud = u3qfu_fink(van, syp, p_yip, way, q_yip);
{
u3_noun p_hud, q_hud;
u3r_cell(hud, &p_hud, &q_hud);
2014-11-06 22:13:57 +03:00
ret = u3nc(u3qc_peg(p_zar, p_hud),
2015-08-28 19:34:36 +03:00
u3k(q_hud));
2014-09-06 00:13:24 +04:00
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-11-05 04:18:47 +03:00
if ( c3n == u3ud(p_yip) ) {
2014-11-06 03:20:01 +03:00
return u3m_bail(c3__fail);
2013-09-29 00:21:18 +04:00
}
else {
2015-08-28 19:34:36 +03:00
ret = u3nt(u3qc_peg(p_zar, p_yip),
c3y,
u3qfu_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
2014-11-06 22:13:57 +03:00
u3wfu_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-11-18 00:56:51 +03:00
if ( (c3n == u3r_mean(cor, u3x_sam_2, &way,
2015-08-28 19:34:36 +03:00
u3x_sam_3, &hyp,
u3x_con, &van,
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_seek(van, sut, way, hyp);
2013-09-29 00:21:18 +04:00
}
}
2015-12-22 03:38:31 +03:00
#if 1
u3_noun
u3qfu_seek(u3_noun van,
u3_noun sut,
u3_noun way,
u3_noun hyp)
{
u3_noun von = u3i_molt(u3k(van), u3x_sam, u3k(sut), 0);
u3_noun gat = u3j_hook(von, "seek");
return u3n_kick_on(u3i_molt(gat,
u3x_sam_2,
u3k(way),
u3x_sam_3,
u3k(hyp),
0));
}
#else
2014-09-06 00:13:24 +04:00
u3_noun
2014-11-06 22:13:57 +03:00
u3qfu_seek(u3_noun van,
2015-08-28 19:34:36 +03:00
u3_noun sut,
u3_noun way,
u3_noun hyp)
2013-09-29 00:21:18 +04:00
{
2015-12-22 01:45:22 +03:00
c3_m fun_m = c3__seek + !!u3r_at(u3qfu_van_vet, van);
2014-11-06 03:20:01 +03:00
u3_noun pro = u3z_find_3(fun_m, sut, way, hyp);
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_seek(van, sut, way, hyp);
2013-09-29 00:21:18 +04:00
2014-11-06 03:20:01 +03:00
return u3z_save_3(fun_m, sut, way, hyp, pro);
2013-09-29 00:21:18 +04:00
}
}
2015-12-22 03:38:31 +03:00
#endif
2013-09-29 00:21:18 +04:00