2013-09-29 00:21:18 +04:00
|
|
|
/* j/6/peek.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
|
|
|
|
|
|
|
/* logic
|
|
|
|
*/
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_noun
|
|
|
|
_cqfu_peek(u3_noun, u3_noun, u3_noun, u3_atom);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-09-06 00:13:24 +04:00
|
|
|
static u3_noun
|
2014-08-21 01:18:34 +04:00
|
|
|
_peek_in(
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_noun van,
|
|
|
|
u3_noun sut,
|
|
|
|
u3_noun way,
|
|
|
|
u3_atom axe,
|
|
|
|
u3_noun gil)
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_noun p_sut, q_sut;
|
|
|
|
u3_noun pro;
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-09-06 00:13:24 +04:00
|
|
|
if ( (u3_no == u3du(sut)) ) switch ( sut ) {
|
|
|
|
default: return u3_cm_bail(c3__fail);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
|
|
|
case c3__noun: {
|
|
|
|
return c3__noun;
|
|
|
|
}
|
|
|
|
case c3__void: {
|
|
|
|
return c3__void;
|
|
|
|
}
|
|
|
|
}
|
2014-09-06 00:13:24 +04:00
|
|
|
else switch ( u3h(sut) ) {
|
|
|
|
default: return u3_cm_bail(c3__fail);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
|
|
|
case c3__atom: {
|
|
|
|
return c3__void;
|
|
|
|
}
|
2014-02-18 20:42:47 +04:00
|
|
|
case c3__bull: {
|
2014-09-06 00:13:24 +04:00
|
|
|
if ( (u3_no == u3_cr_trel(sut, 0, &p_sut, &q_sut)) ) {
|
|
|
|
return u3_cm_bail(c3__fail);
|
2014-02-18 20:42:47 +04:00
|
|
|
} else {
|
2014-08-21 01:18:34 +04:00
|
|
|
return _peek_in(van, q_sut, way, axe, gil);
|
2014-02-18 20:42:47 +04:00
|
|
|
}
|
|
|
|
}
|
2013-09-29 00:21:18 +04:00
|
|
|
case c3__cell: {
|
2014-09-06 00:13:24 +04:00
|
|
|
if ( (u3_no == u3_cr_trel(sut, 0, &p_sut, &q_sut)) ) {
|
|
|
|
return u3_cm_bail(c3__fail);
|
2013-09-29 00:21:18 +04:00
|
|
|
} else {
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_atom tip = u3_cqc_cap(axe);
|
|
|
|
u3_atom tap = u3_cqc_mas(axe);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-08-21 01:18:34 +04:00
|
|
|
if ( 2 == tip ) {
|
2014-09-03 09:46:55 +04:00
|
|
|
pro = _cqfu_peek(van, p_sut, way, tap);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
else {
|
2014-09-03 09:46:55 +04:00
|
|
|
pro = _cqfu_peek(van, q_sut, way, tap);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
2014-09-06 00:13:24 +04:00
|
|
|
u3z(tap);
|
|
|
|
u3z(tip);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
|
|
|
return pro;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case c3__core: {
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_noun pq_sut, qq_sut, rq_sut;
|
|
|
|
u3_noun prq_sut, qrq_sut;
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-09-06 00:13:24 +04:00
|
|
|
if ( (u3_no == u3_cr_trel(sut, 0, &p_sut, &q_sut)) ||
|
|
|
|
(u3_no == u3_cr_trel(q_sut, &pq_sut, &qq_sut, &rq_sut)) ||
|
|
|
|
(u3_no == u3_cr_cell(rq_sut, &prq_sut, &qrq_sut)) )
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-09-06 00:13:24 +04:00
|
|
|
return u3_cm_bail(c3__fail);
|
2013-09-29 00:21:18 +04:00
|
|
|
} else {
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_atom tip = u3_cqc_cap(axe);
|
|
|
|
u3_atom tap = u3_cqc_mas(axe);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-08-21 01:18:34 +04:00
|
|
|
if ( 3 == tip ) {
|
2014-09-06 00:13:24 +04:00
|
|
|
if ( u3_no == u3_cqfu_park(van, sut, way, tap) )
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-09-06 00:13:24 +04:00
|
|
|
// u3_noun dun = u3_cqfu_dunq(van, "type", sut);
|
|
|
|
u3_noun waz = u3_cqfu_shep
|
|
|
|
(van, "axis", 'd', u3k(axe));
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-09-06 00:13:24 +04:00
|
|
|
// u3_ct_push(u3nc(c3__mean, dun));
|
|
|
|
u3_ct_push(u3nc(c3__mean, waz));
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-09-06 00:13:24 +04:00
|
|
|
return u3_cm_error("peek-park");
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
2014-09-03 09:46:55 +04:00
|
|
|
else pro = _cqfu_peek(van, p_sut, way, tap);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
pro = c3__noun;
|
|
|
|
}
|
2014-09-06 00:13:24 +04:00
|
|
|
u3z(tap);
|
|
|
|
u3z(tip);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
|
|
|
return pro;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case c3__cube: {
|
2014-09-06 00:13:24 +04:00
|
|
|
if ( (u3_no == u3_cr_trel(sut, 0, &p_sut, &q_sut)) ) {
|
|
|
|
return u3_cm_bail(c3__fail);
|
2013-09-29 00:21:18 +04:00
|
|
|
} else {
|
2014-08-21 01:18:34 +04:00
|
|
|
return _peek_in(van, q_sut, way, axe, gil);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
case c3__face: {
|
2014-09-06 00:13:24 +04:00
|
|
|
if ( (u3_no == u3_cr_trel(sut, 0, &p_sut, &q_sut)) ) {
|
|
|
|
return u3_cm_bail(c3__fail);
|
2013-09-29 00:21:18 +04:00
|
|
|
} else {
|
2014-08-21 01:18:34 +04:00
|
|
|
return _peek_in(van, q_sut, way, axe, gil);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
case c3__fork: {
|
2014-09-06 00:13:24 +04:00
|
|
|
if ( (u3_no == u3_cr_trel(sut, 0, &p_sut, &q_sut)) ) {
|
|
|
|
return u3_cm_bail(c3__fail);
|
2013-09-29 00:21:18 +04:00
|
|
|
} else {
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_noun hed = _peek_in(van, p_sut, way, axe, gil);
|
|
|
|
u3_noun tal = _peek_in(van, q_sut, way, axe, gil);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-09-06 00:13:24 +04:00
|
|
|
pro = u3_cqf_fork(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
|
|
|
}
|
2013-09-29 00:21:18 +04:00
|
|
|
case c3__hold: {
|
2014-09-06 00:13:24 +04:00
|
|
|
p_sut = u3t(sut);
|
|
|
|
if ( (u3_yes == u3_cqdi_has(gil, sut)) ) {
|
2013-09-29 00:21:18 +04:00
|
|
|
return c3__void;
|
2014-04-22 05:22:11 +04:00
|
|
|
}
|
2013-09-29 00:21:18 +04:00
|
|
|
else {
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_noun zoc = u3_cqdi_put(gil, sut);
|
|
|
|
u3_noun fop = u3_cqfu_repo(van, sut);
|
|
|
|
u3_noun pro = _peek_in(van, fop, way, 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_peek(
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_noun van,
|
|
|
|
u3_noun sut,
|
|
|
|
u3_noun way,
|
|
|
|
u3_atom axe)
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-08-21 01:18:34 +04:00
|
|
|
if ( 1 == axe ) {
|
2014-09-06 00:13:24 +04:00
|
|
|
return u3k(sut);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
2014-09-06 00:13:24 +04:00
|
|
|
else return _peek_in(van, sut, way, axe, u3_nul);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* boilerplate
|
|
|
|
*/
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_noun
|
|
|
|
u3_cwfu_peek(
|
|
|
|
u3_noun cor)
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_noun sut, way, axe, van;
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-09-06 00:13:24 +04:00
|
|
|
if ( (u3_no == u3_cr_mean(cor, u3_cv_sam_2, &way,
|
|
|
|
u3_cv_sam_3, &axe,
|
|
|
|
u3_cv_con, &van,
|
2013-09-29 00:21:18 +04:00
|
|
|
0)) ||
|
2014-09-06 00:13:24 +04:00
|
|
|
(u3_no == u3ud(axe)) ||
|
|
|
|
(u3_none == (sut = u3_cr_at(u3_cv_sam, van))) )
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-09-06 00:13:24 +04:00
|
|
|
return u3_cm_bail(c3__fail);
|
2013-09-29 00:21:18 +04:00
|
|
|
} else {
|
2014-09-03 09:46:55 +04:00
|
|
|
return _cqfu_peek(van, sut, way, axe);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_noun
|
|
|
|
u3_cqfu_peek(u3_noun van,
|
|
|
|
u3_noun sut,
|
|
|
|
u3_noun way,
|
|
|
|
u3_noun axe)
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-08-28 23:40:40 +04:00
|
|
|
c3_m fun_m = c3__peek;
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_noun pro = u3_cz_find_3(fun_m, sut, way, axe);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-09-06 00:13:24 +04: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_peek(van, sut, way, axe);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-09-06 00:13:24 +04:00
|
|
|
return u3_cz_save_3(fun_m, sut, way, axe, pro);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
}
|