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
|
|
|
|
*/
|
|
|
|
u2_noun
|
2014-09-03 09:46:55 +04:00
|
|
|
_cqfu_cull(u2_noun, u2_noun, u2_bean, u2_atom, u2_noun);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-04-22 05:22:11 +04:00
|
|
|
static u2_noun
|
2014-08-21 01:18:34 +04:00
|
|
|
_cull_in(
|
2014-09-04 01:33:18 +04:00
|
|
|
u2_noun van,
|
|
|
|
u2_noun sut,
|
|
|
|
u2_bean pol,
|
|
|
|
u2_atom axe,
|
|
|
|
u2_noun ref,
|
|
|
|
u2_noun now,
|
|
|
|
u2_noun lat,
|
|
|
|
u2_noun vil)
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2013-12-26 21:12:07 +04:00
|
|
|
u2_noun ret, p_sut, q_sut;
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-08-21 01:18:34 +04:00
|
|
|
if ( u2_no == u2du(sut) ) switch ( sut ) {
|
|
|
|
default: return u2_cm_bail(c3__fail);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
|
|
|
case c3__noun: {
|
2014-09-03 07:36:29 +04:00
|
|
|
u2_noun pyr = u2_cqfu_repo(van, sut);
|
2014-09-03 09:46:55 +04:00
|
|
|
u2_noun yot = _cqfu_cull(van, pyr, pol, axe, ref);
|
2014-04-22 05:22:11 +04:00
|
|
|
|
2014-08-21 01:18:34 +04:00
|
|
|
if ( u2_yes == u2_cr_sing(pyr, yot) ) {
|
|
|
|
ret = u2k(sut);
|
2013-09-29 00:21:18 +04:00
|
|
|
} else {
|
2014-08-21 01:18:34 +04:00
|
|
|
ret = u2k(yot);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
2014-08-21 01:18:34 +04:00
|
|
|
u2z(pyr);
|
|
|
|
u2z(yot);
|
2013-09-29 00:21:18 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case c3__void: {
|
|
|
|
ret = c3__void;
|
|
|
|
}
|
|
|
|
}
|
2014-08-21 01:18:34 +04:00
|
|
|
else switch ( u2h(sut) ) {
|
|
|
|
default: return u2_cm_bail(c3__fail);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
|
|
|
case c3__atom: {
|
2014-04-22 05:22:11 +04:00
|
|
|
ret = c3__void;
|
2013-09-29 00:21:18 +04:00
|
|
|
break;
|
|
|
|
}
|
2014-08-21 01:18:34 +04:00
|
|
|
case c3__bull: u2_cx_cell(u2t(sut), &p_sut, &q_sut);
|
2013-12-26 21:12:07 +04:00
|
|
|
{
|
2014-09-03 09:46:55 +04:00
|
|
|
u2_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-08-21 01:18:34 +04:00
|
|
|
if ( u2_yes == u2_cr_sing(hic, q_sut) ) {
|
|
|
|
ret = u2k(sut);
|
2013-12-26 21:12:07 +04:00
|
|
|
} else {
|
2014-09-03 07:36:29 +04:00
|
|
|
ret = u2_cqf_bull(p_sut, hic);
|
2013-12-26 21:12:07 +04:00
|
|
|
}
|
2014-08-21 01:18:34 +04:00
|
|
|
u2z(hic);
|
2013-12-26 21:12:07 +04:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2014-08-21 01:18:34 +04:00
|
|
|
case c3__cell: u2_cx_cell(u2t(sut), &p_sut, &q_sut);
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
|
|
|
u2_noun hub;
|
|
|
|
|
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-03 07:36:29 +04:00
|
|
|
ret = u2_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-03 07:36:29 +04:00
|
|
|
ret = u2_cqf_cell(p_sut, hub);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
2014-08-21 01:18:34 +04:00
|
|
|
u2z(hub);
|
2013-09-29 00:21:18 +04:00
|
|
|
break;
|
|
|
|
}
|
2014-08-21 01:18:34 +04:00
|
|
|
case c3__core: u2_cx_cell(u2t(sut), &p_sut, &q_sut);
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-08-21 01:18:34 +04:00
|
|
|
if ( 3 != now ) {
|
|
|
|
ret = u2k(sut);
|
2013-09-29 00:21:18 +04:00
|
|
|
} else {
|
2014-09-03 09:46:55 +04:00
|
|
|
u2_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-03 07:36:29 +04:00
|
|
|
ret = u2_cqf_core(hub, q_sut);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-08-21 01:18:34 +04:00
|
|
|
u2z(hub);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2014-08-21 01:18:34 +04:00
|
|
|
case c3__face: u2_cx_cell(u2t(sut), &p_sut, &q_sut);
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-09-03 09:46:55 +04:00
|
|
|
u2_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-08-21 01:18:34 +04:00
|
|
|
if ( u2_yes == u2_cr_sing(hic, q_sut) ) {
|
|
|
|
ret = u2k(sut);
|
2013-09-29 00:21:18 +04:00
|
|
|
} else {
|
2014-09-03 07:36:29 +04:00
|
|
|
ret = u2_cqf_face(p_sut, hic);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
2014-08-21 01:18:34 +04:00
|
|
|
u2z(hic);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2014-08-21 01:18:34 +04:00
|
|
|
case c3__fork: u2_cx_cell(u2t(sut), &p_sut, &q_sut);
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-09-03 07:36:29 +04:00
|
|
|
if ( u2_yes == u2_cqdi_has(vil, sut) ) {
|
2013-09-29 00:21:18 +04:00
|
|
|
return c3__void;
|
|
|
|
} else {
|
2014-09-03 07:36:29 +04:00
|
|
|
u2_noun zoc = u2_cqdi_put(vil, sut);
|
2013-09-29 00:21:18 +04:00
|
|
|
u2_noun sin = _cull_in
|
2014-08-21 01:18:34 +04:00
|
|
|
(van, p_sut, pol, axe, ref, now, lat, zoc);
|
2013-09-29 00:21:18 +04:00
|
|
|
u2_noun dex = _cull_in
|
2014-08-21 01:18:34 +04:00
|
|
|
(van, q_sut, pol, axe, ref, now, lat, zoc);
|
2014-04-22 05:22:11 +04:00
|
|
|
|
2014-09-03 07:36:29 +04:00
|
|
|
ret = u2_cqf_fork(sin, dex);
|
2014-08-21 01:18:34 +04:00
|
|
|
u2z(sin);
|
|
|
|
u2z(dex);
|
|
|
|
u2z(zoc);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
2014-04-22 05:22:11 +04:00
|
|
|
case c3__cube:
|
|
|
|
case c3__hold:
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-09-03 07:36:29 +04:00
|
|
|
u2_noun pyr = u2_cqfu_repo(van, sut);
|
2014-08-21 01:18:34 +04:00
|
|
|
u2_noun yot = _cull_in(van, pyr, pol, axe, ref, now, lat, vil);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-08-21 01:18:34 +04:00
|
|
|
if ( u2_yes == u2_cr_sing(pyr, yot) ) {
|
2013-09-29 00:21:18 +04:00
|
|
|
if ( c3__void == pyr ) {
|
|
|
|
ret = c3__void;
|
|
|
|
}
|
2014-08-21 01:18:34 +04:00
|
|
|
else ret = u2k(sut);
|
2013-09-29 00:21:18 +04:00
|
|
|
} else {
|
2014-08-21 01:18:34 +04:00
|
|
|
ret = u2k(yot);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
2014-08-21 01:18:34 +04:00
|
|
|
u2z(pyr);
|
|
|
|
u2z(yot);
|
2013-09-29 00:21:18 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-08-21 01:18:34 +04:00
|
|
|
u2z(lat);
|
2013-09-29 00:21:18 +04:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-09-04 01:33:18 +04:00
|
|
|
u2_noun
|
2014-09-03 09:46:55 +04:00
|
|
|
_cqfu_cull(
|
2014-09-04 01:33:18 +04:00
|
|
|
u2_noun van,
|
|
|
|
u2_noun sut,
|
|
|
|
u2_bean pol,
|
|
|
|
u2_atom axe,
|
|
|
|
u2_noun ref)
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-08-21 01:18:34 +04:00
|
|
|
if ( 1 == axe ) {
|
2013-09-29 00:21:18 +04:00
|
|
|
if ( u2_yes == pol ) {
|
2014-09-03 07:36:29 +04:00
|
|
|
return u2_cqfu_fuse(van, sut, ref);
|
2013-09-29 00:21:18 +04:00
|
|
|
} else {
|
2014-09-03 07:36:29 +04:00
|
|
|
return u2_cqfu_crop(van, sut, ref);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
} else {
|
2014-09-03 07:36:29 +04:00
|
|
|
u2_atom now = u2_cqc_cap(axe);
|
|
|
|
u2_atom lat = u2_cqc_mas(axe);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-08-21 01:18:34 +04:00
|
|
|
return _cull_in(van, sut, pol, axe, ref, now, lat, u2_nul);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
}
|
2014-04-22 05:22:11 +04:00
|
|
|
|
2013-09-29 00:21:18 +04:00
|
|
|
/* boilerplate
|
|
|
|
*/
|
2014-09-04 01:33:18 +04:00
|
|
|
u2_noun
|
|
|
|
u2_cwfu_cull(u2_noun cor)
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
|
|
|
u2_noun sut, axe, pol, ref, van;
|
|
|
|
|
2014-08-21 01:18:34 +04:00
|
|
|
if ( (u2_no == u2_cr_mean(cor, u2_cv_sam_2, &pol,
|
2014-04-22 05:22:11 +04:00
|
|
|
u2_cv_sam_6, &axe,
|
2013-09-29 00:21:18 +04:00
|
|
|
u2_cv_sam_7, &ref,
|
|
|
|
u2_cv_con, &van, 0)) ||
|
2014-08-21 01:18:34 +04:00
|
|
|
(u2_no == u2ud(axe)) ||
|
|
|
|
(u2_none == (sut = u2_cr_at(u2_cv_sam, van))) )
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-08-21 01:18:34 +04:00
|
|
|
return u2_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-04 01:33:18 +04:00
|
|
|
u2_noun
|
|
|
|
u2_cqfu_cull(u2_noun van,
|
|
|
|
u2_noun sut,
|
|
|
|
u2_bean pol,
|
|
|
|
u2_noun axe,
|
|
|
|
u2_noun ref)
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-08-28 23:40:40 +04:00
|
|
|
c3_m fun_m = c3__cull;
|
|
|
|
u2_noun pro = u2_cz_find_4(fun_m, sut, pol, axe, ref);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-08-28 23:40:40 +04:00
|
|
|
if ( u2_none != pro ) {
|
|
|
|
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-08-28 23:40:40 +04:00
|
|
|
return u2_cz_save_4(fun_m, sut, pol, axe, ref, pro);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
}
|