urbit/jets/f/hike.c

137 lines
2.8 KiB
C
Raw Normal View History

2013-09-29 00:21:18 +04:00
/* j/6/hike.c
**
*/
#include "all.h"
2014-09-04 07:10:43 +04:00
2013-09-29 00:21:18 +04:00
/* internal tools
*/
/* _lily_hike_belt_root(): convert (pac) to a list of root tools.
*/
2014-09-06 00:13:24 +04:00
static u3_noun
2015-08-28 19:34:36 +03:00
_lily_hike_belt_root(u3_noun pac)
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
if ( (u3_nul == pac) ) {
return u3_nul;
2013-09-29 00:21:18 +04:00
}
else {
2015-08-28 19:34:36 +03:00
u3_atom axis = u3h(u3h(pac));
u3_noun tool = u3t(u3h(pac));
2014-09-06 00:13:24 +04:00
u3_noun list_tool = _lily_hike_belt_root(u3t(pac));
2013-09-29 00:21:18 +04:00
2014-11-06 03:20:01 +03:00
if ( c3y == u3r_sing(1, axis) ) {
2014-09-06 00:13:24 +04:00
return u3nc(u3k(tool),
2015-08-28 19:34:36 +03:00
list_tool);
2013-09-29 00:21:18 +04:00
}
else return list_tool;
}
}
/* _lily_hike_belt_l(): factor (pac) left.
*/
2014-09-06 00:13:24 +04:00
static u3_noun
2015-08-28 19:34:36 +03:00
_lily_hike_belt_l(u3_noun pac)
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
if ( (u3_nul == pac) ) {
return u3_nul;
2013-09-29 00:21:18 +04:00
}
else {
2014-09-06 00:13:24 +04:00
u3_atom axis = u3h(u3h(pac));
u3_noun tool = u3t(u3h(pac));
2015-08-28 19:34:36 +03:00
u3_noun belt_l = _lily_hike_belt_l(u3t(pac));
2013-09-29 00:21:18 +04:00
{
2014-08-21 01:18:34 +04:00
if ( (1 != axis) &&
2014-11-06 22:13:57 +03:00
(c3y == u3r_sing(2, u3qc_cap(axis))) )
2013-09-29 00:21:18 +04:00
{
2014-11-06 22:13:57 +03:00
u3_atom axis_tap = u3qc_mas(axis);
2013-09-29 00:21:18 +04:00
2015-08-28 19:34:36 +03:00
return u3nc(u3nc(u3k(axis_tap),
u3k(tool)),
belt_l);
2013-09-29 00:21:18 +04:00
}
else return belt_l;
}
}
}
/* _lily_hike_belt_r(): factor (pac) right.
*/
2014-09-06 00:13:24 +04:00
static u3_noun
2015-08-28 19:34:36 +03:00
_lily_hike_belt_r(u3_noun pac)
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
if ( (u3_nul == pac) ) {
return u3_nul;
2013-09-29 00:21:18 +04:00
}
else {
2014-09-06 00:13:24 +04:00
u3_atom axis = u3h(u3h(pac));
u3_noun tool = u3t(u3h(pac));
2015-08-28 19:34:36 +03:00
u3_noun belt_r = _lily_hike_belt_r(u3t(pac));
2013-09-29 00:21:18 +04:00
{
2014-08-21 01:18:34 +04:00
if ( (1 != axis) &&
2014-11-06 22:13:57 +03:00
(c3y == u3r_sing(3, u3qc_cap(axis))) )
2013-09-29 00:21:18 +04:00
{
2014-11-06 22:13:57 +03:00
u3_atom axis_tap = u3qc_mas(axis);
2013-09-29 00:21:18 +04:00
2015-08-28 19:34:36 +03:00
return u3nc(u3nc(u3k(axis_tap),
u3k(tool)),
belt_r);
2013-09-29 00:21:18 +04:00
}
else return belt_r;
}
}
}
/* functions
*/
2014-09-06 00:13:24 +04:00
u3_noun
2015-08-28 19:34:36 +03:00
u3qf_hike(u3_noun axe,
u3_noun pac)
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
if ( (u3_nul == pac) ) {
return u3nc(0, u3k(axe));
2013-09-29 00:21:18 +04:00
}
else {
2014-09-06 00:13:24 +04:00
u3_noun zet = _lily_hike_belt_root(pac);
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04:00
if ( u3_nul != zet ) {
u3_noun fol = u3k(u3h(zet));
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04:00
u3z(zet);
2013-09-29 00:21:18 +04:00
return fol;
}
else {
2014-09-06 00:13:24 +04:00
u3_noun tum = _lily_hike_belt_l(pac);
u3_noun gam = _lily_hike_belt_r(pac);
2014-11-06 22:13:57 +03:00
u3_noun hax = u3qc_peg(axe, 2);
u3_noun moz = u3qc_peg(axe, 3);
u3_noun zip = u3qf_hike(hax, tum);
u3_noun dof = u3qf_hike(moz, gam);
u3_noun fol = u3qf_cons(zip, dof);
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04:00
u3z(tum);
u3z(gam);
u3z(hax);
u3z(moz);
u3z(zip);
u3z(dof);
2013-09-29 00:21:18 +04:00
return fol;
}
}
}
2014-09-06 00:13:24 +04:00
u3_noun
2015-08-28 19:34:36 +03:00
u3wf_hike(u3_noun cor)
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
u3_noun axe, pac;
2013-09-29 00:21:18 +04:00
2014-11-18 00:56:51 +03:00
if ( (c3n == u3r_mean(cor, u3x_sam_2, &axe, u3x_sam_3, &pac, 0)) ||
2014-11-05 04:18:47 +03:00
(c3n == u3ud(axe)) )
2013-09-29 00:21:18 +04:00
{
2014-11-06 03:20:01 +03:00
return u3m_bail(c3__fail);
2013-09-29 00:21:18 +04:00
} else {
2014-11-06 22:13:57 +03:00
return u3qf_hike(axe, pac);
2013-09-29 00:21:18 +04:00
}
}