2013-09-29 00:21:18 +04:00
|
|
|
/* j/6/wrap.c
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
#include "all.h"
|
2014-09-04 07:10:43 +04:00
|
|
|
|
2016-01-11 03:27:36 +03:00
|
|
|
static u3_noun _cqfu_wrap(u3_noun, u3_noun, u3_noun);
|
|
|
|
|
|
|
|
static u3_noun
|
2016-01-14 12:52:50 +03:00
|
|
|
_wrap_fork(u3_noun van, u3_noun p_sut, u3_noun yoz)
|
2016-01-11 03:27:36 +03:00
|
|
|
{
|
|
|
|
if ( u3_nul == p_sut ) {
|
|
|
|
return u3_nul;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return u3nc(_cqfu_wrap(van, u3h(p_sut), yoz),
|
2016-01-14 12:52:50 +03:00
|
|
|
_wrap_fork(van, u3t(p_sut), yoz));
|
2016-01-11 03:27:36 +03:00
|
|
|
}
|
|
|
|
}
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-09-06 00:13:24 +04:00
|
|
|
static u3_noun
|
2015-08-28 19:34:36 +03:00
|
|
|
_cqfu_wrap(u3_noun van,
|
|
|
|
u3_noun sut,
|
|
|
|
u3_noun yoz)
|
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) ) {
|
2014-11-06 03:20:01 +03:00
|
|
|
return u3m_error("wrap-type");
|
2014-04-22 05:22:11 +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_error("wrap-type");
|
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
|
|
|
{
|
2018-05-20 22:34:38 +03:00
|
|
|
u3_noun pq_sut, qq_sut, rq_sut;
|
|
|
|
u3_noun ppq_sut, qpq_sut, rpq_sut;
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2018-05-20 22:34:38 +03:00
|
|
|
if ( c3n == u3r_trel(q_sut, &pq_sut, &qq_sut, &rq_sut) ) {
|
2014-11-06 03:20:01 +03:00
|
|
|
return u3m_bail(c3__fail);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
2018-05-20 22:34:38 +03:00
|
|
|
if ( c3n == u3r_trel(pq_sut, &ppq_sut, &qpq_sut, &rpq_sut) ) {
|
|
|
|
return u3m_bail(c3__fail);
|
|
|
|
}
|
2018-10-26 03:34:49 +03:00
|
|
|
else if ( (c3__gold != rpq_sut) &&
|
|
|
|
(c3__lead != yoz) ) {
|
|
|
|
return u3m_error("wrap-metal");
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
else {
|
2014-09-06 00:13:24 +04:00
|
|
|
return u3nt(c3__core,
|
2015-08-28 19:34:36 +03:00
|
|
|
u3k(p_sut),
|
2018-05-20 22:34:38 +03:00
|
|
|
u3nt(u3nt(u3k(ppq_sut), u3k(qpq_sut), u3k(yoz)),
|
2015-08-28 19:34:36 +03:00
|
|
|
u3k(qq_sut),
|
2018-05-20 22:34:38 +03:00
|
|
|
u3k(rq_sut)));
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
}
|
2016-01-11 12:16:38 +03:00
|
|
|
case c3__fork: p_sut = u3t(sut);
|
|
|
|
{
|
2017-09-28 03:40:12 +03:00
|
|
|
u3_noun yed = u3qdi_tap(p_sut);
|
2016-01-14 12:52:50 +03:00
|
|
|
u3_noun ret = u3kf_fork(_wrap_fork(van, yed, yoz));
|
2016-01-11 12:16:38 +03:00
|
|
|
|
2016-01-13 02:31:02 +03:00
|
|
|
u3z(yed);
|
2016-01-11 12:16:38 +03:00
|
|
|
return ret;
|
|
|
|
}
|
2014-04-22 05:22:11 +04:00
|
|
|
case c3__hold:
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-11-06 22:13:57 +03:00
|
|
|
u3_noun fop = u3qfu_repo(van, sut);
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_noun pro = _cqfu_wrap(van, fop, yoz);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-09-06 00:13:24 +04:00
|
|
|
u3z(fop);
|
2013-09-29 00:21:18 +04:00
|
|
|
return pro;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* boilerplate
|
|
|
|
*/
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_noun
|
2015-08-28 19:34:36 +03:00
|
|
|
u3wfu_wrap(u3_noun cor)
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_noun sut, yoz, van;
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-11-18 00:56:51 +03:00
|
|
|
if ( (c3n == u3r_mean(cor, u3x_sam, &yoz, 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_wrap(van, sut, yoz);
|
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_wrap(u3_noun van,
|
2015-08-28 19:34:36 +03:00
|
|
|
u3_noun sut,
|
|
|
|
u3_noun yoz)
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-09-03 09:46:55 +04:00
|
|
|
return _cqfu_wrap(van, sut, yoz);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|