urbit/j/5/tape.c

57 lines
880 B
C
Raw Normal View History

2013-09-29 00:21:18 +04:00
/* j/3/tape.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
/* functions
*/
2014-09-06 00:13:24 +04:00
static u3_noun
2014-08-20 10:22:41 +04:00
_norm(
2014-09-06 00:13:24 +04:00
u3_noun a)
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
if ( u3_no == u3du(a) ) {
return u3_nul;
2013-09-29 00:21:18 +04:00
} else {
2014-09-06 00:13:24 +04:00
return u3nc(((u3_yes == u3du(u3h(a))) ? u3_nul : u3k(u3h(a))),
_norm(u3t(a)));
2013-09-29 00:21:18 +04:00
}
}
2014-09-06 00:13:24 +04:00
static u3_bean
2014-08-20 10:22:41 +04:00
_good(
2014-09-06 00:13:24 +04:00
u3_noun a)
2013-09-29 00:21:18 +04:00
{
while ( 1 ) {
2014-09-06 00:13:24 +04:00
if ( u3_nul == a ) {
return u3_yes;
2013-09-29 00:21:18 +04:00
}
2014-09-06 00:13:24 +04:00
if ( u3_no == u3ud(u3h(a)) ) {
return u3_no;
2013-09-29 00:21:18 +04:00
}
2014-09-06 00:13:24 +04:00
a = u3t(a);
2013-09-29 00:21:18 +04:00
}
}
2014-09-06 00:13:24 +04:00
u3_noun
u3_cqe_tape(u3_noun a)
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
if ( u3_yes == _good(a) ) {
return u3k(a);
2013-09-29 00:21:18 +04:00
} else {
2014-08-20 10:22:41 +04:00
return _norm(a);
}
2013-09-29 00:21:18 +04:00
}
2014-09-06 00:13:24 +04:00
u3_noun
u3_cwe_tape(u3_noun cor)
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
u3_noun a;
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04:00
if ( (u3_none == (a = 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_cqe_tape(a);
2013-09-29 00:21:18 +04:00
}
}