on c19bc7a help sign in
212 lines 4.4 kB history raw
1:- :~ navhome/'/docs/'
2 next/'true'
3 sort/'6'
4 title/'C'
5 ==
6;>
8# C
10The actual production interpreter. Note gotos for tail-call elimination,
11and manual reference counting. More about the C environment can be found
12in the [runtime system documentation](../../../runtime).
14```
15/* nock(): produce .*(bus fol). Do not virtualize.
16*/
17static u3_noun
18nock(u3_noun bus, u3_noun fol)
20 u3_noun hib, gal;
22 while ( 1 ) {
23 hib = u3h(fol);
24 gal = u3t(fol);
26 if ( c3y == u3r_du(hib) ) {
27 u3_noun poz, riv;
29 poz = nock(u3k(bus), u3k(hib));
30 riv = nock(bus, u3k(gal));
32 u3a_lose(fol);
33 return u3i_cell(poz, riv);
34 }
35 else switch ( hib ) {
36 default: return u3m_bail(c3__exit);
38 case 0: {
39 if ( c3n == u3r_ud(gal) ) {
40 return u3m_bail(c3__exit);
41 }
42 else {
43 u3_noun pro = u3k(u3at(gal, bus));
45 u3a_lose(bus); u3a_lose(fol);
46 return pro;
47 }
48 }
49 c3_assert(!"not reached");
51 case 1: {
52 u3_noun pro = u3k(gal);
54 u3a_lose(bus); u3a_lose(fol);
55 return pro;
56 }
57 c3_assert(!"not reached");
59 case 2: {
60 u3_noun nex = nock(u3k(bus), u3k(u3t(gal)));
61 u3_noun seb = nock(bus, u3k(u3h(gal)));
63 u3a_lose(fol);
64 bus = seb;
65 fol = nex;
66 continue;
67 }
68 c3_assert(!"not reached");
70 case 3: {
71 u3_noun gof, pro;
73 gof = nock(bus, u3k(gal));
74 pro = u3r_du(gof);
76 u3a_lose(gof); u3a_lose(fol);
77 return pro;
78 }
79 c3_assert(!"not reached");
81 case 4: {
82 u3_noun gof, pro;
84 gof = nock(bus, u3k(gal));
85 pro = u3i_vint(gof);
87 u3a_lose(fol);
88 return pro;
89 }
90 c3_assert(!"not reached");
92 case 5: {
93 u3_noun wim = nock(bus, u3k(gal));
94 u3_noun pro = u3r_sing(u3h(wim), u3t(wim));
96 u3a_lose(wim); u3a_lose(fol);
97 return pro;
98 }
99 c3_assert(!"not reached");
101 case 6: {
102 u3_noun b_gal, c_gal, d_gal;
104 u3x_trel(gal, &b_gal, &c_gal, &d_gal);
105 {
106 u3_noun tys = nock(u3k(bus), u3k(b_gal));
107 u3_noun nex;
109 if ( 0 == tys ) {
110 nex = u3k(c_gal);
111 } else if ( 1 == tys ) {
112 nex = u3k(d_gal);
113 } else return u3m_bail(c3__exit);
115 u3a_lose(fol);
116 fol = nex;
117 continue;
118 }
119 }
120 c3_assert(!"not reached");
122 case 7: {
123 u3_noun b_gal, c_gal;
125 u3x_cell(gal, &b_gal, &c_gal);
126 {
127 u3_noun bod = nock(bus, u3k(b_gal));
128 u3_noun nex = u3k(c_gal);
130 u3a_lose(fol);
131 bus = bod;
132 fol = nex;
133 continue;
134 }
135 }
136 c3_assert(!"not reached");
138 case 8: {
139 u3_noun b_gal, c_gal;
141 u3x_cell(gal, &b_gal, &c_gal);
142 {
143 u3_noun heb = nock(u3k(bus), u3k(b_gal));
144 u3_noun bod = u3nc(heb, bus);
145 u3_noun nex = u3k(c_gal);
147 u3a_lose(fol);
148 bus = bod;
149 fol = nex;
150 continue;
151 }
152 }
153 c3_assert(!"not reached");
155 case 9: {
156 u3_noun b_gal, c_gal;
158 u3x_cell(gal, &b_gal, &c_gal);
159 {
160 u3_noun seb = nock(bus, u3k(c_gal));
162 if ( c3n == u3r_ud(b_gal) ) {
163 return u3m_bail(c3__exit);
164 }
165 else {
166 u3_noun nex = u3k(u3at(b_gal, seb));
168 u3a_lose(fol);
169 bus = seb;
170 fol = nex;
171 continue;
172 }
173 }
174 }
175 c3_assert(!"not reached");
177 case 10: {
178 u3_noun p_gal, q_gal;
180 u3x_cell(gal, &p_gal, &q_gal);
181 {
182 u3_noun zep, hod, nex;
184 if ( c3y == u3r_du(p_gal) ) {
185 u3_noun b_gal = u3h(p_gal);
186 u3_noun c_gal = u3t(p_gal);
187 u3_noun d_gal = q_gal;
189 zep = u3k(b_gal);
190 hod = nock(u3k(bus), u3k(c_gal));
191 nex = u3k(d_gal);
192 }
193 else {
194 u3_noun b_gal = p_gal;
195 u3_noun c_gal = q_gal;
197 zep = u3k(b_gal);
198 hod = u3_nul;
199 nex = u3k(c_gal);
200 }
202 u3a_lose(zep);
203 u3a_lose(hod);
205 return nock(bus, nex);
206 }
207 }
208 c3_assert(!"not reached");
209 }
210 }
212```