shrub/j/6/ut_firm.c

118 lines
2.8 KiB
C
Raw Normal View History

2013-09-29 00:21:18 +04:00
/* j/6/firm.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
2014-09-03 09:46:55 +04:00
_cqfu_firm(
2014-09-06 00:13:24 +04:00
u3_noun van,
u3_noun sut,
u3_noun dib)
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
u3_noun 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:
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
return u3_yes;
2013-09-29 00:21:18 +04:00
}
case c3__void:
{
2014-09-06 00:13:24 +04:00
return u3_no;
2013-09-29 00:21:18 +04:00
}
}
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
2014-09-06 00:13:24 +04:00
case c3__atom: p_sut = u3t(sut);
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
return u3ud(dib);
2013-09-29 00:21:18 +04:00
}
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 nun = u3_cr_at(u3h(u3t(u3t(p_sut))), dib);
2014-01-04 06:59:56 +04:00
2014-09-06 00:13:24 +04:00
if ( u3_none == nun ) {
return u3_no;
2014-01-04 06:59:56 +04:00
} else {
2014-09-06 00:13:24 +04:00
return u3_and(_cqfu_firm(van, q_sut, dib),
_cqfu_firm(van, u3t(u3t(u3t(p_sut))),
2014-01-04 06:59:56 +04:00
nun));
}
2013-12-26 21:12:07 +04:00
}
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
return u3_and
(u3du(dib),
u3_and(_cqfu_firm(van, p_sut, u3h(dib)),
_cqfu_firm(van, q_sut, u3t(dib))));
2013-09-29 00:21:18 +04:00
}
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-09-06 00:13:24 +04:00
u3_noun pq_sut, qq_sut, rq_sut, prq_sut, qrq_sut;
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04:00
u3_cx_trel(q_sut, &pq_sut, &qq_sut, &rq_sut);
u3_cx_cell(rq_sut, &prq_sut, &qrq_sut);
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04:00
return u3_and
(u3du(dib),
u3_and
(_cqfu_firm(van, p_sut, u3h(dib)),
((u3_nul == prq_sut) ? u3_cm_error("firm-core")
: u3_cr_sing(prq_sut, u3t(dib)))));
2013-09-29 00:21:18 +04:00
}
2014-09-06 00:13:24 +04:00
case c3__cube: 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
return u3_cr_sing(dib, p_sut);
2013-09-29 00:21:18 +04:00
}
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-03 09:46:55 +04:00
return _cqfu_firm(van, q_sut, dib);
2013-09-29 00:21:18 +04:00
}
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
return u3_or(_cqfu_firm(van, p_sut, dib),
2014-09-03 09:46:55 +04:00
_cqfu_firm(van, q_sut, dib));
2013-09-29 00:21:18 +04:00
}
case c3__hold:
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
u3_noun goy = u3_cqfu_repo(van, sut);
u3_noun ret = _cqfu_firm(van, goy, dib);
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04:00
u3z(goy);
2013-09-29 00:21:18 +04:00
return ret;
}
}
}
/* boilerplate
*/
2014-09-06 00:13:24 +04:00
u3_noun
u3_cwfu_firm(
u3_noun cor)
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
u3_noun sut, dib, van;
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04:00
if ( (u3_no == u3_cr_mean(cor, u3_cv_sam, &dib, u3_cv_con, &van, 0)) ||
(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_firm(van, sut, dib);
2013-09-29 00:21:18 +04:00
}
}
2014-09-06 00:13:24 +04:00
u3_noun
u3_cqfu_firm(u3_noun van,
u3_noun sut,
u3_noun dib)
2013-09-29 00:21:18 +04:00
{
2014-09-03 09:46:55 +04:00
return _cqfu_firm(van, sut, dib);
2013-09-29 00:21:18 +04:00
}