10The actual production Nock interpreter. Note gotos for tail-call elimination,
11and manual reference counting. More about the C environment can be found
12in the [runtime system documentation](../../../vere/runtime).
15/* _n_nock_on(): produce .*(bus fol). Do not virtualize.
18_n_nock_on(u3_noun bus, u3_noun fol)
30 if ( c3y == u3r_du(hib) ) {
33 poz = _n_nock_on(u3k(bus), u3k(hib));
34 riv = _n_nock_on(bus, u3k(gal));
37 return u3i_cell(poz, riv);
40 default: return u3m_bail(c3__exit);
43 if ( c3n == u3r_ud(gal) ) {
44 return u3m_bail(c3__exit);
47 u3_noun pro = u3k(u3at(gal, bus));
49 u3a_lose(bus); u3a_lose(fol);
53 c3_assert(!"not reached");
56 u3_noun pro = u3k(gal);
58 u3a_lose(bus); u3a_lose(fol);
61 c3_assert(!"not reached");
64 u3_noun nex = _n_nock_on(u3k(bus), u3k(u3t(gal)));
65 u3_noun seb = _n_nock_on(bus, u3k(u3h(gal)));
72 c3_assert(!"not reached");
77 gof = _n_nock_on(bus, u3k(gal));
80 u3a_lose(gof); u3a_lose(fol);
83 c3_assert(!"not reached");
88 gof = _n_nock_on(bus, u3k(gal));
94 c3_assert(!"not reached");
97 u3_noun wim = _n_nock_on(bus, u3k(gal));
98 u3_noun pro = u3r_sing(u3h(wim), u3t(wim));
100 u3a_lose(wim); u3a_lose(fol);
103 c3_assert(!"not reached");
106 u3_noun b_gal, c_gal, d_gal;
108 u3x_trel(gal, &b_gal, &c_gal, &d_gal);
110 u3_noun tys = _n_nock_on(u3k(bus), u3k(b_gal));
115 } else if ( 1 == tys ) {
117 } else return u3m_bail(c3__exit);
124 c3_assert(!"not reached");
127 u3_noun b_gal, c_gal;
129 u3x_cell(gal, &b_gal, &c_gal);
131 u3_noun bod = _n_nock_on(bus, u3k(b_gal));
132 u3_noun nex = u3k(c_gal);
140 c3_assert(!"not reached");
143 u3_noun b_gal, c_gal;
145 u3x_cell(gal, &b_gal, &c_gal);
147 u3_noun heb = _n_nock_on(u3k(bus), u3k(b_gal));
148 u3_noun bod = u3nc(heb, bus);
149 u3_noun nex = u3k(c_gal);
157 c3_assert(!"not reached");
160 u3_noun b_gal, c_gal;
162 u3x_cell(gal, &b_gal, &c_gal);
164 u3_noun seb = _n_nock_on(bus, u3k(c_gal));
168 pro = u3j_kick(seb, b_gal);
171 if ( u3_none != pro ) {
176 if ( c3n == u3r_ud(b_gal) ) {
177 return u3m_bail(c3__exit);
180 u3_noun nex = u3k(u3at(b_gal, seb));
190 c3_assert(!"not reached");
193 u3_noun p_gal, q_gal;
195 u3x_cell(gal, &p_gal, &q_gal);
197 u3_noun zep, hod, nex;
199 if ( c3y == u3r_du(p_gal) ) {
200 u3_noun b_gal = u3h(p_gal);
201 u3_noun c_gal = u3t(p_gal);
202 u3_noun d_gal = q_gal;
205 hod = _n_nock_on(u3k(bus), u3k(c_gal));
209 u3_noun b_gal = p_gal;
210 u3_noun c_gal = q_gal;
218 return _n_hint(zep, hod, bus, nex);
223 u3_noun ref = _n_nock_on(u3k(bus), u3k(u3h(gal)));
224 u3_noun gof = _n_nock_on(bus, u3k(u3t(gal)));
228 val = u3m_soft_esc(ref, u3k(gof));
231 if ( !_(u3du(val)) ) {
232 u3m_bail(u3nt(1, gof, 0));
234 if ( !_(u3du(u3t(val))) ) {
236 // replace with proper error stack push
238 u3t_push(u3nc(c3__hunk, _n_mush(gof)));
239 return u3m_bail(c3__exit);
246 pro = u3k(u3t(u3t(val)));
252 c3_assert(!"not reached");
258Building a Nock interpreter in another language is a fun exercise. Check out our community Nock implementations. (Note: these were written for a slightly older version of Nock, Nock 5K. The current version is Nock 4K.):
260;list(src "../../nock/implementations");
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list