urbit/gen164/6/ut_bust.c

152 lines
3.9 KiB
C
Raw Normal View History

2013-09-29 00:21:18 +04:00
/* j/6/bust.c
**
** This file is in the public domain.
*/
#include "all.h"
#include "../pit.h"
/* logic
*/
u2_noun // transfer
2014-08-21 01:18:34 +04:00
j2_mcx(Pt6, ut, bust)(
2013-09-29 00:21:18 +04:00
u2_noun van, // retain
u2_noun sut, // retain
u2_noun dib) // retain
{
2014-08-21 01:18:34 +04:00
u2_noun yam = j2_mcy(Pt6, ut, burn)(van, sut);
u2_noun yib = u2nc
(
u2nc(u2k(u2h(u2h(yam))),
u2k(dib)),
u2k(u2t(yam)));
u2_noun woo = u2nc(c3__cnzy, u2_blip);
u2_noun wox = j2_mcy(Pt6, ut, mint)(van, sut, c3__noun, woo);
u2_noun ret = u2_cn_nock_on(yib, u2k(u2t(wox)));
2013-09-29 00:21:18 +04:00
if ( u2_none == ret ) {
2014-08-21 01:18:34 +04:00
return u2_cm_error("bust-nock");
2013-09-29 00:21:18 +04:00
}
2014-08-21 01:18:34 +04:00
u2z(wox);
u2z(woo);
u2z(yam);
2013-09-29 00:21:18 +04:00
return ret;
}
/* boilerplate
*/
u2_ho_jet
2013-09-29 00:21:18 +04:00
j2_mcj(Pt6, ut, bust)[];
u2_noun // transfer
2014-08-21 01:18:34 +04:00
j2_mc(Pt6, ut, bust)(
2013-09-29 00:21:18 +04:00
u2_noun cor) // retain
{
u2_noun sut, dib, van;
2014-08-21 01:18:34 +04:00
if ( (u2_no == u2_cr_mean(cor, u2_cv_sam, &dib, 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-08-21 01:18:34 +04:00
return j2_mcx(Pt6, ut, bust)(van, sut, dib);
2013-09-29 00:21:18 +04:00
}
}
u2_weak // transfer
2014-08-21 01:18:34 +04:00
j2_mci(Pt6, ut, bust)(
2013-09-29 00:21:18 +04:00
u2_noun van, // retain
u2_noun sut, // retain
2013-09-29 00:21:18 +04:00
u2_noun dib) // retain
{
2014-08-21 01:24:29 +04:00
u2_weak hoc = u2_cj_look(u2k(van), "bust");
2013-09-29 00:21:18 +04:00
if ( u2_none == hoc ) {
c3_assert(!"register bust");
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(dib), 0);
2013-09-29 00:21:18 +04:00
if ( (u2_none == j2_mcj(Pt6, ut, bust)[0].xip) ) {
2014-08-21 01:24:29 +04:00
u2_noun xip = u2_cj_find(u2k(cor));
2013-09-29 00:21:18 +04:00
c3_assert(u2_none != xip);
j2_mcj(Pt6, ut, bust)[0].xip = xip;
}
2014-08-21 01:18:34 +04:00
u2z(gat);
2013-09-29 00:21:18 +04:00
return cor;
}
}
u2_noun // transfer
2014-08-21 01:18:34 +04:00
j2_mcy(Pt6, ut, bust)(
2013-09-29 00:21:18 +04:00
u2_noun van, // retain
u2_noun sut, // retain
u2_noun dib) // retain
{
u2_ho_jet *jet_j = &j2_mcj(Pt6, ut, bust)[0];
if ( (jet_j->sat_s & u2_jet_live) && !(jet_j->sat_s & u2_jet_test) ) {
if ( !(jet_j->sat_s & u2_jet_memo) ) {
2014-08-21 01:18:34 +04:00
return j2_mcx(Pt6, ut, bust)(van, sut, dib);
2013-09-29 00:21:18 +04:00
}
else {
c3_m fun_m = c3__bust;
2014-08-26 20:12:45 +04:00
u2_noun pro = u2_cz_find_2(fun_m, sut, dib);
2013-09-29 00:21:18 +04:00
if ( u2_none != pro ) {
return pro;
}
else {
2014-08-21 01:18:34 +04:00
pro = j2_mcx(Pt6, ut, bust)(van, sut, dib);
2013-09-29 00:21:18 +04:00
2014-08-26 20:12:45 +04:00
return u2_cz_save_2(fun_m, sut, dib, pro);
2013-09-29 00:21:18 +04:00
}
}
}
else {
u2_noun cor, fol, pro;
2014-08-21 01:18:34 +04:00
cor = j2_mci(Pt6, ut, bust)(van, sut, dib);
fol = u2h(cor);
2013-09-29 00:21:18 +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-09-29 00:21:18 +04:00
2014-08-21 01:18:34 +04:00
u2z(cor);
u2z(fol);
2013-09-29 00:21:18 +04:00
return pro;
}
}
u2_weak
2014-08-21 01:18:34 +04:00
j2_mck(Pt6, ut, bust)(
2013-09-29 00:21:18 +04:00
u2_noun cor)
{
u2_noun sut, dib, van;
2014-08-21 01:18:34 +04:00
if ( (u2_no == u2_cr_mean(cor, u2_cv_sam, &dib, u2_cv_con, &van, 0)) ||
(u2_none == (sut = u2_cr_at(u2_cv_sam, van))) )
2013-09-29 00:21:18 +04:00
{
return u2_none;
} else {
2014-08-21 01:18:34 +04:00
return u2nc(u2k(sut), u2k(dib));
2013-09-29 00:21:18 +04:00
}
}
/* structures
*/
u2_ho_jet
2013-09-29 00:21:18 +04:00
j2_mcj(Pt6, ut, bust)[] = {
{ ".2", c3__hevy,
j2_mc(Pt6, ut, bust),
2013-09-29 00:21:18 +04:00
Tier6_b,
u2_none, u2_none,
j2_mck(Pt6, ut, bust), c3__bust,
},
{ }
};