urbit/gen164/5/cue.c

106 lines
2.3 KiB
C
Raw Normal View History

2013-09-29 00:21:18 +04:00
/* j/3/cue.c
**
** This file is in the public domain.
*/
#include "all.h"
#include "../pit.h"
#include "f/nash.h"
2014-08-17 07:57:54 +04:00
2013-09-29 00:21:18 +04:00
/* functions
*/
struct u2_nash* T_r;
2013-09-29 00:21:18 +04:00
static u2_noun // produce
_cue_in(u2_atom a, // retain
u2_atom b) // retain
2013-09-29 00:21:18 +04:00
{
u2_noun p, q;
2013-09-29 00:21:18 +04:00
2014-08-20 10:22:41 +04:00
if ( 0 == j2_mbc(Pt3, cut)(0, b, 1, a) ) {
u2_noun x = j2_mbc(Pt1, inc)(b);
u2_noun c = j2_mby(Pt5, rub)(x, a);
2013-09-29 00:21:18 +04:00
p = j2_mbc(Pt1, inc)(u2k(u2h(c)));
2014-08-20 10:22:41 +04:00
q = u2k(u2t(c));
2014-05-20 20:59:41 +04:00
u2_na_put(T_r, b, (void*)(c3_p)q);
2013-09-29 00:21:18 +04:00
2014-08-20 10:22:41 +04:00
u2z(c);
u2z(x);
2013-09-29 00:21:18 +04:00
}
else {
2014-08-20 10:22:41 +04:00
u2_noun c = j2_mbc(Pt1, add)(2, b);
u2_noun l = j2_mbc(Pt1, inc)(b);
2013-09-29 00:21:18 +04:00
2014-08-20 10:22:41 +04:00
if ( 0 == j2_mbc(Pt3, cut)(0, l, 1, a) ) {
2013-09-29 00:21:18 +04:00
u2_noun u, v, w;
u2_noun x, y;
2014-08-20 10:22:41 +04:00
u = _cue_in(a, c);
x = j2_mbc(Pt1, add)(u2h(u), c);
v = _cue_in(a, x);
2013-09-29 00:21:18 +04:00
2014-08-20 10:22:41 +04:00
w = u2nc(u2k(u2h(u2t(u))),
u2k(u2h(u2t(v))));
2013-09-29 00:21:18 +04:00
2014-08-20 10:22:41 +04:00
y = j2_mbc(Pt1, add)(u2h(u), u2h(v));
2013-09-29 00:21:18 +04:00
2014-08-20 10:22:41 +04:00
p = j2_mbc(Pt1, add)(2, y);
2013-09-29 00:21:18 +04:00
q = w;
2014-05-20 20:59:41 +04:00
u2_na_put(T_r, b, (void*)(c3_p)q);
2013-09-29 00:21:18 +04:00
2014-08-20 10:22:41 +04:00
u2z(u); u2z(v); u2z(x); u2z(y);
2013-09-29 00:21:18 +04:00
}
else {
2014-08-20 10:22:41 +04:00
u2_noun d = j2_mby(Pt5, rub)(c, a);
u2_noun x = u2_na_get(T_r, u2t(d));
2013-09-29 00:21:18 +04:00
2014-08-20 10:22:41 +04:00
p = j2_mbc(Pt1, add)(2, u2h(d));
2014-05-07 22:21:16 +04:00
if ( u2_none == x ) {
2014-08-20 10:22:41 +04:00
return u2_cm_bail(c3__exit);
2013-09-29 00:21:18 +04:00
}
2014-08-20 10:22:41 +04:00
q = u2k(x);
2013-09-29 00:21:18 +04:00
2014-08-20 10:22:41 +04:00
u2z(d);
2013-09-29 00:21:18 +04:00
}
2014-08-20 10:22:41 +04:00
u2z(l);
u2z(c);
2013-09-29 00:21:18 +04:00
}
2014-08-20 10:22:41 +04:00
return u2nt(p, q, 0);
2013-09-29 00:21:18 +04:00
}
u2_noun // transfer
2014-08-20 10:22:41 +04:00
j2_mby(Pt5, cue)(
2013-09-29 00:21:18 +04:00
u2_atom a) // retain
{
T_r = u2_na_make();
2014-04-29 04:13:57 +04:00
2014-08-20 10:22:41 +04:00
u2_noun x = _cue_in(a, 0);
u2_noun y = u2k(u2h(u2t(x)));
u2_na_take(T_r);
T_r = 0;
2014-08-20 10:22:41 +04:00
u2z(x);
return y;
2013-09-29 00:21:18 +04:00
}
u2_noun // transfer
2014-08-20 10:22:41 +04:00
j2_mb(Pt5, cue)(
2013-09-29 00:21:18 +04:00
u2_noun cor) // retain
{
u2_noun a;
2014-08-20 10:22:41 +04:00
if ( (u2_none == (a = u2_cr_at(u2_cv_sam, cor))) ) {
return u2_cm_bail(c3__fail);
2013-09-29 00:21:18 +04:00
} else {
2014-08-20 10:22:41 +04:00
return j2_mby(Pt5, cue)(a);
2013-09-29 00:21:18 +04:00
}
}
/* structures
*/
u2_ho_jet
2013-09-29 00:21:18 +04:00
j2_mbj(Pt5, cue)[] = {
{ ".2", c3__hevy, j2_mb(Pt5, cue), Tier3, u2_none, u2_none },
{ }
};