/* u2_sh_look(): ** ** Produce hook formula from core, or u2_none. */ u2_weak u2_sh_look(u2_wire wir_r, u2_noun cor, const c3_c* tam_c) { u2_ray bas_r = u2_wire_bas_r(wir_r); u2_noun bat = u2_t(cor); u2_noun fol; if ( u2_none != (fol = u2_ch_find_mixt(u2_bask_hag_r(bas_r), tam_c, bat)) ) { return fol; } else { u2_noun xip = u2_sh_find(wir_r, cor); if ( u2_none == xip ) { return u2_none; } else { u2_axis axe_w = _1; while ( 1 ) { fol = u2_sh_cook(wir_r, xip, tam_c); if ( u2_none == fol ) { u2_noun pet = u2_t(u2_t(xip)); if ( _0 == pet ) { return u2_none; } else { u2_axis pax = u2_h(pet); c3_assert(u2_fly_is_cat(pax)); c3_assert((u2_ax_dep(axe_w) + u2_ax_dep(pax)) <= 30); axe_w = u2_ax_peg(axe_w, pax); xip = u2_t(pet); continue; } } else { fol = u2_rl_take(bas_r, fol); if ( _1 != axe_w ) { /* XX: suboptimal; use comb:lily. */ fol = u2_rt(bas_r, u2_nock_flac, u2_rc(bas_r, u2_nock_frag, axe_w), fol); } fol = u2_ch_save_mixt(bas_r, u2_bask_hag_r(bas_r), tam_c, bat, fol); return fol; } } } } }
/* u2_ds_look(): ** ** Produce hook formula from core, or u2_none. */ u2_weak // produce u2_ds_look(u2_wire wir_r, u2_noun cor, // retain const c3_c* tam_c) // retain { u2_noun xip = u2_ds_find(wir_r, cor); if ( u2_none == xip ) { return u2_none; } else { c3_l axe_l = _1; while ( 1 ) { u2_noun fol = _ds_leap(wir_r, xip, tam_c); if ( u2_none == fol ) { u2_noun pet = u2_t(u2_t(xip)); if ( _0 == pet ) { // printf("no joy - %s\n", tam_c); return u2_none; } else { u2_axis pax = u2_h(pet); c3_assert(u2_fly_is_cat(pax)); c3_assert((u2_ax_dep(axe_l) + u2_ax_dep(pax)) <= 30); axe_l = u2_ax_peg(axe_l, pax); xip = u2_t(pet); continue; } } else { if ( _1 != axe_l ) { return u2_rt(wir_r, u2_nock_flac, u2_rc(wir_r, u2_nock_frag, axe_l), fol); } else return fol; } } } }
u2_weak j2_mck(Pt6, ut, seek)(u2_wire wir_r, u2_noun cor) { u2_noun sut, way, hyp, van; if ( (u2_no == u2_mean(cor, u2_cv_sam_2, &way, u2_cv_sam_3, &hyp, u2_cv_con, &van, 0)) || (u2_none == (sut = u2_frag(u2_cv_sam, van))) ) { return u2_none; } else { return u2_rt (wir_r, u2_rx(wir_r, sut), u2_rx(wir_r, way), u2_rx(wir_r, hyp)); } }
u2_weak j2_mck(Pt6, ut, find)(u2_wire wir_r, u2_noun cor) { u2_noun sut, way, cog, van; if ( (u2_no == u2_mean(cor, u2_cw_con, &van, u2_cw_sam_2, &way, u2_cw_sam_3, &cog, 0)) || (u2_none == (sut = u2_frag(u2_cw_sam, van))) ) { return u2_none; } else { return u2_rt (wir_r, u2_rx(wir_r, sut), u2_rx(wir_r, way), u2_rx(wir_r, cog)); } }
/* _nock_hint(): hint with code, data, subject, formula. nock/mink. */ static u2_noun // produce _nock_hint(u2_noun zep, // transfer u2_noun hod, // transfer u2_noun bus, // transfer u2_noun nex, // transfer u2_bean* pon) { u2_noun pro; switch ( zep ) { default: u2z(zep); u2z(hod); return pon ? _nock_mool(bus, nex, pon) : _nock_cool(bus, nex); case c3__lose: case c3__yelp: case c3__bean: case c3__mean: case c3__spot: { u2_noun tax = u2_wire_tax(u2_Wire); u2_noun tac = u2nc(zep, hod); #if 0 if ( c3__spot == zep ) { printf("spot %d/%d : %d/%d\n", u2h(u2h(u2t(hod))), u2t(u2h(u2t(hod))), u2h(u2t(u2t(hod))), u2t(u2t(u2t(hod)))); } #endif u2_wire_tax(u2_Wire) = u2nc(tac, tax); { pro = pon ? _nock_mool(bus, nex, pon) : _nock_cool(bus, nex); } tax = u2k(tax); u2z(u2_wire_tax(u2_Wire)); u2_wire_tax(u2_Wire) = tax; return pro; } case c3__slog: { u2_tx_sys_bit(u2_Wire, u2_yes); u2_tx_slog(u2_Wire, hod); u2_tx_sys_bit(u2_Wire, u2_no); u2z(hod); return pon ? _nock_mool(bus, nex, pon) : _nock_cool(bus, nex); } case c3__mine: { pro = pon ? _nock_mool(bus, nex, pon) : _nock_cool(bus, nex); if ( !pon || (u2_no != *pon) ) { u2_tx_sys_bit(u2_Wire, u2_yes); pro = u2_ds_mine(u2_Wire, hod, pro); u2_tx_sys_bit(u2_Wire, u2_no); } u2z(hod); return pro; } case c3__germ: { pro = pon ? _nock_mool(bus, nex, pon) : _nock_cool(bus, nex); if ( u2_yes == u2_sing(pro, hod) ) { u2z(pro); return hod; } else { u2z(hod); return pro; } } case c3__fast: { pro = pon ? _nock_mool(bus, nex, pon) : _nock_cool(bus, nex); if ( !pon || (u2_no != *pon) ) { u2_noun p_hod, q_hod, r_hod; /* XX: translate hod to old clue form. */ if ( u2_no == u2_as_trel(hod, &p_hod, &q_hod, &r_hod) ) { u2z(hod); return pro; } else { u2_noun xod; if ( u2_yes == u2_dust(q_hod) && (_1 == u2_h(q_hod)) && (_0 == u2_t(q_hod)) ) { q_hod = 0; } xod = u2_rt(u2_Wire, u2k(q_hod), u2k(p_hod), u2k(r_hod)); u2z(hod); hod = xod; } u2_tx_sys_bit(u2_Wire, u2_yes); pro = u2_ds_mine(u2_Wire, hod, pro); u2_tx_sys_bit(u2_Wire, u2_no); } u2z(hod); return pro; } case c3__memo: { u2z(hod); { pro = u2_rl_find_cell(u2_Wire, 0, bus, nex); if ( pro != u2_none ) { u2_tx_did_fin(u2_Wire, 1); u2z(bus); u2z(nex); return pro; } else { u2_noun sav; pro = pon ? _nock_mool(u2k(bus), u2k(nex), pon) : _nock_cool(u2k(bus), u2k(nex)); if ( !pon || (u2_no != *pon) ) { u2_tx_sys_bit(u2_Wire, u2_yes); sav = u2_rl_save_cell(u2_Wire, 0, bus, nex, pro); u2_tx_sys_bit(u2_Wire, u2_no); u2_tx_did_pod(u2_Wire, 1); u2_tx_did_fin(u2_Wire, 1); } else sav = pro; u2z(bus); u2z(nex); return sav; } } } case c3__ping: { u2_tx_sys_bit(u2_Wire, u2_yes); u2_tx_did_act(u2_Wire, hod); u2_tx_sys_bit(u2_Wire, u2_no); u2z(hod); return pon ? _nock_mool(bus, nex, pon) : _nock_cool(bus, nex); } case c3__live: { u2_bean qox; u2_tx_sys_bit(u2_Wire, u2_yes); qox = u2_tx_task_in(u2_Wire, hod); u2_tx_sys_bit(u2_Wire, u2_no); u2z(hod); if ( u2_no == qox ) { return pon ? _nock_mool(bus, nex, pon) : _nock_cool(bus, nex); } else { pro = pon ? _nock_mool(bus, nex, pon) : _nock_cool(bus, nex); u2_tx_task_out(u2_Wire); return pro; } } case c3__sole: { u2z(hod); { pro = pon ? _nock_mool(bus, nex, pon) : _nock_cool(bus, nex); if ( u2_none == pro ) { return u2_none; } else if ( !pon || (u2_no != *pon) ) { u2_noun nuu; u2_tx_sys_bit(u2_Wire, u2_yes); nuu = u2_rl_uniq(u2_Wire, pro); u2_tx_sys_bit(u2_Wire, u2_no); u2_tx_did_fin(u2_Wire, 1); if ( nuu == pro ) { u2_tx_did_pod(u2_Wire, 1); } } return pro; } } } }
/* functions */ u2_weak // transfer j2_mcc(Pt4, by, uni)(u2_wire wir_r, u2_noun a, // retain u2_noun b) // retain { if ( u2_nul == a ) { return u2_rx(wir_r, b); } else if ( u2_nul == b ) { return u2_rx(wir_r, a); } else { u2_noun l_a, n_a, r_a, lr_a, p_n_a, q_n_a; u2_noun l_b, n_b, r_b, lr_b, p_n_b, q_n_b; if ( (u2_no == u2_as_cell(a, &n_a, &lr_a)) ) { return u2_bl_bail(wir_r, c3__exit); } else if ( (u2_no == u2_as_cell(b, &n_b, &lr_b)) ) { return u2_bl_bail(wir_r, c3__exit); } else if ( (u2_no == u2_as_cell(n_a, &p_n_a, &q_n_a)) ) { return u2_bl_bail(wir_r, c3__exit); } else if ( (u2_no == u2_as_cell(n_b, &p_n_b, &q_n_b)) ) { return u2_bl_bail(wir_r, c3__exit); } else if ( u2_no == u2_as_cell(lr_a, &l_a, &r_a) ) { return u2_bl_bail(wir_r, c3__exit); } else if ( u2_no == u2_as_cell(lr_b, &l_b, &r_b) ) { return u2_bl_bail(wir_r, c3__exit); } else if ( u2_yes == j2_mbc(Pt3, vor)(wir_r, p_n_a, p_n_b) ) { if ( u2_yes == u2_sing(p_n_a, p_n_b) ) { return u2_rt(wir_r, u2_rx(wir_r, n_b), j2_mcc(Pt4, by, uni)( wir_r, u2_rx(wir_r, l_a), u2_rx(wir_r, l_b)), j2_mcc(Pt4, by, uni)( wir_r, u2_rx(wir_r, r_a), u2_rx(wir_r, r_b))); } else if ( u2_yes == j2_mbc(Pt3, hor)(wir_r, p_n_b, p_n_a) ) { return j2_mcc(Pt4, by, uni)( wir_r, u2_rt(wir_r, u2_rx(wir_r, n_a), j2_mcc(Pt4, by, uni)(wir_r, u2_rx(wir_r, l_a), u2_rt(wir_r, u2_rx(wir_r, n_b), u2_rx(wir_r, l_b), u2_rx(wir_r, u2_nul))), u2_rx(wir_r, r_a)), u2_rx(wir_r, r_b)); } else { return j2_mcc(Pt4, by, uni)( wir_r, u2_rt(wir_r, u2_rx(wir_r, n_a), u2_rx(wir_r, l_a), j2_mcc(Pt4, by, uni)(wir_r, u2_rx(wir_r, r_a), u2_rt(wir_r, u2_rx(wir_r, n_b), u2_rx(wir_r, u2_nul), u2_rx(wir_r, r_b)))), u2_rx(wir_r, l_b)); } } else if ( u2_yes == u2_sing(p_n_b, p_n_a) ) { return u2_rt( wir_r, u2_rx(wir_r, n_b), j2_mcc(Pt4, by, uni)(wir_r, u2_rx(wir_r, r_b), u2_rx(wir_r, r_a)), j2_mcc(Pt4, by, uni)(wir_r, u2_rx(wir_r, l_b), u2_rx(wir_r, l_a))); } else if ( u2_yes == j2_mbc(Pt3, hor)(wir_r, p_n_a, p_n_b) ) { return j2_mcc(Pt4, by, uni)( wir_r, u2_rx(wir_r, r_a), u2_rt(wir_r, u2_rx(wir_r, n_b), j2_mcc(Pt4, by, uni)(wir_r, u2_rt(wir_r, u2_rx(wir_r, n_a), u2_rx(wir_r, l_a), u2_rx(wir_r, u2_nul)), u2_rx(wir_r, l_b)), u2_rx(wir_r, r_b))); } else { return j2_mcc(Pt4, by, uni)( wir_r, u2_rx(wir_r, l_a), u2_rt(wir_r, u2_rx(wir_r, n_b), u2_rx(wir_r, l_b), j2_mcc(Pt4, by, uni)(wir_r, u2_rx(wir_r, r_b), u2_rt(wir_r, u2_rx(wir_r, n_a), u2_rx(wir_r, u2_nul), u2_rx(wir_r, r_a))))); } } }
/* _ds_chip(): fabricate chip from clue and core. */ static u2_weak // senior _ds_chip(u2_wire wir_r, u2_noun clu, // retain u2_noun cor) // retain { u2_rail bas_r = u2_wire_bas_r(wir_r); u2_noun bud_clu, cop_clu, pic_clu; if ( (u2_no == u2_as_trel(clu, &bud_clu, &cop_clu, &pic_clu)) || (u2_no == _ds_good_bud(bud_clu)) || (u2_no == _ds_good_cop(cop_clu)) || (u2_no == _ds_good_pic(pic_clu)) ) { return u2_none; } else { u2_noun dac, bat, pet; /* disc: dac */ { if ( u2_none == (dac = u2_rx(bas_r, u2_t(clu))) ) { u2_ho_warn_here(); return u2_none; } } #if 1 /* battery: bat */ { if ( u2_none == (bat = u2_rx(bas_r, u2_h(cor))) ) { u2_ho_warn_here(); u2_rz(bas_r, dac); return u2_none; } } #endif #if 0 /* bat: battery */ { // Important to reuse existing battery even if it does not match // the whole chip - since battery is a comparison key, we don't // want duplicates, which compare slowly. // if ( u2_nul == pug ) { bat = u2_rx(bas_r, u2_h(cor)); } else { u2_noun i_pug = u2_h(pug); bat = u2_rx(bas_r, u2_h(u2_t(i_pug))); } if ( u2_none == bat ) { u2_ho_warn_here(); u2_rz(bas_r, dac); return u2_none; } } #endif /* trunk: pet */ { if ( _0 == bud_clu ) { pet = u2_nul; } else { while ( _10 == u2_h(bud_clu) ) { bud_clu = u2_t(u2_t(bud_clu)); } if ( _1 == u2_h(bud_clu) ) { pet = u2_nul; } else { u2_atom axe = u2_t(bud_clu); u2_noun ruc = u2_frag(axe, cor); u2_noun led; if ( u2_none == ruc ) { // u2_err(wir_r, "clu", clu); u2_ho_warn_here(); u2_rz(bas_r, dac); u2_rz(bas_r, bat); return u2_none; } else { if ( u2_none == (led = u2_ds_find(wir_r, ruc)) ) { u2_lo_show("clu", clu); u2_ho_warn_here(); c3_assert(0); u2_rz(bas_r, dac); u2_rz(bas_r, bat); return u2_none; } pet = u2_rc(bas_r, u2_rx(bas_r, axe), u2_rx(bas_r, led)); } } } } return u2_rt(bas_r, dac, bat, pet); } }
/* functions */ u2_weak // transfer j2_mcc(Pt4, by, put)(u2_wire wir_r, u2_noun a, // retain u2_noun b, // retain u2_noun c) // retain { if ( u2_nul == a ) { return u2_rt(wir_r, u2_rc(wir_r, u2_rx(wir_r, b), u2_rx(wir_r, c)), u2_nul, u2_nul); } else { u2_noun l_a, n_a, r_a, pn_a, qn_a; u2_noun d, l_d, n_d, r_d; if ( (u2_no == u2_as_trel(a, &n_a, &l_a, &r_a)) || (u2_no == u2_as_cell(n_a, &pn_a, &qn_a)) ) { return u2_bl_bail(wir_r, c3__exit); } else if ( u2_yes == u2_sing(pn_a, b) ) { if ( u2_yes == u2_sing(qn_a, c) ) { return u2_rx(wir_r, a); } else { return u2_rt (wir_r, u2_rc(wir_r, u2_rx(wir_r, b), u2_rx(wir_r, c)), u2_rx(wir_r, l_a), u2_rx(wir_r, r_a)); } } else { if ( u2_yes == j2_mbc(Pt3, gor)(wir_r, b, pn_a) ) { d = j2_mcc(Pt4, by, put)(wir_r, l_a, b, c); if ( u2_yes == j2_mbc(Pt3, vor)(wir_r, pn_a, u2_h(u2_h(d))) ) { return u2_rt(wir_r, u2_rx(wir_r, n_a), d, u2_rx(wir_r, r_a)); } else { u2_as_trel(d, &n_d, &l_d, &r_d); { u2_noun e = u2_rt (wir_r, u2_rx(wir_r, n_d), u2_rx(wir_r, l_d), u2_rt(wir_r, u2_rx(wir_r, n_a), u2_rx(wir_r, r_d), u2_rx(wir_r, r_a))); u2_rl_lose(wir_r, d); return e; } } } else { d = j2_mcc(Pt4, by, put)(wir_r, r_a, b, c); if ( u2_yes == j2_mbc(Pt3, vor)(wir_r, pn_a, u2_h(u2_h(d))) ) { return u2_rt(wir_r, u2_rx(wir_r, n_a), u2_rx(wir_r, l_a), d); } else { u2_as_trel(d, &n_d, &l_d, &r_d); { u2_noun e = u2_rt (wir_r, u2_rx(wir_r, n_d), u2_rt(wir_r, u2_rx(wir_r, n_a), u2_rx(wir_r, l_a), u2_rx(wir_r, l_d)), u2_rx(wir_r, r_d)); u2_rl_lose(wir_r, d); return e; } } } } } }
/* u2_sh_mine(): substitute active, annotated battery. */ u2_weak // transfer u2_sh_mine(u2_ray wir_r, u2_clue clu, // retain u2_noun cor) // transfer { u2_ray bas_r; u2_noun pay, bat; u2_noun sil, bud, nut; u2_chip xip; if ( 0 == (bas_r = u2_wire_bas_r(wir_r)) ) { return cor; } else if ( (u2_none == u2_as_cell(cor, &pay, &bat)) || (u2_no == u2_dust(bat)) ) { return cor; } else if ( u2_none != (xip = u2_ch_find(u2_bask_hag_r(bas_r), bat)) ) { u2_noun cyr; if ( u2_none == (cyr = u2_rc(wir_r, u2_rx(wir_r, pay), u2_h(u2_t(xip)))) ) { return cor; } else { u2_rl_lose(wir_r, cor); return cyr; } } else if ( (u2_no == u2_as_trel(clu, &bud, &sil, &nut)) || (u2_no == _sh_good_bud(bud)) || (u2_no == _sh_good_sil(sil)) || (u2_no == _sh_good_nut(nut)) ) { return cor; } else { u2_noun dac, bot, pet, xop, cyr; dac = bot = pet = xop = cyr = u2_none; while ( 1 ) { /* disc: dac */ { if ( u2_none == (dac = u2_rl_take(bas_r, u2_t(clu))) ) { break; } } /* battery: bot */ { if ( u2_no == u2_rl_junior(bas_r, bat) ) { /* We need the jet battery to be in the shed, so that we ** have a fast algorithm for distinguishing jet batteries ** by ray address. */ bot = u2_rc(bas_r, u2_h(bat), u2_t(bat)); #if 0 printf("battery: in basket: %d.%x\n", u2_ray_a(u2_dog_a(bot)), u2_ray_b(u2_dog_a(bot))); #endif } else { bot = u2_rl_take(bas_r, bat); #if 0 printf("battery: in shed! %d.%x\n", u2_ray_a(u2_dog_a(bot)), u2_ray_b(u2_dog_a(bot))); #endif } if ( u2_none == bot ) { break; } } /* trunk: pet */ { if ( _0 == bud ) { pet = u2_nul; } else { u2_atom p_bud = u2_t(bud); u2_noun car = u2_frag(p_bud, cor); if ( (u2_none == car) || (u2_no == u2_dust(car)) ) { break; } else { u2_noun but = u2_t(car); u2_noun xup, axe; if ( u2_none == (xup = u2_ch_find(u2_bask_hag_r(bas_r), but)) ) { printf("no base!\n"); u2_err(wir_r, "clu", clu); break; } else u2_rl_gain(bas_r, xup); if ( u2_none == (axe = u2_rl_take(bas_r, p_bud)) ) { u2_rl_lose(bas_r, xup); } if ( u2_none == (pet = u2_rc(bas_r, p_bud, xup)) ) { u2_rl_lose(bas_r, axe); u2_rl_lose(bas_r, xup); break; } } } } /* xop: new chip. */ { if ( u2_none == (xop = u2_rt(bas_r, dac, bot, pet)) ) { break; } if ( u2_none == (u2_ch_save(bas_r, u2_bask_hag_r(bas_r), bot, xop)) ) { break; } u2_rl_lose(bas_r, xop); } /* cyr: new core. */ { u2_noun cyr; if ( u2_none == (cyr = u2_rc(wir_r, u2_rx(wir_r, pay), bot)) ) { break; } else { u2_rl_lose(wir_r, cor); return cyr; } } } u2_ho_warn_here(); #if 0 // XXX: an unknown bug is triggered here; // but basket needs a minor rewrite. // if ( dac != u2_none ) u2_rl_lose(bas_r, dac); if ( bot != u2_none ) u2_rl_lose(bas_r, bot); if ( pet != u2_none ) u2_rl_lose(bas_r, pet); if ( xop != u2_none ) u2_rl_lose(bas_r, xop); #endif return cor; } }