2013-09-29 00:21:18 +04:00
|
|
|
/* j/6/fish.c
|
|
|
|
**
|
|
|
|
** This file is in the public domain.
|
|
|
|
*/
|
|
|
|
#include "all.h"
|
|
|
|
#include "../pit.h"
|
|
|
|
|
|
|
|
/* functions
|
|
|
|
*/
|
|
|
|
static u2_noun
|
2014-08-21 01:18:34 +04:00
|
|
|
_fish_in(
|
2013-09-29 00:21:18 +04:00
|
|
|
u2_noun van,
|
|
|
|
u2_noun sut,
|
|
|
|
u2_atom axe,
|
|
|
|
u2_noun vit)
|
|
|
|
{
|
|
|
|
u2_noun p_sut, q_sut;
|
|
|
|
|
2014-08-21 01:18:34 +04:00
|
|
|
if ( u2_yes == u2ud(sut) ) switch ( sut ) {
|
|
|
|
default: return u2_cm_bail(c3__fail);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
|
|
|
case c3__noun: {
|
2014-08-21 01:18:34 +04:00
|
|
|
return u2nc(1, 0);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
case c3__void: {
|
2014-08-21 01:18:34 +04:00
|
|
|
return u2nc(1, 1);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
}
|
2014-08-21 01:18:34 +04:00
|
|
|
else switch ( u2h(sut) ) {
|
|
|
|
default: return u2_cm_bail(c3__fail);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
|
|
|
case c3__atom: {
|
2014-08-21 01:18:34 +04:00
|
|
|
u2_noun ton = u2nt(3, 0, u2k(axe));
|
2014-09-03 07:36:29 +04:00
|
|
|
u2_noun pro = u2_cqf_flip(ton);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-08-21 01:18:34 +04:00
|
|
|
u2z(ton);
|
2013-09-29 00:21:18 +04:00
|
|
|
return pro;
|
|
|
|
}
|
2013-12-26 21:12:07 +04:00
|
|
|
case c3__bull: {
|
2014-08-21 01:18:34 +04:00
|
|
|
return u2_cm_error("bull-fish");
|
2013-12-26 21:12:07 +04:00
|
|
|
}
|
2013-09-29 00:21:18 +04:00
|
|
|
case c3__cell: {
|
2014-08-21 01:18:34 +04:00
|
|
|
if ( (u2_no == u2_cr_trel(sut, 0, &p_sut, &q_sut)) ) {
|
|
|
|
return u2_cm_bail(c3__fail);
|
2013-09-29 00:21:18 +04:00
|
|
|
} else {
|
2014-08-21 01:18:34 +04:00
|
|
|
u2_noun hut = u2nt(3, 0, u2k(axe));
|
2014-09-03 07:36:29 +04:00
|
|
|
u2_noun lef = u2_cqc_peg(axe, 2);
|
|
|
|
u2_noun rit = u2_cqc_peg(axe, 3);
|
2014-08-21 01:18:34 +04:00
|
|
|
u2_noun hed = _fish_in(van, p_sut, lef, vit);
|
|
|
|
u2_noun tal = _fish_in(van, q_sut, rit, vit);
|
2014-09-03 07:36:29 +04:00
|
|
|
u2_noun hob = u2_cqf_flan(hed, tal);
|
|
|
|
u2_noun vug = u2_cqf_flan(hut, hob);
|
2014-08-21 01:18:34 +04:00
|
|
|
|
|
|
|
u2z(hob);
|
|
|
|
u2z(tal);
|
|
|
|
u2z(hed);
|
|
|
|
u2z(rit);
|
|
|
|
u2z(lef);
|
|
|
|
u2z(hut);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
|
|
|
return vug;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case c3__core: {
|
2014-08-21 01:18:34 +04:00
|
|
|
return u2nc(0, 0);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
case c3__cube: {
|
2014-08-21 01:18:34 +04:00
|
|
|
if ( (u2_no == u2_cr_trel(sut, 0, &p_sut, &q_sut)) ) {
|
|
|
|
return u2_cm_bail(c3__fail);
|
2013-09-29 00:21:18 +04:00
|
|
|
} else {
|
2014-08-21 01:18:34 +04:00
|
|
|
return u2nt
|
|
|
|
(5,
|
|
|
|
u2nc(1, u2k(p_sut)),
|
|
|
|
u2nc(0, u2k(axe)));
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
case c3__face: {
|
2014-08-21 01:18:34 +04:00
|
|
|
if ( (u2_no == u2_cr_trel(sut, 0, &p_sut, &q_sut)) ) {
|
|
|
|
return u2_cm_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-08-21 01:18:34 +04:00
|
|
|
if ( (u2_no == u2_cr_trel(sut, 0, &p_sut, &q_sut)) ) {
|
|
|
|
return u2_cm_bail(c3__fail);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
else {
|
2014-08-21 01:18:34 +04:00
|
|
|
u2_noun hed = _fish_in(van, p_sut, axe, vit);
|
|
|
|
u2_noun tal = _fish_in(van, q_sut, axe, vit);
|
2014-09-03 07:36:29 +04:00
|
|
|
u2_noun pro = u2_cqf_flor(hed, tal);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-08-21 01:18:34 +04:00
|
|
|
u2z(hed);
|
|
|
|
u2z(tal);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
|
|
|
return pro;
|
|
|
|
}
|
2014-04-22 05:22:11 +04:00
|
|
|
}
|
2013-09-29 00:21:18 +04:00
|
|
|
case c3__hold: {
|
2014-08-21 01:18:34 +04:00
|
|
|
p_sut = u2t(sut);
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-09-03 07:36:29 +04:00
|
|
|
if ( (u2_yes == u2_cqdi_has(vit, sut)) ) {
|
|
|
|
// u2_noun dun = u2_cqfu_dunq(van, "type", sut);
|
|
|
|
u2_noun niz = u2_cqfu_shep
|
2014-08-21 01:18:34 +04:00
|
|
|
(van, "axis", 'd', u2k(axe));
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-08-21 01:18:34 +04:00
|
|
|
// u2_ct_push(u2nc(c3__mean, dun));
|
|
|
|
u2_ct_push(u2nc(c3__mean, niz));
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-08-21 01:18:34 +04:00
|
|
|
return u2_cm_error("fish-loop");
|
2013-09-29 00:21:18 +04:00
|
|
|
} else {
|
2014-09-03 07:36:29 +04:00
|
|
|
u2_noun zoc = u2_cqdi_put(vit, sut);
|
|
|
|
u2_noun fop = u2_cqfu_rest(van, sut, p_sut);
|
2014-08-21 01:18:34 +04:00
|
|
|
u2_noun pro = _fish_in(van, fop, axe, zoc);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-08-21 01:18:34 +04:00
|
|
|
u2z(fop);
|
|
|
|
u2z(zoc);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
|
|
|
return pro;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-09-04 01:33:18 +04:00
|
|
|
u2_noun
|
2014-09-03 09:46:55 +04:00
|
|
|
_cqfu_fish(
|
2014-09-04 01:33:18 +04:00
|
|
|
u2_noun van,
|
|
|
|
u2_noun sut,
|
|
|
|
u2_atom axe)
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-08-21 01:18:34 +04:00
|
|
|
return _fish_in(van, sut, axe, u2_nul);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* boilerplate
|
|
|
|
*/
|
2014-09-04 01:33:18 +04:00
|
|
|
u2_noun
|
2014-09-03 09:46:55 +04:00
|
|
|
u2_cwfu_fish(
|
2014-09-04 01:33:18 +04:00
|
|
|
u2_noun cor)
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
|
|
|
u2_noun sut, axe, van;
|
|
|
|
|
2014-08-21 01:18:34 +04:00
|
|
|
if ( (u2_no == u2_cr_mean(cor, u2_cv_sam, &axe, u2_cv_con, &van, 0)) ||
|
|
|
|
(u2_no == u2ud(axe)) ||
|
|
|
|
(u2_none == (sut = u2_cr_at(u2_cv_sam, van))) )
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-08-21 01:18:34 +04:00
|
|
|
return u2_cm_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-04 01:33:18 +04:00
|
|
|
u2_noun
|
|
|
|
u2_cqfu_fish(u2_noun van,
|
|
|
|
u2_noun sut,
|
|
|
|
u2_noun axe)
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-08-28 23:40:40 +04:00
|
|
|
c3_m fun_m = c3__fish;
|
|
|
|
u2_noun pro = u2_cz_find_2(fun_m, sut, axe);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-08-28 23:40:40 +04:00
|
|
|
if ( u2_none != pro ) {
|
|
|
|
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-08-28 23:40:40 +04:00
|
|
|
return u2_cz_save_2(fun_m, sut, axe, pro);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
}
|