shrub/j/f/ut_tock.c

100 lines
2.2 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-11-05 04:18:47 +03:00
if ( c3n == u3du(men) ) {
2014-09-06 00:13:24 +04:00
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);
2014-11-06 22:13:57 +03:00
u3_noun geq = u3qfu_tack(van, pi_men, peh, mur);
2014-09-06 00:13:24 +04:00
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))
2014-11-06 03:20:01 +03:00
: (c3n == u3r_sing(p_geq, u3t(p_mox)))
? u3m_bail(c3__exit)
2014-09-06 00:13:24 +04:00
: u3k(p_mox) ),
2014-10-10 05:27:02 +04:00
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-12 01:01:22 +04:00
_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-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 ) {
2014-11-06 03:20:01 +03:00
return u3m_bail(c3__exit);
2013-09-29 00:21:18 +04:00
} else {
2014-10-10 05:27:02 +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
2014-11-06 22:13:57 +03:00
u3wfu_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-11-18 00:56:51 +03:00
if ( (c3n == u3r_mean(cor, u3x_sam_2, &peh,
u3x_sam_6, &mur,
u3x_sam_7, &men,
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_tock(van, sut, peh, mur, men);
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_tock(u3_noun van,
2014-09-06 00:13:24 +04:00
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
}