예제 #1
0
파일: http.c 프로젝트: jpt4/urbit
/* _http_octs_to_bod(): translate octet-stream noun into body.
*/
static u3_hbod*
_http_octs_to_bod(u3_noun oct)
{
  c3_w len_w;

  if ( !_(u3a_is_cat(u3h(oct))) ) {
    //  2GB max
    u3m_bail(c3__fail); return 0;
  }
  len_w = u3h(oct);

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

    bod_u->len_w = len_w;
    u3r_bytes(0, len_w, bod_u->hun_y, u3t(oct));

    bod_u->nex_u = 0;

    u3z(oct);
    return bod_u;
  }
}
예제 #2
0
파일: po.c 프로젝트: Gunga/urbit
  u3_noun
  u3wcp_ins(u3_noun cor)
  {
    u3_noun x, a, buf;

    if ( (c3n == u3r_mean(cor, u3x_sam, &a, u3x_con_sam, &x, 0)) ||
         (c3n == u3du(x)) ||
         (c3n == u3ud(buf = u3h(x))) ||
         (c3n == u3ud(a)) )
    {
      return u3m_bail(c3__exit);
    } else {
      return _po_find(buf, a);
    }
  }
예제 #3
0
파일: nock.c 프로젝트: OCForks/urbit
/* u3n_slam_on(): produce (gat sam).
*/
u3_noun
u3n_slam_on(u3_noun gat, u3_noun sam)
{
  u3_noun cor = u3nc(u3k(u3h(gat)), u3nc(sam, u3k(u3t(u3t(gat)))));

#if 0
  if ( &u3H->rod_u == u3R ) {
    if ( exc_w == 1 ) {
      c3_assert(0);
    } 
    exc_w++;
  }
#endif
  u3z(gat);
  return u3n_kick_on(cor);
}
예제 #4
0
파일: loss.c 프로젝트: alecbrick/urbit
  //  compute lcs
  //
  static void
  _loss(u3_loss* loc_u)
  {
    while ( u3_nul != loc_u->hel ) {
      u3_noun i_hel = u3h(loc_u->hel);
      u3_noun guy   = u3kdb_get(u3k(loc_u->sev), u3k(i_hel));

      if ( u3_none != guy ) {
        u3_noun gay = u3kb_flop(guy);

        _merg(loc_u, 0, gay);
        u3z(gay);
      }

      loc_u->hel = u3t(loc_u->hel);
    }
  }
예제 #5
0
파일: nock.c 프로젝트: OCForks/urbit
/* _n_mush_in(): see _n_mush().
*/
static u3_noun
_n_mush_in(u3_noun val)
{
  if ( c3n == u3du(val) ) {
    return u3_nul;
  }
  else {
    u3_noun h_val = u3h(val);
    u3_noun ite;

    if ( c3n == u3ud(h_val) ) {
      ite = u3nc(c3__leaf, u3_nul);
    } else {
      ite = u3nc(c3__leaf, u3qe_trip(h_val));
    }
    return u3nc(ite, _n_mush_in(u3t(val)));
  }
}
예제 #6
0
파일: ap.c 프로젝트: OCForks/urbit
    static u3_noun
    _sgcn_a(u3_noun r_gen,
            u3_noun nob)
    {
      if ( c3n == u3du(r_gen) ) {
        return u3k(nob);
      } else {
        u3_noun ir_gen = u3h(r_gen);
        u3_noun tr_gen = u3t(r_gen);
        u3_noun pir_gen, qir_gen;

        u3x_cell(ir_gen, &pir_gen, &qir_gen);

        return u3nc(u3nc(u3nt(c3__dtzz, u3_blip, u3k(pir_gen)),
                         u3nc(c3__zpts, u3k(qir_gen))),
                    _sgcn_a(tr_gen, nob));
      }
    }
예제 #7
0
파일: loss.c 프로젝트: alecbrick/urbit
  //  initialize loss object
  //
  static void
  _lemp(u3_loss* loc_u,
        u3_noun  hel,
        u3_noun  hev)
  {
    loc_u->hel = hel;
    loc_u->lel_w = u3kb_lent(u3k(hel));

    //  Read hev into array.
    {
      c3_w i_w;

      loc_u->hev = c3_malloc(u3kb_lent(u3k(hev)) * sizeof(u3_noun));

      for ( i_w = 0; u3_nul != hev; i_w++ ) {
        loc_u->hev[i_w] = u3h(hev);
        hev = u3t(hev);
      }
      loc_u->lev_w = i_w;
    }
    loc_u->kct_w = 0;
    loc_u->kad = c3_malloc(
                              (1 + c3_min(loc_u->lev_w, loc_u->lel_w)) *
                              sizeof(u3_noun));

    //  Compute equivalence classes.
    //
    loc_u->sev = u3_nul;
    {
      c3_w i_w;

      for ( i_w = 0; i_w < loc_u->lev_w; i_w++ ) {
        u3_noun how = loc_u->hev[i_w];
        u3_noun hav;
        u3_noun teg;

        hav = u3kdb_get(u3k(loc_u->sev), u3k(how));
        teg = u3nc(u3i_words(1, &i_w),
                          (hav == u3_none) ? u3_nul : hav);
        loc_u->sev = u3kdb_put(loc_u->sev, u3k(how), teg);
      }
    }
  }
