2013-09-29 00:21:18 +04:00
|
|
|
/* j/6/ut_rest.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
|
|
|
_rest_in_list(u3_noun van,
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_noun leg)
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-09-06 00:13:24 +04:00
|
|
|
if ( u3_nul == leg ) {
|
|
|
|
return u3_nul;
|
2013-09-29 00:21:18 +04:00
|
|
|
} else {
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_noun i_leg = u3h(leg);
|
|
|
|
u3_noun t_leg = u3t(leg);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2015-08-28 19:34:36 +03:00
|
|
|
return u3nc(u3qfu_play(van, u3h(i_leg), u3t(i_leg)),
|
|
|
|
_rest_in_list(van, t_leg));
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-06 00:13:24 +04:00
|
|
|
static u3_noun
|
2015-08-28 19:34:36 +03:00
|
|
|
_rest_in_stil(u3_noun van,
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_noun gar)
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-11-06 22:13:57 +03:00
|
|
|
u3_noun gun = u3qdi_gas(u3_nul, gar);
|
|
|
|
u3_noun nog = u3qdi_tap(gun, u3_nul);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-09-06 00:13:24 +04:00
|
|
|
u3z(gun);
|
2013-09-29 00:21:18 +04:00
|
|
|
return nog;
|
|
|
|
}
|
|
|
|
|
2014-09-06 00:13:24 +04:00
|
|
|
static u3_noun
|
2015-08-28 19:34:36 +03:00
|
|
|
_rest_in_fork(u3_noun nog,
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_noun fub)
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-11-05 04:18:47 +03:00
|
|
|
if ( c3n == u3du(nog) ) {
|
2013-09-29 00:21:18 +04:00
|
|
|
return fub;
|
|
|
|
} else {
|
2015-08-28 19:34:36 +03:00
|
|
|
u3_noun buf = _rest_in_fork(u3t(nog),
|
|
|
|
u3qf_fork(u3h(nog),
|
|
|
|
fub));
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-09-06 00:13:24 +04:00
|
|
|
u3z(fub);
|
2013-09-29 00:21:18 +04:00
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-06 00:13:24 +04:00
|
|
|
static u3_noun
|
2014-09-17 23:56:55 +04:00
|
|
|
_rest_in(u3_noun van,
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_noun leg)
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_noun gar = _rest_in_list(van, leg);
|
|
|
|
u3_noun nog = _rest_in_stil(van, gar);
|
|
|
|
u3_noun fub = _rest_in_fork(nog, c3__void);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-09-06 00:13:24 +04:00
|
|
|
u3z(gar);
|
|
|
|
u3z(nog);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
|
|
|
return fub;
|
|
|
|
}
|
|
|
|
|
2014-11-06 06:10:22 +03:00
|
|
|
static u3_noun
|
2015-08-28 19:34:36 +03:00
|
|
|
_rest_hit_fan(u3_noun fan,
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_noun leg)
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-09-06 00:13:24 +04:00
|
|
|
if ( u3_nul == leg ) {
|
2014-11-05 04:18:47 +03:00
|
|
|
return c3n;
|
2013-09-29 00:21:18 +04:00
|
|
|
} else {
|
2014-11-06 22:13:57 +03:00
|
|
|
return c3o(u3qdi_has(fan, u3h(leg)),
|
2014-09-06 00:13:24 +04:00
|
|
|
_rest_hit_fan(fan, u3t(leg)));
|
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_rest(u3_noun van,
|
|
|
|
u3_noun sut,
|
|
|
|
u3_noun leg)
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-11-06 22:13:57 +03:00
|
|
|
u3_noun fan = u3r_at(u3qfu_van_fan, van);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-11-05 04:18:47 +03:00
|
|
|
if ( c3y == _rest_hit_fan(fan, leg) ) {
|
2014-11-06 03:20:01 +03:00
|
|
|
return u3m_error("rest-loop");
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
else {
|
2014-11-06 22:13:57 +03:00
|
|
|
u3_noun naf = u3qdi_gas(fan, leg);
|
|
|
|
u3_noun nav = u3i_molt(u3k(van), u3qfu_van_fan, u3k(naf), 0);
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_noun mez = _rest_in(nav, leg);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-09-06 00:13:24 +04:00
|
|
|
u3z(naf);
|
|
|
|
u3z(nav);
|
2013-09-29 00:21:18 +04:00
|
|
|
return mez;
|
|
|
|
}
|
2014-04-22 05:22:11 +04:00
|
|
|
}
|
2013-09-29 00:21:18 +04:00
|
|
|
|
|
|
|
/* boilerplate
|
|
|
|
*/
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_noun
|
2015-08-28 19:34:36 +03:00
|
|
|
u3wfu_rest(u3_noun cor)
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_noun sut, leg, van;
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-11-18 00:56:51 +03:00
|
|
|
if ( (c3n == u3r_mean(cor, u3x_sam, &leg, u3x_con, &van, 0)) ||
|
|
|
|
(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_rest(van, sut, leg);
|
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_rest(u3_noun van,
|
2015-08-28 19:34:36 +03:00
|
|
|
u3_noun sut,
|
|
|
|
u3_noun leg)
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2015-12-22 01:45:22 +03:00
|
|
|
c3_m fun_m = c3__rest + !!u3r_at(u3qfu_van_vet, van);
|
2014-11-06 03:20:01 +03:00
|
|
|
u3_noun pro = u3z_find_2(fun_m, sut, leg);
|
2014-08-28 23:40:40 +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_rest(van, sut, leg);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-11-06 03:20:01 +03:00
|
|
|
return u3z_save_2(fun_m, sut, leg, pro);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
}
|