urbit/gen164/5/tape.c

57 lines
899 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"
#include "../pit.h"
/* functions
*/
2014-09-04 01:33:18 +04:00
static u2_noun
2014-08-20 10:22:41 +04:00
_norm(
2014-09-04 01:33:18 +04:00
u2_noun a)
2013-09-29 00:21:18 +04:00
{
if ( u2_no == u2du(a) ) {
return u2_nul;
} else {
return u2nc(((u2_yes == u2du(u2h(a))) ? u2_nul : u2k(u2h(a))),
2014-08-20 10:22:41 +04:00
_norm(u2t(a)));
2013-09-29 00:21:18 +04:00
}
}
2013-09-29 00:21:18 +04:00
static u2_bean
2014-08-20 10:22:41 +04:00
_good(
2014-09-04 01:33:18 +04:00
u2_noun a)
2013-09-29 00:21:18 +04:00
{
while ( 1 ) {
if ( u2_nul == a ) {
return u2_yes;
}
if ( u2_no == u2ud(u2h(a)) ) {
return u2_no;
}
a = u2t(a);
}
}
2014-09-04 01:33:18 +04:00
u2_noun
u2_cqe_tape(u2_noun a)
2013-09-29 00:21:18 +04:00
{
2014-08-20 10:22:41 +04:00
if ( u2_yes == _good(a) ) {
2013-09-29 00:21:18 +04:00
return u2k(a);
} else {
2014-08-20 10:22:41 +04:00
return _norm(a);
}
2013-09-29 00:21:18 +04:00
}
2014-09-04 01:33:18 +04:00
u2_noun
u2_cwe_tape(u2_noun cor)
2013-09-29 00:21:18 +04:00
{
u2_noun a;
2014-08-20 10:22:41 +04:00
if ( (u2_none == (a = u2_cr_at(u2_cv_sam, cor))) ) {
return u2_cm_bail(c3__fail);
2013-09-29 00:21:18 +04:00
} else {
2014-09-04 01:33:18 +04:00
return u2_cqe_tape(a);
2013-09-29 00:21:18 +04:00
}
}