Beispiel #1
0
/* u3n_nock_an(): as slam_in(), but with empty fly.
*/
u3_noun
u3n_nock_an(u3_noun bus, u3_noun fol)
{
  u3_noun gul = u3nt(u3nt(1, 0, 0), 0, 0);  //  |=(a/{* *} ~)

  return u3n_nock_et(gul, bus, fol);
}
Beispiel #2
0
  u3_noun
  u3qdi_del(u3_noun a,
            u3_noun b)
  {
    if ( u3_nul == a ) {
      return u3_nul;
    }
    else {
      u3_noun l_a, n_a, r_a;

      if ( (c3n == u3r_trel(a, &n_a, &l_a, &r_a)) ) {
        return u3m_bail(c3__exit);
      }
      else if ( c3n == u3r_sing(n_a, b) ) {
        if ( c3y == u3qc_gor(b, n_a) ) {
          return u3nt(u3k(n_a),
                      u3qdi_del(l_a, b),
                      u3k(r_a));
        }
        else {
          return u3nt(u3k(n_a),
                      u3k(l_a),
                      u3qdi_del(r_a, b));
        }
      }
      else {
        return _rebalance(a);
      }
    }
  }
Beispiel #3
0
/* u3n_slam_un(): produce (gat sam), as ++toon.
*/
u3_noun
u3n_slam_un(u3_noun gat, u3_noun sam)
{
  u3_noun fly = u3nt(u3nt(11, 0, 6), 0, 0);  //  |=(a=* .^(a))

  return u3n_slam_in(fly, gat, sam);
}
Beispiel #4
0
/* internal functions
*/
  u3_noun _b_dif_join(u3_noun d, u3_noun e)
  {
    if ( u3_nul == d ) {
      return u3k(e);
    } else if (u3_nul == e) {
      return u3k(d);
    } else {
      u3_noun n_d, l_d, r_d;
      u3_noun n_e, l_e, r_e;
      u3_noun p_n_d, q_n_d;
      u3_noun p_n_e, q_n_e;

      if (    c3n == u3r_trel(d, &n_d, &l_d, &r_d)
           || c3n == u3r_trel(e, &n_e, &l_e, &r_e)
           || c3n == u3r_cell(n_d, &p_n_d, &q_n_d)
           || c3n == u3r_cell(n_e, &p_n_e, &q_n_e) ) {
        return u3m_bail(c3__exit);
      } else {
        if ( c3y == u3qc_vor(p_n_d, p_n_e) ) {
          return u3nt(u3k(n_d),
                      u3k(l_d),
                      _b_dif_join(u3k(r_d), u3k(e)));
        } else {
          return u3nt(u3k(n_e),
                      _b_dif_join(u3k(d), u3k(l_e)),
                      u3k(r_e));
        }
      }
    }
  }
