예제 #1
0
파일: dash.c 프로젝트: mnemnion/urbit
/* u2_ds_mine(): 
**
**   Register and/or save core.
*/
u2_noun                                                           //  transfer
u2_ds_mine(u2_wire wir_r,
           u2_noun clu,                                           //  retain
           u2_noun cor)                                           //  transfer
{
  u2_noun bas_r = u2_wire_bas_r(wir_r);

  if ( u2_no == u2_dust(cor) ) {
    return cor;
  } else {
    u2_noun pay = u2_t(cor);
    u2_noun bat = u2_h(cor);
    u2_noun pug = u2_cs_find(bas_r, u2_wire_des_r(wir_r), 0, bat);
    u2_noun xip, bat_xip;
    u2_noun gop;

    if ( u2_none == pug ) {
      pug = u2_nul;
    }
    if ( u2_none == (xip = _ds_scan(pug, cor)) ) {
      gop = u2_rc(bas_r, (xip = _ds_chip(wir_r, clu, cor)), u2_rx(bas_r, pug));

      if ( u2_none == gop ) {
        return cor;
      } else {
        bat_xip = u2_h(u2_t(xip));

        // {c3_c* xip_c=u2_ho_cstring(xip); printf("%s\n", xip_c); free(xip_c);}
        gop = u2_cs_save(bas_r, u2_wire_des_r(wir_r), 0, bat_xip, gop);
        u2_rz(bas_r, gop);
      }
    }
    else bat_xip = u2_h(u2_t(xip));

    if ( bat_xip != bat ) {
      u2_noun cyr = u2_rc(wir_r, u2_rx(wir_r, pay), bat_xip);

      if ( u2_none == cyr ) {
        return cor;
      }
      else {
        u2_rz(wir_r, cor);
        return cyr;
      }
    }
    else return cor;
  }
}
예제 #2
0
파일: dash.c 프로젝트: mnemnion/urbit
/* u2_ds_find(): find chip by core, or none.
*/
u2_weak                                                           //  senior
u2_ds_find(u2_wire wir_r,
           u2_noun cor)                                           //  retain
{
  if ( u2_no == u2_dust(cor) ) {
    return u2_none;
  } else {
    u2_rail bas_r = u2_wire_bas_r(wir_r);
    u2_noun pug = u2_cs_find(bas_r, u2_wire_des_r(wir_r), 0, u2_h(cor));

    if ( u2_none == pug ) {
      return u2_none;
    }
    else return _ds_scan(pug, cor);
  }
}
예제 #3
0
파일: dash.c 프로젝트: MacTop/urbit
/* u2_ds_find(): find chip by core, or none.
*/
u2_weak                                                           //  senior
u2_ds_find(u2_wire wir_r,
           u2_noun cor)                                           //  retain
{
  if ( u2_no == u2_dust(cor) ) {
    return u2_none;
  } else {
    u2_rail bas_r = u2_wire_bas_r(wir_r);
    u2_noun pug = u2_cs_find(bas_r, u2_wire_des_r(wir_r), 0, u2_h(cor));
    u2_noun out;

    if ( u2_none == pug ) {
      out = u2_none;
    }
    else out = _ds_scan(pug, cor);

#if 0
    if ( (u2_none == out) && (u2_none != pug) ) {
      fprintf(stderr, "half match\r\n");
    }
#endif
    return out;
  }
}
예제 #4
0
파일: dash.c 프로젝트: MacTop/urbit
/* u2_ds_mine():
**
**   Register and/or save core.
*/
u2_noun                                                           //  transfer
u2_ds_mine(u2_wire wir_r,
           u2_noun clu,                                           //  retain
           u2_noun cor)                                           //  transfer
{
  u2_noun bas_r = u2_wire_bas_r(wir_r);

  if ( u2_no == u2_dust(cor) ) {
    return cor;
  } else {
    u2_noun pay = u2_t(cor);
    u2_noun bat = u2_h(cor);
    u2_noun pug = u2_cs_find(bas_r, u2_wire_des_r(wir_r), 0, bat);
    u2_noun xip, bat_xip;
    u2_noun gop;

    if ( u2_none == pug ) {
      pug = u2_nul;
    }
    if ( u2_none == (xip = _ds_scan(pug, cor)) ) {
      gop = u2_rc(bas_r, (xip = _ds_chip(wir_r, clu, cor)), u2_rx(bas_r, pug));

      if ( u2_none == gop ) {
        return cor;
      } else {
        bat_xip = u2_h(u2_t(xip));

#if 0
        {
          c3_c* xip_c = u2_ho_cstring(xip);

          fprintf(stderr, "!%s - lent %d\r\n", xip_c, u2_ckb_lent(gop));
          free(xip_c);
        }
#endif
        gop = u2_cs_save(bas_r, u2_wire_des_r(wir_r), 0, bat_xip, gop);
        {
          u2_noun poo = u2_cs_find(bas_r, u2_wire_des_r(wir_r), 0, bat_xip);

          {
            _ds_scan(poo, cor);
          }
        }
        u2_rz(bas_r, gop);

      }
    }
    else {
      bat_xip = u2_h(u2_t(xip));
    }

    if ( bat_xip != bat ) {
      u2_noun cyr = u2_rc(wir_r, bat_xip, u2_rx(wir_r, pay));

      if ( u2_none == cyr ) {
        return cor;
      }
      else {
        u2_rz(wir_r, cor);
        return cyr;
      }
    }
    else return cor;
  }
}
예제 #5
0
파일: wire.c 프로젝트: MacTop/urbit
/* u2_wr_init():
**
**   Install an empty wire within `hat_r` and `mat_r` in the loom,
**   with memory model `hip`.
**
**   Returns ray to wire, which always equalls the passed `mat_r`.
*/
u2_ray
u2_wr_init(c3_m   hip_m,
           u2_ray hat_r,
           u2_ray mat_r)
{
  u2_ray wir_r;

  wir_r = u2_rl_init(hip_m, hat_r, mat_r);
  u2_rail_hat_r(wir_r) += (c3_wiseof(u2_loom_wire) - c3_wiseof(u2_loom_rail));

#if 1
  u2_wire_bas_r(wir_r) = 0;
#endif

  u2_wire_kit_r(wir_r) = 0;

  u2_cs_init(u2_wire_des_r(wir_r));

  /* Trace stack, garbage.
  */
  {
    u2_wire_tax(wir_r) = u2_nul;
    u2_wire_lan(wir_r) = u2_yes;
  }

  /* Permanent basket = 1/16 of address space.
  */
  {
    u2_ray bas_r;

    bas_r = u2_rl_leap_part(wir_r, c3__sand, 1, 16, 0);
    u2_wire_bas_r(wir_r) = bas_r;

#if 0
    fprintf(stderr, "bas_r %d, hat %d, mat %d, cap %d, rut %d\n",
        bas_r >> LoomPageWords,
        u2_rail_hat_r(bas_r) >> LoomPageWords,
        u2_rail_mat_r(bas_r) >> LoomPageWords,
        u2_rail_cap_r(bas_r) >> LoomPageWords,
        u2_rail_rut_r(bas_r) >> LoomPageWords);

    fprintf(stderr, "wir_r %d, hat %d, mat %d, cap %d, rut %d\n",
        wir_r >> LoomPageWords,
        u2_rail_hat_r(wir_r) >> LoomPageWords,
        u2_rail_mat_r(wir_r) >> LoomPageWords,
        u2_rail_cap_r(wir_r) >> LoomPageWords,
        u2_rail_rut_r(wir_r) >> LoomPageWords);
#endif

    // u2_ba_init(wir_r, 0);
  }

#if 1
  /* Host control.
  */
  {
    u2_ho_push();
  }
#endif

  /* Basic performance tracking.
  */
  {
    u2_wire_bex_r(wir_r) = u2_rl_ralloc(wir_r, c3_wiseof(u2_loom_benx));

    u2_bx_boot(wir_r);
  }

  /* New performance tracking.
  */
  {
    u2_wire_rac_r(wir_r) = u2_tx_init(wir_r);
  }

  /* Global namespace.
  */
  {
    u2_wire_hev_r(wir_r) = u2_hv_init(wir_r);
  }

  /* OS kernel.
  */
  {
    u2_wire_arv_r(wir_r) = u2_rl_ralloc(wir_r, c3_wiseof(u2_reck));
  }

  return wir_r;
}