summaryrefslogtreecommitdiff
path: root/vere/pkg/noun/xtract.h
blob: c527a43c1a10e817728ceb1e931d1c027dac07ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/// @file

#ifndef U3_XTRACT_H
#define U3_XTRACT_H

#include "c3/c3.h"
#include "types.h"
#include "allocate.h"
#include "manage.h"

  /**  Constants.
  **/
    /* Conventional axes for gate call.
    */
#     define u3x_pay         3       //  payload
#     define u3x_sam         6       //  sample
#       define u3x_sam_1     6
#       define u3x_sam_2     12
#       define u3x_sam_3     13
#       define u3x_sam_4     24
#       define u3x_sam_5     25
#       define u3x_sam_6     26
#       define u3x_sam_12    52
#       define u3x_sam_13    53
#       define u3x_sam_7     27
#       define u3x_sam_14    54
#       define u3x_sam_15    55
#       define u3x_sam_30    110
#       define u3x_sam_31    111
#       define u3x_sam_62    222
#       define u3x_sam_63    223
#     define u3x_con         7       //  context
#     define u3x_con_2       14      //  context
#     define u3x_con_3       15      //  context
#     define u3x_con_sam     30      //  sample in gate context
#       define u3x_con_sam_2 60
#       define u3x_con_sam_3 61
#     define u3x_bat         2       //  battery


  /**  Macros.
  **/
    /* Word axis macros.  For 31-bit axes only.
    */

      /* u3x_at (u3at): fragment.
      */
#       define u3x_at(a, b)   u3x_good(u3r_at(a, b))
#       define u3at(a, b)     u3x_at(a, b)

      /* u3x_bite(): xtract/default $bloq and $step from $bite.
      */
#       define u3x_bite(a, b, c)                      \
          do {                                        \
            if ( c3n == u3r_bite(a, b, c) ) {         \
              u3m_bail(c3__exit);                     \
            }                                         \
          } while (0)

      /* u3x_dep(): number of axis bits.
      */
#       define u3x_dep(a_w)   (c3_bits_word(a_w) - 1)

      /* u3x_cap(): root axis, 2 or 3.
      */
#       define u3x_cap(a_w) ({                        \
          u3_assert( 1 < a_w );                       \
          (0x2 | (a_w >> (u3x_dep(a_w) - 1))); })

      /* u3x_mas(): remainder after cap.
      */
#       define u3x_mas(a_w) ({                        \
          u3_assert( 1 < a_w );                       \
          ( (a_w & ~(1 << u3x_dep(a_w))) | (1 << (u3x_dep(a_w) - 1)) ); })

      /* u3x_peg(): connect two axes.
      */
#       define u3x_peg(a_w, b_w) \
          ( (a_w << u3x_dep(b_w)) | (b_w &~ (1 << u3x_dep(b_w))) )

      /* u3x_cell(): divide `a` as a cell `[b c]`.
      */
#       define u3x_cell(a, b, c)                      \
          do {                                        \
            if ( c3n == u3r_cell(a, b, c) ) {         \
              u3m_bail(c3__exit);                     \
            }                                         \
          } while (0)

      /* u3x_trel(): divide `a` as a trel `[b c d]`, or bail.
      */
#       define u3x_trel(a, b, c, d)                   \
          do {                                        \
            if ( c3n == u3r_trel(a, b, c, d) ) {      \
              u3m_bail(c3__exit);                     \
            }                                         \
          } while (0)

      /* u3x_qual(): divide `a` as a quadruple `[b c d e]`.
      */
#       define u3x_qual(a, b, c, d, e)                \
          do {                                        \
            if ( c3n == u3r_qual(a, b, c, d, e) ) {   \
              u3m_bail(c3__exit);                     \
            }                                         \
          } while (0)

      /* u3x_quil(): divide `a` as a quintuple `[b c d e f]`.
      */
#       define u3x_quil(a, b, c, d, e, f)                  \
          do {                                             \
            if ( c3n == u3r_quil(a, b, c, d, e, f) ) {     \
              u3m_bail(c3__exit);                          \
            }                                              \
          } while (0)

      /* u3x_hext(): divide `a` as a hextuple `[b c d e f g]`.
      */
#       define u3x_hext(a, b, c, d, e, f, g)               \
          do {                                             \
            if ( c3n == u3r_hext(a, b, c, d, e, f, g) ) {  \
              u3m_bail(c3__exit);                          \
            }                                              \
          } while (0)

  /**  Functions.
  **/
    /** u3x_*: read, but bail with c3__exit on a crash.
    **/
      /* u3x_atom(): atom or exit.
      */
        inline u3_atom
        u3x_atom(u3_noun a)
        {
          return ( c3y == u3a_is_cell(a) ) ? u3m_bail(c3__exit) : a;
        }

      /* u3x_good(): test for u3_none.
      */
        inline u3_noun
        u3x_good(u3_weak som)
        {
          return ( u3_none == som ) ? u3m_bail(c3__exit) : som;
        }
      
      /* u3x_loob(): loobean or exit.
      */
        inline c3_o
        u3x_loob(u3_noun a)
        {
          return ( a > 1 ) ? u3m_bail(c3__exit) : a;
        }

      /* u3x_mean():
      **
      **   Attempt to deconstruct `a` by axis, noun pairs; 0 terminates.
      **   Axes must be sorted in tree order.
      */
        void
        u3x_mean(u3_noun a, ...);

#endif /* ifndef U3_XTRACT_H */