Exemplo n.º 1
0
/* shim
*/
  u2_noun                                                         //  produce
  j2_mcx(Pt5, shim, fun)(u2_wire wir_r,
                         u2_noun zep,                             //  retain
                         u2_noun tub)                             //  retain
  {
    u2_noun p_tub, q_tub;

    u2_bi_cell(wir_r, tub, &p_tub, &q_tub);

    if ( u2_no == u2_dust(q_tub) ) {
      return _fail(wir_r, tub);
    }
    else {
      u2_noun p_zep, q_zep;
      u2_noun iq_tub = u2_h(q_tub);

      u2_bi_cell(wir_r, zep, &p_zep, &q_zep);
      if ( u2_fly_is_cat(p_zep) && 
           u2_fly_is_cat(q_zep) &&
           u2_fly_is_cat(iq_tub) )
      {
        if ( (iq_tub >= p_zep) && (iq_tub <= q_zep) ) {
          return _next(wir_r, tub);
        }
        else return _fail(wir_r, tub);
      }
      else {
        return u2_bl_bail(wir_r, c3__fail);
      }
    }
  }
/* functions
*/
  u2_weak                                                         //  transfer
  j2_mbc(Pt3, rsh)(u2_wire wir_r,
                   u2_atom a,                                     //  retain
                   u2_atom b,                                     //  retain
                   u2_atom c)                                     //  retain
  {
    if ( !u2_fly_is_cat(a) || (a >= 32) ) {
      return u2_bl_bail(wir_r, c3__fail);
    }
    else if ( !u2_fly_is_cat(b) ) {
      return _0;
    }
    else {
      c3_g a_g   = a;
      c3_w b_w   = b;
      c3_w len_w = u2_met(a_g, c);

      if ( b_w >= len_w ) {
        return _0;
      }
      else {
        u2_ray sal_r = u2_rl_slaq(wir_r, a_g, (len_w - b_w));

        if ( 0 == sal_r ) {
          return u2_bl_bail(wir_r, c3__fail);
        }
        u2_chop(a_g, b_w, (len_w - b_w), 0, sal_r, c);

        // return u2_rl_moot(wir_r, sal_r);
        return u2_rl_malt(wir_r, sal_r);
      }
    }
  }
Exemplo n.º 3
0
/* stew
*/
  static u2_flag
  _stew_wor(u2_wire wir_r,
            u2_noun ort,
            u2_noun wan)
  {
    if ( !u2_fly_is_cat(ort) ) {
      return u2_bl_bail(wir_r, c3__fail);
    }
    else {
      if ( u2_no == u2_dust(wan) ) {
        if ( !u2_fly_is_cat(wan) ) {
          return u2_bl_bail(wir_r, c3__fail);
        }
        else return (ort < wan) ? u2_yes : u2_no;
      }
      else {
        u2_noun h_wan = u2_h(wan);

        if ( !u2_fly_is_cat(h_wan) ) {
          return u2_bl_bail(wir_r, c3__fail);
        }
        else return (ort < h_wan) ? u2_yes : u2_no;
      }
    }
  }
Exemplo n.º 4
0
  u2_noun                                                         //  produce
  j2_mcx(Pt5, stew, fun)(u2_wire wir_r,
                         u2_noun hel,                             //  retain
                         u2_noun tub)                             //  retain
  {
    u2_noun p_tub, q_tub;

    u2_bi_cell(wir_r, tub, &p_tub, &q_tub);
    if ( u2_no == u2_dust(q_tub) ) {
      return _fail(wir_r, tub);
    }
    else {
      u2_noun iq_tub = u2_h(q_tub);

      if ( !u2_fly_is_cat(iq_tub) ) {
        return u2_bl_bail(wir_r, c3__fail);
      } else while ( 1 ) {
        if ( u2_no == u2_dust(hel) ) {
          return _fail(wir_r, tub);
        } 
        else {
          u2_noun n_hel, l_hel, r_hel;
          u2_noun pn_hel, qn_hel;
          c3_t    bit_t;

          u2_bi_trel(wir_r, hel, &n_hel, &l_hel, &r_hel);
          u2_bi_cell(wir_r, n_hel, &pn_hel, &qn_hel);

          if ( (u2_no == u2_dust(pn_hel)) ) {
            bit_t = (iq_tub == pn_hel);
          }
          else {
            u2_noun hpn_hel = u2_h(pn_hel);
            u2_noun tpn_hel = u2_t(pn_hel);

            if ( !u2_fly_is_cat(hpn_hel) || !u2_fly_is_cat(tpn_hel) ) {
              return _fail(wir_r, tub);
            }
            else bit_t = (iq_tub >= hpn_hel) && (iq_tub <= tpn_hel);
          }

          if ( bit_t ) {
            return u2_bl_good
              (wir_r, u2_nk_mong(wir_r, qn_hel, u2_rx(wir_r, tub)));
          } else {
            if ( u2_yes == _stew_wor(wir_r, iq_tub, pn_hel) ) {
              hel = l_hel;
            }
            else hel = r_hel;
          }
        }
      }
    }
  }