Beispiel #5
0
/* u3n_nock_un(): produce .*(bus fol), as ++toon.
*/
u3_noun
u3n_nock_un(u3_noun bus, u3_noun fol)
{
  u3_noun fly = u3nt(u3nt(11, 0, 6), 0, 0);  //  |=(a=* .^(a))

  return u3n_nock_in(fly, bus, fol);
}
Beispiel #6
0
static u3_noun
_in_uni(u3_noun a, u3_noun b)
{
  u3_noun n_a, l_a, r_a,
          n_b, l_b, r_b,
          neb, sub, naw, pro;
  if ( u3_nul == a ) {
    return u3k(b);
  }
  else if ( u3_nul == b ) {
    return u3k(a);
  }
  else if ( (c3n == u3r_trel(a, &n_a, &l_a, &r_a))
         || (c3n == u3r_trel(b, &n_b, &l_b, &r_b)) )
  {
    return u3m_bail(c3__exit);
  }
  else if ( c3n == u3qc_mor(n_a, n_b) ) {
    if ( c3y == u3r_sing(n_a, n_b) ) {
      return u3nt(u3k(n_b), _in_uni(l_a, l_b), _in_uni(r_a, r_b));
    }
    else if ( c3y == u3qc_gor(n_a, n_b) ) {
      naw = u3nt(u3k(n_a), u3k(l_a), u3_nul);
      sub = _in_uni(naw, l_b);
      neb = u3nt(u3k(n_b), sub, u3k(r_b));
      pro = _in_uni(r_a, neb);
      u3z(naw); u3z(neb);
      return pro;
    }
    else {
      naw = u3nt(u3k(n_a), u3_nul, u3k(r_a));
      sub = _in_uni(naw, r_b);
      neb = u3nt(u3k(n_b), u3k(l_b),  sub);
      pro = _in_uni(l_a, neb);
      u3z(naw); u3z(neb);
      return pro;
    }
  }
  else if ( c3y == u3r_sing(n_b, n_a) ) {
    return u3nt(u3k(n_b), _in_uni(l_a, l_b), _in_uni(r_a, r_b));
  }
  else if ( c3y == u3qc_gor(n_b, n_a) ) {
    neb = u3nt(u3k(n_b), u3k(l_b), u3_nul);
    sub = _in_uni(l_a, neb);
    naw = u3nt(u3k(n_a), sub, u3k(r_a));
    pro = _in_uni(naw, r_b);
    u3z(neb); u3z(naw);
    return pro;
  }
  else {
    neb = u3nt(u3k(n_b), u3_nul, u3k(r_b));
    sub = _in_uni(r_a, neb);
    naw = u3nt(u3k(n_a), u3k(l_a), sub);
    pro = _in_uni(naw, l_b);
    u3z(neb); u3z(naw);
    return pro;
  }
}
Beispiel #7
0
/* functions
*/
  u3_noun
  u3qdi_int(u3_noun a,
            u3_noun b)
  {
    if ( u3_nul == a ) {
      return u3k(u3_nul);
    }
    else if ( u3_nul == b ) {
      return u3k(u3_nul);
    }
    else {
      u3_noun l_a, n_a, r_a, lr_a;
      u3_noun l_b, n_b, r_b, lr_b;
      u3_noun c;

      if ( (c3n == u3r_cell(a, &n_a, &lr_a)) ) {
        return u3m_bail(c3__exit);
      }
      else if ( (c3n == u3r_cell(b, &n_b, &lr_b)) ) {
        return u3m_bail(c3__exit);
      }
      else {
        if ( c3y == u3qc_mor(n_b, n_a) ) {
          c = a;    a = b;       b = c;
          c = n_a;  n_a = n_b;   n_b = c;
          c = lr_a; lr_a = lr_b; lr_b = c;
        }
        if ( c3n == u3r_cell(lr_a, &l_a, &r_a) ) {
          return u3m_bail(c3__exit);
        }
        else if ( c3n == u3r_cell(lr_b, &l_b, &r_b) ) {
          return u3m_bail(c3__exit);
        }
        else if ( c3y == u3r_sing(n_a, n_b) ) {
          return u3nt(u3k(n_a),
                      u3qdi_int(l_a, l_b),
                      u3qdi_int(r_a, r_b));
        }
        else if ( c3y == u3qc_gor(n_b, n_a) ) {
          return u3qdi_uni(u3qdi_int(l_a,
                                     u3nt(n_b,
                                          l_b,
                                          u3_nul)),
                           u3qdi_int(a,
                                     r_b));
        }
        else {
          return u3qdi_uni(u3qdi_int(r_a,
                                     u3nt(n_b,
                                          u3_nul,
                                          r_b)),
                           u3qdi_int(a,
                                     l_b));
        }
      }
    }
  }
