urbit/j/6/ut_burn.c

120 lines
2.7 KiB
C
Raw Normal View History

2013-09-29 00:21:18 +04:00
/* j/6/ut_burn.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
static u3_noun
2014-08-21 01:18:34 +04:00
_burn_in(
2014-09-06 00:13:24 +04:00
u3_noun van,
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-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
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-09-06 00:13:24 +04:00
return u3_cm_error("burn-void");
2013-09-29 00:21:18 +04:00
}
}
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
2014-08-21 01:18:34 +04:00
case c3__atom: return 0;
2014-09-06 00:13:24 +04:00
case c3__bull: u3_cx_cell(u3t(sut), &p_sut, &q_sut);
2013-12-26 21:12:07 +04:00
{
2014-08-21 01:18:34 +04:00
return _burn_in(van, q_sut, gil);
2013-12-26 21:12:07 +04:00
}
2014-09-06 00:13:24 +04:00
case c3__cell: u3_cx_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-09-06 00:13:24 +04:00
case c3__core: u3_cx_cell(u3t(sut), &p_sut, &q_sut);
u3_cx_trel(q_sut, &pq_sut, &qq_sut, &rq_sut);
u3_cx_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-09-06 00:13:24 +04:00
case c3__cube: u3_cx_cell(u3t(sut), &p_sut, &q_sut);
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
return u3k(p_sut);
2013-09-29 00:21:18 +04:00
}
2014-09-06 00:13:24 +04:00
case c3__face: u3_cx_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
}
2014-09-06 00:13:24 +04:00
case c3__fork: u3_cx_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, p_sut, gil);
2013-09-29 00:21:18 +04:00
}
2014-09-06 00:13:24 +04:00
case c3__hold: p_sut = u3t(sut);
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
if ( (u3_yes == u3_cqdi_has(gil, sut)) ) {
u3_noun sux = u3_cqfu_dunq(van, "type", sut);
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04:00
u3_ct_push(u3nc(c3__mean, sux));
return u3_cm_error("burn-loop");
}
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 = _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;
}
}
}
}
2014-09-06 00:13:24 +04:00
u3_noun
2014-09-03 09:46:55 +04:00
_cqfu_burn(
2014-09-06 00:13:24 +04:00
u3_noun van,
u3_noun sut)
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
return _burn_in(van, sut, u3_nul);
2013-09-29 00:21:18 +04:00
}
2014-09-06 00:13:24 +04:00
u3_noun
u3_cqfu_burn(
u3_noun van,
u3_noun sut)
2013-09-29 00:21:18 +04:00
{
2014-09-03 09:46:55 +04:00
c3_m fun_m = c3__burn;
2014-09-06 00:13:24 +04:00
u3_noun pro = u3_cz_find(fun_m, sut);
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04: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-09-06 00:13:24 +04:00
return u3_cz_save(fun_m, sut, pro);
2013-09-29 00:21:18 +04:00
}
}
2014-09-06 00:13:24 +04:00
u3_noun
u3_cwfu_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-09-06 00:13:24 +04:00
if ( u3_none == (sut = u3_cr_at(u3_cv_sam, cor)) ) {
return u3_cm_bail(c3__fail);
2013-09-29 00:21:18 +04:00
} else {
2014-09-06 00:13:24 +04:00
return u3_cqfu_burn(cor, sut);
2013-09-29 00:21:18 +04:00
}
}