/* functions
*/
  u2_weak                                                         //  transfer
  j2_mbc(Pt3, cat)(u2_wire wir_r,
                   u2_atom a,                                     //  retain
                   u2_atom b,                                     //  retain
                   u2_atom c)                                     //  retain
  {
    if ( !u2_fly_is_cat(a) || (a >= 32) ) {
      return u2_bl_bail(wir_r, c3__fail);
    }
    else {
      c3_g   a_g = a;
      c3_w   lew_w = u2_met(a_g, b);
      c3_w   ler_w = u2_met(a_g, c);
      c3_w   all_w = (lew_w + ler_w);

      if ( 0 == all_w ) {
        return 0;
      } else {
        u2_ray sal_r = u2_rl_slaq(wir_r, a_g, all_w);

        if ( 0 == sal_r ) {
          return u2_bl_bail(wir_r, c3__fail);
        }
        else {
          u2_chop(a_g, 0, lew_w, 0, sal_r, b);
          u2_chop(a_g, 0, ler_w, lew_w, sal_r, c);
        }
        // return u2_rl_moot(wir_r, sal_r);
        return u2_rl_malt(wir_r, sal_r);
      }
    }
  }
/* functions
*/
  u2_weak                                                         //  transfer
  j2_mbc(Pt2, scag)(u2_wire wir_r,
                    u2_atom a,                                    //  retain
                    u2_noun b)                                    //  retain
  {
    if ( !u2_fly_is_cat(a) ) {
      return u2_bl_bail(wir_r, c3__fail);
    }
    else {
      u2_noun acc;
      c3_w i_w = a;

      if ( !i_w )
	return u2_nul;

      while ( i_w ) {
        if ( u2_no == u2_dust(b) ) {
          return u2_nul;
        }
	acc = u2_cn_cell( u2_h(b), acc );
	b = u2_t(b);
	i_w--;
      }

      return u2_ckb_flop(acc);
    }
  }
Exemplo n.º 7
0
  static u2_noun                                                  //  produce
  _og_list(u2_wire wir_r,
           u2_noun a,                                             //  retain
           u2_noun b,                                             //  retain
           u2_noun c)                                             //  retain
  {
    u2_noun l = u2_nul;

    if ( !u2_fly_is_cat(b) ) {
      return u2_bl_bail(wir_r, c3__fail);
    }
    while ( 0 != b ) {
      u2_noun x = j2_mbc(Pt3, mix)(wir_r, a, c);
      u2_noun y = j2_mbc(Pt3, mix)(wir_r, b, x);
      u2_noun d = j2_mbc(Pt5, shas)(wir_r, c3_s4('o','g','-','b'), y);
      u2_noun m;

      u2z(x); u2z(y);

      if ( b < 256 ) {
        u2_noun e = j2_mbc(Pt3, end)(wir_r, 0, b, d);
        
        u2z(d);
        m = u2nc(b, e);
        b = 0;
      } else {
        m = u2nc(256, d);
        c = d;

        b -= 256;
      }
      l = u2nc(m, l);
    }
    return u2_ckb_flop(l);
  }
  u2_weak                                                         //  produce
  j2_mbc(Pt5, shal)(u2_wire wir_r,
                    u2_atom a,                                    //  retain
                    u2_atom b)                                    //  retain
  {
    c3_assert(u2_fly_is_cat(a));
    c3_y* fat_y = c3_malloc(a + 1);

    u2_bytes(0, a, fat_y, b);
    {
      c3_y dig_y[64];
#if defined(U2_OS_osx)
      CC_SHA512_CTX ctx_h;

      CC_SHA512_Init(&ctx_h);
      CC_SHA512_Update(&ctx_h, fat_y, a);
      CC_SHA512_Final(dig_y, &ctx_h);
#else
      SHA512_CTX ctx_h;

      SHA512_Init(&ctx_h);
      SHA512_Update(&ctx_h, fat_y, a);
      SHA512_Final(dig_y, &ctx_h);
#endif
      free(fat_y);
      return u2_rl_bytes(wir_r, 64, dig_y);
    }
  }