예제 #8
0
파일: ut_crop.c 프로젝트: agentultra/urbit
  static u3_noun
  _crop_sint(
             u3_noun van,
             u3_noun sut,
             u3_noun ref,
             u3_noun bix)
  {
    u3_noun p_ref, q_ref;

    switch ( u3h(ref) ) {
      default: return u3m_bail(c3__fail);

      case c3__bull: u3x_cell(u3t(ref), &p_ref, &q_ref);
      {
        return _crop_dext(van, sut, q_ref, bix);
      }
      case c3__core:
      case c3__cube: {
        return u3k(sut);
      }
      case c3__face: u3x_cell(u3t(ref), &p_ref, &q_ref);
      {
        return _crop_dext(van, sut, q_ref, bix);
      }
      case c3__fork: u3x_cell(u3t(ref), &p_ref, &q_ref);
      {
        u3_noun hin = _crop_dext(van, sut, p_ref, bix);
        u3_noun ret = _crop_dext(van, hin, q_ref, bix);

        u3z(hin);
        return ret;
      }
      case c3__hold: p_ref = u3t(ref);
      {
        u3_noun rep = u3qfu_repo(van, ref);
        u3_noun ret = _crop_dext(van, sut, rep, bix);

        u3z(rep);
        return ret;
      }
    }
  }
예제 #9
0
파일: po.c 프로젝트: Gunga/urbit
  u3_noun
  u3wcp_tos(u3_noun cor)
  {
    u3_noun x, a, buf;

    if ( (c3n == u3r_mean(cor, u3x_sam, &a, u3x_con_sam, &x, 0)) ||
         (c3n == u3du(x)) ||
         (c3n == u3ud(buf = u3h(x))) ||
         (c3n == u3ud(a)) ||
         (a >= 256) )
    {
      return u3m_bail(c3__exit);
    }
    else {
      c3_y byt_y[3];

      u3r_bytes((a * 3), 3, byt_y, buf);
      return (byt_y[0] | (byt_y[1] << 8) | (byt_y[2] << 16));
    }
  }
예제 #10
0
파일: parse.c 프로젝트: Gunga/urbit
/* just
*/
  u3_noun
  _cqe_just_fun(u3_noun daf,
                u3_noun tub)
  {
    u3_noun p_tub, q_tub;

    u3x_cell(tub, &p_tub, &q_tub);

    if ( c3n == u3du(q_tub) ) {
      return _fail(tub);
    }
    else {
      u3_noun iq_tub = u3h(q_tub);

      if ( c3y == u3r_sing(daf, iq_tub) ) {
        return _next(tub);
      }
      else return _fail(tub);
    }
  }
예제 #11
0
파일: ap.c 프로젝트: OCForks/urbit
    static u3_noun
    _smcl_in(u3_noun q_gen)
    {
      u3_noun hq_gen = u3h(q_gen);
      u3_noun tq_gen = u3t(q_gen);

      if ( c3n == u3du(tq_gen) ) {
        return u3nt(c3__tsgr,
                    u3nc(u3_nul, 3),
                    u3k(hq_gen));
      } else {
        return u3nc(c3__cnhp,
                    u3nq(u3nc(u3_nul, 2),
                         u3nt(c3__tsgr,
                              u3nc(u3_nul, 3),
                              u3k(hq_gen)),
                         _smcl_in(tq_gen),
                         u3_nul));
      }
    }
예제 #12
0
파일: ut_fish.c 프로젝트: OCForks/urbit
  static u3_noun
  _fish_fork(u3_noun van,
             u3_noun p_sut,
             u3_atom axe,
             u3_noun vit)
  {
    if ( u3_nul == p_sut ) {
      return u3nc(1, 1);
    } 
    else {
      u3_noun hed = _fish_in(van, u3h(p_sut), axe, vit);
      u3_noun tal = _fish_fork(van, u3t(p_sut), axe, vit);
      u3_noun pro = u3qf_flor(hed, tal);

      u3z(hed);
      u3z(tal);

      return pro;
    }
  }
예제 #13
0
파일: sist.c 프로젝트: wrmsr/urbit
/* _sist_suck(): past failure.
*/
static void
_sist_suck(u3_noun ovo, u3_noun gon)
{
  uL(fprintf(uH, "sing: ovum failed!\n"));
  {
    c3_c* hed_c = u3r_string(u3h(u3t(ovo)));

    uL(fprintf(uH, "fail %s\n", hed_c));
    free(hed_c);
  }

  u3_lo_punt(2, u3kb_flop(u3k(u3t(gon))));
  // u3_loom_exit();
#if 1
  u3_lo_exit();

  exit(1);
#else
  u3z(ovo); u3z(gon);
#endif
}
예제 #14
0
파일: unix.c 프로젝트: juped/your-urbit
/* _unix_write_file_hard(): write to a file, overwriting what's there
*/
static c3_w
_unix_write_file_hard(c3_c* pax_c, u3_noun mim)
{
    c3_i  fid_i = open(pax_c, O_WRONLY | O_CREAT | O_TRUNC, 0666);
    c3_w  len_w, rit_w, siz_w, mug_w = 0;
    c3_y* dat_y;

    u3_noun dat = u3t(u3t(mim));

    if ( fid_i < 0 ) {
        uL(fprintf(uH, "error opening %s for writing: %s\r\n",
                   pax_c, strerror(errno)));
        u3z(mim);
        return 0;
    }

    siz_w = u3h(u3t(mim));
    len_w = u3r_met(3, dat);
    dat_y = c3_malloc(siz_w);
    memset(dat_y, 0, siz_w);

    u3r_bytes(0, len_w, dat_y, dat);
    u3z(mim);

    rit_w = write(fid_i, dat_y, siz_w);

    if ( rit_w != siz_w ) {
        uL(fprintf(uH, "error writing %s: %s\r\n",
                   pax_c, strerror(errno)));
        mug_w = 0;
    }
    else {
        mug_w = u3r_mug_bytes(dat_y, len_w);
    }

    close(fid_i);
    free(dat_y);

    return mug_w;
}
예제 #15
0
파일: ap.c 프로젝트: OCForks/urbit
  /** rake
  **/
    u3_noun
    u3qfp_rake(u3_noun gen)
    {
      u3_noun p_gen, q_gen;

      if ( c3y == u3ud(gen) ) {
        return u3nc(u3k(gen), u3_nul);
      }
      else switch ( u3h(gen) ) {
        default: return u3m_error("rake-twig");

        case u3_nul:  return u3nc(u3k(gen), u3_nul);

        case c3__cnzy: {
          return u3nc(u3k(u3t(gen)), u3_nul);
        }
        case c3__cnzz: {
          return u3k(u3t(gen));
        }
        case c3__cnts: {
          if ( c3n == u3r_cell(u3t(gen), &p_gen, &q_gen) ) {
            return u3m_bail(c3__fail);
          }
          else {
            if ( u3_nul != q_gen ) {
              return u3m_bail(c3__fail);
            }
            else {
              return u3k(p_gen);
            }
          }
        }
        case c3__zpcb: {
          if ( c3n == u3r_cell(u3t(gen), &p_gen, &q_gen) ) {
            return u3m_bail(c3__fail);
          }
          else return u3qfp_rake(q_gen);
        }
      }
    }
