2013-09-29 00:21:18 +04:00
|
|
|
/* j/6/wrap.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
|
|
|
|
2014-09-06 00:13:24 +04:00
|
|
|
static u3_noun
|
2014-09-03 09:46:55 +04:00
|
|
|
_cqfu_wrap(
|
2014-09-06 00:13:24 +04:00
|
|
|
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
|
|
|
{
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_noun pq_sut, qq_sut, rq_sut;
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-11-06 03:20:01 +03:00
|
|
|
if ( c3n == u3r_trel(q_sut, &pq_sut, &qq_sut, &rq_sut) ) {
|
|
|
|
return u3m_bail(c3__fail);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
else if ( c3__gold != pq_sut ) {
|
2014-11-06 03:20:01 +03:00
|
|
|
return u3m_error("wrap-gold");
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
else {
|
2014-09-06 00:13:24 +04:00
|
|
|
return u3nt(c3__core,
|
|
|
|
u3k(p_sut),
|
|
|
|
u3nt(u3k(yoz),
|
|
|
|
u3k(qq_sut),
|
|
|
|
u3k(rq_sut)));
|
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-06 22:13:57 +03:00
|
|
|
return u3qf_fork
|
2014-09-03 09:46:55 +04:00
|
|
|
(_cqfu_wrap(van, p_sut, yoz),
|
|
|
|
_cqfu_wrap(van, q_sut, yoz));
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
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
|
2014-11-06 22:13:57 +03:00
|
|
|
u3wfu_wrap(
|
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, yoz, van;
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-11-06 03:20:01 +03:00
|
|
|
if ( (c3n == u3r_mean(cor, u3v_sam, &yoz, u3v_con, &van, 0)) ||
|
|
|
|
(u3_none == (sut = u3r_at(u3v_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,
|
2014-09-06 00:13:24 +04: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
|
|
|
}
|