shrub/g/n.c

411 lines
8.0 KiB
C
Raw Normal View History

2014-09-11 04:01:32 +04:00
/* g/n.c
2014-09-05 23:55:16 +04:00
**
** This file is in the public domain.
*/
#include "all.h"
/* _cn_hint(): process hint.
*/
2014-09-06 00:13:24 +04:00
static u3_noun
_cn_hint(u3_noun zep,
u3_noun hod,
u3_noun bus,
u3_noun nex)
2014-09-05 23:55:16 +04:00
{
switch ( zep ) {
default: {
2014-09-06 00:13:24 +04:00
u3_ca_lose(zep);
u3_ca_lose(hod);
2014-09-05 23:55:16 +04:00
2014-09-06 00:13:24 +04:00
return u3_cn_nock_on(bus, nex);
2014-09-05 23:55:16 +04:00
}
case c3__hunk:
case c3__lose:
case c3__mean:
case c3__spot: {
2014-09-06 00:13:24 +04:00
u3_noun tac = u3nc(zep, hod);
u3_noun pro;
2014-09-05 23:55:16 +04:00
2014-09-06 00:13:24 +04:00
u3_ct_push(tac);
2014-09-05 23:55:16 +04:00
#if 0
if ( c3__spot == zep ) {
printf("spot %d/%d : %d/%d\n",
2014-09-06 00:13:24 +04:00
u3h(u3h(u3t(hod))),
u3t(u3h(u3t(hod))),
u3h(u3t(u3t(hod))),
u3t(u3t(u3t(hod))));
2014-09-05 23:55:16 +04:00
}
#endif
2014-09-06 00:13:24 +04:00
pro = u3_cn_nock_on(bus, nex);
u3_ct_drop();
2014-09-05 23:55:16 +04:00
return pro;
}
case c3__slog: {
2014-09-06 00:13:24 +04:00
u3_ct_slog(hod);
return u3_cn_nock_on(bus, nex);
2014-09-05 23:55:16 +04:00
}
case c3__germ: {
2014-09-06 00:13:24 +04:00
u3_noun pro = u3_cn_nock_on(bus, nex);
2014-09-05 23:55:16 +04:00
2014-09-06 00:13:24 +04:00
if ( u3_yes == u3_cr_sing(pro, hod) ) {
u3z(pro); return hod;
2014-09-05 23:55:16 +04:00
} else {
2014-09-06 00:13:24 +04:00
u3z(hod); return pro;
2014-09-05 23:55:16 +04:00
}
}
case c3__fast: {
2014-09-06 00:13:24 +04:00
u3_noun pro = u3_cn_nock_on(bus, nex);
2014-09-05 23:55:16 +04:00
2014-09-06 00:13:24 +04:00
return u3_cj_mine(hod, pro);
2014-09-05 23:55:16 +04:00
}
case c3__memo: {
2014-09-06 00:13:24 +04:00
u3z(hod);
2014-09-17 04:29:12 +04:00
#if 0
return u3_cn_nock_on(bus, nex);
#else
2014-09-05 23:55:16 +04:00
{
2014-09-06 00:13:24 +04:00
u3_noun pro = u3_cz_find_2(c3__nock, bus, nex);
2014-09-05 23:55:16 +04:00
2014-09-06 00:13:24 +04:00
if ( pro != u3_none ) {
2014-09-05 23:55:16 +04:00
return pro;
}
2014-09-17 04:29:12 +04:00
pro = u3_cn_nock_on(u3k(bus), u3k(nex));
2014-09-05 23:55:16 +04:00
2014-09-06 00:13:24 +04:00
u3_cz_save_2(c3__nock, bus, nex, pro);
u3z(bus); u3z(nex);
2014-09-05 23:55:16 +04:00
}
2014-09-17 04:29:12 +04:00
#endif
2014-09-05 23:55:16 +04:00
}
case c3__sole: {
2014-09-06 00:13:24 +04:00
u3z(hod);
2014-09-05 23:55:16 +04:00
{
2014-09-06 00:13:24 +04:00
u3_noun pro = u3_cn_nock_on(bus, nex);
2014-09-05 23:55:16 +04:00
2014-09-17 04:29:12 +04:00
// return u3_cz_uniq(pro);
return pro;
2014-09-05 23:55:16 +04:00
}
}
}
}
2014-09-06 00:13:24 +04:00
/* u3_cn_nock_on(): produce .*(bus fol). Do not virtualize.
2014-09-05 23:55:16 +04:00
*/
2014-09-06 00:13:24 +04:00
u3_noun
u3_cn_nock_on(u3_noun bus, u3_noun fol)
2014-09-05 23:55:16 +04:00
{
2014-09-06 00:13:24 +04:00
u3_noun hib, gal;
2014-09-05 23:55:16 +04:00
while ( 1 ) {
2014-09-06 00:13:24 +04:00
hib = u3h(fol);
gal = u3t(fol);
2014-09-05 23:55:16 +04:00
2014-09-16 03:56:37 +04:00
u3N++;
2014-09-06 00:13:24 +04:00
if ( u3_yes == u3_cr_du(hib) ) {
u3_noun poz, riv;
2014-09-05 23:55:16 +04:00
2014-09-06 00:13:24 +04:00
poz = u3_cn_nock_on(u3k(bus), u3k(hib));
riv = u3_cn_nock_on(bus, u3k(gal));
2014-09-05 23:55:16 +04:00
2014-09-06 00:13:24 +04:00
u3_ca_lose(fol);
return u3_ci_cell(poz, riv);
2014-09-05 23:55:16 +04:00
}
else switch ( hib ) {
2014-09-06 00:13:24 +04:00
default: return u3_cm_bail(c3__exit);
2014-09-05 23:55:16 +04:00
case 0: {
2014-09-06 00:13:24 +04:00
if ( u3_no == u3_cr_ud(gal) ) {
return u3_cm_bail(c3__exit);
2014-09-05 23:55:16 +04:00
}
else {
2014-09-06 00:13:24 +04:00
u3_noun pro = u3k(u3at(gal, bus));
2014-09-05 23:55:16 +04:00
2014-09-06 00:13:24 +04:00
u3_ca_lose(bus); u3_ca_lose(fol);
2014-09-05 23:55:16 +04:00
return pro;
}
}
c3_assert(!"not reached");
case 1: {
2014-09-06 00:13:24 +04:00
u3_noun pro = u3k(gal);
2014-09-05 23:55:16 +04:00
2014-09-06 00:13:24 +04:00
u3_ca_lose(bus); u3_ca_lose(fol);
2014-09-05 23:55:16 +04:00
return pro;
}
c3_assert(!"not reached");
case 2: {
2014-09-06 00:13:24 +04:00
u3_noun nex = u3_cn_nock_on(u3k(bus), u3k(u3t(gal)));
u3_noun seb = u3_cn_nock_on(bus, u3k(u3h(gal)));
2014-09-05 23:55:16 +04:00
2014-09-06 00:13:24 +04:00
u3_ca_lose(fol);
2014-09-05 23:55:16 +04:00
bus = seb;
fol = nex;
continue;
}
c3_assert(!"not reached");
case 3: {
2014-09-06 00:13:24 +04:00
u3_noun gof, pro;
2014-09-05 23:55:16 +04:00
2014-09-06 00:13:24 +04:00
gof = u3_cn_nock_on(bus, u3k(gal));
pro = u3_cr_du(gof);
2014-09-05 23:55:16 +04:00
2014-09-06 00:13:24 +04:00
u3_ca_lose(gof); u3_ca_lose(fol);
2014-09-05 23:55:16 +04:00
return pro;
}
c3_assert(!"not reached");
case 4: {
2014-09-06 00:13:24 +04:00
u3_noun gof, pro;
2014-09-05 23:55:16 +04:00
2014-09-06 00:13:24 +04:00
gof = u3_cn_nock_on(bus, u3k(gal));
pro = u3_ci_vint(gof);
2014-09-05 23:55:16 +04:00
2014-09-06 00:13:24 +04:00
u3_ca_lose(fol);
2014-09-05 23:55:16 +04:00
return pro;
}
c3_assert(!"not reached");
case 5: {
2014-09-06 00:13:24 +04:00
u3_noun wim = u3_cn_nock_on(bus, u3k(gal));
u3_noun pro = u3_cr_sing(u3h(wim), u3t(wim));
2014-09-05 23:55:16 +04:00
2014-09-06 00:13:24 +04:00
u3_ca_lose(wim); u3_ca_lose(fol);
2014-09-05 23:55:16 +04:00
return pro;
}
c3_assert(!"not reached");
case 6: {
2014-09-06 00:13:24 +04:00
u3_noun b_gal, c_gal, d_gal;
2014-09-05 23:55:16 +04:00
2014-09-06 00:13:24 +04:00
u3_cx_trel(gal, &b_gal, &c_gal, &d_gal);
2014-09-05 23:55:16 +04:00
{
2014-09-06 00:13:24 +04:00
u3_noun tys = u3_cn_nock_on(u3k(bus), u3k(b_gal));
u3_noun nex;
2014-09-05 23:55:16 +04:00
if ( 0 == tys ) {
2014-09-06 00:13:24 +04:00
nex = u3k(c_gal);
2014-09-05 23:55:16 +04:00
} else if ( 1 == tys ) {
2014-09-06 00:13:24 +04:00
nex = u3k(d_gal);
} else return u3_cm_bail(c3__exit);
2014-09-05 23:55:16 +04:00
2014-09-06 00:13:24 +04:00
u3_ca_lose(fol);
2014-09-05 23:55:16 +04:00
fol = nex;
continue;
}
}
c3_assert(!"not reached");
case 7: {
2014-09-06 00:13:24 +04:00
u3_noun b_gal, c_gal;
2014-09-05 23:55:16 +04:00
2014-09-06 00:13:24 +04:00
u3_cx_cell(gal, &b_gal, &c_gal);
2014-09-05 23:55:16 +04:00
{
2014-09-06 00:13:24 +04:00
u3_noun bod = u3_cn_nock_on(bus, u3k(b_gal));
u3_noun nex = u3k(c_gal);
2014-09-05 23:55:16 +04:00
2014-09-06 00:13:24 +04:00
u3_ca_lose(fol);
2014-09-05 23:55:16 +04:00
bus = bod;
fol = nex;
continue;
}
}
c3_assert(!"not reached");
case 8: {
2014-09-06 00:13:24 +04:00
u3_noun b_gal, c_gal;
2014-09-05 23:55:16 +04:00
2014-09-06 00:13:24 +04:00
u3_cx_cell(gal, &b_gal, &c_gal);
2014-09-05 23:55:16 +04:00
{
2014-09-06 00:13:24 +04:00
u3_noun heb = u3_cn_nock_on(u3k(bus), u3k(b_gal));
u3_noun bod = u3nc(heb, bus);
u3_noun nex = u3k(c_gal);
2014-09-05 23:55:16 +04:00
2014-09-06 00:13:24 +04:00
u3_ca_lose(fol);
2014-09-05 23:55:16 +04:00
bus = bod;
fol = nex;
continue;
}
}
c3_assert(!"not reached");
case 9: {
2014-09-06 00:13:24 +04:00
u3_noun b_gal, c_gal;
2014-09-05 23:55:16 +04:00
2014-09-06 00:13:24 +04:00
u3_cx_cell(gal, &b_gal, &c_gal);
2014-09-05 23:55:16 +04:00
{
2014-09-06 00:13:24 +04:00
u3_noun seb = u3_cn_nock_on(bus, u3k(c_gal));
u3_noun pro = u3_cj_kick(seb, b_gal);
2014-09-05 23:55:16 +04:00
2014-09-06 00:13:24 +04:00
if ( u3_none != pro ) {
u3_ca_lose(fol);
2014-09-05 23:55:16 +04:00
return pro;
}
else {
2014-09-06 00:13:24 +04:00
if ( u3_no == u3_cr_ud(b_gal) ) {
return u3_cm_bail(c3__exit);
2014-09-05 23:55:16 +04:00
}
else {
2014-09-06 00:13:24 +04:00
u3_noun nex = u3k(u3at(b_gal, seb));
2014-09-05 23:55:16 +04:00
2014-09-06 00:13:24 +04:00
u3_ca_lose(fol);
2014-09-05 23:55:16 +04:00
bus = seb;
fol = nex;
continue;
}
}
}
}
c3_assert(!"not reached");
case 10: {
2014-09-06 00:13:24 +04:00
u3_noun p_gal, q_gal;
2014-09-05 23:55:16 +04:00
2014-09-06 00:13:24 +04:00
u3_cx_cell(gal, &p_gal, &q_gal);
2014-09-05 23:55:16 +04:00
{
2014-09-06 00:13:24 +04:00
u3_noun zep, hod, nex;
2014-09-05 23:55:16 +04:00
2014-09-06 00:13:24 +04:00
if ( u3_yes == u3_cr_du(p_gal) ) {
u3_noun b_gal = u3h(p_gal);
u3_noun c_gal = u3t(p_gal);
u3_noun d_gal = q_gal;
2014-09-05 23:55:16 +04:00
2014-09-06 00:13:24 +04:00
zep = u3k(b_gal);
hod = u3_cn_nock_on(u3k(bus), u3k(c_gal));
nex = u3k(d_gal);
2014-09-05 23:55:16 +04:00
}
else {
2014-09-06 00:13:24 +04:00
u3_noun b_gal = p_gal;
u3_noun c_gal = q_gal;
2014-09-05 23:55:16 +04:00
2014-09-06 00:13:24 +04:00
zep = u3k(b_gal);
hod = u3_nul;
nex = u3k(c_gal);
2014-09-05 23:55:16 +04:00
}
2014-09-06 00:13:24 +04:00
u3_ca_lose(fol);
2014-09-05 23:55:16 +04:00
return _cn_hint(zep, hod, bus, nex);
}
}
case 11: {
c3_assert(!"11 remains stubbed out");
}
c3_assert(!"not reached");
}
}
}
2014-09-06 00:13:24 +04:00
/* u3_cn_kick_on(): fire `gat` without changing the sample.
2014-09-05 23:55:16 +04:00
*/
2014-09-06 00:13:24 +04:00
u3_noun
u3_cn_kick_on(u3_noun gat)
2014-09-05 23:55:16 +04:00
{
2014-09-06 00:13:24 +04:00
return u3_cj_kink(gat, 2);
2014-09-05 23:55:16 +04:00
}
2014-09-06 00:13:24 +04:00
/* u3_cn_slam_on(): produce (gat sam).
2014-09-05 23:55:16 +04:00
*/
2014-09-06 00:13:24 +04:00
u3_noun
u3_cn_slam_on(u3_noun gat, u3_noun sam)
2014-09-05 23:55:16 +04:00
{
2014-09-06 00:13:24 +04:00
u3_noun cor = u3nc(u3k(u3h(gat)), u3nc(sam, u3k(u3t(u3t(gat)))));
2014-09-05 23:55:16 +04:00
2014-09-06 00:13:24 +04:00
u3z(gat);
return u3_cn_kick_on(cor);
2014-09-05 23:55:16 +04:00
}
2014-09-06 00:13:24 +04:00
/* u3_cn_nock_un(): produce .*(bus fol), as ++toon.
2014-09-05 23:55:16 +04:00
*/
2014-09-06 00:13:24 +04:00
u3_noun
u3_cn_nock_un(u3_noun bus, u3_noun fol)
2014-09-05 23:55:16 +04:00
{
2014-09-06 00:13:24 +04:00
u3_noun ton;
2014-09-05 23:55:16 +04:00
2014-09-06 00:13:24 +04:00
u3_cm_leap();
if ( u3_blip != u3_cm_trap() ) {
2014-09-06 00:13:24 +04:00
u3_noun ton;
2014-09-05 23:55:16 +04:00
2014-09-06 00:13:24 +04:00
if ( 0 != u3R->net.nyd ) {
ton = u3nc(1, u3R->net.nyd);
2014-09-05 23:55:16 +04:00
} else {
2014-09-06 00:13:24 +04:00
ton = u3nc(2, u3R->bug.tax);
2014-09-05 23:55:16 +04:00
}
2014-09-06 00:13:24 +04:00
u3_cm_fall();
ton = u3_ca_gain(ton);
u3_cm_flog(0);
2014-09-05 23:55:16 +04:00
}
else {
2014-09-06 00:13:24 +04:00
u3_noun pro = u3_cn_nock_on(bus, fol);
2014-09-05 23:55:16 +04:00
2014-09-06 00:13:24 +04:00
u3_cm_fall();
ton = u3nc(0, u3_ca_gain(pro));
2014-09-05 23:55:16 +04:00
}
2014-09-06 00:13:24 +04:00
u3z(bus); u3z(fol); return ton;
2014-09-05 23:55:16 +04:00
}
2014-09-06 00:13:24 +04:00
/* u3_cn_slam_un(): produce (gat sam), as ++toon.
2014-09-05 23:55:16 +04:00
*/
2014-09-06 00:13:24 +04:00
u3_noun
u3_cn_slam_un(u3_noun gat, u3_noun sam)
2014-09-05 23:55:16 +04:00
{
2014-09-06 00:13:24 +04:00
u3_noun ton;
2014-09-05 23:55:16 +04:00
2014-09-06 00:13:24 +04:00
u3_cm_leap();
if ( u3_blip != u3_cm_trap() ) {
2014-09-06 00:13:24 +04:00
u3_noun ton;
2014-09-05 23:55:16 +04:00
2014-09-06 00:13:24 +04:00
if ( 0 != u3R->net.nyd ) {
ton = u3nc(1, u3R->net.nyd);
2014-09-05 23:55:16 +04:00
} else {
2014-09-06 00:13:24 +04:00
ton = u3nc(2, u3R->bug.tax);
2014-09-05 23:55:16 +04:00
}
2014-09-06 00:13:24 +04:00
u3_cm_fall();
ton = u3_ca_gain(ton);
u3_cm_flog(0);
2014-09-05 23:55:16 +04:00
}
else {
2014-09-06 00:13:24 +04:00
u3_noun pro = u3_cn_slam_on(gat, sam);
2014-09-05 23:55:16 +04:00
2014-09-06 00:13:24 +04:00
u3_cm_fall();
ton = u3nc(0, u3_ca_gain(pro));
2014-09-05 23:55:16 +04:00
}
2014-09-06 00:13:24 +04:00
u3z(gat); u3z(sam); return ton;
2014-09-05 23:55:16 +04:00
}
2014-09-06 00:13:24 +04:00
/* u3_cn_nock_in(): produce .*(bus fol), as ++toon, in namespace.
2014-09-05 23:55:16 +04:00
*/
2014-09-06 00:13:24 +04:00
u3_noun
u3_cn_nock_in(u3_noun fly, u3_noun bus, u3_noun fol)
2014-09-05 23:55:16 +04:00
{
// XX implement 11
//
2014-09-06 00:13:24 +04:00
u3z(fly); return u3_cn_nock_un(bus, fol);
2014-09-05 23:55:16 +04:00
}
2014-09-06 00:13:24 +04:00
/* u3_cn_slam_in(): produce (gat sam), as ++toon, in namespace.
2014-09-05 23:55:16 +04:00
*/
2014-09-06 00:13:24 +04:00
u3_noun
u3_cn_slam_in(u3_noun fly, u3_noun gat, u3_noun sam)
2014-09-05 23:55:16 +04:00
{
// XX implement 11
//
2014-09-06 00:13:24 +04:00
u3z(fly); return u3_cn_slam_un(gat, sam);
2014-09-05 23:55:16 +04:00
}
2014-09-06 00:13:24 +04:00
/* u3_cn_nock_an(): as slam_in(), but with empty fly.
2014-09-05 23:55:16 +04:00
*/
2014-09-06 00:13:24 +04:00
u3_noun
u3_cn_nock_an(u3_noun bus, u3_noun fol)
2014-09-05 23:55:16 +04:00
{
2014-09-06 00:13:24 +04:00
return u3_cn_nock_un(bus, fol);
2014-09-05 23:55:16 +04:00
}