2013-09-29 00:21:18 +04:00
|
|
|
/* j/6/ut_burn.c
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
#include "all.h"
|
2014-09-04 07:10:43 +04:00
|
|
|
|
2013-09-29 00:21:18 +04:00
|
|
|
|
|
|
|
/* logic
|
|
|
|
*/
|
2016-01-13 21:06:42 +03:00
|
|
|
static u3_noun
|
2016-01-14 04:46:01 +03:00
|
|
|
_bran_in(u3_noun van, u3_noun sut, u3_noun gil);
|
2016-01-13 21:06:42 +03:00
|
|
|
|
|
|
|
static u3_noun
|
2016-01-14 04:46:01 +03:00
|
|
|
_bran_frog(u3_noun van,
|
2016-01-13 21:06:42 +03:00
|
|
|
u3_noun yed,
|
|
|
|
u3_noun gil)
|
|
|
|
{
|
|
|
|
if ( u3_nul == yed ) {
|
|
|
|
return u3_nul;
|
|
|
|
} else {
|
2016-01-14 04:46:01 +03:00
|
|
|
u3_noun dis = _bran_in(van, u3h(yed), gil);
|
|
|
|
u3_noun mor = _bran_frog(van, u3t(yed), gil);
|
2016-01-13 21:06:42 +03:00
|
|
|
|
|
|
|
if ( u3_nul == dis ) return mor;
|
|
|
|
if ( u3_nul == mor ) return dis;
|
|
|
|
{
|
|
|
|
u3_noun u_dis = u3t(dis);
|
|
|
|
u3_noun u_mor = u3t(mor);
|
|
|
|
|
|
|
|
if ( u3du(u_dis) == u3du(u_mor) ) {
|
|
|
|
if ( c3y == u3qc_gor(u_mor, u_dis) ) {
|
|
|
|
u3z(dis);
|
|
|
|
return mor;
|
|
|
|
} else {
|
|
|
|
u3z(mor);
|
|
|
|
return dis;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ( c3y == u3ud(u_dis) ) {
|
|
|
|
u3z(mor);
|
|
|
|
return dis;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
u3z(dis);
|
|
|
|
return mor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static u3_noun
|
2016-01-14 04:46:01 +03:00
|
|
|
_bran_in(u3_noun van,
|
2016-01-13 21:06:42 +03:00
|
|
|
u3_noun sut,
|
|
|
|
u3_noun gil)
|
|
|
|
{
|
|
|
|
u3_noun p_sut, q_sut, pq_sut, qq_sut, rq_sut, prq_sut, qrq_sut;
|
|
|
|
|
|
|
|
if ( c3n == u3du(sut) ) switch ( sut ) {
|
|
|
|
default: return u3m_bail(c3__fail);
|
|
|
|
|
|
|
|
case c3__noun: return u3nc(u3_nul, 0);
|
|
|
|
case c3__void: {
|
|
|
|
return u3_nul;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else switch ( u3h(sut) ) {
|
|
|
|
default: return u3m_bail(c3__fail);
|
|
|
|
|
|
|
|
case c3__atom: u3x_cell(u3t(sut), &p_sut, &q_sut);
|
|
|
|
{
|
|
|
|
if ( c3y == u3du(q_sut) ) {
|
|
|
|
return u3nc(u3_nul, u3k(u3t(q_sut)));
|
|
|
|
} else {
|
|
|
|
return u3nc(u3_nul, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case c3__cell: u3x_cell(u3t(sut), &p_sut, &q_sut);
|
|
|
|
{
|
2016-01-14 04:46:01 +03:00
|
|
|
u3_noun hed = _bran_in(van, p_sut, gil);
|
2016-01-13 21:06:42 +03:00
|
|
|
|
|
|
|
if ( u3_nul == hed ) {
|
|
|
|
return u3_nul;
|
|
|
|
}
|
|
|
|
else {
|
2016-01-14 04:46:01 +03:00
|
|
|
u3_noun tal = _bran_in(van, q_sut, gil);
|
2016-01-13 21:06:42 +03:00
|
|
|
|
|
|
|
if ( u3_nul == tal ) {
|
|
|
|
u3z(hed);
|
|
|
|
return u3_nul;
|
|
|
|
}
|
2016-01-14 04:46:01 +03:00
|
|
|
else {
|
|
|
|
u3_noun ret = u3nt(u3_nul, u3k(u3t(hed)), u3k(u3t(tal)));
|
|
|
|
|
|
|
|
u3z(hed);
|
|
|
|
u3z(tal);
|
|
|
|
return ret;
|
|
|
|
}
|
2016-01-13 21:06:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
case c3__core: u3x_cell(u3t(sut), &p_sut, &q_sut);
|
|
|
|
u3x_trel(q_sut, &pq_sut, &qq_sut, &rq_sut);
|
|
|
|
u3x_cell(rq_sut, &prq_sut, &qrq_sut);
|
|
|
|
{
|
2016-01-14 04:46:01 +03:00
|
|
|
u3_noun pay = _bran_in(van, p_sut, gil);
|
2016-01-13 21:06:42 +03:00
|
|
|
|
|
|
|
if ( u3_nul == pay ) {
|
|
|
|
return u3_nul;
|
|
|
|
}
|
|
|
|
else {
|
2016-01-14 04:46:01 +03:00
|
|
|
u3_noun ret = u3nt(u3_nul, u3k(prq_sut), u3k(u3t(pay)));
|
|
|
|
|
|
|
|
u3z(pay);
|
|
|
|
return ret;
|
2016-01-13 21:06:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
case c3__face: u3x_cell(u3t(sut), &p_sut, &q_sut);
|
|
|
|
{
|
2016-01-14 04:46:01 +03:00
|
|
|
return _bran_in(van, q_sut, gil);
|
2016-01-13 21:06:42 +03:00
|
|
|
}
|
|
|
|
case c3__fork: p_sut = u3t(sut);
|
|
|
|
{
|
|
|
|
u3_noun yed = u3qdi_tap(p_sut, u3_nul);
|
2016-01-14 04:46:01 +03:00
|
|
|
u3_noun ret = _bran_frog(van, yed, gil);
|
2016-01-13 21:06:42 +03:00
|
|
|
|
|
|
|
u3z(yed);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
case c3__frog: p_sut = u3t(sut);
|
|
|
|
{
|
2016-01-14 04:46:01 +03:00
|
|
|
return _bran_in(van, u3h(p_sut), gil);
|
2016-01-13 21:06:42 +03:00
|
|
|
}
|
|
|
|
case c3__hold:
|
|
|
|
{
|
|
|
|
if ( (c3y == u3qdi_has(gil, sut)) ) {
|
|
|
|
return u3_nul;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
u3_noun zoc = u3qdi_put(gil, sut);
|
|
|
|
u3_noun fop = u3qfu_repo(van, sut);
|
2016-01-14 04:46:01 +03:00
|
|
|
u3_noun pro = _bran_in(van, fop, zoc);
|
2016-01-13 21:06:42 +03:00
|
|
|
|
|
|
|
u3z(fop);
|
|
|
|
u3z(zoc);
|
|
|
|
|
|
|
|
return pro;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
u3_noun
|
2016-01-14 04:46:01 +03:00
|
|
|
_cqfu_bran(u3_noun van,
|
2016-01-13 21:06:42 +03:00
|
|
|
u3_noun sut)
|
|
|
|
{
|
2016-01-14 04:46:01 +03:00
|
|
|
u3_noun unt = _bran_in(van, sut, u3_nul);
|
2016-01-13 21:06:42 +03:00
|
|
|
|
|
|
|
if ( u3_nul == unt ) {
|
2016-01-14 04:46:01 +03:00
|
|
|
return u3m_error("bran");
|
2016-01-13 21:06:42 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
u3_noun ret = u3k(u3t(unt));
|
|
|
|
|
|
|
|
u3z(unt);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
2016-01-14 04:46:01 +03:00
|
|
|
|
|
|
|
#if 0
|
2014-09-06 00:13:24 +04:00
|
|
|
static u3_noun
|
2015-08-28 19:34:36 +03:00
|
|
|
_burn_in(u3_noun van,
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_noun sut,
|
|
|
|
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, pq_sut, qq_sut, rq_sut, prq_sut, qrq_sut;
|
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
|
|
|
|
2014-08-21 01:18:34 +04:00
|
|
|
case c3__noun: return 0;
|
2013-09-29 00:21:18 +04:00
|
|
|
case c3__void: {
|
2014-11-06 03:20:01 +03:00
|
|
|
return u3m_error("burn-void");
|
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
|
|
|
|
2015-12-28 23:53:10 +03:00
|
|
|
case c3__atom: u3x_cell(u3t(sut), &p_sut, &q_sut);
|
|
|
|
{
|
|
|
|
if ( c3y == u3du(q_sut) ) {
|
|
|
|
return u3k(u3t(q_sut));
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2014-11-06 03:20:01 +03:00
|
|
|
case c3__cell: u3x_cell(u3t(sut), &p_sut, &q_sut);
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-09-06 00:13:24 +04:00
|
|
|
return u3nc
|
2014-08-21 01:18:34 +04:00
|
|
|
(_burn_in(van, p_sut, gil),
|
|
|
|
_burn_in(van, q_sut, gil));
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
2014-11-06 03:20:01 +03:00
|
|
|
case c3__core: u3x_cell(u3t(sut), &p_sut, &q_sut);
|
|
|
|
u3x_trel(q_sut, &pq_sut, &qq_sut, &rq_sut);
|
|
|
|
u3x_cell(rq_sut, &prq_sut, &qrq_sut);
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-09-06 00:13:24 +04:00
|
|
|
return u3nc
|
|
|
|
(u3k(prq_sut),
|
2014-08-21 01:18:34 +04:00
|
|
|
_burn_in(van, p_sut, gil));
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
2014-11-06 03:20:01 +03:00
|
|
|
case c3__face: u3x_cell(u3t(sut), &p_sut, &q_sut);
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-08-21 01:18:34 +04:00
|
|
|
return _burn_in(van, q_sut, gil);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
2016-01-11 12:16:38 +03:00
|
|
|
case c3__fork: p_sut = u3t(sut);
|
|
|
|
{
|
2016-01-13 02:31:02 +03:00
|
|
|
return _burn_in(van, u3h(p_sut), gil);
|
2016-01-11 12:16:38 +03:00
|
|
|
}
|
2016-01-11 03:27:36 +03:00
|
|
|
case c3__frog: p_sut = u3t(sut);
|
|
|
|
{
|
|
|
|
return _burn_in(van, u3h(p_sut), gil);
|
|
|
|
}
|
2016-01-11 09:37:59 +03:00
|
|
|
case c3__hold:
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-11-06 22:13:57 +03:00
|
|
|
if ( (c3y == u3qdi_has(gil, sut)) ) {
|
|
|
|
u3_noun sux = u3qfu_dunq(van, "type", sut);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-11-06 03:20:01 +03:00
|
|
|
u3t_push(u3nc(c3__mean, sux));
|
|
|
|
return u3m_error("burn-loop");
|
2014-04-22 05:22:11 +04:00
|
|
|
}
|
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 = _burn_in(van, fop, 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-01-14 04:46:01 +03:00
|
|
|
#endif
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_noun
|
2015-08-28 19:34:36 +03:00
|
|
|
_cqfu_burn(u3_noun van,
|
|
|
|
u3_noun sut)
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2016-01-14 04:46:01 +03:00
|
|
|
#if 1
|
|
|
|
return _cqfu_bran(van, sut);
|
|
|
|
#else
|
|
|
|
u3_noun old = _burn_in(van, sut, u3_nul);
|
|
|
|
u3_noun new = _cqfu_bran(van, sut);
|
|
|
|
|
|
|
|
if ( c3n == u3r_sing(old, new) ) {
|
|
|
|
u3m_p("burn: old", u3r_mug(old));
|
|
|
|
u3m_p("burn: new", u3r_mug(new));
|
|
|
|
}
|
|
|
|
u3z(old);
|
|
|
|
return new;
|
2016-01-13 21:06:42 +03:00
|
|
|
#endif
|
2016-01-14 04:46:01 +03:00
|
|
|
}
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_noun
|
2015-08-28 19:34:36 +03:00
|
|
|
u3qfu_burn(u3_noun van,
|
|
|
|
u3_noun sut)
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2015-12-22 01:45:22 +03:00
|
|
|
c3_m fun_m = c3__burn + !!u3r_at(u3qfu_van_vet, van);
|
2014-11-06 03:20:01 +03:00
|
|
|
u3_noun pro = u3z_find(fun_m, sut);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-11-06 02:36:30 +03:00
|
|
|
if ( u3_none != pro ) {
|
2014-09-03 09:46:55 +04:00
|
|
|
return pro;
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
else {
|
2014-09-03 09:46:55 +04:00
|
|
|
pro = _cqfu_burn(van, sut);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-11-06 03:20:01 +03:00
|
|
|
return u3z_save(fun_m, sut, pro);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_noun
|
2015-08-28 19:34:36 +03:00
|
|
|
u3wfu_burn(u3_noun cor)
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_noun sut;
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-11-18 00:56:51 +03:00
|
|
|
if ( u3_none == (sut = u3r_at(u3x_sam, cor)) ) {
|
2014-11-06 03:20:01 +03:00
|
|
|
return u3m_bail(c3__fail);
|
2013-09-29 00:21:18 +04:00
|
|
|
} else {
|
2014-11-06 22:13:57 +03:00
|
|
|
return u3qfu_burn(cor, sut);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
}
|