urbit/jets/d/in_uni.c

105 lines
2.1 KiB
C
Raw Normal View History

/* j/4/in_uni.c
**
*/
#include "all.h"
2014-09-04 07:10:43 +04:00
2016-11-09 08:38:19 +03:00
/* internal functions
*/
static u3_noun
_in_uni(u3_noun a, u3_noun b)
{
u3_noun n_a, l_a, r_a,
n_b, l_b, r_b,
neb, sub, naw, pro;
if ( u3_nul == a ) {
return u3k(b);
}
else if ( u3_nul == b ) {
return u3k(a);
}
else if ( (c3n == u3r_trel(a, &n_a, &l_a, &r_a))
|| (c3n == u3r_trel(b, &n_b, &l_b, &r_b)) )
{
return u3m_bail(c3__exit);
}
else if ( c3n == u3qc_vor(n_a, n_b) ) {
if ( c3y == u3r_sing(n_a, n_b) ) {
return u3nt(u3k(n_b), _in_uni(l_a, l_b), _in_uni(r_a, r_b));
}
else if ( c3y == u3qc_gor(n_a, n_b) ) {
2016-11-09 08:38:19 +03:00
naw = u3nt(u3k(n_a), u3k(l_a), u3_nul);
sub = _in_uni(naw, l_b);
neb = u3nt(u3k(n_b), sub, u3k(r_b));
pro = _in_uni(r_a, neb);
u3z(naw); u3z(neb);
return pro;
}
else {
naw = u3nt(u3k(n_a), u3_nul, u3k(r_a));
sub = _in_uni(naw, r_b);
neb = u3nt(u3k(n_b), u3k(l_b), sub);
pro = _in_uni(l_a, neb);
u3z(naw); u3z(neb);
return pro;
}
}
else if ( c3y == u3r_sing(n_b, n_a) ) {
return u3nt(u3k(n_b), _in_uni(l_a, l_b), _in_uni(r_a, r_b));
}
else if ( c3y == u3qc_gor(n_b, n_a) ) {
2016-11-09 08:38:19 +03:00
neb = u3nt(u3k(n_b), u3k(l_b), u3_nul);
sub = _in_uni(l_a, neb);
naw = u3nt(u3k(n_a), sub, u3k(r_a));
pro = _in_uni(naw, r_b);
u3z(neb); u3z(naw);
return pro;
}
else {
neb = u3nt(u3k(n_b), u3_nul, u3k(r_b));
sub = _in_uni(r_a, neb);
naw = u3nt(u3k(n_a), u3k(l_a), sub);
pro = _in_uni(naw, l_b);
u3z(neb); u3z(naw);
return pro;
}
}
/* functions
*/
u3_noun
u3kdi_uni(u3_noun a,
u3_noun b)
{
u3_noun c = u3qdi_uni(a, b);
u3z(a);
u3z(b);
return c;
}
2014-09-06 00:13:24 +04:00
u3_noun
2015-08-28 16:26:00 +03:00
u3qdi_uni(u3_noun a,
u3_noun b)
{
2016-11-09 08:38:19 +03:00
if ( c3y == u3r_sing(a, b) ) {
2014-09-06 00:13:24 +04:00
return u3k(a);
}
else {
2016-11-09 08:38:19 +03:00
return _in_uni(a, b);
}
}
2014-09-06 00:13:24 +04:00
u3_noun
2015-08-28 16:26:00 +03:00
u3wdi_uni(u3_noun cor)
{
2014-09-06 00:13:24 +04:00
u3_noun a, b;
2014-11-18 00:56:51 +03:00
if ( c3n == u3r_mean(cor, u3x_sam, &b, u3x_con_sam, &a, 0) ) {
2014-11-06 03:20:01 +03:00
return u3m_bail(c3__exit);
} else {
2014-11-06 22:13:57 +03:00
return u3qdi_uni(a, b);
}
}