shrub/jets/f/ut_firm.c

117 lines
2.7 KiB
C
Raw Normal View History

2013-09-29 00:21:18 +04:00
/* j/6/firm.c
**
*/
#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-11-05 04:18:47 +03:00
if ( c3n == u3du(sut) ) switch ( sut ) {
2014-11-06 03:20:01 +03:00
default: return u3m_bail(c3__fail);
2013-09-29 00:21:18 +04:00
case c3__noun:
2013-09-29 00:21:18 +04:00
{
2014-11-05 04:18:47 +03:00
return c3y;
2013-09-29 00:21:18 +04:00
}
case c3__void:
{
2014-11-05 04:18:47 +03:00
return c3n;
2013-09-29 00:21:18 +04:00
}
}
2014-09-06 00:13:24 +04:00
else switch ( u3h(sut) ) {
2014-11-06 03:20:01 +03:00
default: return u3m_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-11-06 03:20:01 +03:00
case c3__bull: u3x_cell(u3t(sut), &p_sut, &q_sut);
2013-12-26 21:12:07 +04:00
{
2014-11-06 03:20:01 +03:00
u3_noun nun = u3r_at(u3h(u3t(u3t(p_sut))), dib);
2014-01-04 06:59:56 +04:00
2014-11-06 02:36:30 +03:00
if ( u3_none == nun ) {
2014-11-05 04:18:47 +03:00
return c3n;
2014-01-04 06:59:56 +04:00
} else {
2014-11-05 04:18:47 +03:00
return c3a(_cqfu_firm(van, q_sut, dib),
2014-09-06 00:13:24 +04:00
_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-11-06 03:20:01 +03:00
case c3__cell: u3x_cell(u3t(sut), &p_sut, &q_sut);
2013-09-29 00:21:18 +04:00
{
2014-11-05 04:18:47 +03:00
return c3a
2014-09-06 00:13:24 +04:00
(u3du(dib),
2014-11-05 04:18:47 +03:00
c3a(_cqfu_firm(van, p_sut, u3h(dib)),
2014-09-06 00:13:24 +04:00
_cqfu_firm(van, q_sut, u3t(dib))));
2013-09-29 00:21:18 +04:00
}
2014-11-06 03:20:01 +03:00
case c3__core: u3x_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-11-06 03:20:01 +03:00
u3x_trel(q_sut, &pq_sut, &qq_sut, &rq_sut);
u3x_cell(rq_sut, &prq_sut, &qrq_sut);
2013-09-29 00:21:18 +04:00
2014-11-05 04:18:47 +03:00
return c3a
2014-09-06 00:13:24 +04:00
(u3du(dib),
2014-11-05 04:18:47 +03:00
c3a
2014-09-06 00:13:24 +04:00
(_cqfu_firm(van, p_sut, u3h(dib)),
2014-11-06 03:20:01 +03:00
((u3_nul == prq_sut) ? u3m_error("firm-core")
: u3r_sing(prq_sut, u3t(dib)))));
2013-09-29 00:21:18 +04:00
}
2014-11-06 03:20:01 +03:00
case c3__cube: u3x_cell(u3t(sut), &p_sut, &q_sut);
2013-09-29 00:21:18 +04:00
{
2014-11-06 03:20:01 +03:00
return u3r_sing(dib, p_sut);
2013-09-29 00:21:18 +04:00
}
2014-11-06 03:20:01 +03:00
case c3__face: u3x_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-11-06 03:20:01 +03:00
case c3__fork: u3x_cell(u3t(sut), &p_sut, &q_sut);
2013-09-29 00:21:18 +04:00
{
2014-11-05 04:18:47 +03:00
return c3o(_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-11-06 22:13:57 +03:00
u3_noun goy = u3qfu_repo(van, sut);
2014-09-06 00:13:24 +04:00
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
2014-11-06 22:13:57 +03:00
u3wfu_firm(
2014-09-06 00:13:24 +04:00
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-11-18 00:56:51 +03:00
if ( (c3n == u3r_mean(cor, u3x_sam, &dib, u3x_con, &van, 0)) ||
(u3_none == (sut = u3r_at(u3x_sam, van))) )
2013-09-29 00:21:18 +04:00
{
2014-11-06 03:20:01 +03:00
return u3m_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
2014-11-06 22:13:57 +03:00
u3qfu_firm(u3_noun van,
2014-09-06 00:13:24 +04:00
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
}