urbit/j/f/ut_fish.c

169 lines
3.8 KiB
C
Raw Normal View History

2013-09-29 00:21:18 +04:00
/* j/6/fish.c
**
*/
#include "all.h"
2014-09-04 07:10:43 +04:00
2013-09-29 00:21:18 +04:00
/* functions
*/
2014-09-06 00:13:24 +04:00
static u3_noun
2014-08-21 01:18:34 +04:00
_fish_in(
2014-09-06 00:13:24 +04:00
u3_noun van,
u3_noun sut,
u3_atom axe,
u3_noun vit)
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
u3_noun p_sut, q_sut;
2013-09-29 00:21:18 +04:00
2014-11-05 04:18:47 +03:00
if ( c3y == u3ud(sut) ) switch ( sut ) {
2014-11-06 03:20:01 +03:00
default: return u3m_bail(c3__fail);
2013-09-29 00:21:18 +04:00
case c3__noun: {
2014-09-06 00:13:24 +04:00
return u3nc(1, 0);
2013-09-29 00:21:18 +04:00
}
case c3__void: {
2014-09-06 00:13:24 +04:00
return u3nc(1, 1);
2013-09-29 00:21:18 +04:00
}
}
2014-09-06 00:13:24 +04:00
else switch ( u3h(sut) ) {
2014-11-06 03:20:01 +03:00
default: return u3m_bail(c3__fail);
2013-09-29 00:21:18 +04:00
case c3__atom: {
2014-09-06 00:13:24 +04:00
u3_noun ton = u3nt(3, 0, u3k(axe));
2014-11-06 22:13:57 +03:00
u3_noun pro = u3qf_flip(ton);
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04:00
u3z(ton);
2013-09-29 00:21:18 +04:00
return pro;
}
2013-12-26 21:12:07 +04:00
case c3__bull: {
2014-11-06 03:20:01 +03:00
return u3m_error("bull-fish");
2013-12-26 21:12:07 +04:00
}
2013-09-29 00:21:18 +04:00
case c3__cell: {
2014-11-06 03:20:01 +03:00
if ( (c3n == u3r_trel(sut, 0, &p_sut, &q_sut)) ) {
return u3m_bail(c3__fail);
2013-09-29 00:21:18 +04:00
} else {
2014-09-06 00:13:24 +04:00
u3_noun hut = u3nt(3, 0, u3k(axe));
2014-11-06 22:13:57 +03:00
u3_noun lef = u3qc_peg(axe, 2);
u3_noun rit = u3qc_peg(axe, 3);
2014-09-06 00:13:24 +04:00
u3_noun hed = _fish_in(van, p_sut, lef, vit);
u3_noun tal = _fish_in(van, q_sut, rit, vit);
2014-11-06 22:13:57 +03:00
u3_noun hob = u3qf_flan(hed, tal);
u3_noun vug = u3qf_flan(hut, hob);
2014-09-06 00:13:24 +04:00
u3z(hob);
u3z(tal);
u3z(hed);
u3z(rit);
u3z(lef);
u3z(hut);
2013-09-29 00:21:18 +04:00
return vug;
}
}
case c3__core: {
2014-09-06 00:13:24 +04:00
return u3nc(0, 0);
2013-09-29 00:21:18 +04:00
}
case c3__cube: {
2014-11-06 03:20:01 +03:00
if ( (c3n == u3r_trel(sut, 0, &p_sut, &q_sut)) ) {
return u3m_bail(c3__fail);
2013-09-29 00:21:18 +04:00
} else {
2014-09-06 00:13:24 +04:00
return u3nt
2014-08-21 01:18:34 +04:00
(5,
2014-09-06 00:13:24 +04:00
u3nc(1, u3k(p_sut)),
u3nc(0, u3k(axe)));
2013-09-29 00:21:18 +04:00
}
}
case c3__face: {
2014-11-06 03:20:01 +03:00
if ( (c3n == u3r_trel(sut, 0, &p_sut, &q_sut)) ) {
return u3m_bail(c3__fail);
} else {
2014-08-21 01:18:34 +04:00
return _fish_in(van, q_sut, axe, vit);
2013-09-29 00:21:18 +04:00
}
}
case c3__fork: {
2014-11-06 03:20:01 +03:00
if ( (c3n == u3r_trel(sut, 0, &p_sut, &q_sut)) ) {
return u3m_bail(c3__fail);
2013-09-29 00:21:18 +04:00
}
else {
2014-09-06 00:13:24 +04:00
u3_noun hed = _fish_in(van, p_sut, axe, vit);
u3_noun tal = _fish_in(van, q_sut, axe, vit);
2014-11-06 22:13:57 +03:00
u3_noun pro = u3qf_flor(hed, tal);
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04:00
u3z(hed);
u3z(tal);
2013-09-29 00:21:18 +04:00
return pro;
}
}
2013-09-29 00:21:18 +04:00
case c3__hold: {
2014-09-06 00:13:24 +04:00
p_sut = u3t(sut);
2013-09-29 00:21:18 +04:00
{
2014-11-06 22:13:57 +03:00
if ( (c3y == u3qdi_has(vit, sut)) ) {
// u3_noun dun = u3qfu_dunq(van, "type", sut);
u3_noun niz = u3qfu_shep
2014-09-06 00:13:24 +04:00
(van, "axis", 'd', u3k(axe));
2013-09-29 00:21:18 +04:00
2014-11-06 03:20:01 +03:00
// u3t_push(u3nc(c3__mean, dun));
u3t_push(u3nc(c3__mean, niz));
2013-09-29 00:21:18 +04:00
2014-11-06 03:20:01 +03:00
return u3m_error("fish-loop");
2013-09-29 00:21:18 +04:00
} else {
2014-11-06 22:13:57 +03:00
u3_noun zoc = u3qdi_put(vit, sut);
u3_noun fop = u3qfu_rest(van, sut, p_sut);
2014-09-06 00:13:24 +04:00
u3_noun pro = _fish_in(van, fop, axe, zoc);
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04:00
u3z(fop);
u3z(zoc);
2013-09-29 00:21:18 +04:00
return pro;
}
}
}
}
}
2014-09-06 00:13:24 +04:00
u3_noun
2014-09-03 09:46:55 +04:00
_cqfu_fish(
2014-09-06 00:13:24 +04:00
u3_noun van,
u3_noun sut,
u3_atom axe)
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
return _fish_in(van, sut, axe, u3_nul);
2013-09-29 00:21:18 +04:00
}
/* boilerplate
*/
2014-09-06 00:13:24 +04:00
u3_noun
2014-11-06 22:13:57 +03:00
u3wfu_fish(
2014-09-06 00:13:24 +04:00
u3_noun cor)
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
u3_noun sut, axe, van;
2013-09-29 00:21:18 +04:00
2014-11-18 00:56:51 +03:00
if ( (c3n == u3r_mean(cor, u3x_sam, &axe, u3x_con, &van, 0)) ||
2014-11-05 04:18:47 +03:00
(c3n == u3ud(axe)) ||
2014-11-18 00:56:51 +03:00
(u3_none == (sut = u3r_at(u3x_sam, van))) )
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-09-03 09:46:55 +04:00
return _cqfu_fish(van, sut, axe);
2013-09-29 00:21:18 +04:00
}
}
2014-09-06 00:13:24 +04:00
u3_noun
2014-11-06 22:13:57 +03:00
u3qfu_fish(u3_noun van,
2014-09-06 00:13:24 +04:00
u3_noun sut,
u3_noun axe)
2013-09-29 00:21:18 +04:00
{
2014-08-28 23:40:40 +04:00
c3_m fun_m = c3__fish;
2014-11-06 03:20:01 +03:00
u3_noun pro = u3z_find_2(fun_m, sut, axe);
2013-09-29 00:21:18 +04:00
2014-11-06 02:36:30 +03:00
if ( u3_none != pro ) {
2014-08-28 23:40:40 +04:00
return pro;
2013-09-29 00:21:18 +04:00
}
else {
2014-09-03 09:46:55 +04:00
pro = _cqfu_fish(van, sut, axe);
2013-09-29 00:21:18 +04:00
2014-11-06 03:20:01 +03:00
return u3z_save_2(fun_m, sut, axe, pro);
2013-09-29 00:21:18 +04:00
}
}