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
|
|
|
|
*/
|
2016-01-11 03:27:36 +03:00
|
|
|
static u3_noun
|
|
|
|
_fish_in(u3_noun, u3_noun, u3_atom, u3_noun);
|
|
|
|
|
|
|
|
static u3_noun
|
|
|
|
_fish_frog(u3_noun van,
|
|
|
|
u3_noun p_sut,
|
|
|
|
u3_atom axe,
|
|
|
|
u3_noun vit)
|
|
|
|
{
|
|
|
|
if ( u3_nul == p_sut ) {
|
|
|
|
return u3nc(1, 1);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
u3_noun hed = _fish_in(van, u3h(p_sut), axe, vit);
|
|
|
|
u3_noun tal = _fish_frog(van, u3t(p_sut), axe, vit);
|
|
|
|
u3_noun pro = u3qf_flor(hed, tal);
|
|
|
|
|
|
|
|
u3z(hed);
|
|
|
|
u3z(tal);
|
|
|
|
|
|
|
|
return pro;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-06 00:13:24 +04:00
|
|
|
static u3_noun
|
2015-08-28 19:34:36 +03:00
|
|
|
_fish_in(u3_noun van,
|
2014-09-06 00:13:24 +04:00
|
|
|
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: {
|
2015-12-27 07:58:07 +03:00
|
|
|
if ( (c3n == u3r_trel(sut, 0, &p_sut, &q_sut)) ) {
|
|
|
|
return u3m_bail(c3__fail);
|
|
|
|
} else {
|
2015-12-28 23:53:10 +03:00
|
|
|
if ( c3n == u3du(q_sut) ) {
|
|
|
|
u3_noun ton = u3nt(3, 0, u3k(axe));
|
|
|
|
u3_noun pro = u3qf_flip(ton);
|
|
|
|
|
|
|
|
u3z(ton);
|
|
|
|
return pro;
|
|
|
|
} else {
|
|
|
|
return u3nt(5,
|
|
|
|
u3nc(1, u3k(u3t(q_sut))),
|
|
|
|
u3nc(0, u3k(axe)));
|
|
|
|
}
|
2015-12-27 07:58:07 +03:00
|
|
|
}
|
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__face: {
|
2014-11-06 03:20:01 +03:00
|
|
|
if ( (c3n == u3r_trel(sut, 0, &p_sut, &q_sut)) ) {
|
|
|
|
return u3m_bail(c3__fail);
|
2014-04-22 05:22:11 +04:00
|
|
|
} 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;
|
|
|
|
}
|
2014-04-22 05:22:11 +04:00
|
|
|
}
|
2016-01-11 03:27:36 +03:00
|
|
|
case c3__frog: {
|
|
|
|
p_sut = u3t(sut);
|
|
|
|
return _fish_frog(van, p_sut, axe, vit);
|
|
|
|
}
|
2016-01-11 10:04:34 +03: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);
|
2016-01-11 09:37:59 +03:00
|
|
|
u3_noun fop = u3qfu_repo(van, 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
|
2015-08-28 19:34:36 +03:00
|
|
|
_cqfu_fish(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
|
2015-08-28 19:34:36 +03:00
|
|
|
u3wfu_fish(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,
|
2015-08-28 19:34:36 +03:00
|
|
|
u3_noun sut,
|
|
|
|
u3_noun axe)
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2015-12-22 01:45:22 +03:00
|
|
|
c3_m fun_m = c3__fish + !!u3r_at(u3qfu_van_vet, van);
|
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
|
|
|
}
|
|
|
|
}
|