urbit/j/6/ut_repo.c

77 lines
1.7 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"
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
u3_cqfu_repo(
u3_noun van,
u3_noun sut)
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
u3_noun p_sut, q_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 u3k(sut);
2013-09-29 00:21:18 +04:00
case c3__noun:
2014-09-06 00:13:24 +04:00
return u3nt(c3__fork,
u3nc(c3__atom, u3_blip),
u3nt(c3__cell, c3__noun, c3__noun));
2013-09-29 00:21:18 +04:00
}
2014-09-06 00:13:24 +04:00
else switch ( u3h(sut) ) {
2013-09-29 00:21:18 +04:00
default: {
2014-09-06 00:13:24 +04:00
return u3_cm_error("repo-flat");
2013-09-29 00:21:18 +04:00
}
2013-12-26 21:12:07 +04:00
case c3__bull: {
2014-09-06 00:13:24 +04:00
if ( u3_no == u3_cr_cell(u3t(sut), &p_sut, &q_sut)) {
return u3_cm_bail(c3__fail);
2013-12-26 21:12:07 +04:00
} else {
2014-09-06 00:13:24 +04:00
return u3k(q_sut);
2013-12-26 21:12:07 +04:00
}
}
2013-09-29 00:21:18 +04:00
case c3__core: {
2014-09-06 00:13:24 +04:00
if ( u3_no == u3_cr_cell(u3t(sut), &p_sut, &q_sut) ) {
return u3_cm_bail(c3__fail);
2013-09-29 00:21:18 +04:00
} else {
2014-09-06 00:13:24 +04:00
return u3nt(c3__cell, c3__noun, u3k(p_sut));
2013-09-29 00:21:18 +04:00
}
}
case c3__cube: {
2014-09-06 00:13:24 +04:00
if ( u3_no == u3_cr_cell(u3t(sut), &p_sut, &q_sut)) {
return u3_cm_bail(c3__fail);
2013-09-29 00:21:18 +04:00
} else {
2014-09-06 00:13:24 +04:00
return u3k(q_sut);
2013-09-29 00:21:18 +04:00
}
}
case c3__face: {
2014-09-06 00:13:24 +04:00
if ( u3_no == u3_cr_cell(u3t(sut), &p_sut, &q_sut)) {
return u3_cm_bail(c3__fail);
2013-09-29 00:21:18 +04:00
} else {
2014-09-06 00:13:24 +04:00
return u3k(q_sut);
2013-09-29 00:21:18 +04:00
}
}
case c3__hold: {
2014-09-06 00:13:24 +04:00
p_sut = u3t(sut);
return u3_cqfu_rest(van, sut, p_sut);
2013-09-29 00:21:18 +04:00
}
}
}
2014-09-06 00:13:24 +04:00
u3_noun
u3_cwfu_repo(
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_repo(cor, sut);
2013-09-29 00:21:18 +04:00
}
}