urbit/j/f/ut_conk.c

84 lines
1.7 KiB
C
Raw Normal View History

2013-12-18 05:47:20 +04:00
/* j/6/ut_conk.c
**
** This file is in the public domain.
*/
#include "all.h"
2014-09-04 07:10:43 +04:00
2013-12-18 05:47:20 +04:00
/* logic
*/
2014-11-06 06:10:22 +03:00
u3_noun
2014-10-28 20:36:22 +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) ) {
2014-11-06 22:13:57 +03:00
return u3qf_face(got, sut);
}
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)));
2014-11-06 22:13:57 +03:00
u3_noun ret = u3qf_face(u3h(u3t(got)), cok);
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-06 03:20:01 +03:00
if ( (c3n == u3r_mean(cor, u3v_sam, &got,
u3v_con, &van,
2013-12-18 05:47:20 +04:00
0)) ||
2014-11-06 03:20:01 +03:00
(u3_none == (sut = u3r_at(u3v_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,
2014-09-06 00:13:24 +04: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
}