2013-09-29 00:21:18 +04:00
|
|
|
/* j/6/wrap.c
|
|
|
|
**
|
|
|
|
** This file is in the public domain.
|
|
|
|
*/
|
|
|
|
#include "all.h"
|
|
|
|
#include "../pit.h"
|
|
|
|
|
|
|
|
static u2_noun // produce
|
2014-09-03 09:46:55 +04:00
|
|
|
_cqfu_wrap(
|
2013-09-29 00:21:18 +04:00
|
|
|
u2_noun van, // retain
|
|
|
|
u2_noun sut, // retain
|
|
|
|
u2_noun yoz) // retain
|
|
|
|
{
|
|
|
|
u2_noun p_sut, q_sut;
|
|
|
|
|
2014-08-21 01:18:34 +04:00
|
|
|
if ( u2_no == u2du(sut) ) {
|
|
|
|
return u2_cm_error("wrap-type");
|
2014-04-22 05:22:11 +04:00
|
|
|
}
|
2014-08-21 01:18:34 +04:00
|
|
|
else switch ( u2h(sut) ) {
|
|
|
|
default: return u2_cm_error("wrap-type");
|
2013-09-29 00:21:18 +04:00
|
|
|
|
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
|
|
|
{
|
|
|
|
u2_noun pq_sut, qq_sut, rq_sut;
|
|
|
|
|
2014-08-21 01:18:34 +04:00
|
|
|
if ( u2_no == u2_cr_trel(q_sut, &pq_sut, &qq_sut, &rq_sut) ) {
|
|
|
|
return u2_cm_bail(c3__fail);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
else if ( c3__gold != pq_sut ) {
|
2014-08-21 01:18:34 +04:00
|
|
|
return u2_cm_error("wrap-gold");
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
else {
|
2014-08-21 01:18:34 +04:00
|
|
|
return u2nt(c3__core,
|
|
|
|
u2k(p_sut),
|
|
|
|
u2nt(u2k(yoz),
|
|
|
|
u2k(qq_sut),
|
|
|
|
u2k(rq_sut)));
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
}
|
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
|
|
|
return u2_cqf_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-09-03 07:36:29 +04:00
|
|
|
u2_noun fop = u2_cqfu_repo(van, sut);
|
2014-09-03 09:46:55 +04:00
|
|
|
u2_noun pro = _cqfu_wrap(van, fop, yoz);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-08-21 01:18:34 +04:00
|
|
|
u2z(fop);
|
2013-09-29 00:21:18 +04:00
|
|
|
return pro;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* boilerplate
|
|
|
|
*/
|
|
|
|
u2_noun // transfer
|
2014-09-03 09:46:55 +04:00
|
|
|
u2_cwfu_wrap(
|
2013-09-29 00:21:18 +04:00
|
|
|
u2_noun cor) // retain
|
|
|
|
{
|
|
|
|
u2_noun sut, yoz, van;
|
|
|
|
|
2014-08-21 01:18:34 +04:00
|
|
|
if ( (u2_no == u2_cr_mean(cor, u2_cv_sam, &yoz, u2_cv_con, &van, 0)) ||
|
|
|
|
(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_wrap(van, sut, yoz);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
u2_noun // transfer
|
2014-09-03 07:36:29 +04:00
|
|
|
u2_cqfu_wrap(u2_noun van, // retain
|
2013-09-29 00:21:18 +04:00
|
|
|
u2_noun sut, // retain
|
|
|
|
u2_noun yoz) // retain
|
|
|
|
{
|
2014-09-03 09:46:55 +04:00
|
|
|
return _cqfu_wrap(van, sut, yoz);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|