Exemplo n.º 9
0
Arquivo: shed.c Projeto: Gruelty/urbit
/* 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;
        }
      }
    }
  }
}
/* functions
*/
  u2_weak                                                         //  transfer
  j2_mbc(Pt3, cut)(u2_wire wir_r,
                   u2_atom a,                                     //  retain
                   u2_atom b,                                     //  retain
                   u2_atom c,                                     //  retain
                   u2_atom d)                                     //  retain
  {
    if ( !u2_fly_is_cat(a) || (a >= 32) ) {
      return u2_bl_bail(wir_r, c3__fail);
    }
    if ( !u2_fly_is_cat(b) ) {
      return _0;
    }
    if ( !u2_fly_is_cat(c) ) {
      c = 0x7fffffff;
    }

    {
      c3_g a_g   = a;
      c3_w b_w   = b;
      c3_w c_w   = c;
      c3_w len_w = u2_met(a_g, d);

      if ( (_0 == c_w) || (b_w >= len_w) ) {
        return _0;
      }
      if ( b_w + c_w > len_w ) {
        c_w = (len_w - b_w);
      }
      if ( (b_w == 0) && (c_w == len_w) ) {
        return u2_rx(wir_r, d);
      }
      else {
        u2_ray sal_r = u2_rl_slaq(wir_r, a_g, c_w);

        if ( 0 == sal_r ) {
          return u2_bl_bail(wir_r, c3__fail);
        }
        u2_chop(a_g, b_w, c_w, 0, sal_r, d);

        return u2_rl_malt(wir_r, sal_r);
      }
    }
  }
Exemplo n.º 11
0
Arquivo: met.c Projeto: mnemnion/urbit
/* functions
*/
  u2_weak                                                         //  transfer
  j2_mbc(Pt3, met)(u2_wire wir_r, 
                   u2_atom a,                                     //  retain
                   u2_atom b)                                     //  retain
  {
    if ( !u2_fly_is_cat(a) || (a >= 32) ) {
      if ( _0 == b ) {
        return _0;
      } else return _1;
    }
    else {
      c3_w met_w = u2_met(a, b);

      if ( !u2_fly_is_cat(met_w) ) {
        return u2_rl_words(wir_r, 1, &met_w);
      }
      else return u2_met(a, b);
    }
  }
Exemplo n.º 12
0
  static u2_noun                                                  //  produce
  _last(u2_wire wir_r,
        u2_noun zyc,                                              //  retain
        u2_noun naz)                                              //  retain
  {
    u2_noun p_zyc, q_zyc, p_naz, q_naz;

    u2_bi_cell(wir_r, zyc, &p_zyc, &q_zyc);
    u2_bi_cell(wir_r, naz, &p_naz, &q_naz);

    if ( !u2_fly_is_cat(p_zyc) || !u2_fly_is_cat(q_zyc) ||
         !u2_fly_is_cat(p_naz) || !u2_fly_is_cat(q_naz) )
    {
      return u2_bl_bail(wir_r, c3__fail);
    } else {
      if ( p_zyc == p_naz ) {
        return (q_zyc > q_naz) ? u2_rx(wir_r, zyc) : u2_rx(wir_r, naz);
      }
      else {
        return (p_zyc > p_naz) ? u2_rx(wir_r, zyc) : u2_rx(wir_r, naz);
      }
    }
  }
  u2_weak                                                         //  produce
  j2_mb(Pt5, shal)(u2_wire wir_r,
                   u2_noun cor)                                   //  retain
  {
    u2_noun a, b;

    if ( (u2_none == (a = u2_frag(u2_cv_sam_2, cor))) ||
         (u2_none == (b = u2_frag(u2_cv_sam_3, cor))) ||
         (u2_no == u2_stud(a)) ||
         (u2_no == u2_fly_is_cat(a)) ||
         (u2_no == u2_stud(b)) )
    {
      return u2_bl_bail(wir_r, c3__exit);
    } else {
      return j2_mbc(Pt5, shal)(wir_r, a, b);
    }
  }