Beispiel #8
0
/* _n_mush(): tank from failed path request.
*/
static u3_noun 
_n_mush(u3_noun val)
{
  u3_noun pro;

  pro = u3nt(c3__rose,
             u3nt(u3nc('/', u3_nul), u3nc('/', u3_nul), u3_nul),
             _n_mush_in(val));
  u3z(val);
  return pro;
}
Beispiel #9
0
/* logic
*/
  u3_noun
  u3qfu_repo(
                        u3_noun van,
                        u3_noun sut)
  {
    u3_noun p_sut, q_sut;

    if ( c3n == u3du(sut) ) switch ( sut ) {
      default: return u3k(sut);

      case c3__noun:
        return u3nt(c3__fork,
                            u3nc(c3__atom, u3_blip),
                            u3nt(c3__cell, c3__noun, c3__noun));
    }
    else switch ( u3h(sut) ) {
      default: {
        return u3m_error("repo-flat");
      }

      case c3__bull: {
        if ( c3n == u3r_cell(u3t(sut), &p_sut, &q_sut)) {
          return u3m_bail(c3__fail);
        } else {
          return u3k(q_sut);
        }
      }
      case c3__core: {
        if ( c3n == u3r_cell(u3t(sut), &p_sut, &q_sut) ) {
          return u3m_bail(c3__fail);
        } else {
          return u3nt(c3__cell, c3__noun, u3k(p_sut));
        }
      }
      case c3__cube: {
        if ( c3n == u3r_cell(u3t(sut), &p_sut, &q_sut)) {
          return u3m_bail(c3__fail);
        } else {
          return u3k(q_sut);
        }
      }
      case c3__face: {
        if ( c3n == u3r_cell(u3t(sut), &p_sut, &q_sut)) {
          return u3m_bail(c3__fail);
        } else {
          return u3k(q_sut);
        }
      }
      case c3__hold: {
        p_sut = u3t(sut);
        return u3qfu_rest(van, sut, p_sut);
      }
    }
  }
Beispiel #10
0
/* functions
*/
  static u3_noun
  _rebalance(u3_noun a)
  {
    u3_noun l_a, n_a, r_a;

    if ( c3n == u3r_trel(a, &n_a, &l_a, &r_a) ) {
      return u3m_bail(c3__exit);
    }
    else {
      if ( u3_nul == l_a) {
        return u3k(r_a);
      }
      else if ( u3_nul == r_a) {
        return u3k(l_a);
      }
      else {
        u3_noun n_l_a, l_l_a, r_l_a;
        u3_noun n_r_a, l_r_a, r_r_a;

        if ( (c3n == u3r_trel(l_a, &n_l_a, &l_l_a, &r_l_a) ) ||
             (c3n == u3r_trel(r_a, &n_r_a, &l_r_a, &r_r_a) ) ) {
          return u3m_bail(c3__exit);
        }
        else {
          if ( c3y == u3qc_mor(n_l_a, n_r_a) ) {
            u3_noun new_right = u3nt(u3k(n_a),
                                     u3k(r_l_a),
                                     u3k(r_a));

            u3_noun ret = u3nt(u3k(n_l_a),
                               u3k(l_l_a),
                               _rebalance(new_right));
            u3z(new_right);

            return ret;
          }
          else {
            u3_noun new_left = u3nt(u3k(n_a),
                                    u3k(l_a),
                                    u3k(l_r_a));

            u3_noun ret = u3nt(u3k(n_r_a),
                               _rebalance(new_left),
                               u3k(r_r_a));
            u3z(new_left);

            return ret;
          }
        }
      }
    }
  }