예제 #16
0
파일: flip.c 프로젝트: aulux/urbit
/* functions
*/
  u3_noun
  u3qf_flip(
                    u3_noun hel)
  {
    if ( c3y == u3r_sing(1, u3h(hel)) ) {
      if ( (c3y == u3t(hel)) ) {
        return u3nc(1, c3n);
      }
      else {
        c3_assert((c3n == u3t(hel)));

        return u3nc(1, c3y);
      }
    }
    else {
      return u3nq
        (6,
               u3k(hel),
               u3nc(1, c3n),
               u3nc(1, c3y));
    }
  }
예제 #17
0
파일: ut_mint.c 프로젝트: agentultra/urbit
  static u3_noun
  _mint_cond(
             u3_noun pex,
             u3_noun yom,
             u3_noun woq)
  {
    if ( 1 == u3h(pex) ) {
      if ( 0 == u3t(pex) ) {
        u3z(pex);
        u3z(woq);

        return yom;
      }
      else if ( 1 == u3t(pex) ) {
        u3z(pex);
        u3z(yom);

        return woq;
      }
    }
    return u3nq(6, pex, yom, woq);
  }
예제 #18
0
파일: snag.c 프로젝트: OCForks/urbit
/* functions
*/
  u3_noun
  u3qb_snag(u3_atom a,
            u3_noun b)
  {
    if ( !_(u3a_is_cat(a)) ) {
      return u3m_bail(c3__fail);
    }
    else {
      c3_w len_w = a;

      while ( len_w ) {
        if ( c3n == u3du(b) ) {
          return u3m_bail(c3__exit);
        }
        b = u3t(b);
        len_w--;
      }
      if ( c3n == u3du(b) ) {
        return u3m_bail(c3__exit);
      }
      return u3k(u3h(b));
    }
  }
예제 #19
0
파일: parse.c 프로젝트: Gunga/urbit
  static u3_noun
  _next(u3_noun tub)
  {
    u3_noun p_tub, q_tub;
    u3_noun zac;

    u3x_cell(tub, &p_tub, &q_tub);
    if ( c3n == u3du(q_tub) ) {
      return _fail(tub);
    }
    else {
      u3_noun iq_tub = u3h(q_tub);
      u3_noun tq_tub = u3t(q_tub);

      zac = _slip(iq_tub, p_tub);

      return u3nc(zac,
                  u3nq(u3_nul,
                       u3k(iq_tub),
                       u3k(zac),
                       u3k(tq_tub)));
    }
  }
예제 #20
0
파일: ut_play.c 프로젝트: OCForks/urbit
 static u3_noun
 _play_sand(u3_noun odo, u3_noun bob)
 { 
   if ( c3y == u3ud(bob) ) {
     if ( 'n' == odo ) {
       if ( (bob != 0) ) {
         return u3m_bail(c3__exit);
       } else {
         return u3nq(c3__atom, odo, u3_nul, bob);
       }
     }
     if ( 'f' == odo ) {
       if ( (bob > 1) ) {
         return u3m_bail(c3__exit);
       } else {
         return _play_bean();
       }
     }
     return u3nt(c3__atom, u3k(odo), u3_nul);
   }
   else return u3nt(c3__cell, _play_rock(odo, u3h(bob)), 
                              _play_rock(odo, u3t(bob)));
 }
