mirror of
https://github.com/urbit/shrub.git
synced 2024-12-18 07:42:20 +03:00
391 lines
9.0 KiB
C
391 lines
9.0 KiB
C
|
/* include/g/r.h
|
||
|
**
|
||
|
** This file is in the public domain.
|
||
|
*/
|
||
|
/** u2_cr_*: read without ever crashing.
|
||
|
**/
|
||
|
#if 1
|
||
|
# define u2_cr_du(a) u2_co_is_cell(a)
|
||
|
# define u2_cr_ud(a) u2_co_is_atom(a)
|
||
|
#else
|
||
|
/* u2_cr_du(): u2_yes iff `a` is cell.
|
||
|
*/
|
||
|
u2_bean
|
||
|
u2_cr_du(u2_noun a);
|
||
|
|
||
|
/* u2_cr_ud(): u2_no iff `a` is cell.
|
||
|
*/
|
||
|
u2_bean
|
||
|
u2_cr_ud(u2_noun a);
|
||
|
#endif
|
||
|
|
||
|
/* u2_cr_at(): fragment `a` of `b`, or u2_none.
|
||
|
*/
|
||
|
u2_weak
|
||
|
u2_cr_at(u2_atom a,
|
||
|
u2_weak b);
|
||
|
|
||
|
/* u2_cr_mean():
|
||
|
**
|
||
|
** Attempt to deconstruct `a` by axis, noun pairs; 0 terminates.
|
||
|
** Axes must be sorted in tree order.
|
||
|
*/
|
||
|
u2_bean
|
||
|
u2_cr_mean(u2_noun a,
|
||
|
...);
|
||
|
|
||
|
/* u2_cr_mug():
|
||
|
**
|
||
|
** Compute and/or recall the mug (31-bit hash) of (a).
|
||
|
*/
|
||
|
c3_w
|
||
|
u2_cr_mug(u2_noun a);
|
||
|
|
||
|
/* u2_cr_mug_string():
|
||
|
**
|
||
|
** Compute the mug of `a`, LSB first.
|
||
|
*/
|
||
|
c3_w
|
||
|
u2_cr_mug_string(const c3_c *a_c);
|
||
|
|
||
|
/* u2_cr_mug_words():
|
||
|
**
|
||
|
** Compute the mug of `buf`, `len`, LSW first.
|
||
|
*/
|
||
|
c3_w
|
||
|
u2_cr_mug_words(const c3_w *buf_w,
|
||
|
c3_w len_w);
|
||
|
|
||
|
/* u2_cr_mug_cell():
|
||
|
**
|
||
|
** Compute the mug of `[a b]`.
|
||
|
*/
|
||
|
c3_w
|
||
|
u2_cr_mug_cell(u2_noun a,
|
||
|
u2_noun b);
|
||
|
|
||
|
/* u2_cr_mug_trel():
|
||
|
**
|
||
|
** Compute the mug of `[a b c]`.
|
||
|
*/
|
||
|
c3_w
|
||
|
u2_cr_mug_trel(u2_noun a,
|
||
|
u2_noun b,
|
||
|
u2_noun c);
|
||
|
|
||
|
/* u2_cr_mug_qual():
|
||
|
**
|
||
|
** Compute the mug of `[a b c d]`.
|
||
|
*/
|
||
|
c3_w
|
||
|
u2_cr_mug_qual(u2_noun a,
|
||
|
u2_noun b,
|
||
|
u2_noun c,
|
||
|
u2_noun d);
|
||
|
|
||
|
/* u2_cr_mug_both():
|
||
|
**
|
||
|
** Join two mugs.
|
||
|
*/
|
||
|
c3_w
|
||
|
u2_cr_mug_both(c3_w a_w,
|
||
|
c3_w b_w);
|
||
|
|
||
|
/* u2_cr_fing():
|
||
|
**
|
||
|
** Yes iff (a) and (b) are the same copy of the same noun.
|
||
|
** (Ie, by pointer equality - u2_cr_sing with false negatives.)
|
||
|
*/
|
||
|
u2_bean
|
||
|
u2_cr_fing(u2_noun a,
|
||
|
u2_noun b);
|
||
|
|
||
|
/* u2_cr_fing_cell():
|
||
|
**
|
||
|
** Yes iff `[p q]` and `b` are the same copy of the same noun.
|
||
|
*/
|
||
|
u2_bean
|
||
|
u2_cr_fing_cell(u2_noun p,
|
||
|
u2_noun q,
|
||
|
u2_noun b);
|
||
|
|
||
|
/* u2_cr_fing_mixt():
|
||
|
**
|
||
|
** Yes iff `[p q]` and `b` are the same copy of the same noun.
|
||
|
*/
|
||
|
u2_bean
|
||
|
u2_cr_fing_mixt(const c3_c* p_c,
|
||
|
u2_noun q,
|
||
|
u2_noun b);
|
||
|
|
||
|
/* u2_cr_fing_trel():
|
||
|
**
|
||
|
** Yes iff `[p q r]` and `b` are the same copy of the same noun.
|
||
|
*/
|
||
|
u2_bean
|
||
|
u2_cr_fing_trel(u2_noun p,
|
||
|
u2_noun q,
|
||
|
u2_noun r,
|
||
|
u2_noun b);
|
||
|
|
||
|
/* u2_cr_fing_qual():
|
||
|
**
|
||
|
** Yes iff `[p q r s]` and `b` are the same copy of the same noun.
|
||
|
*/
|
||
|
u2_bean
|
||
|
u2_cr_fing_qual(u2_noun p,
|
||
|
u2_noun q,
|
||
|
u2_noun r,
|
||
|
u2_noun s,
|
||
|
u2_noun b);
|
||
|
|
||
|
/* u2_cr_sing():
|
||
|
**
|
||
|
** Yes iff (a) and (b) are the same noun.
|
||
|
*/
|
||
|
u2_bean
|
||
|
u2_cr_sing(u2_noun a,
|
||
|
u2_noun b);
|
||
|
|
||
|
/* u2_cr_sing_c():
|
||
|
**
|
||
|
** Yes iff (b) is the same noun as the C string [a].
|
||
|
*/
|
||
|
u2_bean
|
||
|
u2_cr_sing_c(const c3_c* a_c,
|
||
|
u2_noun b);
|
||
|
|
||
|
/* u2_cr_sing_cell():
|
||
|
**
|
||
|
** Yes iff `[p q]` and `b` are the same noun.
|
||
|
*/
|
||
|
u2_bean
|
||
|
u2_cr_sing_cell(u2_noun p,
|
||
|
u2_noun q,
|
||
|
u2_noun b);
|
||
|
|
||
|
/* u2_cr_sing_mixt():
|
||
|
**
|
||
|
** Yes iff `[p q]` and `b` are the same noun.
|
||
|
*/
|
||
|
u2_bean
|
||
|
u2_cr_sing_mixt(const c3_c* p_c,
|
||
|
u2_noun q,
|
||
|
u2_noun b);
|
||
|
|
||
|
/* u2_cr_sing_trel():
|
||
|
**
|
||
|
** Yes iff `[p q r]` and `b` are the same noun.
|
||
|
*/
|
||
|
u2_bean
|
||
|
u2_cr_sing_trel(u2_noun p,
|
||
|
u2_noun q,
|
||
|
u2_noun r,
|
||
|
u2_noun b);
|
||
|
|
||
|
/* u2_cr_sing_qual():
|
||
|
**
|
||
|
** Yes iff `[p q r s]` and `b` are the same noun.
|
||
|
*/
|
||
|
u2_bean
|
||
|
u2_cr_sing_qual(u2_noun p,
|
||
|
u2_noun q,
|
||
|
u2_noun r,
|
||
|
u2_noun s,
|
||
|
u2_noun b);
|
||
|
|
||
|
/* u2_cr_nord():
|
||
|
**
|
||
|
** Return 0, 1 or 2 if `a` is below, equal to, or above `b`.
|
||
|
*/
|
||
|
u2_atom
|
||
|
u2_cr_nord(u2_noun a,
|
||
|
u2_noun b);
|
||
|
|
||
|
/* u2_cr_mold():
|
||
|
**
|
||
|
** Divide `a` as a mold `[b.[p q] c]`.
|
||
|
*/
|
||
|
u2_bean
|
||
|
u2_cr_mold(u2_noun a,
|
||
|
u2_noun* b,
|
||
|
u2_noun* c);
|
||
|
|
||
|
/* u2_cr_cell():
|
||
|
**
|
||
|
** Divide `a` as a cell `[b c]`.
|
||
|
*/
|
||
|
u2_bean
|
||
|
u2_cr_cell(u2_noun a,
|
||
|
u2_noun* b,
|
||
|
u2_noun* c);
|
||
|
|
||
|
/* u2_cr_trel():
|
||
|
**
|
||
|
** Divide `a` as a trel `[b c]`.
|
||
|
*/
|
||
|
u2_bean
|
||
|
u2_cr_trel(u2_noun a,
|
||
|
u2_noun* b,
|
||
|
u2_noun* c,
|
||
|
u2_noun* d);
|
||
|
|
||
|
/* u2_cr_qual():
|
||
|
**
|
||
|
** Divide (a) as a qual (b c d e).
|
||
|
*/
|
||
|
u2_bean
|
||
|
u2_cr_qual(u2_noun a,
|
||
|
u2_noun* b,
|
||
|
u2_noun* c,
|
||
|
u2_noun* d,
|
||
|
u2_noun* e);
|
||
|
|
||
|
/* u2_cr_p():
|
||
|
**
|
||
|
** & [0] if [a] is of the form [b *c].
|
||
|
*/
|
||
|
u2_bean
|
||
|
u2_cr_p(u2_noun a,
|
||
|
u2_noun b,
|
||
|
u2_noun* c);
|
||
|
|
||
|
/* u2_cr_bush():
|
||
|
**
|
||
|
** Factor [a] as a bush [b.[p q] c].
|
||
|
*/
|
||
|
u2_bean
|
||
|
u2_cr_bush(u2_noun a,
|
||
|
u2_noun* b,
|
||
|
u2_noun* c);
|
||
|
|
||
|
/* u2_cr_pq():
|
||
|
**
|
||
|
** & [0] if [a] is of the form [b *c d].
|
||
|
*/
|
||
|
u2_bean
|
||
|
u2_cr_pq(u2_noun a,
|
||
|
u2_noun b,
|
||
|
u2_noun* c,
|
||
|
u2_noun* d);
|
||
|
|
||
|
/* u2_cr_pqr():
|
||
|
**
|
||
|
** & [0] if [a] is of the form [b *c *d *e].
|
||
|
*/
|
||
|
u2_bean
|
||
|
u2_cr_pqr(u2_noun a,
|
||
|
u2_noun b,
|
||
|
u2_noun* c,
|
||
|
u2_noun* d,
|
||
|
u2_noun* e);
|
||
|
|
||
|
/* u2_cr_pqrs():
|
||
|
**
|
||
|
** & [0] if [a] is of the form [b *c *d *e *f].
|
||
|
*/
|
||
|
u2_bean
|
||
|
u2_cr_pqrs(u2_noun a,
|
||
|
u2_noun b,
|
||
|
u2_noun* c,
|
||
|
u2_noun* d,
|
||
|
u2_noun* e,
|
||
|
u2_noun* f);
|
||
|
|
||
|
/* u2_cr_met():
|
||
|
**
|
||
|
** 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
|
||
|
u2_cr_met(c3_y a_y,
|
||
|
u2_atom b);
|
||
|
|
||
|
/* u2_cr_bit():
|
||
|
**
|
||
|
** Return bit (a_w) of (b).
|
||
|
*/
|
||
|
c3_b
|
||
|
u2_cr_bit(c3_w a_w,
|
||
|
u2_atom b);
|
||
|
|
||
|
/* u2_cr_byte():
|
||
|
**
|
||
|
** Return byte (a_w) of (b).
|
||
|
*/
|
||
|
c3_y
|
||
|
u2_cr_byte(c3_w a_w,
|
||
|
u2_atom b);
|
||
|
|
||
|
/* u2_cr_bytes():
|
||
|
**
|
||
|
** Copy bytes (a_w) through (a_w + b_w - 1) from (d) to (c).
|
||
|
*/
|
||
|
void
|
||
|
u2_cr_bytes(c3_w a_w,
|
||
|
c3_w b_w,
|
||
|
c3_y* c_y,
|
||
|
u2_atom d);
|
||
|
|
||
|
/* u2_cr_chop():
|
||
|
**
|
||
|
** 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
|
||
|
u2_cr_chop(c3_g met_g,
|
||
|
c3_w fum_w,
|
||
|
c3_w wid_w,
|
||
|
c3_w tou_w,
|
||
|
c3_w* dst_w,
|
||
|
u2_atom src);
|
||
|
|
||
|
/* u2_cr_mp():
|
||
|
**
|
||
|
** Copy (b) into (a_mp).
|
||
|
*/
|
||
|
void
|
||
|
u2_cr_mp(mpz_t a_mp,
|
||
|
u2_atom b);
|
||
|
|
||
|
/* u2_cr_word():
|
||
|
**
|
||
|
** Return word (a_w) of (b).
|
||
|
*/
|
||
|
c3_w
|
||
|
u2_cr_word(c3_w a_w,
|
||
|
u2_atom b);
|
||
|
|
||
|
/* u2_cr_chub():
|
||
|
**
|
||
|
** Return double-word (a_w) of (b).
|
||
|
*/
|
||
|
c3_d
|
||
|
u2_cr_chub(c3_w a_w,
|
||
|
u2_atom b);
|
||
|
|
||
|
/* u2_cr_words():
|
||
|
**
|
||
|
** Copy words (a_w) through (a_w + b_w - 1) from (d) to (c).
|
||
|
*/
|
||
|
void
|
||
|
u2_cr_words(c3_w a_w,
|
||
|
c3_w b_w,
|
||
|
c3_w* c_w,
|
||
|
u2_atom d);
|
||
|
|
||
|
/* u2_cr_string(): `a`, a text atom, as malloced C string.
|
||
|
*/
|
||
|
c3_c*
|
||
|
u2_cr_string(u2_atom a);
|
||
|
|
||
|
/* u2_cr_tape(): `a`, a list of bytes, as malloced C string.
|
||
|
*/
|
||
|
c3_y*
|
||
|
u2_cr_tape(u2_noun a);
|
||
|
|
||
|
|