urbit/gen164/6/ut_swab.c

119 lines
3.3 KiB
C
Raw Normal View History

2013-09-29 00:21:18 +04:00
/* j/6/swab.c
**
** This file is in the public domain.
*/
#include "all.h"
#include "../pit.h"
/* internals
*/
/* functions
*/
2013-12-15 12:23:23 +04:00
u2_noun // produce
2014-08-21 01:18:34 +04:00
j2_mcx(Pt6, ut, snub)(
2013-12-15 12:23:23 +04:00
u2_noun van, // retain
u2_noun sut, // retain
u2_noun har) // retain
{
2014-08-21 01:18:34 +04:00
if ( u2_no == u2du(har) ) {
2013-12-15 12:23:23 +04:00
return u2_nul;
} else {
2014-08-21 01:18:34 +04:00
u2_noun i_har = u2h(har);
u2_noun t_har = u2t(har);
u2_noun pi_har = u2h(i_har);
u2_noun qi_har = u2t(i_har);
u2_noun peh = j2_mbc(Pt2, flop)(pi_har);
u2_noun ret = u2nc(u2nc(peh, u2k(qi_har)),
2013-12-15 12:23:23 +04:00
j2_mcx(Pt6, ut, snub)
2014-08-21 01:18:34 +04:00
(van, sut, t_har));
2013-12-15 12:23:23 +04:00
return ret;
}
}
2013-09-29 00:21:18 +04:00
/* boilerplate
*/
u2_ho_jet
2013-12-15 12:23:23 +04:00
j2_mcj(Pt6, ut, snub)[];
u2_noun // transfer
2014-08-21 01:18:34 +04:00
j2_mc(Pt6, ut, snub)(
2013-12-15 12:23:23 +04:00
u2_noun cor) // retain
{
u2_noun van, sut, har;
2014-08-21 01:18:34 +04:00
if ( (u2_no == u2_cr_mean(cor, u2_cv_sam, &har,
u2_cv_con, &van,
2013-12-15 12:23:23 +04:00
0)) ||
2014-08-21 01:18:34 +04:00
(u2_none == (sut = u2_cr_at(u2_cv_sam, van))) )
2013-12-15 12:23:23 +04:00
{
2014-08-21 01:18:34 +04:00
return u2_cm_bail(c3__fail);
2013-12-15 12:23:23 +04:00
} else {
2014-08-21 01:18:34 +04:00
return j2_mcx(Pt6, ut, snub)(van, sut, har);
2013-12-15 12:23:23 +04:00
}
}
u2_weak // transfer
2014-08-21 01:18:34 +04:00
j2_mci(Pt6, ut, snub)(
2013-12-15 12:23:23 +04:00
u2_noun van, // retain
u2_noun sut, // retain
u2_noun har) // retain
{
2014-08-21 01:24:29 +04:00
u2_weak hoc = u2_cj_look(u2k(van), "snub");
2013-12-15 12:23:23 +04:00
if ( u2_none == hoc ) {
c3_assert(!"register snub");
return u2_none;
} else {
2014-08-21 01:18:34 +04:00
u2_weak von = u2_ci_molt(u2k(van), u2_cv_sam, u2k(sut), 0);
u2_weak gat = u2_cn_nock_on(von, hoc);
u2_weak cor = u2_ci_molt(u2k(gat), u2_cv_sam, u2k(har),
2013-12-15 12:23:23 +04:00
0);
if ( (u2_none == j2_mcj(Pt6, ut, snub)[0].xip) ) {
2014-08-21 01:24:29 +04:00
u2_noun xip = u2_cj_find(u2k(cor));
2013-12-15 12:23:23 +04:00
c3_assert(u2_none != xip);
j2_mcj(Pt6, ut, snub)[0].xip = xip;
}
2014-08-21 01:18:34 +04:00
u2z(gat);
2013-12-15 12:23:23 +04:00
return cor;
}
}
u2_noun // transfer
2014-08-21 01:18:34 +04:00
j2_mcy(Pt6, ut, snub)(
2013-12-15 12:23:23 +04:00
u2_noun van, // retain
u2_noun sut, // retain
u2_noun har) // retain
{
u2_ho_jet *jet_j = &j2_mcj(Pt6, ut, snub)[0];
if ( jet_j->sat_s == u2_jet_live ) {
2014-08-21 01:18:34 +04:00
return j2_mcx(Pt6, ut, snub)(van, sut, har);
2013-12-15 12:23:23 +04:00
}
else {
u2_noun cor, fol, pro;
2014-08-21 01:18:34 +04:00
cor = j2_mci(Pt6, ut, snub)(van, sut, har);
fol = u2h(cor);
2013-12-15 12:23:23 +04:00
2014-08-21 01:18:34 +04:00
pro = u2_ho_use(jet_j, cor, fol);
if ( u2_none == pro ) return u2_cm_bail(c3__fail);
2013-12-15 12:23:23 +04:00
2014-08-21 01:18:34 +04:00
u2z(cor);
u2z(fol);
2013-12-15 12:23:23 +04:00
return pro;
}
}
2013-09-29 00:21:18 +04:00
/* structures
*/
u2_ho_jet
2013-12-15 12:23:23 +04:00
j2_mcj(Pt6, ut, snub)[] = {
{ ".2", c3__hevy, j2_mc(Pt6, ut, snub), Tier6_c, u2_none, u2_none },
{ }
};