예제 #21
0
파일: term.c 프로젝트: laanwj/urbit
/* u3_term_ef_blit(): send %blit list to specific terminal.
*/
void
u3_term_ef_blit(c3_l     tid_l,
                u3_noun  bls)
{
  u3_utty* uty_u = _term_ef_get(tid_l);

  if ( 0 == uty_u ) {
    // uL(fprintf(uH, "no terminal %d\n", tid_l));
    // uL(fprintf(uH, "uty_u %p\n", u3_Host.uty_u));

    u3z(bls); return;
  }

  {
    u3_noun bis = bls;

    while ( c3y == u3du(bis) ) {
      _term_ef_blit(uty_u, u3k(u3h(bis)));
      bis = u3t(bis);
    }
    u3z(bls);
  }
}
예제 #22
0
파일: sist.c 프로젝트: wrmsr/urbit
/* _sist_sing(): replay ovum from the past, time already set.
*/
static void
_sist_sing(u3_noun ovo)
{
  u3_noun gon = u3m_soft(0, u3v_poke, u3k(ovo));

  if ( u3_blip != u3h(gon) ) {
    _sist_suck(ovo, gon);
  }
  else {
    u3_noun vir = u3k(u3h(u3t(gon)));
    u3_noun cor = u3k(u3t(u3t(gon)));
    u3_noun nug;

    u3z(gon);
    nug = u3v_nick(vir, cor);

    if ( u3_blip != u3h(nug) ) {
      _sist_suck(ovo, nug);
    }
    else {
      vir = u3h(u3t(nug));
      cor = u3k(u3t(u3t(nug)));

      while ( u3_nul != vir ) {
        u3_noun fex = u3h(vir);
        u3_noun fav = u3t(fex);

        if ( (c3__init == u3h(fav)) || (c3__inuk == u3h(fav)) ) {
          u3A->own = u3nc(u3k(u3t(fav)), u3A->own);
        }
        vir = u3t(vir);
      }
      u3z(nug);
      u3z(u3A->roc);
      u3A->roc = cor;
    }
    u3z(ovo);
  }
}
예제 #23
0
파일: parse.c 프로젝트: Gunga/urbit
/* stew
*/
  static u3_noun
  _stew_wor(u3_noun ort,
            u3_noun wan)
  {
    if ( !_(u3a_is_cat(ort)) ) {
      return u3m_bail(c3__fail);
    }
    else {
      if ( c3n == u3du(wan) ) {
        if ( !_(u3a_is_cat(wan)) ) {
          return u3m_bail(c3__fail);
        }
        else return (ort < wan) ? c3y : c3n;
      }
      else {
        u3_noun h_wan = u3h(wan);

        if ( !_(u3a_is_cat(h_wan)) ) {
          return u3m_bail(c3__fail);
        }
        else return (ort < h_wan) ? c3y : c3n;
      }
    }
  }
예제 #24
0
파일: ut_mint.c 프로젝트: agentultra/urbit
  static u3_noun
  _mint_grow(
             u3_noun van,
             u3_noun sut,
             u3_noun gol,
             u3_atom mel,
             u3_noun ruf,
             u3_noun dab)
  {
    u3_noun dan = _mint_in(van, sut, c3__noun, ruf);
    u3_noun p_dan = u3h(dan);
    u3_noun q_dan = u3t(dan);
    u3_noun toc = _mint_core
      (u3k(p_dan),
              u3nt(c3__gold,
                           u3k(p_dan),
                           u3nc(u3_nul, u3k(dab))));
    u3_noun dez = _mint_bake(van, toc, dab);
    u3_noun zod = u3nc(1, dez);
    u3_noun cot = _mint_core
      (u3k(p_dan),
              u3nt(mel,
                           u3k(p_dan),
                           u3nc(u3k(dez),
                                        u3k(dab))));
    u3_noun ret = u3nc
      (
       _mint_nice(van, gol, cot),
       u3qf_cons(zod, q_dan));

    u3z(zod);
    u3z(toc);
    u3z(dan);

    return ret;
  }
예제 #25
0
파일: loss.c 프로젝트: alecbrick/urbit
  static void
  _merg(u3_loss* loc_u,
        c3_w     inx_w,
        u3_noun  gay)
  {
    if ( (u3_nul == gay) || (inx_w > loc_u->kct_w) ) {
      return;
    }
    else {
      u3_noun i_gay = u3h(gay);
      c3_w    goy_w = u3r_word(0, i_gay);
      u3_noun bik;

      bik = _bink(loc_u, &inx_w, loc_u->kct_w, goy_w);

      if ( c3y == bik ) {
        _merg(loc_u, inx_w + 1, u3t(gay));
        _lune(loc_u, inx_w, goy_w);
      }
      else {
        _merg(loc_u, inx_w, u3t(gay));
      }
    }
  }
예제 #26
0
파일: by_put.c 프로젝트: Gunga/urbit
/* functions
*/
  u3_noun
  u3qdb_put(u3_noun a,
            u3_noun b,
            u3_noun c)
  {
    if ( u3_nul == a ) {
      return u3nt(
                   u3nc(u3k(b),
                                u3k(c)),
                   u3_nul,
                   u3_nul);
    }
    else {
      u3_noun l_a, n_a, r_a, pn_a, qn_a;
      u3_noun d, l_d, n_d, r_d;

      if ( (c3n == u3r_trel(a, &n_a, &l_a, &r_a)) ||
           (c3n == u3r_cell(n_a, &pn_a, &qn_a)) )
      {
        return u3m_bail(c3__exit);
      }
      else if ( c3y == u3r_sing(pn_a, b) ) {
        if ( c3y == u3r_sing(qn_a, c) ) {
          return u3k(a);
        } else {
          return u3nt
            (u3nc(u3k(b), u3k(c)),
                    u3k(l_a),
                    u3k(r_a));
        }
      }
      else {
        if ( c3y == u3qc_gor(b, pn_a) ) {
          d = u3qdb_put(l_a, b, c);

          if ( c3y == u3qc_vor(pn_a, u3h(u3h(d))) ) {
            return u3nt(u3k(n_a),
                                d,
                                u3k(r_a));
          }
          else {
            u3r_trel(d, &n_d, &l_d, &r_d);
            {
              u3_noun e = u3nt
                (u3k(n_d),
                 u3k(l_d),
                 u3nt(u3k(n_a),
                      u3k(r_d),
                      u3k(r_a)));

              u3z(d);
              return e;
            }
          }
        }
        else {
          d = u3qdb_put(r_a, b, c);

          if ( c3y == u3qc_vor(pn_a, u3h(u3h(d))) ) {
            return u3nt(u3k(n_a),
                        u3k(l_a),
                        d);
          }
          else {
            u3r_trel(d, &n_d, &l_d, &r_d);
            {
              u3_noun e = u3nt
                (u3k(n_d),
                 u3nt(u3k(n_a),
                      u3k(l_a),
                      u3k(l_d)),
                      u3k(r_d));

              u3z(d);
              return e;
            }
          }
        }
      }
    }
  }
