urbit/j/6/ut_conk.c

82 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-09-06 00:13:24 +04:00
u3_bean
2014-10-28 20:36:22 +03:00
_cqfu_conk(u3_noun van, u3_noun sut, u3_noun got)
{
2014-09-06 00:13:24 +04:00
if ( u3_yes == u3ud(got) ) {
return u3_cqf_face(got, sut);
}
2014-09-06 00:13:24 +04:00
else switch ( u3h(got) ) {
default: return u3_cm_bail(c3__fail);
case 0: {
2014-09-06 00:13:24 +04:00
return u3k(sut);
}
case 1: {
2014-09-06 00:13:24 +04:00
return u3_cqf_face
(u3h(u3t(got)),
_cqfu_conk(van, sut, u3t(u3t(got))));
}
case 2: {
2014-09-06 00:13:24 +04:00
u3_bean vet = u3_cr_at(u3_cqfu_van_vet, van);
2014-10-28 20:36:22 +03:00
u3_noun hed, tal, deh, lat, ret;
2014-09-06 00:13:24 +04:00
if ( u3_yes == vet ) {
u3_noun cel = u3nt(c3__cell, c3__noun, c3__noun);
2014-09-06 00:13:24 +04:00
if ( u3_no == u3_cqfu_nest(van, cel, u3_yes, sut) ) {
return u3_cm_bail(c3__fail);
}
2014-09-06 00:13:24 +04:00
u3z(cel);
}
2014-09-06 00:13:24 +04:00
hed = u3_cqfu_peek(van, sut, c3__both, 2);
tal = u3_cqfu_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-10-28 20:36:22 +03:00
ret = u3_cqf_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
u3_cwfu_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-09-06 00:13:24 +04:00
if ( (u3_no == u3_cr_mean(cor, u3_cv_sam, &got,
u3_cv_con, &van,
2013-12-18 05:47:20 +04:00
0)) ||
2014-09-06 00:13:24 +04:00
(u3_none == (sut = u3_cr_at(u3_cv_sam, van))) )
2013-12-18 05:47:20 +04:00
{
2014-09-06 00:13:24 +04:00
return u3_cm_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
u3_cqfu_conk(u3_noun van,
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
}