9The actual production Nock interpreter. Note gotos for tail-call elimination,
10and manual reference counting. More about the C environment can be found
11in the [runtime system documentation](../../../runtime).
14/* nock(): produce .*(bus fol). Do not virtualize.
17nock(u3_noun bus, u3_noun fol)
25 if ( c3y == u3r_du(hib) ) {
28 poz = nock(u3k(bus), u3k(hib));
29 riv = nock(bus, u3k(gal));
32 return u3i_cell(poz, riv);
35 default: return u3m_bail(c3__exit);
38 if ( c3n == u3r_ud(gal) ) {
39 return u3m_bail(c3__exit);
42 u3_noun pro = u3k(u3at(gal, bus));
44 u3a_lose(bus); u3a_lose(fol);
48 c3_assert(!"not reached");
51 u3_noun pro = u3k(gal);
53 u3a_lose(bus); u3a_lose(fol);
56 c3_assert(!"not reached");
59 u3_noun nex = nock(u3k(bus), u3k(u3t(gal)));
60 u3_noun seb = nock(bus, u3k(u3h(gal)));
67 c3_assert(!"not reached");
72 gof = nock(bus, u3k(gal));
75 u3a_lose(gof); u3a_lose(fol);
78 c3_assert(!"not reached");
83 gof = nock(bus, u3k(gal));
89 c3_assert(!"not reached");
92 u3_noun wim = nock(bus, u3k(gal));
93 u3_noun pro = u3r_sing(u3h(wim), u3t(wim));
95 u3a_lose(wim); u3a_lose(fol);
98 c3_assert(!"not reached");
101 u3_noun b_gal, c_gal, d_gal;
103 u3x_trel(gal, &b_gal, &c_gal, &d_gal);
105 u3_noun tys = nock(u3k(bus), u3k(b_gal));
110 } else if ( 1 == tys ) {
112 } else return u3m_bail(c3__exit);
119 c3_assert(!"not reached");
122 u3_noun b_gal, c_gal;
124 u3x_cell(gal, &b_gal, &c_gal);
126 u3_noun bod = nock(bus, u3k(b_gal));
127 u3_noun nex = u3k(c_gal);
135 c3_assert(!"not reached");
138 u3_noun b_gal, c_gal;
140 u3x_cell(gal, &b_gal, &c_gal);
142 u3_noun heb = nock(u3k(bus), u3k(b_gal));
143 u3_noun bod = u3nc(heb, bus);
144 u3_noun nex = u3k(c_gal);
152 c3_assert(!"not reached");
155 u3_noun b_gal, c_gal;
157 u3x_cell(gal, &b_gal, &c_gal);
159 u3_noun seb = nock(bus, u3k(c_gal));
161 if ( c3n == u3r_ud(b_gal) ) {
162 return u3m_bail(c3__exit);
165 u3_noun nex = u3k(u3at(b_gal, seb));
174 c3_assert(!"not reached");
177 u3_noun p_gal, q_gal;
179 u3x_cell(gal, &p_gal, &q_gal);
181 u3_noun zep, hod, nex;
183 if ( c3y == u3r_du(p_gal) ) {
184 u3_noun b_gal = u3h(p_gal);
185 u3_noun c_gal = u3t(p_gal);
186 u3_noun d_gal = q_gal;
189 hod = nock(u3k(bus), u3k(c_gal));
193 u3_noun b_gal = p_gal;
194 u3_noun c_gal = q_gal;
204 return nock(bus, nex);
207 c3_assert(!"not reached");
213Building a Nock interpreter in another language is a fun exercise. Check out our community Nock implementations:
215<list src="../../nock/implementations" className="nock"></list>
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