예제 #1
0
파일: benx.c 프로젝트: Gruelty/urbit
/* u2_bx_bean_ent(), u2_bx_bean_out(): enter and exit source position.
*/
void
u2_bx_bean_ent(u2_ray  wir_r,
               u2_noun hod)                                       //  transfer
{
  u2_ray bex_r, bas_r;

  if ( (0 == (bex_r = u2_wire_bex_r(wir_r))) ||
       (0 == (bas_r = u2_wire_bas_r(wir_r))) )
  {
    u2_rl_lose(wir_r, hod);
    return;
  } 
  else {
    u2_noun naz = u2_rl_uniq(wir_r, hod);

    u2_rl_lose(wir_r, hod);
    if ( u2_none != naz ) { 
      u2_noun zof = u2_rc
        (bas_r, u2_rx(bas_r, naz), u2_rx(bas_r, u2_benx_at(bex_r, zof)));
      
      if ( u2_none != zof ) {
        u2_rl_lose(bas_r, u2_benx_at(bex_r, zof));
        u2_benx_at(bex_r, zof) = zof;
      }
    }
  }
}
예제 #2
0
파일: nock.c 프로젝트: sillsm/urbit
/* _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;
        }
    }
    }
}