urbit/j/f/ut_seek.c

296 lines
6.1 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-11-06 22:13:57 +03:00
u3_noun nuy = u3qf_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 ) {
2014-11-06 03:20:01 +03:00
return u3m_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)) ) {
2014-11-06 03:20:01 +03:00
return u3m_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-11-06 03:20:01 +03:00
u3r_cell(tor, &p_tor, &q_tor);
2014-11-05 04:18:47 +03:00
if ( c3y == u3h(q_tor) ) {
2014-09-06 00:13:24 +04:00
return u3_nul;
2013-09-29 00:21:18 +04:00
}
2014-11-06 03:20:01 +03:00
u3r_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-11-06 22:13:57 +03:00
if ( u3kb_lent(u3k(hey)) !=
u3kb_lent(u3k(qq_tor)) )
2013-09-29 00:21:18 +04:00
{
2014-11-06 03:20:01 +03:00
return u3m_error("silk");
2013-09-29 00:21:18 +04:00
}
2014-09-06 00:13:24 +04:00
ret = u3nq
(u3_nul,
2014-11-05 04:18:47 +03:00
c3n,
2014-11-06 22:13:57 +03:00
u3qc_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
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 {
2014-11-05 04:18:47 +03:00
yip = u3nt(c3n, 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-11-06 03:20:01 +03:00
u3r_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-11-05 04:18:47 +03:00
if ( c3y == u3h(yip) ) {
2014-09-06 00:13:24 +04:00
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-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
2014-11-06 03:20:01 +03:00
if ( c3n == u3r_cell(u3t(yip), &p_yip, &q_yip) ) {
return u3m_bail(c3__fail);
2013-09-29 00:21:18 +04:00
}
2014-11-06 22:13:57 +03:00
hud = u3qfu_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-11-06 03:20:01 +03:00
u3r_cell(hud, &p_hud, &q_hud);
2013-09-29 00:21:18 +04:00
2014-11-06 22:13:57 +03:00
ret = u3nc(u3qc_peg(p_zar, p_hud),
2014-09-06 00:13:24 +04:00
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-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 {
2014-09-06 00:13:24 +04:00
ret = u3nt
2014-11-06 22:13:57 +03:00
(u3qc_peg(p_zar, p_yip),
2014-11-05 04:18:47 +03:00
c3y,
2014-11-06 22:13:57 +03:00
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,
u3x_sam_3, &hyp,
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_seek(van, sut, way, hyp);
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_seek(u3_noun van,
2014-09-06 00:13:24 +04:00
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-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
}
}
2014-09-06 00:13:24 +04:00
u3_noun
2014-11-06 22:13:57 +03:00
u3qfu_seep(u3_noun van,
2014-09-06 00:13:24 +04:00
u3_noun sut,
u3_noun way,
u3_noun hyp)
2013-12-26 21:12:07 +04:00
{
2014-11-06 22:13:57 +03:00
u3_noun zar = u3qfu_seek(van, sut, way, hyp);
2014-09-06 00:13:24 +04:00
u3_noun p_zar = u3h(zar);
u3_noun q_zar = u3t(zar);
2014-01-05 00:19:59 +04:00
2014-11-05 04:18:47 +03:00
if ( c3y != u3h(q_zar) ) {
2014-11-06 03:20:01 +03:00
return u3m_bail(c3__exit);
2013-12-26 21:12:07 +04:00
}
else {
2014-09-11 16:34:00 +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;
}
}
2014-09-11 16:34:00 +04:00
u3_noun
2014-11-06 22:13:57 +03:00
u3wfu_seep(u3_noun cor)
2014-09-11 16:34:00 +04:00
{
u3_noun sut, way, hyp, van;
2014-11-18 00:56:51 +03:00
if ( (c3n == u3r_mean(cor, u3x_sam_2, &way,
u3x_sam_3, &hyp,
u3x_con, &van,
2014-09-11 16:34:00 +04:00
0)) ||
2014-11-18 00:56:51 +03:00
(u3_none == (sut = u3r_at(u3x_sam, van))) )
2014-09-11 16:34:00 +04:00
{
2014-11-06 03:20:01 +03:00
return u3m_bail(c3__fail);
2014-09-11 16:34:00 +04:00
} else {
2014-11-06 22:13:57 +03:00
return u3qfu_seep(van, sut, way, hyp);
2014-09-11 16:34:00 +04:00
}
}