urbit/i/n/r.h

410 lines
9.3 KiB
C
Raw Normal View History

2014-11-08 01:54:59 +03:00
/* i/n/r.h
2014-09-04 07:44:53 +04:00
**
** This file is in the public domain.
*/
2014-11-06 03:20:01 +03:00
/** u3r_*: read without ever crashing.
2014-09-04 07:44:53 +04:00
**/
#if 1
2014-11-06 03:20:01 +03:00
# define u3r_du(a) u3a_is_cell(a)
# define u3r_ud(a) u3a_is_atom(a)
2014-09-04 07:44:53 +04:00
#else
2014-11-06 03:20:01 +03:00
/* u3r_du(): c3y iff `a` is cell.
2014-09-04 07:44:53 +04:00
*/
2014-11-06 06:10:22 +03:00
c3_o
2014-11-06 03:20:01 +03:00
u3r_du(u3_noun a);
2014-09-04 07:44:53 +04:00
2014-11-06 03:20:01 +03:00
/* u3r_ud(): c3n iff `a` is cell.
2014-09-04 07:44:53 +04:00
*/
2014-11-06 06:10:22 +03:00
c3_o
2014-11-06 03:20:01 +03:00
u3r_ud(u3_noun a);
2014-09-04 07:44:53 +04:00
#endif
2014-11-06 03:20:01 +03:00
/* u3r_at(): fragment `a` of `b`, or u3_none.
2014-09-04 07:44:53 +04:00
*/
2014-09-06 00:13:24 +04:00
u3_weak
2014-11-06 03:20:01 +03:00
u3r_at(u3_atom a,
2014-09-06 00:13:24 +04:00
u3_weak b);
2014-09-04 07:44:53 +04:00
2014-11-06 03:20:01 +03:00
/* u3r_mean():
2014-09-04 07:44:53 +04:00
**
** Attempt to deconstruct `a` by axis, noun pairs; 0 terminates.
** Axes must be sorted in tree order.
*/
2014-11-06 06:10:22 +03:00
c3_o
2014-11-06 03:20:01 +03:00
u3r_mean(u3_noun a,
2014-09-04 07:44:53 +04:00
...);
2014-11-06 03:20:01 +03:00
/* u3r_mug():
2014-09-04 07:44:53 +04:00
**
** Compute and/or recall the mug (31-bit hash) of (a).
*/
c3_w
2014-11-06 03:20:01 +03:00
u3r_mug(u3_noun a);
2014-09-04 07:44:53 +04:00
2014-11-06 03:20:01 +03:00
/* u3r_mug_string():
2014-09-04 07:44:53 +04:00
**
** Compute the mug of `a`, LSB first.
*/
c3_w
2014-11-06 03:20:01 +03:00
u3r_mug_string(const c3_c *a_c);
2014-09-04 07:44:53 +04:00
2014-11-06 03:20:01 +03:00
/* u3r_mug_words():
2014-09-04 07:44:53 +04:00
**
** Compute the mug of `buf`, `len`, LSW first.
*/
c3_w
2014-11-06 03:20:01 +03:00
u3r_mug_words(const c3_w *buf_w,
2014-09-04 07:44:53 +04:00
c3_w len_w);
2014-11-06 03:20:01 +03:00
/* u3r_mug_cell():
2014-09-04 07:44:53 +04:00
**
** Compute the mug of `[a b]`.
*/
c3_w
2014-11-06 03:20:01 +03:00
u3r_mug_cell(u3_noun a,
2014-09-06 00:13:24 +04:00
u3_noun b);
2014-09-04 07:44:53 +04:00
2014-11-06 03:20:01 +03:00
/* u3r_mug_trel():
2014-09-04 07:44:53 +04:00
**
** Compute the mug of `[a b c]`.
*/
c3_w
2014-11-06 03:20:01 +03:00
u3r_mug_trel(u3_noun a,
2014-09-06 00:13:24 +04:00
u3_noun b,
u3_noun c);
2014-09-04 07:44:53 +04:00
2014-11-06 03:20:01 +03:00
/* u3r_mug_qual():
2014-09-04 07:44:53 +04:00
**
** Compute the mug of `[a b c d]`.
*/
c3_w
2014-11-06 03:20:01 +03:00
u3r_mug_qual(u3_noun a,
2014-09-06 00:13:24 +04:00
u3_noun b,
u3_noun c,
u3_noun d);
2014-09-04 07:44:53 +04:00
2014-11-06 03:20:01 +03:00
/* u3r_mug_both():
2014-09-04 07:44:53 +04:00
**
** Join two mugs.
*/
c3_w
2014-11-06 03:20:01 +03:00
u3r_mug_both(c3_w a_w,
2014-09-04 07:44:53 +04:00
c3_w b_w);
2014-11-06 03:20:01 +03:00
/* u3r_fing():
2014-09-04 07:44:53 +04:00
**
** Yes iff (a) and (b) are the same copy of the same noun.
2014-11-06 03:20:01 +03:00
** (Ie, by pointer equality - u3r_sing with false negatives.)
2014-09-04 07:44:53 +04:00
*/
2014-11-06 06:10:22 +03:00
c3_o
2014-11-06 03:20:01 +03:00
u3r_fing(u3_noun a,
2014-09-06 00:13:24 +04:00
u3_noun b);
2014-09-04 07:44:53 +04:00
2014-11-06 03:20:01 +03:00
/* u3r_fing_cell():
2014-09-04 07:44:53 +04:00
**
** Yes iff `[p q]` and `b` are the same copy of the same noun.
*/
2014-11-06 06:10:22 +03:00
c3_o
2014-11-06 03:20:01 +03:00
u3r_fing_cell(u3_noun p,
2014-09-06 00:13:24 +04:00
u3_noun q,
u3_noun b);
2014-09-04 07:44:53 +04:00
2014-11-06 03:20:01 +03:00
/* u3r_fing_mixt():
2014-09-04 07:44:53 +04:00
**
** Yes iff `[p q]` and `b` are the same copy of the same noun.
*/
2014-11-06 06:10:22 +03:00
c3_o
2014-11-06 03:20:01 +03:00
u3r_fing_mixt(const c3_c* p_c,
2014-09-06 00:13:24 +04:00
u3_noun q,
u3_noun b);
2014-09-04 07:44:53 +04:00
2014-11-06 03:20:01 +03:00
/* u3r_fing_trel():
2014-09-04 07:44:53 +04:00
**
** Yes iff `[p q r]` and `b` are the same copy of the same noun.
*/
2014-11-06 06:10:22 +03:00
c3_o
2014-11-06 03:20:01 +03:00
u3r_fing_trel(u3_noun p,
2014-09-06 00:13:24 +04:00
u3_noun q,
u3_noun r,
u3_noun b);
2014-09-04 07:44:53 +04:00
2014-11-06 03:20:01 +03:00
/* u3r_fing_qual():
2014-09-04 07:44:53 +04:00
**
** Yes iff `[p q r s]` and `b` are the same copy of the same noun.
*/
2014-11-06 06:10:22 +03:00
c3_o
2014-11-06 03:20:01 +03:00
u3r_fing_qual(u3_noun p,
2014-09-06 00:13:24 +04:00
u3_noun q,
u3_noun r,
u3_noun s,
u3_noun b);
2014-09-04 07:44:53 +04:00
2014-11-06 03:20:01 +03:00
/* u3r_sing():
2014-09-04 07:44:53 +04:00
**
** Yes iff (a) and (b) are the same noun.
*/
2014-11-06 06:10:22 +03:00
c3_o
2014-11-06 03:20:01 +03:00
u3r_sing(u3_noun a,
2014-09-06 00:13:24 +04:00
u3_noun b);
2014-09-04 07:44:53 +04:00
2014-11-06 03:20:01 +03:00
/* u3r_sung(): yes iff (a) and (b) are the same noun, unifying equals.
2014-10-09 02:16:24 +04:00
**
** Make sure you have no live, uncounted pointers to any noun
** within (a) or (b)!
*/
2014-11-06 06:10:22 +03:00
c3_o
2014-11-06 03:20:01 +03:00
u3r_sung(u3_noun a,
2014-10-09 02:16:24 +04:00
u3_noun b);
2014-11-06 03:20:01 +03:00
/* u3r_sing_c):
2014-09-04 07:44:53 +04:00
**
** Yes iff (b) is the same noun as the C string [a].
*/
2014-11-06 06:10:22 +03:00
c3_o
2014-11-06 03:20:01 +03:00
u3r_sing_c(const c3_c* a_c,
2014-09-06 00:13:24 +04:00
u3_noun b);
2014-09-04 07:44:53 +04:00
2014-11-06 03:20:01 +03:00
/* u3r_sing_cell():
2014-09-04 07:44:53 +04:00
**
** Yes iff `[p q]` and `b` are the same noun.
*/
2014-11-06 06:10:22 +03:00
c3_o
2014-11-06 03:20:01 +03:00
u3r_sing_cell(u3_noun p,
2014-09-06 00:13:24 +04:00
u3_noun q,
u3_noun b);
2014-09-04 07:44:53 +04:00
2014-11-06 03:20:01 +03:00
/* u3r_sing_mixt():
2014-09-04 07:44:53 +04:00
**
** Yes iff `[p q]` and `b` are the same noun.
*/
2014-11-06 06:10:22 +03:00
c3_o
2014-11-06 03:20:01 +03:00
u3r_sing_mixt(const c3_c* p_c,
2014-09-06 00:13:24 +04:00
u3_noun q,
u3_noun b);
2014-09-04 07:44:53 +04:00
2014-11-06 03:20:01 +03:00
/* u3r_sing_trel():
2014-09-04 07:44:53 +04:00
**
** Yes iff `[p q r]` and `b` are the same noun.
*/
2014-11-06 06:10:22 +03:00
c3_o
2014-11-06 03:20:01 +03:00
u3r_sing_trel(u3_noun p,
2014-09-06 00:13:24 +04:00
u3_noun q,
u3_noun r,
u3_noun b);
2014-09-04 07:44:53 +04:00
2014-11-06 03:20:01 +03:00
/* u3r_sing_qual():
2014-09-04 07:44:53 +04:00
**
** Yes iff `[p q r s]` and `b` are the same noun.
*/
2014-11-06 06:10:22 +03:00
c3_o
2014-11-06 03:20:01 +03:00
u3r_sing_qual(u3_noun p,
2014-09-06 00:13:24 +04:00
u3_noun q,
u3_noun r,
u3_noun s,
u3_noun b);
2014-09-04 07:44:53 +04:00
2014-11-06 03:20:01 +03:00
/* u3r_nord():
2014-09-04 07:44:53 +04:00
**
** Return 0, 1 or 2 if `a` is below, equal to, or above `b`.
*/
2014-09-06 00:13:24 +04:00
u3_atom
2014-11-06 03:20:01 +03:00
u3r_nord(u3_noun a,
2014-09-06 00:13:24 +04:00
u3_noun b);
2014-09-04 07:44:53 +04:00
2014-11-06 03:20:01 +03:00
/* u3r_mold():
2014-09-04 07:44:53 +04:00
**
** Divide `a` as a mold `[b.[p q] c]`.
*/
2014-11-06 06:10:22 +03:00
c3_o
2014-11-06 03:20:01 +03:00
u3r_mold(u3_noun a,
2014-09-06 00:13:24 +04:00
u3_noun* b,
u3_noun* c);
2014-09-04 07:44:53 +04:00
2014-11-06 03:20:01 +03:00
/* u3r_cell():
2014-09-04 07:44:53 +04:00
**
** Divide `a` as a cell `[b c]`.
*/
2014-11-06 06:10:22 +03:00
c3_o
2014-11-06 03:20:01 +03:00
u3r_cell(u3_noun a,
2014-09-06 00:13:24 +04:00
u3_noun* b,
u3_noun* c);
2014-09-04 07:44:53 +04:00
2014-11-06 03:20:01 +03:00
/* u3r_trel():
2014-09-04 07:44:53 +04:00
**
** Divide `a` as a trel `[b c]`.
*/
2014-11-06 06:10:22 +03:00
c3_o
2014-11-06 03:20:01 +03:00
u3r_trel(u3_noun a,
2014-09-06 00:13:24 +04:00
u3_noun* b,
u3_noun* c,
u3_noun* d);
2014-09-04 07:44:53 +04:00
2014-11-06 03:20:01 +03:00
/* u3r_qual():
2014-09-04 07:44:53 +04:00
**
2014-10-22 00:53:27 +04:00
** Divide (a) as a qual [b c d e f].
2014-09-04 07:44:53 +04:00
*/
2014-11-06 06:10:22 +03:00
c3_o
2014-11-06 03:20:01 +03:00
u3r_qual(u3_noun a,
2014-09-06 00:13:24 +04:00
u3_noun* b,
u3_noun* c,
u3_noun* d,
u3_noun* e);
2014-09-04 07:44:53 +04:00
2014-11-06 03:20:01 +03:00
/* u3r_quil():
2014-10-22 00:53:27 +04:00
**
** Divide (a) as a quil [b c d e f].
*/
2014-11-06 06:10:22 +03:00
c3_o
2014-11-06 03:20:01 +03:00
u3r_quil(u3_noun a,
2014-10-22 00:53:27 +04:00
u3_noun* b,
u3_noun* c,
u3_noun* d,
u3_noun* e,
u3_noun* f);
2014-11-06 03:20:01 +03:00
/* u3r_p():
2014-09-04 07:44:53 +04:00
**
** & [0] if [a] is of the form [b *c].
*/
2014-11-06 06:10:22 +03:00
c3_o
2014-11-06 03:20:01 +03:00
u3r_p(u3_noun a,
2014-09-06 00:13:24 +04:00
u3_noun b,
u3_noun* c);
2014-09-04 07:44:53 +04:00
2014-11-06 03:20:01 +03:00
/* u3r_bush():
2014-09-04 07:44:53 +04:00
**
** Factor [a] as a bush [b.[p q] c].
*/
2014-11-06 06:10:22 +03:00
c3_o
2014-11-06 03:20:01 +03:00
u3r_bush(u3_noun a,
2014-09-06 00:13:24 +04:00
u3_noun* b,
u3_noun* c);
2014-09-04 07:44:53 +04:00
2014-11-06 03:20:01 +03:00
/* u3r_pq():
2014-09-04 07:44:53 +04:00
**
** & [0] if [a] is of the form [b *c d].
*/
2014-11-06 06:10:22 +03:00
c3_o
2014-11-06 03:20:01 +03:00
u3r_pq(u3_noun a,
2014-09-06 00:13:24 +04:00
u3_noun b,
u3_noun* c,
u3_noun* d);
2014-09-04 07:44:53 +04:00
2014-11-06 03:20:01 +03:00
/* u3r_pqr():
2014-09-04 07:44:53 +04:00
**
** & [0] if [a] is of the form [b *c *d *e].
*/
2014-11-06 06:10:22 +03:00
c3_o
2014-11-06 03:20:01 +03:00
u3r_pqr(u3_noun a,
2014-09-06 00:13:24 +04:00
u3_noun b,
u3_noun* c,
u3_noun* d,
u3_noun* e);
2014-09-04 07:44:53 +04:00
2014-11-06 03:20:01 +03:00
/* u3r_pqrs():
2014-09-04 07:44:53 +04:00
**
** & [0] if [a] is of the form [b *c *d *e *f].
*/
2014-11-06 06:10:22 +03:00
c3_o
2014-11-06 03:20:01 +03:00
u3r_pqrs(u3_noun a,
2014-09-06 00:13:24 +04:00
u3_noun b,
u3_noun* c,
u3_noun* d,
u3_noun* e,
u3_noun* f);
2014-09-04 07:44:53 +04:00
2014-11-06 03:20:01 +03:00
/* u3r_met():
2014-09-04 07:44:53 +04:00
**
** Return the size of (b) in bits, rounded up to
** (1 << a_y).
**
** For example, (a_y == 3) returns the size in bytes.
*/
c3_w
2014-11-06 03:20:01 +03:00
u3r_met(c3_y a_y,
2014-09-06 00:13:24 +04:00
u3_atom b);
2014-09-04 07:44:53 +04:00
2014-11-06 03:20:01 +03:00
/* u3r_bit():
2014-09-04 07:44:53 +04:00
**
** Return bit (a_w) of (b).
*/
c3_b
2014-11-06 03:20:01 +03:00
u3r_bit(c3_w a_w,
2014-09-06 00:13:24 +04:00
u3_atom b);
2014-09-04 07:44:53 +04:00
2014-11-06 03:20:01 +03:00
/* u3r_byte():
2014-09-04 07:44:53 +04:00
**
** Return byte (a_w) of (b).
*/
c3_y
2014-11-06 03:20:01 +03:00
u3r_byte(c3_w a_w,
2014-09-06 00:13:24 +04:00
u3_atom b);
2014-09-04 07:44:53 +04:00
2014-11-06 03:20:01 +03:00
/* u3r_bytes():
2014-09-04 07:44:53 +04:00
**
** Copy bytes (a_w) through (a_w + b_w - 1) from (d) to (c).
*/
void
2014-11-06 03:20:01 +03:00
u3r_bytes(c3_w a_w,
2014-09-04 07:44:53 +04:00
c3_w b_w,
c3_y* c_y,
2014-09-06 00:13:24 +04:00
u3_atom d);
2014-09-04 07:44:53 +04:00
2014-11-06 03:20:01 +03:00
/* u3r_chop():
2014-09-04 07:44:53 +04:00
**
** Into the bloq space of `met`, from position `fum` for a
** span of `wid`, to position `tou`, XOR from atom `src`
** into ray `dst`.
*/
void
2014-11-06 03:20:01 +03:00
u3r_chop(c3_g met_g,
2014-09-04 07:44:53 +04:00
c3_w fum_w,
c3_w wid_w,
c3_w tou_w,
c3_w* dst_w,
2014-09-06 00:13:24 +04:00
u3_atom src);
2014-09-04 07:44:53 +04:00
2014-11-06 03:20:01 +03:00
/* u3r_mp():
2014-09-04 07:44:53 +04:00
**
** Copy (b) into (a_mp).
*/
void
2014-11-06 03:20:01 +03:00
u3r_mp(mpz_t a_mp,
2014-09-06 00:13:24 +04:00
u3_atom b);
2014-09-04 07:44:53 +04:00
2014-11-06 03:20:01 +03:00
/* u3r_word():
2014-09-04 07:44:53 +04:00
**
** Return word (a_w) of (b).
*/
c3_w
2014-11-06 03:20:01 +03:00
u3r_word(c3_w a_w,
2014-09-06 00:13:24 +04:00
u3_atom b);
2014-09-04 07:44:53 +04:00
2014-11-06 03:20:01 +03:00
/* u3r_chub():
2014-09-04 07:44:53 +04:00
**
** Return double-word (a_w) of (b).
*/
c3_d
2014-11-06 03:20:01 +03:00
u3r_chub(c3_w a_w,
2014-09-06 00:13:24 +04:00
u3_atom b);
2014-09-04 07:44:53 +04:00
2014-11-06 03:20:01 +03:00
/* u3r_words():
2014-09-04 07:44:53 +04:00
**
** Copy words (a_w) through (a_w + b_w - 1) from (d) to (c).
*/
void
2014-11-06 03:20:01 +03:00
u3r_words(c3_w a_w,
2014-09-04 07:44:53 +04:00
c3_w b_w,
c3_w* c_w,
2014-09-06 00:13:24 +04:00
u3_atom d);
2014-09-04 07:44:53 +04:00
2014-11-06 03:20:01 +03:00
/* u3r_string(): `a`, a text atom, as malloced C string.
2014-09-04 07:44:53 +04:00
*/
c3_c*
2014-11-06 03:20:01 +03:00
u3r_string(u3_atom a);
2014-09-04 07:44:53 +04:00
2014-11-06 03:20:01 +03:00
/* u3r_tape(): `a`, a list of bytes, as malloced C string.
2014-09-04 07:44:53 +04:00
*/
c3_y*
2014-11-06 03:20:01 +03:00
u3r_tape(u3_noun a);