urbit/j/f/ut_fire.c

176 lines
4.0 KiB
C
Raw Normal View History

2013-09-29 00:21:18 +04:00
/* j/6/fire.c
**
*/
#include "all.h"
2014-09-04 07:10:43 +04:00
2013-09-29 00:21:18 +04:00
/* logic
*/
2014-11-06 06:10:22 +03:00
static u3_noun
2014-09-06 00:13:24 +04:00
_fire_mull(u3_noun van,
u3_noun sut,
u3_noun dox,
u3_noun gen)
2013-09-29 00:21:18 +04:00
{
2014-11-06 22:13:57 +03:00
u3_noun rib = u3r_at(u3qfu_van_rib, van);
2014-09-06 00:13:24 +04:00
u3_noun key = u3nt(u3k(sut),
u3k(dox),
u3k(gen));
2014-11-06 06:10:22 +03:00
u3_noun ret;
2014-09-06 00:13:24 +04:00
2014-11-06 22:13:57 +03:00
if ( c3y == u3qdi_has(rib, key) ) {
2014-11-05 04:18:47 +03:00
ret = c3y;
2013-09-29 00:21:18 +04:00
}
else {
2014-11-06 22:13:57 +03:00
u3_noun rob = u3qdi_put(rib, key);
2014-11-06 03:20:01 +03:00
u3_noun von = u3i_molt(u3k(van),
2014-11-06 22:13:57 +03:00
u3qfu_van_rib, u3k(rob),
2013-09-29 00:21:18 +04:00
0);
2014-11-06 22:13:57 +03:00
ret = u3qfu_mull(von, sut, c3__noun, dox, gen);
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04:00
u3z(von);
u3z(rob);
2013-09-29 00:21:18 +04:00
}
2014-09-06 00:13:24 +04:00
u3z(key);
2013-09-29 00:21:18 +04:00
return ret;
}
2014-09-06 00:13:24 +04:00
static u3_noun
_fire_each(u3_noun van,
u3_noun vet,
u3_noun typ,
u3_noun gat)
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
u3_noun p_typ, q_typ, pq_typ, qq_typ, rq_typ;
u3_noun h_gat, t_gat;
2013-09-29 00:21:18 +04:00
2014-11-05 04:18:47 +03:00
if ( (c3n == u3du(typ)) || (c3__core != u3h(typ)) ) {
2014-11-06 03:20:01 +03:00
return u3m_error("fire-core");
} else if
2014-11-06 03:20:01 +03:00
( (c3n == u3r_cell(u3t(typ), &p_typ, &q_typ)) ||
(c3n == u3r_trel(q_typ, &pq_typ, &qq_typ, &rq_typ)) ||
(c3n == u3r_cell(gat, &h_gat, &t_gat)) )
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-06 00:13:24 +04:00
u3_noun dox = u3nt
(c3__core, u3k(qq_typ), u3k(q_typ));
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04:00
if ( c3__ash == u3h(gat) ) {
2014-11-05 04:18:47 +03:00
if ( (c3y == vet) &&
2014-11-06 22:13:57 +03:00
(c3n == u3qfu_nest
2014-11-05 04:18:47 +03:00
(van, qq_typ, c3y, p_typ)) )
2013-09-29 00:21:18 +04:00
{
#if 0
2014-11-06 22:13:57 +03:00
u3_noun dun = u3qfu_dunq(van, "need", qq_typ);
u3_noun niz = u3qfu_dunq(van, "have", p_typ);
2013-09-29 00:21:18 +04:00
2014-11-06 03:20:01 +03:00
u3t_push(u3nc(c3__mean, niz));
u3t_push(u3nc(c3__mean, dun));
2013-09-29 00:21:18 +04:00
#endif
2014-11-06 03:20:01 +03:00
return u3m_error("fire-dry");
2013-09-29 00:21:18 +04:00
}
else {
2014-09-06 00:13:24 +04:00
return u3nc(dox, u3k(t_gat));
2013-09-29 00:21:18 +04:00
}
}
else {
2014-09-06 00:13:24 +04:00
c3_assert(c3__elm == u3h(gat));
2013-09-29 00:21:18 +04:00
2014-11-05 04:18:47 +03:00
if ( (c3y == vet) &&
2014-11-06 03:20:01 +03:00
// (c3n == u3r_sing(p_typ, qq_typ)) &&
2014-11-05 04:18:47 +03:00
(c3n == _fire_mull(van, typ, dox, t_gat)) )
2013-09-29 00:21:18 +04:00
{
#if 0
2014-11-06 22:13:57 +03:00
u3_noun dun = u3qfu_dunq(van, "wild", typ);
u3_noun niz = u3qfu_dunq(van, "tame", dox);
2013-09-29 00:21:18 +04:00
2014-11-06 03:20:01 +03:00
u3t_push(u3nc(c3__mean, dun));
u3t_push(u3nc(c3__mean, niz));
2013-09-29 00:21:18 +04:00
#endif
2014-11-06 03:20:01 +03:00
return u3m_error("fire-wet");
2013-09-29 00:21:18 +04:00
}
else {
2014-09-06 00:13:24 +04:00
u3z(dox);
return u3nc(u3k(typ), u3k(t_gat));
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
_fire_in(
2014-09-06 00:13:24 +04:00
u3_noun van,
u3_noun vet,
u3_noun hag)
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
if ( u3_nul == hag ) {
return u3_nul;
2013-09-29 00:21:18 +04:00
}
else {
2014-09-06 00:13:24 +04:00
u3_noun i_hag = u3h(hag);
u3_noun t_hag = u3t(hag);
2013-09-29 00:21:18 +04:00
2014-11-05 04:18:47 +03:00
if ( c3n == u3du(i_hag) ) {
2014-11-06 03:20:01 +03:00
return u3m_bail(c3__fail);
2013-09-29 00:21:18 +04:00
} else {
2014-09-06 00:13:24 +04:00
return u3nc
(_fire_each(van, vet, u3h(i_hag), u3t(i_hag)),
2014-08-21 01:18:34 +04:00
_fire_in(van, vet, t_hag));
2013-09-29 00:21:18 +04:00
}
}
}
2014-09-06 00:13:24 +04:00
u3_noun
2014-09-03 09:46:55 +04:00
_cqfu_fire(
2014-09-06 00:13:24 +04:00
u3_noun van,
u3_noun sut,
u3_noun hag)
2013-09-29 00:21:18 +04:00
{
2014-11-06 22:13:57 +03:00
u3_noun vet = u3r_at(u3qfu_van_vet, van);
2013-09-29 00:21:18 +04:00
{
2014-11-05 04:18:47 +03:00
if ( (c3y == u3du(hag)) && (u3_nul == u3t(hag)) ) {
2014-09-06 00:13:24 +04:00
u3_noun i_hag = u3h(hag);
u3_noun pi_hag = u3h(i_hag);
u3_noun qi_hag = u3t(i_hag);
2014-09-06 00:13:24 +04:00
if ( c3__elm == u3h(qi_hag) ) {
u3_noun qqi_hag = u3t(qi_hag);
2014-11-05 04:18:47 +03:00
if ( c3y == u3du(qqi_hag) &&
2014-09-06 00:13:24 +04:00
(u3_nul == u3h(qqi_hag)) &&
(1 == u3t(qqi_hag)) )
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
return u3k(pi_hag);
2013-09-29 00:21:18 +04:00
}
}
}
}
2014-09-06 00:13:24 +04:00
return u3nc(c3__hold, _fire_in(van, vet, hag));
2013-09-29 00:21:18 +04:00
}
/* boilerplate
*/
2014-09-06 00:13:24 +04:00
u3_noun
2014-11-06 22:13:57 +03:00
u3wfu_fire(
2014-09-06 00:13:24 +04:00
u3_noun cor)
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
u3_noun sut, hag, van;
2013-09-29 00:21:18 +04:00
2014-11-18 00:56:51 +03:00
if ( (c3n == u3r_mean(cor, u3x_sam, &hag, u3x_con, &van, 0)) ||
(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_fire(van, sut, hag);
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_fire(u3_noun van,
2014-09-06 00:13:24 +04:00
u3_noun sut,
u3_noun hag)
2013-09-29 00:21:18 +04:00
{
2014-09-03 09:46:55 +04:00
return _cqfu_fire(van, sut, hag);
2013-09-29 00:21:18 +04:00
}