예제 #27
0
파일: nock.c 프로젝트: OCForks/urbit
/* _n_hint(): process hint.
*/
static u3_noun
_n_hint(u3_noun zep, 
        u3_noun hod,
        u3_noun bus,
        u3_noun nex)
{
  switch ( zep ) {
    default: {
      // u3m_p("weird zep", zep);
      u3a_lose(zep);
      u3a_lose(hod);

      return _n_nock_on(bus, nex);
    }

    case c3__hunk:
    case c3__lose:
    case c3__mean:
    case c3__spot: {
      u3_noun tac = u3nc(zep, hod);
      u3_noun pro;

      u3t_push(tac);
#if 0
      {
        static int low_i;

        if ( !low_i ) {
          low_i = 1;
          if ( 0 == (u3R->pro.nox_d % 65536ULL) ) {
            if ( c3__spot == zep ) {
              uL(fprintf(uH, "spot %d/%d : %d/%d\r\n",
                             u3h(u3h(u3t(hod))),
                             u3t(u3h(u3t(hod))),
                             u3h(u3t(u3t(hod))),
                             u3t(u3t(u3t(hod)))));
            }
          }
          low_i = 0;
        }
      }
#endif
      pro = _n_nock_on(bus, nex);
      u3t_drop();

      return pro;
    }

    case c3__live: {
      if ( c3y == u3ud(hod) ) {
        u3t_off(noc_o);
        u3t_heck(hod);
        u3t_on(noc_o);
      } else {
        u3z(hod);
      }
      return _n_nock_on(bus, nex);
    }

    case c3__slog: {
      if ( !(u3C.wag_w & u3o_quiet) ) {
        u3t_off(noc_o);
        u3t_slog(hod);
        u3t_on(noc_o);
      }
      return _n_nock_on(bus, nex);
    }

    case c3__germ: {
      u3_noun pro = _n_nock_on(bus, nex);

      if ( c3y == u3r_sing(pro, hod) ) {
        u3z(pro); return hod;
      } else {
        u3z(hod); return pro;
      }
    }

    case c3__fast: {
      u3_noun pro = _n_nock_on(bus, nex);

      u3t_off(noc_o);
      u3j_mine(hod, u3k(pro));
      u3t_on(noc_o);

      return pro;
    }

    case c3__memo: {
      u3z(hod);
#if 0
      return _n_nock_on(bus, nex);
#else
      {
        u3_noun pro = u3z_find_2(c3__nock, bus, nex);

        if ( pro != u3_none ) {
          u3z(bus); u3z(nex);
          return pro;
        }
        pro = _n_nock_on(u3k(bus), u3k(nex));

        if ( &(u3H->rod_u) != u3R ) {
          u3z_save_2(c3__nock, bus, nex, pro);
        }

        u3z(bus); u3z(nex);

        return pro;
      }
#endif
    }

    case c3__sole: {
      u3z(hod);
      {
        u3_noun pro = _n_nock_on(bus, nex);

        // return u3z_uniq(pro);
        return pro;
      }
    }
  }
}
예제 #28
0
파일: ut_play.c 프로젝트: Gunga/urbit
  static u3_noun
  _play_in(u3_noun van,
           u3_noun sut,
           u3_noun gen)
  {
    u3_noun p_gen, q_gen, r_gen;

    if ( c3n == u3du(gen) ) {
      open: {
        u3_noun ter = u3r_at(u3x_con_3, van);
        u3_noun rex = u3qfp_open(ter, gen);
        u3_noun ret;

        if ( c3y == u3r_sing(rex, gen) ) {
          u3_noun zix = u3qfu_shep(van, "gene", 'q', u3k(gen));

          u3t_push(u3nc(c3__mean, zix));
          return u3m_error("play-open");
        }
        ret = _play_x(van, sut, rex);
        u3z(rex);

        return ret;
      }
    }
    else if ( c3y == u3du(u3h(gen)) ) {
      _play_used();
      {
        u3_noun dis = _play_x(van, sut, u3h(gen));
        u3_noun dat = _play_x(van, sut, u3t(gen));
        u3_noun ret = u3qf_cell(dis, dat);

        u3z(dis);
        u3z(dat);
        return ret;
      }
    }
    else switch ( u3h(gen) ) {
      default: goto open;

      case c3__bcpt: u3x_cell(u3t(gen), &p_gen, &q_gen);
      _play_used();
      {
        u3_noun sep = u3qfu_seep(van, sut, c3__read, p_gen);
        u3_noun axe = u3h(sep);
        u3_noun rex = u3qfl_whip(van, q_gen, axe);
        u3_noun ret = _play_x(van, sut, rex);

        u3z(sep);
        u3z(rex);

        return ret;
      }
      case c3__wtts: u3x_cell(u3t(gen), &p_gen, &q_gen);
      _play_used();
      {
        return _play_bean();
      }
      case c3__wtcl: u3x_trel(u3t(gen), &p_gen, &q_gen, &r_gen);
      _play_used();
      {
        u3_noun fex = u3qfu_gain(van, sut, p_gen);
        u3_noun wux = u3qfu_lose(van, sut, p_gen);
        u3_noun dez = (fex == c3__void) ? c3__void
                                        : _play_x(van, fex, q_gen);
        u3_noun doz = (wux == c3__void) ? c3__void
                                        : _play_x(van, wux, r_gen);
        u3_noun ret = u3qf_fork(dez, doz);

        u3z(dez); u3z(doz);
        u3z(fex); u3z(wux);
        return ret;
      }
      case c3__clhp: u3x_cell(u3t(gen), &p_gen, &q_gen);
      _play_used();
      {
        u3_noun dis = _play_x(van, sut, p_gen);
        u3_noun dat = _play_x(van, sut, q_gen);
        u3_noun ret = u3qf_cell(dis, dat);

        u3z(dis);
        u3z(dat);
        return ret;
      }
      case c3__dtkt: p_gen = u3t(gen);
      _play_used();
      {
        return c3__noun;
      }
      case c3__dtwt: p_gen = u3t(gen);
      _play_used();
      {
        return _play_bean();
      }
      case c3__dtts: u3x_cell(u3t(gen), &p_gen, &q_gen);
      _play_used();
      {
        return _play_bean();
      }
      case c3__dtls: p_gen = u3t(gen);
      _play_used();
      {
        return u3nc(c3__atom, u3_blip);
      }
      case c3__dtzz: u3x_cell(u3t(gen), &p_gen, &q_gen);
      _play_used();
      {
        u3_noun boc = (c3n == u3ud(q_gen))
                        ? c3__noun
                        : u3nc(c3__atom, u3k(p_gen));
        u3_noun ret = u3qf_cube(q_gen, boc);

        u3z(boc);
        return ret;
      }
      case c3__dttr: u3x_cell(u3t(gen), &p_gen, &q_gen);
      _play_used();
      {
        return c3__noun;
      }
      case c3__dtzy: u3x_cell(u3t(gen), &p_gen, &q_gen);
      _play_used();
      {
        if ( 'f' == p_gen ) {
          if ( (q_gen > 1) ) {
            return u3m_bail(c3__exit);
          } else {
            return _play_bean();
          }
        }
        else return u3nc(c3__atom, u3k(p_gen));
      }
      case c3__ktbr: p_gen = u3t(gen);
      _play_used();
      {
        u3_noun boc = _play_x(van, sut, p_gen);
        u3_noun pro = u3qfu_wrap(van, boc, c3__iron);

        u3z(boc);
        return pro;
      }
      case c3__ktpm: p_gen = u3t(gen);
      _play_used();
      {
        u3_noun boc = _play_x(van, sut, p_gen);
        u3_noun pro = u3qfu_wrap(van, boc, c3__zinc);

        u3z(boc);
        return pro;
      }
      case c3__ktwt: p_gen = u3t(gen);
      _play_used();
      {
        u3_noun boc = _play_x(van, sut, p_gen);
        u3_noun pro = u3qfu_wrap(van, boc, c3__lead);

        u3z(boc);
        return pro;
      }
      case c3__ktts: u3x_cell(u3t(gen), &p_gen, &q_gen);
      _play_used();
      {
        u3_noun boc = _play_x(van, sut, q_gen);
        u3_noun ret = u3qfu_conk(van, boc, p_gen);

        u3z(boc);
        return ret;
      }
      case c3__ktzp: u3x_cell(u3t(gen), &p_gen, &q_gen);
      _play_used();
      {
        u3_noun boc = _play_x(van, sut, q_gen);
        u3_noun ret = u3qfu_conk(van, boc, p_gen);

        u3z(boc);
        return ret;
      }
      case c3__ktsg: p_gen = u3t(gen);
      _play_used();
      {
        return _play_x(van, sut, p_gen);
      }
      case c3__kthx: u3x_cell(u3t(gen), &p_gen, &q_gen);
      _play_used();
      {
        return _play_x(van, sut, p_gen);
      }
      case c3__ktls: u3x_cell(u3t(gen), &p_gen, &q_gen);
      _play_used();
      {
        return _play_x(van, sut, p_gen);
      }
      case c3__tsgr: u3x_cell(u3t(gen), &p_gen, &q_gen);
      _play_used();
      {
        u3_noun boc = _play_x(van, sut, p_gen);
        u3_noun ret = _play_x(van, boc, q_gen);

        u3z(boc);
        return ret;
      }
      case c3__tstr: u3x_trel(u3t(gen), &p_gen, &q_gen, &r_gen);
      _play_used();
      {
        u3_noun sep = u3qfu_seep(van, sut, c3__both, q_gen);
        u3_noun bid = u3nt(u3k(p_gen), u3k(q_gen), sep);
        u3_noun boc = u3qf_bull(bid, sut);
        u3_noun ret = _play_x(van, boc, r_gen);

        u3z(bid);
        u3z(boc);

        return ret;
      }
      case c3__cnts: u3x_cell(u3t(gen), &p_gen, &q_gen);
      _play_used();
      {
        u3_noun sec = u3qfu_seek(van, sut, c3__read, p_gen);
        u3_noun lar = _play_foil(sec);
        u3_noun q_lar = u3t(lar);
        u3_noun qq_lar = u3t(q_lar);
        u3_noun mew = u3qfu_snub(van, sut, q_gen);
        u3_noun rag = _play_edit(van, sut, mew, u3k(qq_lar));
        u3_noun ret = u3qfu_fire(van, sut, rag);

        u3z(rag);
        u3z(mew);
        u3z(lar);

        return ret;
      }
      case c3__pmcl: u3x_cell(u3t(gen), &p_gen, &q_gen);
      _play_used();
      {
        u3_noun ruf = u3nt(c3__clhp,
                           u3nc(u3_nul, 1),
                           u3k(p_gen));
        u3_noun ret = _play_grow(van, sut, c3__zinc, ruf, q_gen);

        u3z(ruf);
        return ret;
      }
      case c3__brcn: p_gen = u3t(gen);
      _play_used();
      {
        u3_noun ruf = u3nc(u3_nul, 1);
        u3_noun ret = _play_grow(van, sut, c3__gold, ruf, p_gen);

        u3z(ruf);
        return ret;
      }
      case c3__pmcn: p_gen = u3t(gen);
      _play_used();
      {
        u3_noun ruf = u3nc(u3_nul, 1);
        u3_noun ret = _play_grow(van, sut, c3__lead, ruf, p_gen);

        u3z(ruf);
        return ret;
      }
      case c3__pmls: u3x_cell(u3t(gen), &p_gen, &q_gen);
      _play_used();
      {
        u3_noun ruf = u3nt(c3__clhp,
                           u3nc(u3_nul, 1),
                           u3k(p_gen));
        u3_noun ret = _play_grow(van, sut, c3__iron, ruf, q_gen);

        u3z(ruf);
        return ret;
      }
      case c3__sgzp: u3x_cell(u3t(gen), &p_gen, &q_gen);
      _play_used();
      {
        u3_noun typ = u3qfu_play(van, sut, p_gen);
        u3_noun dug = u3qfu_duck(van, typ);
        u3_noun ret;

        u3t_push(u3nc(c3__mean, dug));
        {
          ret = _play_x(van, sut, q_gen);
        }
        u3t_drop();

        u3z(typ);
        return ret;
      }
      case c3__sggr: u3x_cell(u3t(gen), &p_gen, &q_gen);
      _play_used();
      {
        return _play_x(van, sut, q_gen);
      }
      case c3__zpts: p_gen = u3t(gen);
      _play_used();
      {
        return c3__noun;
      }
      case c3__zpcm: u3x_cell(u3t(gen), &p_gen, &q_gen);
      _play_used();
      {
        return _play_x(van, sut, p_gen);
      }
      case c3__zpcb: u3x_cell(u3t(gen), &p_gen, &q_gen);
      {
        u3_noun ret;

        u3t_push(u3nc(c3__mean, _play_loc(van, p_gen)));
        {
          ret = _play_x(van, sut, q_gen);
        }
        u3t_drop();
        return ret;
      }
      case c3__zpcn:
      _play_used();
      {
        u3_noun pet = u3j_hook(u3k(van), "seed");
        u3_noun ret = u3k(u3h(pet));

        u3z(pet);
        return ret;
      }
      case c3__zpsm: u3x_cell(u3t(gen), &p_gen, &q_gen);
      _play_used();
      {
        u3_noun zur = _play_x(van, sut, p_gen);
        u3_noun vos = _play_x(van, sut, q_gen);
        u3_noun ret = u3qf_cell(zur, vos);

        u3z(zur);
        u3z(vos);

        return ret;
      }
      case c3__zpfs:
      case c3__zpzp:
      _play_used();
      {
        return c3__void;
      }
    }
  }
