urbit/j/e/tape.c

57 lines
853 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-11-05 04:18:47 +03:00
if ( c3n == u3du(a) ) {
2014-09-06 00:13:24 +04:00
return u3_nul;
2013-09-29 00:21:18 +04:00
} else {
2014-11-05 04:18:47 +03:00
return u3nc(((c3y == u3du(u3h(a))) ? u3_nul : u3k(u3h(a))),
2014-09-06 00:13:24 +04:00
_norm(u3t(a)));
2013-09-29 00:21:18 +04:00
}
}
2014-11-06 06:10:22 +03:00
static u3_noun
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 ) {
2014-11-05 04:18:47 +03:00
return c3y;
2013-09-29 00:21:18 +04:00
}
2014-11-05 04:18:47 +03:00
if ( c3n == u3ud(u3h(a)) ) {
return c3n;
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
2014-11-06 22:13:57 +03:00
u3qe_tape(u3_noun a)
2013-09-29 00:21:18 +04:00
{
2014-11-05 04:18:47 +03:00
if ( c3y == _good(a) ) {
2014-09-06 00:13:24 +04:00
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
2014-11-06 22:13:57 +03:00
u3we_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-11-18 00:56:51 +03:00
if ( (u3_none == (a = u3r_at(u3x_sam, cor))) ) {
2014-11-06 03:20:01 +03:00
return u3m_bail(c3__fail);
2013-09-29 00:21:18 +04:00
} else {
2014-11-06 22:13:57 +03:00
return u3qe_tape(a);
2013-09-29 00:21:18 +04:00
}
}