urbit/j/6/ut_wrap.c

81 lines
1.8 KiB
C
Raw Normal View History

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-09-06 00:13:24 +04:00
if ( u3_no == u3du(sut) ) {
return u3_cm_error("wrap-type");
}
2014-09-06 00:13:24 +04:00
else switch ( u3h(sut) ) {
default: return u3_cm_error("wrap-type");
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;
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04:00
if ( u3_no == u3_cr_trel(q_sut, &pq_sut, &qq_sut, &rq_sut) ) {
return u3_cm_bail(c3__fail);
2013-09-29 00:21:18 +04:00
}
else if ( c3__gold != pq_sut ) {
2014-09-06 00:13:24 +04:00
return u3_cm_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-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_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
}
case c3__hold:
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
u3_noun fop = u3_cqfu_repo(van, sut);
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
u3_cwfu_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-09-06 00:13:24 +04:00
if ( (u3_no == u3_cr_mean(cor, u3_cv_sam, &yoz, 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_wrap(van, sut, yoz);
2013-09-29 00:21:18 +04:00
}
}
2014-09-06 00:13:24 +04:00
u3_noun
u3_cqfu_wrap(u3_noun van,
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
}