예제 #29
0
파일: nock.c 프로젝트: OCForks/urbit
/* _n_nock_on(): produce .*(bus fol).  Do not virtualize.
*/
static u3_noun
_n_nock_on(u3_noun bus, u3_noun fol)
{
  u3_noun hib, gal;

  while ( 1 ) {
    hib = u3h(fol);
    gal = u3t(fol);

    u3R->pro.nox_d += 1;

    if ( c3y == u3r_du(hib) ) {
      u3_noun poz, riv;

      poz = _n_nock_on(u3k(bus), u3k(hib));
      riv = _n_nock_on(bus, u3k(gal));

      u3a_lose(fol);
      return u3i_cell(poz, riv);
    }
    else switch ( hib ) {
      default: return u3m_bail(c3__exit);

      case 0: {
        if ( c3n == u3r_ud(gal) ) {
          return u3m_bail(c3__exit);
        }
        else {
          u3_noun pro = u3k(u3at(gal, bus));

          u3a_lose(bus); u3a_lose(fol);
          return pro;
        }
      }
      c3_assert(!"not reached");

      case 1: {
        u3_noun pro = u3k(gal);

        u3a_lose(bus); u3a_lose(fol);
        return pro;
      }
      c3_assert(!"not reached");

      case 2: {
        u3_noun nex = _n_nock_on(u3k(bus), u3k(u3t(gal)));
        u3_noun seb = _n_nock_on(bus, u3k(u3h(gal)));

        u3a_lose(fol);
        bus = seb;
        fol = nex;
        continue;
      }
      c3_assert(!"not reached");

      case 3: {
        u3_noun gof, pro;

        gof = _n_nock_on(bus, u3k(gal));
        pro = u3r_du(gof);

        u3a_lose(gof); u3a_lose(fol);
        return pro;
      }
      c3_assert(!"not reached");

      case 4: {
        u3_noun gof, pro;

        gof = _n_nock_on(bus, u3k(gal));
        pro = u3i_vint(gof);

        u3a_lose(fol);
        return pro;
      }
      c3_assert(!"not reached");

      case 5: {
        u3_noun wim = _n_nock_on(bus, u3k(gal));
        u3_noun pro = u3r_sing(u3h(wim), u3t(wim));

        u3a_lose(wim); u3a_lose(fol);
        return pro;
      }
      c3_assert(!"not reached");

      case 6: {
        u3_noun b_gal, c_gal, d_gal;

        u3x_trel(gal, &b_gal, &c_gal, &d_gal);
        {
          u3_noun tys = _n_nock_on(u3k(bus), u3k(b_gal));
          u3_noun nex;

          if ( 0 == tys ) {
            nex = u3k(c_gal);
          } else if ( 1 == tys ) {
            nex = u3k(d_gal);
          } else return u3m_bail(c3__exit);

          u3a_lose(fol);
          fol = nex;
          continue;
        }
      }
      c3_assert(!"not reached");

      case 7: {
        u3_noun b_gal, c_gal;

        u3x_cell(gal, &b_gal, &c_gal);
        {
          u3_noun bod = _n_nock_on(bus, u3k(b_gal));
          u3_noun nex = u3k(c_gal);

          u3a_lose(fol);
          bus = bod;
          fol = nex;
          continue;
        }
      }
      c3_assert(!"not reached");

      case 8: {
        u3_noun b_gal, c_gal;

        u3x_cell(gal, &b_gal, &c_gal);
        {
          u3_noun heb = _n_nock_on(u3k(bus), u3k(b_gal));
          u3_noun bod = u3nc(heb, bus);
          u3_noun nex = u3k(c_gal);

          u3a_lose(fol);
          bus = bod;
          fol = nex;
          continue;
        }
      }
      c3_assert(!"not reached");

      case 9: {
        u3_noun b_gal, c_gal;

        u3x_cell(gal, &b_gal, &c_gal);
        {
          u3_noun seb = _n_nock_on(bus, u3k(c_gal));
          u3_noun pro;
         
          u3t_off(noc_o);
          pro = u3j_kick(seb, b_gal);
          u3t_on(noc_o);

          if ( u3_none != pro ) {
            u3a_lose(fol);
            return pro;
          }
          else {
            if ( c3n == u3r_ud(b_gal) ) {
              return u3m_bail(c3__exit);
            }
            else {
              u3_noun nex = u3k(u3at(b_gal, seb));

              u3a_lose(fol);
              bus = seb;
              fol = nex;
              continue;
            }
          }
        }
      }
      c3_assert(!"not reached");

      case 10: {
        u3_noun p_gal, q_gal;

        u3x_cell(gal, &p_gal, &q_gal);
        {
          u3_noun zep, hod, nex;

          if ( c3y == u3r_du(p_gal) ) {
            u3_noun b_gal = u3h(p_gal);
            u3_noun c_gal = u3t(p_gal);
            u3_noun d_gal = q_gal;

            zep = u3k(b_gal);
            hod = _n_nock_on(u3k(bus), u3k(c_gal));
            nex = u3k(d_gal);
          }
          else {
            u3_noun b_gal = p_gal;
            u3_noun c_gal = q_gal;

            zep = u3k(b_gal);
            hod = u3_nul;
            nex = u3k(c_gal);
          }

          u3a_lose(fol);
          return _n_hint(zep, hod, bus, nex);
        }
      }

      case 11: {
        u3_noun ref = _n_nock_on(u3k(bus), u3k(u3h(gal)));
        u3_noun gof = _n_nock_on(bus, u3k(u3t(gal)));
        u3_noun val;

        u3t_off(noc_o);
        val = u3m_soft_esc(ref, u3k(gof));
        u3t_on(noc_o);

        if ( !_(u3du(val)) ) {
          u3m_bail(u3nt(1, gof, 0));
        } 
        if ( !_(u3du(u3t(val))) ) {
          //
          //  replace with proper error stack push
          //
          u3t_push(u3nc(c3__hunk, _n_mush(gof)));
          return u3m_bail(c3__exit);
        }
        else {
          u3_noun pro;

          u3z(gof);
          u3z(fol);
          pro = u3k(u3t(u3t(val)));
          u3z(val);

          return pro;
        }
      }  
      c3_assert(!"not reached");
    }
  }
}
예제 #30
0
파일: term.c 프로젝트: laanwj/urbit
/* _term_ef_blit(): send blit to terminal.
*/
static void
_term_ef_blit(u3_utty* uty_u,
              u3_noun  blt)
{
  switch ( u3h(blt) ) {
    default: break;
    case c3__bel: {
      if ( c3n == u3_Host.ops_u.dem ) {
        _term_it_write_txt(uty_u, uty_u->ufo_u.out.bel_y);
      }
    } break;

    case c3__clr: {
      if ( c3n == u3_Host.ops_u.dem ) {
        _term_it_show_blank(uty_u);
        _term_it_refresh_line(uty_u);
      }
    } break;

    case c3__hop: {
      if ( c3n == u3_Host.ops_u.dem ) {
        _term_it_show_cursor(uty_u, u3t(blt));
      }
    } break;

    case c3__lin: {
      u3_noun lin = u3t(blt);
      c3_w    len_w = u3kb_lent(u3k(lin));
      c3_w*   lin_w = c3_malloc(4 * len_w);

      {
        c3_w i_w;

        for ( i_w = 0; u3_nul != lin; i_w++, lin = u3t(lin) ) {
          lin_w[i_w] = u3r_word(0, u3h(lin));
        }
      }

      if ( c3n == u3_Host.ops_u.dem ) {
        _term_it_show_clear(uty_u);
        _term_it_show_line(uty_u, lin_w, len_w);
      } else {
        _term_it_show_line(uty_u, lin_w, len_w);
      }
    } break;

    case c3__mor: {
      _term_it_show_more(uty_u);
    } break;

    case c3__sav: {
      _term_it_save(u3k(u3h(u3t(blt))), u3k(u3t(u3t(blt))));
    } break;

    case c3__sag: {
      u3_noun pib = u3k(u3t(u3t(blt)));
      u3_noun jam;

      fprintf(stderr, "jamming...\r\n");
      jam = u3ke_jam(pib);
      fprintf(stderr, "jammed.\r\n");

      _term_it_save(u3k(u3h(u3t(blt))), jam);
    } break;
  }
  u3z(blt);

  return;
}