urbit/j/6/ut_tock.c

105 lines
2.5 KiB
C
Raw Normal View History

2013-09-29 00:21:18 +04:00
/* j/6/tock.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
/* internals
*/
2014-09-06 00:13:24 +04:00
static u3_noun
2014-08-21 01:18:34 +04:00
_tock_in(
2014-09-06 00:13:24 +04:00
u3_noun van,
u3_noun sut,
u3_noun peh,
u3_noun mur,
u3_noun men)
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
if ( u3_no == u3du(men) ) {
return u3nc(u3_nul, u3_nul);
}
2013-09-29 00:21:18 +04:00
else {
2014-09-06 00:13:24 +04:00
u3_noun i_men = u3h(men);
u3_noun pi_men = u3h(i_men);
u3_noun qi_men = u3t(i_men);
u3_noun t_men = u3t(men);
u3_noun geq = u3_cqfu_tack(van, pi_men, peh, mur);
u3_noun p_geq = u3h(geq);
u3_noun q_geq = u3t(geq);
u3_noun mox = _tock_in(van, sut, peh, mur, t_men);
u3_noun p_mox = u3h(mox);
u3_noun q_mox = u3t(mox);
u3_noun ret;
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04:00
ret = u3nc(
( (u3_nul == p_mox)
? u3nc(u3_nul, u3k(p_geq))
: (u3_no == u3_cr_sing(p_geq, u3t(p_mox)))
? u3_cm_bail(c3__exit)
: u3k(p_mox) ),
u3nc(u3nc(u3k(q_geq),
u3k(qi_men)),
u3k(q_mox)));
2014-08-21 01:18:34 +04:00
2014-09-06 00:13:24 +04:00
u3z(mox);
u3z(geq);
2013-09-29 00:21:18 +04:00
return ret;
}
}
2013-09-29 00:21:18 +04:00
/* functions
*/
2014-09-06 00:13:24 +04:00
u3_noun
2014-09-03 09:46:55 +04:00
_cqfu_tock(
2014-09-06 00:13:24 +04:00
u3_noun van,
u3_noun sut,
u3_noun peh,
u3_noun mur,
u3_noun men)
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
u3_noun wib = _tock_in(van, sut, peh, mur, men);
u3_noun p_wib = u3h(wib);
u3_noun q_wib = u3t(wib);
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04:00
if ( u3_nul == p_wib ) {
return u3_cm_bail(c3__exit);
2013-09-29 00:21:18 +04:00
} else {
2014-09-06 00:13:24 +04:00
u3_noun ret = u3nc(u3k(u3t(p_wib)),
u3k(q_wib));
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04:00
u3z(wib);
2013-09-29 00:21:18 +04:00
return ret;
}
}
/* boilerplate
*/
2014-09-06 00:13:24 +04:00
u3_noun
u3_cwfu_tock(
u3_noun cor)
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
u3_noun van, sut, peh, mur, men;
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, &peh,
u3_cv_sam_6, &mur,
u3_cv_sam_7, &men,
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_tock(van, sut, peh, mur, men);
2013-09-29 00:21:18 +04:00
}
}
2014-09-06 00:13:24 +04:00
u3_noun
u3_cqfu_tock(u3_noun van,
u3_noun sut,
u3_noun peh,
u3_noun mur,
u3_noun men)
2013-09-29 00:21:18 +04:00
{
2014-09-03 09:46:55 +04:00
return _cqfu_tock(van, sut, peh, mur, men);
2013-09-29 00:21:18 +04:00
}