shrub/jets/f/ut_peek.c

215 lines
4.8 KiB
C
Raw Normal View History

2013-09-29 00:21:18 +04:00
/* j/6/peek.c
**
*/
#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
static u3_noun
_peek_in(u3_noun, u3_noun, u3_noun, u3_atom, u3_noun);
static u3_noun
2016-01-14 12:52:50 +03:00
_peek_fork(u3_noun van, u3_noun p_sut, u3_noun way, u3_noun axe, u3_noun gil)
{
if ( u3_nul == p_sut ) {
return u3_nul;
2016-08-01 11:55:42 +03:00
}
else {
return u3nc(_peek_in(van, u3h(p_sut), way, axe, gil),
2016-01-14 12:52:50 +03:00
_peek_fork(van, u3t(p_sut), way, axe, gil));
}
}
2014-09-06 00:13:24 +04:00
static u3_noun
2015-08-28 19:34:36 +03:00
_peek_in(u3_noun van,
2014-09-06 00:13:24 +04:00
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-11-05 04:18:47 +03:00
if ( (c3n == u3du(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: {
return c3__noun;
}
case c3__void: {
return c3__void;
}
}
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: {
return c3__void;
}
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-11-06 22:13:57 +03:00
u3_atom tip = u3qc_cap(axe);
u3_atom tap = u3qc_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-11-06 03:20:01 +03:00
if ( (c3n == u3r_trel(sut, 0, &p_sut, &q_sut)) ||
(c3n == u3r_trel(q_sut, &pq_sut, &qq_sut, &rq_sut)) ||
(c3n == u3r_cell(rq_sut, &prq_sut, &qrq_sut)) )
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 {
2016-08-01 11:55:42 +03:00
u3_atom now = u3qc_cap(axe);
u3_atom lat = u3qc_mas(axe);
2013-09-29 00:21:18 +04:00
2016-08-01 11:55:42 +03:00
if ( 3 == now ) {
2016-10-28 03:26:40 +03:00
u3_noun pec = u3qfu_peel(van, sut, way, pq_sut);
2016-08-01 11:55:42 +03:00
u3_noun sam = u3h(pec);
u3_noun con = u3t(pec);
2013-09-29 00:21:18 +04:00
2016-08-01 11:55:42 +03:00
if ( c3y == c3a(sam, con) ) {
pro = _cqfu_peek(van, p_sut, way, lat);
2013-09-29 00:21:18 +04:00
}
2016-08-01 11:55:42 +03:00
else {
u3_noun typ;
{
u3_noun hed, tal;
if ( c3n == sam ) {
hed = c3__noun;
} else {
hed = _cqfu_peek(van, p_sut, way, 2);
}
if ( c3n == con ) {
tal = c3__noun;
} else {
tal = _cqfu_peek(van, p_sut, way, 3);
}
typ = u3qf_cell(hed, tal);
u3z(hed);
u3z(tal);
}
pro = _cqfu_peek(van, typ, way, lat);
u3z(typ);
}
u3z(pec);
2013-09-29 00:21:18 +04:00
}
else {
pro = c3__noun;
}
2016-08-01 11:55:42 +03:00
u3z(lat);
u3z(now);
2013-09-29 00:21:18 +04:00
return pro;
}
}
case c3__help:
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);
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: p_sut = u3t(sut);
{
u3_noun yed = u3qdi_tap(p_sut);
2016-01-14 12:52:50 +03:00
u3_noun ret = u3kf_fork(_peek_fork(van, yed, way, axe, gil));
2016-01-13 02:31:02 +03:00
u3z(yed);
return ret;
}
2016-01-11 10:04:34 +03:00
case c3__hold: {
2014-11-06 22:13:57 +03:00
if ( (c3y == u3qdi_has(gil, sut)) ) {
2013-09-29 00:21:18 +04:00
return c3__void;
}
2013-09-29 00:21:18 +04:00
else {
2014-11-06 22:13:57 +03:00
u3_noun zoc = u3qdi_put(gil, sut);
u3_noun fop = u3qfu_repo(van, sut);
2014-09-06 00:13:24 +04:00
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
2015-08-28 19:34:36 +03:00
_cqfu_peek(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
2015-08-28 19:34:36 +03:00
u3wfu_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-11-18 00:56:51 +03:00
if ( (c3n == u3r_mean(cor, u3x_sam_2, &way,
2015-08-28 19:34:36 +03:00
u3x_sam_3, &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_peek(van, sut, way, 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_peek(u3_noun van,
2015-08-28 19:34:36 +03:00
u3_noun sut,
u3_noun way,
u3_noun axe)
2013-09-29 00:21:18 +04:00
{
2017-04-01 03:24:42 +03:00
c3_m fun_m = 144 + c3__peek + ((!!u3r_at(u3qfu_van_vet, van)) << 8);
2014-11-06 03:20:01 +03:00
u3_noun pro = u3z_find_3(fun_m, sut, way, 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_peek(van, sut, way, axe);
2013-09-29 00:21:18 +04:00
2014-11-06 03:20:01 +03:00
return u3z_save_3(fun_m, sut, way, axe, pro);
2013-09-29 00:21:18 +04:00
}
}