Beispiel #11
0
/* functions
*/
  u3_noun
  u3qf_comb(u3_noun mal,
            u3_noun buz)
  {
    if ( (u3_none == mal) || (u3_none == buz) ) {
      return u3_none;
    }
    else {
      u3_noun p_mal, q_mal, p_buz, q_buz, pp_buz, pq_buz;

      if ( (c3y == u3r_p(mal, 0, &p_mal)) && (0 != p_mal) ) {
        if ( (c3y == u3r_p(buz, 0, &p_buz)) && (0 != p_buz) ) {
          return u3nc(0,
                      u3qc_peg(p_mal, p_buz));
        }
        else if ( c3y == u3r_pq(buz, 2, &p_buz, &q_buz) &&
                  c3y == u3r_p(p_buz, 0, &pp_buz) &&
                  c3y == u3r_p(q_buz, 0, &pq_buz) )
        {
          return u3nt(2,
                      u3nc(0,
                           u3qc_peg(p_mal, pp_buz)),
                      u3nc(0,
                           u3qc_peg(p_mal, pq_buz)));
        }
        else return u3nt(7, 
                         u3k(mal),
                         u3k(buz));
      }
#if 1
      else if ( (c3y == u3r_bush(mal, &p_mal, &q_mal)) &&
                (c3y == u3du(p_mal)) &&
                (c3y == u3du(q_mal)) &&
                (0 == u3h(q_mal)) &&
                (1 == u3t(q_mal)) )
      {
        return u3nt(8, 
                    u3k(p_mal),
                    u3k(buz));
      }
#endif
      else if ( (c3y == u3r_p(buz, 0, &p_buz)) &&
                (c3y == u3r_sing(1, p_buz)) )
      {
        return u3k(mal);
      }
      else return u3nt(7, 
                       u3k(mal),
                       u3k(buz));
    }
  }
Beispiel #12
0
/* _unix_initial_update_file(): read file, but don't watch
*/
static u3_noun
_unix_initial_update_file(c3_c* pax_c)
{
    struct stat buf_u;
    c3_i  fid_i = open(pax_c, O_RDONLY, 0644);
    c3_ws len_ws, red_ws;
    c3_y* dat_y;

    if ( fid_i < 0 || fstat(fid_i, &buf_u) < 0 ) {
        if ( ENOENT == errno ) {
            return u3_nul;
        }
        else {
            uL(fprintf(uH, "error opening initial file %s: %s\r\n",
                       pax_c, strerror(errno)));
            return u3_nul;
        }
    }

    len_ws = buf_u.st_size;
    dat_y = c3_malloc(len_ws);

    red_ws = read(fid_i, dat_y, len_ws);

    if ( close(fid_i) < 0 ) {
        uL(fprintf(uH, "error closing initial file %s: %s\r\n",
                   pax_c, strerror(errno)));
    }

    if ( len_ws != red_ws ) {
        if ( red_ws < 0 ) {
            uL(fprintf(uH, "error reading initial file %s: %s\r\n",
                       pax_c, strerror(errno)));
        }
        else {
            uL(fprintf(uH, "wrong # of bytes read in initial file %s: %d %d\r\n",
                       pax_c, len_ws, red_ws));
        }
        free(dat_y);
        return u3_nul;
    }
    else {
        u3_noun pax = _unix_string_to_path_helper(pax_c + strlen(U3_LIB) + 6); /* XX VERY BAD */
        u3_noun mim = u3nt(c3__text, u3i_string("plain"), u3_nul);
        u3_noun dat = u3nt(mim, len_ws, u3i_bytes(len_ws, dat_y));

        free(dat_y);
        return u3nc(u3nt(pax, u3_nul, dat), u3_nul);
    }
}
Beispiel #13
0
/* u3n_nock_an(): as slam_in(), but with empty fly.
*/
u3_noun
u3n_nock_an(u3_noun bus, u3_noun fol)
{
  u3_noun fly = u3nt(u3nc(1, 0), 0, 0);  //  |=(a=* ~)

  return u3n_nock_in(fly, bus, fol);
}
Beispiel #14
0
Datei: temp.c Projekt: josl/urbit
/* u3_temp_io_poll(): update temp IO state.
*/
void
u3_temp_io_poll(void)
{
  u3_temp* teh_u = &u3_Host.teh_u;
  u3_noun  wen   = u3v_keep(u3nt(u3_blip, c3__temp, u3_nul));

  if ( (u3_nul != wen) &&
       (c3y == u3du(wen)) &&
       (c3y == u3ud(u3t(wen))) )
  {
    c3_d gap_d = u3_time_gap_ms(u3k(u3A->now), u3k(u3t(wen)));

#if 0
    fprintf(stderr, "gap_d %llu, plus %llu\r\n", 
        gap_d, gap_d + (c3_d)teh_u->run_w);
#endif
    gap_d += teh_u->run_w;

    if ( c3y == teh_u->alm ) {
      uv_timer_stop(&teh_u->tim_u);
    }
    else teh_u->alm = c3y;

    uv_timer_start(&teh_u->tim_u, _temp_time_cb, gap_d, 0);
  }
  else {
    if ( c3y == teh_u->alm ) {
      uv_timer_stop(&teh_u->tim_u);
    }
    teh_u->alm = c3n;
  }
  u3z(wen);
}
Beispiel #15
0
  static u3_noun
  _fire_mull(u3_noun van,
             u3_noun sut,
             u3_noun dox,
             u3_noun gen)
  {
    u3_noun rib = u3r_at(u3qfu_van_rib, van);
    u3_noun key = u3nt(u3k(sut),
                       u3k(dox),
                       u3k(gen));
    u3_noun ret;

    if ( c3n == _fire_vet(van) ) {
      ret = c3y;
    }
    if ( c3y == u3qdi_has(rib, key) ) {
      ret = c3y;
    }
    else {
      u3_noun rob = u3qdi_put(rib, key);
      u3_noun von = u3i_molt(u3k(van),
                             u3qfu_van_rib,
                             u3k(rob),
                             0);
      u3_noun mul = u3qfu_mull(von, sut, c3__noun, dox, gen);

      ret = c3y;
  
      u3z(mul);
      u3z(von);
      u3z(rob);
    }
    u3z(key);
    return ret;
  }
