urbit/j/6/cons.c

56 lines
1.2 KiB
C
Raw Normal View History

2013-09-29 00:21:18 +04:00
/* j/6/cons.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
/* functions
*/
2014-09-04 01:33:18 +04:00
u2_noun
2014-09-03 07:36:29 +04:00
u2_cqf_cons(
2014-09-04 01:33:18 +04:00
u2_noun vur,
u2_noun sed)
2013-09-29 00:21:18 +04:00
{
u2_noun p_vur, p_sed;
2014-08-21 01:18:34 +04:00
if ( u2_yes == u2_cr_p(vur, 1, &p_vur) &&
u2_yes == u2_cr_p(sed, 1, &p_sed) ) {
return u2nt(1,
u2k(p_vur),
u2k(p_sed));
2013-09-29 00:21:18 +04:00
}
2014-08-21 01:18:34 +04:00
else if ( u2_yes == u2_cr_p(vur, 0, &p_vur) &&
u2_yes == u2_cr_p(sed, 0, &p_sed) &&
!(u2_yes == u2_cr_sing(1, p_vur)) &&
!(u2_yes == u2_cr_sing(p_vur, p_sed)) &&
(0 == u2_cr_nord(p_vur, p_sed)) )
2013-09-29 00:21:18 +04:00
{
2014-09-03 07:36:29 +04:00
u2_atom fub = u2_cqa_div(p_vur, 2);
u2_atom nof = u2_cqa_div(p_sed, 2);
2013-09-29 00:21:18 +04:00
2014-08-21 01:18:34 +04:00
if ( u2_yes == u2_cr_sing(fub, nof) ) {
u2z(nof);
2013-09-29 00:21:18 +04:00
2014-08-21 01:18:34 +04:00
return u2nc(0, fub);
2013-09-29 00:21:18 +04:00
}
else {
2014-08-21 01:18:34 +04:00
u2z(fub);
u2z(nof);
2013-09-29 00:21:18 +04:00
}
}
2014-08-21 01:18:34 +04:00
return u2nc(u2k(vur), u2k(sed));
2013-09-29 00:21:18 +04:00
}
2014-09-04 01:33:18 +04:00
u2_noun
2014-09-03 09:46:55 +04:00
u2_cwf_cons(
2014-09-04 01:33:18 +04:00
u2_noun cor)
2013-09-29 00:21:18 +04:00
{
u2_noun vur, sed;
2014-08-21 01:18:34 +04:00
if ( u2_no == u2_cr_mean(cor, u2_cv_sam_2, &vur, u2_cv_sam_3, &sed, 0) ) {
return u2_cm_bail(c3__fail);
2013-09-29 00:21:18 +04:00
} else {
2014-09-03 07:36:29 +04:00
return u2_cqf_cons(vur, sed);
2013-09-29 00:21:18 +04:00
}
}