urbit/gen164/6/ut_repo.c

77 lines
1.9 KiB
C
Raw Normal View History

2013-09-29 00:21:18 +04:00
/* j/6/ut_repo.c
**
** This file is in the public domain.
*/
#include "all.h"
#include "../pit.h"
/* logic
*/
u2_noun // transfer
2014-09-03 07:36:29 +04:00
u2_cqfu_repo(
2013-09-29 00:21:18 +04:00
u2_noun van, // retain
u2_noun sut) // retain
{
2013-12-26 21:12:07 +04:00
u2_noun p_sut, q_sut;
2013-09-29 00:21:18 +04:00
2014-08-21 01:18:34 +04:00
if ( u2_no == u2du(sut) ) switch ( sut ) {
default: return u2k(sut);
2013-09-29 00:21:18 +04:00
case c3__noun:
2014-08-21 01:18:34 +04:00
return u2nt(c3__fork,
u2nc(c3__atom, u2_blip),
u2nt(c3__cell, c3__noun, c3__noun));
2013-09-29 00:21:18 +04:00
}
2014-08-21 01:18:34 +04:00
else switch ( u2h(sut) ) {
2013-09-29 00:21:18 +04:00
default: {
2014-08-21 01:18:34 +04:00
return u2_cm_error("repo-flat");
2013-09-29 00:21:18 +04:00
}
2013-12-26 21:12:07 +04:00
case c3__bull: {
2014-08-21 01:18:34 +04:00
if ( u2_no == u2_cr_cell(u2t(sut), &p_sut, &q_sut)) {
return u2_cm_bail(c3__fail);
2013-12-26 21:12:07 +04:00
} else {
2014-08-21 01:18:34 +04:00
return u2k(q_sut);
2013-12-26 21:12:07 +04:00
}
}
2013-09-29 00:21:18 +04:00
case c3__core: {
2014-08-21 01:18:34 +04:00
if ( u2_no == u2_cr_cell(u2t(sut), &p_sut, &q_sut) ) {
return u2_cm_bail(c3__fail);
2013-09-29 00:21:18 +04:00
} else {
2014-08-21 01:18:34 +04:00
return u2nt(c3__cell, c3__noun, u2k(p_sut));
2013-09-29 00:21:18 +04:00
}
}
case c3__cube: {
2014-08-21 01:18:34 +04:00
if ( u2_no == u2_cr_cell(u2t(sut), &p_sut, &q_sut)) {
return u2_cm_bail(c3__fail);
2013-09-29 00:21:18 +04:00
} else {
2014-08-21 01:18:34 +04:00
return u2k(q_sut);
2013-09-29 00:21:18 +04:00
}
}
case c3__face: {
2014-08-21 01:18:34 +04:00
if ( u2_no == u2_cr_cell(u2t(sut), &p_sut, &q_sut)) {
return u2_cm_bail(c3__fail);
2013-09-29 00:21:18 +04:00
} else {
2014-08-21 01:18:34 +04:00
return u2k(q_sut);
2013-09-29 00:21:18 +04:00
}
}
case c3__hold: {
2014-08-21 01:18:34 +04:00
p_sut = u2t(sut);
2014-09-03 07:36:29 +04:00
return u2_cqfu_rest(van, sut, p_sut);
2013-09-29 00:21:18 +04:00
}
}
}
u2_noun // transfer
2014-09-03 09:46:55 +04:00
u2_cwfu_repo(
2013-09-29 00:21:18 +04:00
u2_noun cor) // retain
{
u2_noun sut;
2014-08-21 01:18:34 +04:00
if ( u2_none == (sut = u2_cr_at(u2_cv_sam, cor)) ) {
return u2_cm_bail(c3__fail);
2013-09-29 00:21:18 +04:00
} else {
2014-09-03 07:36:29 +04:00
return u2_cqfu_repo(cor, sut);
2013-09-29 00:21:18 +04:00
}
}