Beispiel #16
0
 static u3_noun
 _play_bean()
 {
   return u3kf_fork(u3nt(u3nq(c3__atom, 'f', u3_nul, 0),
                         u3nq(c3__atom, 'f', u3_nul, 1),
                         u3_nul));
 }
Beispiel #17
0
/* u3_term_ef_ctlc(): send ^C on console.
*/
void
u3_term_ef_ctlc(void)
{
  u3_noun pax = u3nq(u3_blip, c3__term, '1', u3_nul);

  u3v_plan(pax, u3nt(c3__belt, c3__ctl, 'c'));
}
Beispiel #18
0
  static u3_noun
  _play_foil(u3_noun pok)
  {
    u3_noun p_pok = u3h(pok);
    u3_noun q_pok = u3t(pok);
    u3_noun ret;

    if ( c3y == u3h(q_pok) ) {
      u3_noun pq_pok = u3t(q_pok);

      ret = u3nc(u3k(p_pok),
                 u3nc(u3_nul,
                      u3nc(u3nc(u3k(pq_pok),
                                u3nt(c3__elm, u3_nul, 1)),
                           u3_nul)));
    }
    else {
      u3_noun pq_pok = u3h(u3t(q_pok));
      u3_noun qq_pok = u3t(u3t(q_pok));

      ret = u3nc(u3k(p_pok),
                 u3nc(u3k(pq_pok),
                      u3k(qq_pok)));
    }
    u3z(pok);
    return ret;
  }
Beispiel #19
0
 static u3_noun
 _play_bean(void)
 {
   return u3nt(c3__fork,
               u3nq(c3__cube, 0, c3__atom, 'f'),
               u3nq(c3__cube, 1, c3__atom, 'f'));
 }
Beispiel #20
0
u3_noun 
u3z_save_2(c3_m fun, u3_noun one, u3_noun two, u3_noun val)
{
  u3_noun key = u3nt(fun, u3k(one), u3k(two));

  u3h_put(u3R->cax.har_p, key, u3k(val));
  u3z(key);
  return val;
}
Beispiel #21
0
 static u3_noun
 _play_rock(u3_noun odo, u3_noun bob)
 { 
   if ( c3y == u3ud(bob) ) {
     return u3nq(c3__atom, u3k(odo), u3_nul, u3k(bob));
   }
   else return u3nt(c3__cell, _play_rock(odo, u3h(bob)), 
                              _play_rock(odo, u3t(bob)));
 }