Exemplo n.º 14
0
Arquivo: dash.c Projeto: MacTop/urbit
/* 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;
      }
    }
  }
}
Exemplo n.º 15
0
Arquivo: slag.c Projeto: Gruelty/urbit
/* functions
*/
  u2_weak                                                         //  transfer
  j2_mbc(Pt2, slag)(u2_wire wir_r, 
                    u2_atom a,                                    //  retain
                    u2_noun b)                                    //  retain
  {
    if ( !u2_fly_is_cat(a) ) {
      return u2_bl_bail(wir_r, c3__fail);
    }
    else {
      c3_w len_w = a;

      while ( len_w ) {
        if ( u2_no == u2_dust(b) ) {
          return u2_nul;
        }
        b = u2_t(b);
        len_w--;
      }
      return u2_rx(wir_r, b);
    }
  }
Exemplo n.º 16
0
/* _http_octs_to_bod(): translate octet-stream noun into body.
*/
static u2_hbod*
_http_octs_to_bod(u2_noun oct)
{
  c3_w len_w;

  if ( !u2_fly_is_cat(u2h(oct)) ) {
    //  2GB max
    u2_cm_bail(c3__fail); return 0;
  }
  len_w = u2h(oct);

  {
    u2_hbod* bod_u = c3_malloc(len_w + sizeof(*bod_u));

    bod_u->len_w = len_w;
    u2_cr_bytes(0, len_w, bod_u->hun_y, u2t(oct));

    bod_u->nex_u = 0;

    u2z(oct);
    return bod_u;
  }
}
/* functions
*/
  u2_weak                                                         //  transfer
  j2_mbc(Pt3, rap)(u2_wire wir_r,
                   u2_atom a,                                     //  retain
                   u2_noun b)                                     //  retain
  {
    if ( !u2_fly_is_cat(a) || (a >= 32) ) {
      return u2_bl_bail(wir_r, c3__exit);
    }
    else {
      c3_g   a_g = a;
      c3_w   tot_w = 0;
      u2_ray sal_r;

      /* Measure and validate the slab required.
      */
      {
        u2_noun cab = b;

        while ( 1 ) {
          u2_noun h_cab;
          c3_w    len_w;

          if ( _0 == cab ) {
            break;
          }
          else if ( u2_no == u2_dust(cab) ) {
            return u2_bl_bail(wir_r, c3__exit);
          }
          else if ( u2_no == u2_stud(h_cab = u2_h(cab)) ) {
            return u2_bl_bail(wir_r, c3__exit);
          }
          else if ( (tot_w + (len_w = u2_met(a_g, h_cab))) < tot_w ) {
            return u2_bl_bail(wir_r, c3__fail);
          }
          tot_w += len_w;
          cab = u2_t(cab);
        }
        if ( 0 == tot_w ) {
          return _0;
        }
        if ( 0 == (sal_r = u2_rl_slaq(wir_r, a_g, tot_w)) ) {
          return u2_bl_bail(wir_r, c3__fail);
        }
      }

      /* Chop the list atoms in.
      */
      {
        u2_noun cab = b;
        c3_w    pos_w = 0;

        while ( _0 != cab ) {
          u2_noun h_cab = u2_h(cab);
          c3_w    len_w = u2_met(a_g, h_cab);

          u2_chop(a_g, 0, len_w, pos_w, sal_r, h_cab);
          pos_w += len_w;
          cab = u2_t(cab);
        }
      }
      // return u2_rl_moot(wir_r, sal_r);
      return u2_rl_malt(wir_r, sal_r);
    }
  }