shrub/jets/f/ut_conk.c

91 lines
1.8 KiB
C
Raw Normal View History

2013-12-18 05:47:20 +04:00
/* j/6/ut_conk.c
**
*/
#include "all.h"
2014-09-04 07:10:43 +04:00
2013-12-18 05:47:20 +04:00
/* logic
*/
2017-09-28 03:40:12 +03:00
static u3_noun
2015-08-28 19:34:36 +03:00
_cqfu_conk(u3_noun van,
u3_noun sut,
u3_noun got)
{
2014-11-05 04:18:47 +03:00
if ( c3y == u3ud(got) ) {
2017-09-28 03:40:12 +03:00
u3_noun nux = u3nc(u3_nul, u3k(got));
u3_noun ret = u3qf_face(nux, sut);
u3z(nux);
return ret;
}
2014-09-06 00:13:24 +04:00
else switch ( u3h(got) ) {
2014-11-06 03:20:01 +03:00
default: return u3m_bail(c3__fail);
case 0: {
2014-09-06 00:13:24 +04:00
return u3k(sut);
}
case 1: {
2014-10-31 00:40:05 +03:00
u3_noun cok = _cqfu_conk(van, sut, u3t(u3t(got)));
2017-09-28 03:40:12 +03:00
u3_noun nux = u3k(u3h(u3t(got)));
u3_noun ret = u3qf_face(nux, cok);
2014-10-31 00:40:05 +03:00
2017-09-28 03:40:12 +03:00
u3z(nux);
2014-10-31 00:40:05 +03:00
u3z(cok);
return ret;
}
case 2: {
2014-11-06 22:13:57 +03:00
u3_noun vet = u3r_at(u3qfu_van_vet, van);
2014-10-28 20:36:22 +03:00
u3_noun hed, tal, deh, lat, ret;
2014-11-05 04:18:47 +03:00
if ( c3y == vet ) {
2014-09-06 00:13:24 +04:00
u3_noun cel = u3nt(c3__cell, c3__noun, c3__noun);
2014-11-06 22:13:57 +03:00
if ( c3n == u3qfu_nest(van, cel, c3y, sut) ) {
2014-11-06 03:20:01 +03:00
return u3m_bail(c3__fail);
}
2014-09-06 00:13:24 +04:00
u3z(cel);
}
2014-11-06 22:13:57 +03:00
hed = u3qfu_peek(van, sut, c3__both, 2);
tal = u3qfu_peek(van, sut, c3__both, 3);
2014-10-28 20:36:22 +03:00
deh = _cqfu_conk(van, hed, u3h(u3t(got)));
lat = _cqfu_conk(van, tal, u3t(u3t(got)));
2014-11-06 22:13:57 +03:00
ret = u3qf_cell(deh, lat);
2014-10-28 20:36:22 +03:00
u3z(lat);
u3z(deh);
2014-09-06 00:13:24 +04:00
u3z(tal);
2014-10-28 20:36:22 +03:00
u3z(hed);
return ret;
}
}
}
2013-12-18 05:47:20 +04:00
/* boilerplate
*/
2014-09-06 00:13:24 +04:00
u3_noun
2014-11-06 22:13:57 +03:00
u3wfu_conk(u3_noun cor)
2013-12-18 05:47:20 +04:00
{
2014-09-06 00:13:24 +04:00
u3_noun sut, got, van;
2013-12-18 05:47:20 +04:00
2014-11-18 00:56:51 +03:00
if ( (c3n == u3r_mean(cor, u3x_sam, &got,
2015-08-28 19:34:36 +03:00
u3x_con, &van,
0)) ||
2014-11-18 00:56:51 +03:00
(u3_none == (sut = u3r_at(u3x_sam, van))) )
2013-12-18 05:47:20 +04:00
{
2014-11-06 03:20:01 +03:00
return u3m_bail(c3__fail);
2013-12-18 05:47:20 +04:00
} else {
2014-09-03 09:46:55 +04:00
return _cqfu_conk(van, sut, got);
2013-12-18 05:47:20 +04:00
}
}
2014-09-06 00:13:24 +04:00
u3_noun
2014-11-06 22:13:57 +03:00
u3qfu_conk(u3_noun van,
2015-08-28 19:34:36 +03:00
u3_noun sut,
u3_noun got)
2013-12-18 05:47:20 +04:00
{
2014-09-03 09:46:55 +04:00
return _cqfu_conk(van, sut, got);
2013-12-18 05:47:20 +04:00
}