Beispiel #22
0
u3_weak 
u3z_find_2(c3_m fun, u3_noun one, u3_noun two)
{
  u3_noun key = u3nt(fun, u3k(one), u3k(two));
  u3_noun val;

  val = u3h_get(u3R->cax.har_p, key);
  u3z(key);
  return val;
}
Beispiel #23
0
 static u3_noun
 _mint_core(
            u3_noun pac,
            u3_noun con)
 {
   if ( (c3__void == pac) ) {
     return c3__void;
   } else {
     return u3nt(c3__core, pac, con);
   }
 }
Beispiel #24
0
/* _term_it_save(): save file by path.
*/
static void
_term_it_save(u3_noun pax, u3_noun pad)
{
  c3_c* pax_c;

  pax = u3nt(c3_s4('.','u','r','b'), c3_s3('p','u','t'), pax);
  pax_c = _term_it_path(c3y, pax);

  u3_walk_save(pax_c, 0, pad);
  free(pax_c);
}
Beispiel #25
0
/* functions
*/
  u3_noun
  u3qf_cube(u3_noun dil,
            u3_noun goq)
  {
    if ( c3__void == goq ) {
      return c3__void;
    }
    else return u3nt(c3__cube, 
                     u3k(dil),
                     u3k(goq));
  }
Beispiel #26
0
/* functions
*/
  u3_noun
  u3qf_face(u3_noun sag,
            u3_noun tip)
  {
    if ( c3__void == tip ) {
      return c3__void;
    }
    else return u3nt(c3__face,
                     u3k(sag),
                     u3k(tip));
  }
Beispiel #27
0
    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));
      }
    }
Beispiel #28
0
  static u3_noun
  _play_core(u3_noun pac,
             u3_noun con)
  {
    if ( (c3__void == pac) ) {
      u3z(con);

      return c3__void;
    } else {
      return u3nt(c3__core, pac, con);
    }
  }
Beispiel #29
0
/* _http_pox_to_noun(): translate srv/con/req to path noun (pox).
*/
static u3_noun
_http_pox_to_noun(c3_w sev_l, c3_w coq_l, c3_w seq_l)
{
  return
    u3nt(
      u3_blip,
      c3__http,
      u3nq(u3dc("scot", c3_s2('u','v'), sev_l),
           u3dc("scot", c3_s2('u','d'), coq_l),
           u3dc("scot", c3_s2('u','d'), seq_l),
           u3_nul));
}
Beispiel #30
0
/* logic
*/
  static u3_noun
  _cqfu_conk(u3_noun van,
             u3_noun sut,
             u3_noun got)
  {
    if ( c3y == u3ud(got) ) {
      u3_noun ret = u3qf_face(u3k(got), sut);

      return ret;
    }
    else switch ( u3h(got) ) {
      default: return u3m_bail(c3__fail);

      case 0: {
        return u3k(sut);
      }
      case 1: {
        u3_noun c*k = _cqfu_conk(van, sut, u3t(u3t(got)));
        u3_noun nux = u3k(u3h(u3t(got)));
        u3_noun ret = u3qf_face(nux, c*k);

        u3z(nux);
        u3z(c*k);
        return ret;
      }
      case 2: {
        u3_noun vet = u3r_at(u3qfu_van_vet, van);
        u3_noun hed, tal, deh, lat, ret;

        if ( c3y == vet ) {
          u3_noun cel = u3nt(c3__cell, c3__noun, c3__noun);

          if ( c3n == u3qfu_nest(van, cel, c3y, sut) ) {
            return u3m_bail(c3__fail);
          }
          u3z(cel);
        }
        hed = u3qfu_peek(van, sut, c3__both, 2);
        tal = u3qfu_peek(van, sut, c3__both, 3);
        deh = _cqfu_conk(van, hed, u3h(u3t(got)));
        lat = _cqfu_conk(van, tal, u3t(u3t(got)));

        ret = u3qf_cell(deh, lat);

        u3z(lat);
        u3z(deh);
        u3z(tal);
        u3z(hed);

        return ret;
      }
    }
  }