shrub/j/6/ut_cull.c

212 lines
4.8 KiB
C
Raw Normal View History

2013-09-29 00:21:18 +04:00
/* j/6/cull.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
/* logic
*/
2014-09-06 00:13:24 +04:00
u3_noun
_cqfu_cull(u3_noun, u3_noun, u3_bean, u3_atom, u3_noun);
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04:00
static u3_noun
2014-08-21 01:18:34 +04:00
_cull_in(
2014-09-06 00:13:24 +04:00
u3_noun van,
u3_noun sut,
u3_bean pol,
u3_atom axe,
u3_noun ref,
u3_noun now,
u3_noun lat,
u3_noun vil)
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
u3_noun ret, p_sut, q_sut;
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04:00
if ( u3_no == u3du(sut) ) switch ( sut ) {
default: return u3_cm_bail(c3__fail);
2013-09-29 00:21:18 +04:00
case c3__noun: {
2014-09-06 00:13:24 +04:00
u3_noun pyr = u3_cqfu_repo(van, sut);
u3_noun yot = _cqfu_cull(van, pyr, pol, axe, ref);
2014-09-06 00:13:24 +04:00
if ( u3_yes == u3_cr_sing(pyr, yot) ) {
ret = u3k(sut);
2013-09-29 00:21:18 +04:00
} else {
2014-09-06 00:13:24 +04:00
ret = u3k(yot);
2013-09-29 00:21:18 +04:00
}
2014-09-06 00:13:24 +04:00
u3z(pyr);
u3z(yot);
2013-09-29 00:21:18 +04:00
break;
}
case c3__void: {
ret = c3__void;
}
}
2014-09-06 00:13:24 +04:00
else switch ( u3h(sut) ) {
default: return u3_cm_bail(c3__fail);
2013-09-29 00:21:18 +04:00
case c3__atom: {
ret = c3__void;
2013-09-29 00:21:18 +04:00
break;
}
2014-09-06 00:13:24 +04:00
case c3__bull: u3_cx_cell(u3t(sut), &p_sut, &q_sut);
2013-12-26 21:12:07 +04:00
{
2014-09-06 00:13:24 +04:00
u3_noun hic = _cqfu_cull
2014-08-21 01:18:34 +04:00
(van, q_sut, pol, axe, ref);
2013-12-26 21:12:07 +04:00
2014-09-06 00:13:24 +04:00
if ( u3_yes == u3_cr_sing(hic, q_sut) ) {
ret = u3k(sut);
2013-12-26 21:12:07 +04:00
} else {
2014-09-06 00:13:24 +04:00
ret = u3_cqf_bull(p_sut, hic);
2013-12-26 21:12:07 +04:00
}
2014-09-06 00:13:24 +04:00
u3z(hic);
2013-12-26 21:12:07 +04:00
break;
}
2014-09-06 00:13:24 +04:00
case c3__cell: u3_cx_cell(u3t(sut), &p_sut, &q_sut);
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
u3_noun hub;
2013-09-29 00:21:18 +04:00
2014-08-21 01:18:34 +04:00
if ( 2 == now ) {
2014-09-03 09:46:55 +04:00
hub = _cqfu_cull(van, p_sut, pol, lat, ref);
2014-09-06 00:13:24 +04:00
ret = u3_cqf_cell(hub, q_sut);
2013-09-29 00:21:18 +04:00
} else {
2014-09-03 09:46:55 +04:00
hub = _cqfu_cull(van, q_sut, pol, lat, ref);
2014-09-06 00:13:24 +04:00
ret = u3_cqf_cell(p_sut, hub);
2013-09-29 00:21:18 +04:00
}
2014-09-06 00:13:24 +04:00
u3z(hub);
2013-09-29 00:21:18 +04:00
break;
}
2014-09-06 00:13:24 +04:00
case c3__core: u3_cx_cell(u3t(sut), &p_sut, &q_sut);
2013-09-29 00:21:18 +04:00
{
2014-08-21 01:18:34 +04:00
if ( 3 != now ) {
2014-09-06 00:13:24 +04:00
ret = u3k(sut);
2013-09-29 00:21:18 +04:00
} else {
2014-09-06 00:13:24 +04:00
u3_noun hub = _cqfu_cull
2014-08-21 01:18:34 +04:00
(van, p_sut, pol, lat, ref);
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04:00
ret = u3_cqf_core(hub, q_sut);
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04:00
u3z(hub);
2013-09-29 00:21:18 +04:00
}
break;
}
2014-09-06 00:13:24 +04:00
case c3__face: u3_cx_cell(u3t(sut), &p_sut, &q_sut);
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
u3_noun hic = _cqfu_cull
2014-08-21 01:18:34 +04:00
(van, q_sut, pol, axe, ref);
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04:00
if ( u3_yes == u3_cr_sing(hic, q_sut) ) {
ret = u3k(sut);
2013-09-29 00:21:18 +04:00
} else {
2014-09-06 00:13:24 +04:00
ret = u3_cqf_face(p_sut, hic);
2013-09-29 00:21:18 +04:00
}
2014-09-06 00:13:24 +04:00
u3z(hic);
2013-09-29 00:21:18 +04:00
break;
}
2014-09-06 00:13:24 +04:00
case c3__fork: u3_cx_cell(u3t(sut), &p_sut, &q_sut);
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
if ( u3_yes == u3_cqdi_has(vil, sut) ) {
2013-09-29 00:21:18 +04:00
return c3__void;
} else {
2014-09-06 00:13:24 +04:00
u3_noun zoc = u3_cqdi_put(vil, sut);
u3_noun sin = _cull_in
2014-08-21 01:18:34 +04:00
(van, p_sut, pol, axe, ref, now, lat, zoc);
2014-09-06 00:13:24 +04:00
u3_noun dex = _cull_in
2014-08-21 01:18:34 +04:00
(van, q_sut, pol, axe, ref, now, lat, zoc);
2014-09-06 00:13:24 +04:00
ret = u3_cqf_fork(sin, dex);
u3z(sin);
u3z(dex);
u3z(zoc);
2013-09-29 00:21:18 +04:00
return ret;
}
}
case c3__cube:
case c3__hold:
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
u3_noun pyr = u3_cqfu_repo(van, sut);
u3_noun yot = _cull_in(van, pyr, pol, axe, ref, now, lat, vil);
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04:00
if ( u3_yes == u3_cr_sing(pyr, yot) ) {
2013-09-29 00:21:18 +04:00
if ( c3__void == pyr ) {
ret = c3__void;
}
2014-09-06 00:13:24 +04:00
else ret = u3k(sut);
2013-09-29 00:21:18 +04:00
} else {
2014-09-06 00:13:24 +04:00
ret = u3k(yot);
2013-09-29 00:21:18 +04:00
}
2014-09-06 00:13:24 +04:00
u3z(pyr);
u3z(yot);
2013-09-29 00:21:18 +04:00
break;
}
}
2014-09-06 00:13:24 +04:00
u3z(lat);
2013-09-29 00:21:18 +04:00
return ret;
}
2014-09-06 00:13:24 +04:00
u3_noun
2014-09-03 09:46:55 +04:00
_cqfu_cull(
2014-09-06 00:13:24 +04:00
u3_noun van,
u3_noun sut,
u3_bean pol,
u3_atom axe,
u3_noun ref)
2013-09-29 00:21:18 +04:00
{
2014-08-21 01:18:34 +04:00
if ( 1 == axe ) {
2014-09-06 00:13:24 +04:00
if ( u3_yes == pol ) {
return u3_cqfu_fuse(van, sut, ref);
2013-09-29 00:21:18 +04:00
} else {
2014-09-06 00:13:24 +04:00
return u3_cqfu_crop(van, sut, ref);
2013-09-29 00:21:18 +04:00
}
} else {
2014-09-06 00:13:24 +04:00
u3_atom now = u3_cqc_cap(axe);
u3_atom lat = u3_cqc_mas(axe);
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04:00
return _cull_in(van, sut, pol, axe, ref, now, lat, u3_nul);
2013-09-29 00:21:18 +04:00
}
}
2013-09-29 00:21:18 +04:00
/* boilerplate
*/
2014-09-06 00:13:24 +04:00
u3_noun
u3_cwfu_cull(u3_noun cor)
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
u3_noun sut, axe, pol, ref, van;
if ( (u3_no == u3_cr_mean(cor, u3_cv_sam_2, &pol,
u3_cv_sam_6, &axe,
u3_cv_sam_7, &ref,
u3_cv_con, &van, 0)) ||
(u3_no == u3ud(axe)) ||
(u3_none == (sut = u3_cr_at(u3_cv_sam, van))) )
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
return u3_cm_bail(c3__fail);
2013-09-29 00:21:18 +04:00
} else {
2014-09-03 09:46:55 +04:00
return _cqfu_cull(van, sut, pol, axe, ref);
2013-09-29 00:21:18 +04:00
}
}
2014-09-06 00:13:24 +04:00
u3_noun
u3_cqfu_cull(u3_noun van,
u3_noun sut,
u3_bean pol,
u3_noun axe,
u3_noun ref)
2013-09-29 00:21:18 +04:00
{
2014-08-28 23:40:40 +04:00
c3_m fun_m = c3__cull;
2014-09-06 00:13:24 +04:00
u3_noun pro = u3_cz_find_4(fun_m, sut, pol, axe, ref);
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04: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_cull(van, sut, pol, axe, ref);
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04:00
return u3_cz_save_4(fun_m, sut, pol, axe, ref, pro);
2013-09-29 00:21:18 +04:00
}
}