Пример #1
0
Файл: unix.c Проект: esaul/urbit
/* _unix_desk_sync_into(): sync external changes to desk.
*/
static void
_unix_desk_sync_into(u2_noun  who,
                     u2_noun  hox,
                     u2_noun  syd,
                     u2_udir* dir_u)
{
  u2_noun xun, bur, doz, fav, pax;

  xun = _unix_dir_ankh(dir_u);
  bur = _unix_desk_peek(hox, u2k(syd), u2k(u2A->wen));

  if ( (u2_no == u2_sing(u2h(xun), u2h(bur)))) //&&
  //     (u2_no == _unix_ankh_sing(xun, bur)) )
  {
    doz = u2_dc("cost", xun, bur);

    pax = u2nq(u2_blip, c3__sync, u2k(u2A->sen), u2_nul);
    fav = u2nq(c3__into, who, syd, u2nc(u2_yes, doz));

    u2_reck_plan(u2A, pax, fav);
  }
  else {
    u2z(who); u2z(syd); u2z(xun); u2z(bur);
  }
}
  /* _cf_path_1: write at/inpath.
  */
  static c3_w
  _cf_path_1(c3_c*   buf_c,
             c3_w    pos_w,
             u2_noun hut)                                         //  retain
  {
    if ( u2_no == u2_cr_du(hut) ) {
      c3_w met_w = u2_cr_met(3, hut);

      if ( buf_c ) u2_cr_bytes(0, met_w, (c3_y*)(buf_c + pos_w), hut);
      return (pos_w + met_w);
    }
    else {
      c3_w met_w  = u2_cr_met(3, u2h(hut));
      c3_w end_w  = _cf_path_1(buf_c, pos_w, u2t(hut));
      u2_noun san = u2h(hut);

      if ( buf_c ) buf_c[end_w] = '/';
      end_w++;

      // little security thing - last ditch
      //
      if ( c3_s2('.', '.') == san ) {
        san = c3_s3('.','.','.');
      }
      if ( buf_c ) u2_cr_bytes(0, met_w, (c3_y*)(buf_c + end_w), san);
      end_w += met_w;

      return end_w;
    }
  }
Пример #3
0
/* _http_list_to_heds(): list to C headers.
*/
static u2_hhed*
_http_list_to_heds(u2_noun lix)
{
  u2_noun  yix = lix;
  u2_hhed* hed_u = 0;

  while ( 1 ) {
    if ( u2_nul == lix ) {
      break;
    }
    else {
      u2_noun  i_lix = u2h(lix);
      u2_noun  pi_lix = u2h(i_lix);
      u2_noun  qi_lix = u2t(i_lix);
      u2_noun  t_lix = u2t(lix);
      u2_hhed* nex_u = c3_malloc(sizeof(u2_hhed));

      nex_u->nam_c = u2_cr_string(pi_lix);
      nex_u->val_c = u2_cr_string(qi_lix);
      nex_u->nex_u = hed_u;

      hed_u = nex_u;
      lix = t_lix;
    }
  }
  u2z(yix);
  return hed_u;
}
Пример #4
0
/* _unix_desk_sync_miso(): sync out change.
*/
static void
_unix_desk_sync_miso(u2_udir* dir_u, u2_noun pax, u2_noun mis)
{
  if ( (u2_no == u2du(pax)) || u2_no == u2du(u2t(pax)) ) {
    c3_assert(0);

    u2z(pax); u2z(mis);
  }
  else {
    u2_noun i_pax = u2h(pax); 
    u2_noun t_pax = u2t(pax);
    u2_noun it_pax = u2h(t_pax);
    u2_noun tt_pax = u2t(t_pax);

    if ( u2_nul == tt_pax ) {
      _unix_desk_sync_tofu(dir_u, u2k(i_pax), u2k(it_pax), mis);
    } 
    else {
      u2_udir** dis_u = _unix_pdir(dir_u, u2k(i_pax));

      if ( !*dis_u ) {
        *dis_u = malloc(sizeof(u2_udir));

        _unix_dir_forge(*dis_u, dir_u, u2k(i_pax));
      }
      _unix_desk_sync_miso(*dis_u, u2k(t_pax), mis);
    }
  }
  u2z(pax);
}
Пример #5
0
Файл: unix.c Проект: esaul/urbit
/* _unix_dir_ankh_file(): process a file for ankh.
*/
static u2_noun
_unix_dir_ankh_file(u2_noun pam, u2_noun wib, u2_noun baw, u2_noun woz)
{
  u2_weak ole;
  if ( u2_no == u2du(wib) ) {
    ole = u2_ckd_by_get(u2k(pam), u2k(wib));

    if ( u2_none == ole ) {
      ole = u2_do("cosh", u2nt(0, woz, u2_nul));
    } else {
      u2_noun elo;

      elo = u2_do("cosh", u2nt(0, woz, u2k(u2t(u2t(ole)))));
      u2z(ole);

      ole = elo;
    }
    pam = u2_ckd_by_put(pam, wib, ole);
  }
  else {
    u2_noun fid = u2h(wib);
    u2_noun har = u2t(wib);

    ole = u2_ckd_by_get(u2k(pam), u2k(fid));

    if ( u2_none == ole ) {
      ole = u2nt
        (0, u2_nul, u2_ckd_by_put(u2_nul,
                                  u2k(har),
                                  u2_do("cosh", u2nt(0, woz, u2_nul))));
      ole = u2_do("cosh", ole);
    }
    else {
      u2_noun roo = u2t(u2t(ole));
      u2_weak tup = u2_ckd_by_get(u2k(roo), u2k(har));
      u2_noun oor, elo;

      if ( u2_none == tup ) {
        tup = u2_do("cosh", u2nt(0, woz, u2_nul));
      } else {
        u2_noun upt;

        upt = u2_do("cosh", u2nt(0, woz, u2k(u2t(u2t(tup)))));
        u2z(tup);

        tup = upt;
      }
      oor = u2_ckd_by_put(u2k(roo), u2k(har), tup);
      elo = u2_do("cosh", u2nt(0, u2k(u2h(u2t(ole))), oor));

      u2z(ole); ole = elo;
    }
    pam = u2_ckd_by_put(pam, u2k(fid), ole);
    u2z(wib);
  }
  return pam;
}
Пример #6
0
/* _unix_desk_sync_soba(): sync computed changes.
*/
static void
_unix_desk_sync_soba(u2_udir* dir_u, u2_noun doz)
{
  u2_noun zod = doz;

  while ( u2_nul != zod ) {
    _unix_desk_sync_miso(dir_u, u2k(u2h(u2h(zod))), u2k(u2t(u2h(zod))));
    zod = u2t(zod);
  }
  u2z(doz);
}
Пример #7
0
/* _unix_dir_arch(): resolve directory to old style arch.
*/
static u2_noun
_unix_dir_arch(u2_udir* dir_u)
{
  u2_udir* dis_u;
  u2_ufil* fil_u;
  u2_noun pam = u2_nul;

  for ( dis_u = dir_u->dis_u; dis_u; dis_u = dis_u->nex_u ) {
    u2_noun pre = _unix_dir_name(dis_u);
    u2_noun arc = _unix_dir_arch(dis_u);

    // uL(fprintf(uH, "dir %s\n", u2_cr_string(pre)));
    pam = u2_ckd_by_put(pam, pre, arc);
  }

  for ( fil_u = dir_u->fil_u; fil_u; fil_u = fil_u->nex_u ) {
    u2_noun wib = _unix_file_name(fil_u);
    u2_noun baw = _unix_file_load(fil_u);
    u2_noun has = u2_do("sham", u2k(baw));
    u2_noun fil = u2nt(u2_yes, has, baw);

    if ( u2_no == u2du(wib) ) {
      // uL(fprintf(uH, "file %s\n", u2_cr_string(wib)));
      pam = u2_ckd_by_put(pam, wib, fil);
    }
    else {
      u2_weak ole = u2_ckd_by_get(u2k(pam), u2k(u2h(wib)));
      u2_noun arc, rac;

      // uL(fprintf(uH, "file %s.%s\n", u2_cr_string(u2h(wib)),
      //                               u2_cr_string(u2t(wib))));

      if ( u2_none == ole ) {
        arc = u2nc(u2_no, u2_nul);
      } 
      else if ( u2_yes == u2h(ole) ) {
        u2z(ole);
        arc = u2nc(u2_no, u2_nul);
      }
      else arc = ole;

      rac = u2nc(u2_no, u2_ckd_by_put(u2k(u2t(arc)), u2k(u2t(wib)), fil));
      pam = u2_ckd_by_put(pam, u2k(u2h(wib)), rac);

      u2z(wib); u2z(arc);
    }
  }
  return u2nc(u2_no, pam);
}
Пример #8
0
/* u2_term_ef_boil(): initial effects for loaded servers.
*/
void
u2_term_ef_boil(c3_l     old_l,
                c3_l     ono_l)
{
  if ( ono_l ) {
    u2_noun oan = u2_dc("scot", c3__uv, old_l);
    u2_noun tid_l;

    for ( tid_l = 1; tid_l <= ono_l; tid_l++ ) {
      u2_noun tin = u2_dc("scot", c3__ud, tid_l);
      u2_noun pax = u2nc(c3__gold, u2nq(c3__term, u2k(oan), tin, u2_nul));
      u2_noun hud = u2nc(c3__wipe, u2_nul);

      u2_reck_plan(u2A, pax, hud);
    }
    u2z(oan);
  }

  {
    u2_noun pax = u2nc(c3__gold, u2nq(c3__term, u2k(u2A->sen), '1', u2_nul));

    u2_reck_plan(u2A, u2k(pax), u2nc(c3__init, u2k(u2h(u2A->own))));
    u2_reck_plan(u2A, u2k(pax), u2nc(c3__blew, u2_term_get_blew(u2A, 1)));
    u2_reck_plan(u2A, u2k(pax), u2nc(c3__hail, u2_nul));

    u2z(pax);
  }
}
Пример #9
0
/* logic
*/
  u2_bean                                                         //  transfer
  j2_mcx(Pt6, ut, conk)(u2_wire wir_r, 
                        u2_noun van,                              //  retain
                        u2_noun sut,                              //  retain
                        u2_noun got)                              //  retain
  {
    if ( u2_yes == u2ud(got) ) {
      return j2_mby(Pt6, face)(wir_r, got, sut);
    }
    else switch ( u2h(got) ) {
      default: return u2_cm_bail(c3__fail);

      case 0: {
        return u2k(sut);
      }
      case 1: {
        return j2_mby(Pt6, face)
          (wir_r, u2h(u2t(got)), 
                 j2_mcx(Pt6, ut, conk)(wir_r, van, sut, u2t(u2t(got))));
      }
      case 2: {
        u2_bean vet = u2_frag(j2_ut_van_vet, van); 
        u2_noun hed, tal, ret;

        if ( u2_yes == vet ) {
          u2_noun cel = u2nt(c3__cell, c3__noun, c3__noun);
          
          if ( u2_no == j2_mcy(Pt6, ut, nest)(wir_r, van, cel, u2_yes, sut) ) {
            return u2_bl_bail(wir_r, c3__fail);
          }
          u2z(cel);
        }
        hed = j2_mcy(Pt6, ut, peek)(wir_r, van, sut, c3__both, 2);
        tal = j2_mcy(Pt6, ut, peek)(wir_r, van, sut, c3__both, 3);

        ret = j2_mby(Pt6, cell)
          (wir_r, 
           j2_mcx(Pt6, ut, conk)(wir_r, van, hed, u2h(u2t(got))),
           j2_mcx(Pt6, ut, conk)(wir_r, van, tal, u2t(u2t(got))));

        u2z(hed);
        u2z(tal);

        return ret;
      }
    }
  }
Пример #10
0
/* _lo_tape(): dump a tape, old style.  Don't do this.
*/
static void
_lo_tape(u2_reck* rec_u, FILE* fil_u, u2_noun tep)
{
  u2_noun tap = tep;

  while ( u2_nul != tap ) {
    c3_c car_c;

    if ( u2h(tap) >= 127 ) {
      car_c = '?';
    } else car_c = u2h(tap);

    putc(car_c, fil_u);
    tap = u2t(tap);
  }
  u2z(tep);
}
Пример #11
0
/* u2_lo_punt(): dump tank list.
*/
void
u2_lo_punt(c3_l tab_l, u2_noun tac)
{
  u2_noun blu   = u2_term_get_blew(0);
  c3_l    col_l = u2h(blu);
  u2_noun cat   = tac;

  //  We are calling nock here, but hopefully need no protection.
  //
  while ( u2_yes == u2_cr_du(cat) ) {
    u2_noun wol = u2_dc("wash", u2nc(tab_l, col_l), u2k(u2h(cat)));

    _lo_wall(u2_Arv, wol);
    cat = u2t(cat);
  }
  u2z(tac);
  u2z(blu);
}
Пример #12
0
/* _term_it_path(): path for console file.
*/
static c3_c*
_term_it_path(u2_bean fyl, u2_noun pax)
{
  c3_w len_w;
  c3_c *pas_c;

  //  measure
  //
  len_w = strlen(u2_Host.cpu_c);
  {
    u2_noun wiz = pax;

    while ( u2_nul != wiz ) {
      len_w += (1 + u2_cr_met(3, u2h(wiz)));
      wiz = u2t(wiz);
    }
  }

  //  cut
  //
  pas_c = malloc(len_w + 1);
  strncpy(pas_c, u2_Host.cpu_c, len_w);
  pas_c[len_w] = '\0';
  {
    u2_noun wiz   = pax;
    c3_c*   waq_c = (pas_c + strlen(pas_c));

    while ( u2_nul != wiz ) {
      c3_w tis_w = u2_cr_met(3, u2h(wiz));

      if ( (u2_yes == fyl) && (u2_nul == u2t(wiz)) ) {
        *waq_c++ = '.';
      } else *waq_c++ = '/';

      u2_cr_bytes(0, tis_w, (c3_y*)waq_c, u2h(wiz));
      waq_c += tis_w;

      wiz = u2t(wiz);
    }
    *waq_c = 0;
  }
  u2z(pax);
  return pas_c;
}
Пример #13
0
/* nock_molg(): function call (mung) with kode.  Arguments transferred.
*/
static u2_noun
_nock_molg(u2_noun  gat,
           u2_noun  sam,
           u2_kode* pon)
{
  if ( (u2_no == u2du(gat)) || (u2_no == u2du(u2t(gat))) ) {
    *pon = 2; return u2_cm_wail();
  }
  else {
    u2_noun cor, fol;

    cor = u2nc(u2k(u2h(gat)), u2nc(sam, u2k(u2t(u2t(gat)))));
    fol = u2k(u2h(gat));
    u2z(gat);

    //  XX  try to chip with u2_ds_find?  but a rare case...
    return _nock_mool(cor, fol, pon);
  }
}
Пример #14
0
Файл: unix.c Проект: esaul/urbit
/* _unix_dir_ankh(): resolve directory to new style ankh.
*/
static u2_noun
_unix_dir_ankh(u2_udir* dir_u)
{
  u2_udir* dis_u;
  u2_ufil* fil_u;
  u2_noun pam = u2_nul;

  for ( dis_u = dir_u->dis_u; dis_u; dis_u = dis_u->nex_u ) {
    u2_noun pre = _unix_dir_name(dis_u);
    u2_noun ank = _unix_dir_ankh(dis_u);

    // uL(fprintf(uH, "dir %s\n", u2_cr_string(pre)));
    if ( 0 != u2h(ank) ) {
      pam = u2_ckd_by_put(pam, pre, ank);
    }
  }

  if ( !dir_u->par_u->par_u ) {                        //  toplevel
    for ( fil_u = dir_u->par_u->fil_u; fil_u; fil_u = fil_u->nex_u ) {
      //  uL(fprintf(uH, "top %s\n", fil_u->pax_c));
      u2_noun wib = _unix_file_tame(fil_u);
      if ( u2_none == wib ) continue;
      u2_noun dur = _unix_dir_name(dir_u);
      if ( u2_no == u2_sing(dur, u2h(wib)) ) {         //  wrong desk
        u2z(wib); u2z(dur);
        continue;
      }
      u2_noun baw = _unix_file_load(fil_u);
      u2_noun woz = u2nt(u2_nul, u2_do("sham", u2k(baw)), baw);
      u2z(dur);
      pam = _unix_dir_ankh_file(pam, u2k(u2t(wib)), baw, woz);
      u2z(wib);
    }
  }

  for ( fil_u = dir_u->fil_u; fil_u; fil_u = fil_u->nex_u ) {
    u2_noun wib = _unix_file_name(fil_u);
    u2_noun baw = _unix_file_load(fil_u);
    u2_noun woz = u2nt(u2_nul, u2_do("sham", u2k(baw)), baw);
    pam = _unix_dir_ankh_file(pam, wib, baw, woz);
  }
  return u2_do("cosh", u2nt(0, u2_nul, pam));
}
Пример #15
0
Файл: unix.c Проект: esaul/urbit
static u2_bean
_unix_ankh_sing_map(u2_noun mun, u2_noun mur)           //  retain
{
  u2_noun n_mun, l_mun, r_mun;
  u2_noun n_mur, l_mur, r_mur;

  if ( (u2_nul == mun) && (u2_nul == mur) ) { return u2_yes; }
  if ( (u2_nul == mun) || (u2_nul == mur) ) { return u2_no; }

  u2_cx_trel(mun, &n_mun, &l_mun, &r_mun);
  u2_cx_trel(mur, &n_mur, &l_mur, &r_mur);

  if ( (u2_no == (u2_sing(u2h(n_mun), u2h(n_mur)))) ||
       (u2_no == _unix_ankh_sing_in(u2t(n_mun), u2t(n_mur))) ||
       (u2_no == _unix_ankh_sing_map(l_mun, l_mur)) ||
       (u2_no == _unix_ankh_sing_map(r_mun, r_mur)) ) 
  {
    return u2_no;
  } else return u2_yes;
}
Пример #16
0
  u2_noun                                                         //  transfer
  j2_mcy(Pt6, ut, seep)(u2_wire wir_r,
                        u2_noun van,                              //  retain
                        u2_noun sut,                              //  retain
                        u2_noun way,                              //  retain
                        u2_noun hyp)                              //  retain
  {
    u2_noun zar = j2_mcy(Pt6, ut, seek)(wir_r, van, sut, way, hyp);
    u2_noun p_zar = u2h(zar);
    u2_noun q_zar = u2t(zar);
    
    if ( u2_yes != u2h(q_zar) ) {
      return u2_cm_bail(c3__exit);
    }
    else {
      u2_noun ret = u2_bc(wir_r, u2_rx(wir_r, p_zar), u2_rx(wir_r, u2t(q_zar)));

      u2_rz(wir_r, zar);
      return ret;
    }
  }
Пример #17
0
/* _nock_pray_mool(): load from namespace, in virtual mode.
*/
static u2_noun
_nock_pray_mool(u2_noun gof, u2_kode *pon)                        //  transfer
{
    u2_noun lad = u2_hevn_at(lad);

    c3_assert(u2_yes == u2du(lad));
    c3_assert(0 == *pon);
    {
        u2_noun i_lad = u2fh(lad);
        u2_noun t_lad = u2ft(lad);
        u2_noun pro;
        u2_noun hoe;

        u2_hevn_at(lad) = t_lad;
        if ( 0 != (hoe = u2_cm_trap()) ) {
            u2_cm_done();

            return u2_cm_bail(u2k(u2h(hoe)));
        }
        else {
            if ( u2_nul == t_lad ) {
                pro = u2_cn_mung(u2k(i_lad), u2k(gof));
            } else {
                pro = _nock_molg(u2k(i_lad), u2k(gof), pon);
            }
            u2_cm_done();

            c3_assert(t_lad == u2_hevn_at(lad));
            u2_hevn_at(lad) = lad;

            if ( 0 != *pon ) {
                u2z(gof);

                return pro;
            } else {
                if ( u2_no == u2du(pro) ) {
                    *pon = 1;
                    u2z(pro);
                    return u2nc(gof, u2_nul);
                }
                else {
                    u2_noun res = u2k(u2t(pro));

                    u2z(gof);
                    u2z(pro);
                    return res;
                }
            }
        }
    }
}
Пример #18
0
/* _nock_moog(): u2_cn_mink() with fly set.
*/
static u2_noun
_nock_moog(u2_noun bus,
           u2_noun fol)
{
    u2_noun res;
    u2_kode pon;

    pon = 0;
    {
        u2_noun hoe;

        if ( 0 != (hoe = u2_cm_trap()) ) {
            if ( u2h(hoe) == c3__exit ) {
                res = u2nc(2, u2k(u2t(hoe)));

                c3_assert(0);
                u2z(hoe);
            }
            else if ( u2h(hoe) == c3__need ) {
                res = u2nc(1, u2k(u2t(hoe)));
                u2z(hoe);
            }
            else {
                u2_noun wac = u2k(u2h(hoe));

                u2z(hoe);
                return u2_cm_bail(wac);
            }
        }
        else {
            u2_noun pro = _nock_mool(bus, fol, &pon);

            u2_cm_done();
            res = u2nc(pon, pro);
        }
    }
    return res;
}
Пример #19
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;
  }
}
Пример #20
0
Файл: unix.c Проект: esaul/urbit
/* _unix_desk_sync_tako(): sync out change.
*/
static void
_unix_desk_sync_tako(u2_udir* dir_u, u2_noun pax, u2_noun mis)
{
  if ( (u2_no == u2du(pax)) ) {
    c3_assert(!"tack");
  }
  else if ( u2_no == u2du(u2t(pax)) ) {                //  at toplevel
    u2_noun i_pax = u2h(pax);
    u2_noun t_pax = u2t(pax);
    c3_c* par_u = strrchr(dir_u->pax_c, '/') + 1;
    u2_noun pem = u2_ci_string(par_u);
    c3_assert( u2_nul == t_pax );                      //  XX ugly, wrong

    _unix_desk_sync_tofu(dir_u->par_u, pem, u2k(i_pax), mis);
  }
  else {
    u2_noun i_pax = u2h(pax);
    u2_noun t_pax = u2t(pax);
    u2_noun it_pax = u2h(t_pax);
    u2_noun tt_pax = u2t(t_pax);

    if ( u2_nul == tt_pax ) {
      _unix_desk_sync_tofu(dir_u, u2k(i_pax), u2k(it_pax), mis);
    }
    else {
      u2_udir** dis_u = _unix_pdir(dir_u, u2k(i_pax));

      if ( !*dis_u ) {
        *dis_u = c3_malloc(sizeof(u2_udir));

        _unix_dir_forge(*dis_u, dir_u, u2k(i_pax));
      }
      _unix_desk_sync_tako(*dis_u, u2k(t_pax), mis);
    }
  }
  u2z(pax);
}
Пример #21
0
/* _lo_hard(): standard hard wrapper.  Produces result and/or asserts.
*/
static u2_noun
_lo_hard(u2_reck* rec_u, u2_funk fun_f, u2_noun arg)
{
  u2_noun pro = u2_lo_soft(rec_u, 0, fun_f, arg);

  if ( u2_blip == u2h(pro) ) {
    u2_noun poo = u2k(u2t(pro));

    u2z(pro); return poo;
  }
  else {
    u2_lo_punt(2, u2k(u2t(pro)));
    u2z(pro);
    c3_assert(0);
  }
}
Пример #22
0
/* _lo_wall(): dump a wall, old style.  Don't do this.
*/
static void
_lo_wall(u2_reck* rec_u, u2_noun wol)
{
  FILE* fil_u = u2_term_io_hija();
  u2_noun wal = wol;

  while ( u2_nul != wal ) {
    _lo_tape(rec_u, fil_u, u2k(u2h(wal)));

    putc(13, fil_u);
    putc(10, fil_u);

    wal = u2t(wal);
  }
  u2_term_io_loja(0);
  u2z(wol);
}
/* u2_cr_tape(): `a`, a list of bytes, as malloced C string.
*/
c3_y*
u2_cr_tape(u2_noun a)
{
  u2_noun b;
  c3_w    i_w;
  c3_y    *a_y;

  for ( i_w = 0, b=a; u2_yes == u2du(b); i_w++, b=u2t(b) )
    ;
  a_y = c3_malloc(i_w + 1);

  for ( i_w = 0, b=a; u2_yes == u2du(b); i_w++, b=u2t(b) ) {
    a_y[i_w] = u2h(b);
  }
  a_y[i_w] = 0;

  return a_y;
}
/* u2_term_ef_blit(): send %blit list to specific terminal.
*/
void
u2_term_ef_blit(c3_l     tid_l,
                u2_noun  bls)
{
  u2_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", u2_Host.uty_u));

    u2z(bls); return;
  }

  {
    u2_noun bis = bls;

    while ( u2_yes == u2du(bis) ) {
      _term_ef_blit(uty_u, u2k(u2h(bis)));
      bis = u2t(bis);
    }
    u2z(bls);
  }
}
Пример #25
0
/* _term_ef_blit(): send blit to terminal.
*/
static void
_term_ef_blit(u2_utty* uty_u,
              u2_noun  blt)
{
  switch ( u2h(blt) ) {
    default: break;
    case c3__bel: {
      if ( u2_no == u2_Host.ops_u.dem ) {
        _term_it_write_txt(uty_u, uty_u->ufo_u.out.bel_y);
      }
    } break;

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

    case c3__hop: {
      if ( u2_no == u2_Host.ops_u.dem ) {
        _term_it_show_cursor(uty_u, u2t(blt));
      }
    } break;

    case c3__lin: {
      u2_noun lin = u2t(blt);
      c3_w    len_w = u2_ckb_lent(u2k(lin));
      c3_w*   lin_w = malloc(4 * len_w);

      {
        c3_w i_w;

        for ( i_w = 0; u2_nul != lin; i_w++, lin = u2t(lin) ) {
          lin_w[i_w] = u2_cr_word(0, u2h(lin));
        }
      }

      if ( u2_no == u2_Host.ops_u.dem ) {
        _term_it_show_clear(uty_u);
        _term_it_show_line(uty_u, lin_w, len_w);
      } else {
        while ( uty_u->out_u ) {
          u2_ubuf* out_u = uty_u->out_u;
          uty_u->out_u = uty_u->out_u->nex_u;
          if ( 0 == uty_u->out_u ) {
            c3_assert(out_u == uty_u->tou_u);
            uty_u->tou_u = 0;
          }
          free(out_u);
        }
        _term_it_show_line(uty_u, lin_w, len_w);
      }
    } break;

    case c3__mor: {
      if ( u2_no == u2_Host.ops_u.dem ) {
        _term_it_show_more(uty_u);
      } else {
        _term_it_show_more(uty_u);
        _term_it_do_writes(uty_u);
      }
    } break;

    case c3__sav: {
      _term_it_save(u2k(u2h(u2t(blt))), u2k(u2t(u2t(blt))));
    } break;
  }
  u2z(blt);

  return;
}
Пример #26
0
/* _unix_desk_sync_tofu(): sync out file install.
*/
static void
_unix_desk_sync_tofu(u2_udir* dir_u,
                     u2_noun  pre,
                     u2_noun  ext,
                     u2_noun  mis)
{
  c3_c*     pox_c = _unix_file_form(dir_u, u2k(pre), u2_no, u2k(ext));
  c3_c*     pux_c = _unix_file_form(dir_u, u2k(pre), u2_yes, u2k(ext));
  u2_ufil** fil_u;

  // uL(fprintf(uH, "tofu pox_c %s op %s\n", pox_c, u2_cr_string(u2h(mis))));

  fil_u = &(dir_u->fil_u); 
  while ( 1 ) {                               //  XX crude!
    if ( !*fil_u || 
         !strcmp((*fil_u)->pax_c, pox_c) ||
         !strcmp((*fil_u)->pax_c, pux_c) )
    {
      break;
    }
    else fil_u = &((*fil_u)->nex_u);
  }
 
  if ( *fil_u && (c3__del == u2h(mis)) ) {
    u2_ufil* ded_u = *fil_u;

    *fil_u = ded_u->nex_u;
    _unix_unlink(ded_u->pax_c);
    _unix_file_free(ded_u);

    free(ded_u);
    free(pox_c);
    free(pux_c);
  }
  else {
    u2_noun god, oat;
    c3_c*   pax_c;

    if ( *fil_u ) {
      u2_noun old = _unix_file_load(*fil_u);
      c3_assert(c3__mut == u2h(mis));

      god = _unix_desk_sync_udon(u2k(u2t(mis)), old);
      _unix_unlink((*fil_u)->pax_c);
      free((*fil_u)->pax_c);
    } 
    else {
      c3_assert(c3__ins == u2h(mis));
      god = u2k(u2t(mis));
    }

    if ( u2_yes == u2du(god) ) {
      oat = u2_cke_jam(god);
      pax_c = pux_c; free(pox_c);
    } else {
      oat = god;
      pax_c = pox_c; free(pux_c);
    }

    if ( *fil_u ) {
      (*fil_u)->dot_c = (pax_c + ((*fil_u)->dot_c - (*fil_u)->pax_c));
      (*fil_u)->pax_c = pax_c;

      mpz_clear((*fil_u)->mod_mp);
      u2_cr_mp((*fil_u)->mod_mp, u2A->now);
    } 
    else {
      mpz_t mod_mp;

      u2_cr_mp(mod_mp, u2A->now);
      *fil_u = malloc(sizeof(u2_ufil));

      _unix_file_watch(*fil_u, dir_u, pax_c, mod_mp);
      mpz_clear(mod_mp);
    }

    _unix_save((*fil_u)->pax_c, oat);
  }
  u2z(pre); u2z(ext); u2z(mis);
}
Пример #27
0
  static u2_noun                                                  //  produce
  _mint_in(u2_wire wir_r, 
           u2_noun van,                                           //  retain
           u2_noun sut,                                           //  retain
           u2_noun gol,                                           //  retain
           u2_noun gen)                                           //  retain
  {
    u2_noun p_gen, q_gen, r_gen;
    u2_noun ret;

    if ( (c3__void == sut) && 
         !((u2_yes == u2_dust(gen)) && (c3__zpcb == u2_h(gen))) )
    {
      if ( (u2_no == _mint_vet(wir_r, van))
           || ((u2_yes == u2_dust(gen)) && 
               ((c3__zpfs == u2_h(gen)) || (c3__zpzp == u2_h(gen)))) )
      {
        return u2_bt(wir_r, c3__void, _0, _0);
      }
      else {
        return u2_bl_error(wir_r, "mint-vain");
      }
    }

    if ( u2_no == u2_dust(gen) ) {
      u2_noun ter = u2_frag(u2_cw_con_2, van);
      u2_noun rex = j2_mcy(Pt6, ap, open)(wir_r, ter, gen);

      ret = _mint_in(wir_r, van, sut, gol, rex);
      u2_rl_lose(wir_r, rex);

      return ret;
    } 
    else if ( u2_yes == u2_dust(u2_h(gen)) ) {
      _mint_used(wir_r);
      {
        u2_noun hed = _mint_in(wir_r, van, sut, c3__noun, u2_h(gen));
        u2_noun tal = _mint_in(wir_r, van, sut, c3__noun, u2_t(gen));
        u2_noun typ = j2_mby(Pt6, cell)(wir_r, u2_h(hed), u2_h(tal));

        ret = u2_bc
          (wir_r,
           _mint_nice(wir_r, van, gol, typ),
           j2_mby(Pt6, cons)(wir_r, u2_t(hed), u2_t(tal)));

        u2_rl_lose(wir_r, hed);
        u2_rl_lose(wir_r, tal);

        return ret;
      }
    } else switch ( u2_h(gen) ) {
      default: {
        u2_noun ter = u2_frag(u2_cw_con_2, van);
        u2_noun rex = j2_mcy(Pt6, ap, open)(wir_r, ter, gen);

        if ( u2_yes == u2_sing(rex, gen) ) {
#if 1
          u2_noun zix = j2_mcy(Pt6, ut, shep)
                (wir_r, van, "gene", 'q', u2_rx(wir_r, gen));

          u2_bl_push(wir_r, u2_bc(wir_r, c3__mean, zix));
          return u2_bl_error(wir_r, "mint-open");
#else
          u2_err(wir_r, "h", u2_h(gen));
          return u2_bl_bail(wir_r, c3__fail);
#endif
        }
        ret = _mint_in(wir_r, van, sut, gol, rex);
        u2_rl_lose(wir_r, rex);

        return ret;
      }
      
      case c3__wtcn: u2_bi_cell(wir_r, u2_t(gen), &p_gen, &q_gen);
      _mint_used(wir_r);
      {
        u2_noun vol = _mint_corn(wir_r, van, sut, q_gen);
        u2_noun axe = _mint_coke(wir_r, vol);
        u2_noun wam = j2_mcy(Pt6, ut, play)(wir_r, van, sut, p_gen);

        ret = u2_bc
          (wir_r,
           _mint_nice(wir_r, van, gol, _mint_flag(wir_r)),
           j2_mcy(Pt6, ut, fish)(wir_r, van, wam, axe));

        u2_rl_lose(wir_r, axe);
        u2_rl_lose(wir_r, wam);
        return ret;
      }
      case c3__wtcl: u2_bi_trel(wir_r, u2_t(gen), &p_gen, &q_gen, &r_gen);
      _mint_used(wir_r);
      {
        u2_noun bol = _mint_flag(wir_r);
        u2_noun nor = _mint_in(wir_r, van, sut, bol, p_gen);
        u2_noun fex = j2_mcy(Pt6, ut, gain)(wir_r, van, sut, p_gen);
        u2_noun wux = j2_mcy(Pt6, ut, lose)(wir_r, van, sut, p_gen);
        u2_noun duy = (c3__void == fex)
                        ? ( (c3__void == wux)
                             ?  u2_bc(wir_r, _0, _0)
                             :  u2_bc(wir_r, _1, _1) )
                        : ( (c3__void == wux)
                            ?  u2_bc(wir_r, _1, _0)
                            :  u2_rx(wir_r, u2_t(nor)) );
        u2_noun hiq = _mint_in(wir_r, van, fex, gol, q_gen);
        u2_noun ran = _mint_in(wir_r, van, wux, gol, r_gen);

        ret = u2_bc
          (wir_r, j2_mby(Pt6, fork)(wir_r, u2_h(hiq), u2_h(ran)),
                  _mint_cond(wir_r, duy, 
                                    u2_rx(wir_r, u2_t(hiq)),
                                    u2_rx(wir_r, u2_t(ran))));

        u2_rl_lose(wir_r, ran);
        u2_rl_lose(wir_r, hiq);
        u2_rl_lose(wir_r, nor);
        u2_rl_lose(wir_r, wux);
        u2_rl_lose(wir_r, fex);
        u2_rl_lose(wir_r, bol);

        return ret;
      }
      case c3__clhp: u2_bi_cell(wir_r, u2_t(gen), &p_gen, &q_gen);
      _mint_used(wir_r);
      {
        u2_noun hed = _mint_in(wir_r, van, sut, c3__noun, p_gen);
        u2_noun tal = _mint_in(wir_r, van, sut, c3__noun, q_gen);
        u2_noun typ = j2_mby(Pt6, cell)(wir_r, u2_h(hed), u2_h(tal));

        ret = u2_bc
          (wir_r,
           _mint_nice(wir_r, van, gol, typ),
           j2_mby(Pt6, cons)(wir_r, u2_t(hed), u2_t(tal)));

        u2_rl_lose(wir_r, hed);
        u2_rl_lose(wir_r, tal);

        return ret;
      }
      case c3__dtts: u2_bi_cell(wir_r, u2_t(gen), &p_gen, &q_gen);
      _mint_used(wir_r);
      {
        u2_noun typ = _mint_nice(wir_r, van, gol, _mint_flag(wir_r));

        return u2_bc
          (wir_r, 
           typ,
           u2_bt(wir_r, _5, _mint_corn(wir_r, van, sut, p_gen),
                            _mint_corn(wir_r, van, sut, q_gen)));
      }
      case c3__dtwt: p_gen = u2_t(gen);
      _mint_used(wir_r);
      {
        u2_noun typ = _mint_nice(wir_r, van, gol, _mint_flag(wir_r));

        return u2_bc
          (wir_r, 
           typ,
           u2_bc(wir_r, _3, _mint_corn(wir_r, van, sut, p_gen)));
      }
      case c3__dtkt: p_gen = u2_t(gen);
      _mint_used(wir_r);
      {
        u2_noun tom = c3__noun;
        u2_noun sam = _mint_in(wir_r, van, sut, tom, p_gen);

        ret = u2_bc
          (wir_r, 
           _mint_nice(wir_r, van, gol, tom),
           u2_bc(wir_r, _11, u2_rx(wir_r, u2_t(sam))));
        
        u2_rz(wir_r, sam);
        return ret;
      }
      case c3__dtls: p_gen = u2_t(gen);
      _mint_used(wir_r);
      {
        u2_noun tom = u2_bc(wir_r, c3__atom, u2_blip);
        u2_noun sam = _mint_in(wir_r, van, sut, tom, p_gen);

        ret = u2_bc
          (wir_r, 
           _mint_nice(wir_r, van, gol, tom),
           u2_bc(wir_r, _4, u2_rx(wir_r, u2_t(sam))));
        
        u2_rz(wir_r, sam);
        return ret;
      }
      case c3__dtsg: u2_bi_cell(wir_r, u2_t(gen), &p_gen, &q_gen);
      _mint_used(wir_r);
      {
        u2_noun boc = (u2_no == u2_stud(q_gen)) 
                        ? c3__noun
                        : u2_bc(wir_r, c3__atom, u2_rx(wir_r, p_gen));
        u2_noun typ = j2_mby(Pt6, cube)(wir_r, q_gen, boc);
        u2_noun ret = 
            u2_bc(wir_r,
                  _mint_nice(wir_r, van, gol, typ),
                  u2_bc(wir_r, _1, u2_rx(wir_r, q_gen)));

        u2_rz(wir_r, boc);
        return ret;
      }
      case c3__dttr: u2_bi_cell(wir_r, u2_t(gen), &p_gen, &q_gen);
      _mint_used(wir_r);
      {
        return u2_bc
          (wir_r, 
           _mint_nice(wir_r, van, gol, c3__noun),
           u2_bt(wir_r, _2, _mint_corn(wir_r, van, sut, p_gen),
                            _mint_corn(wir_r, van, sut, q_gen)));
      }
      case c3__dtpt: u2_bi_cell(wir_r, u2_t(gen), &p_gen, &q_gen);
      _mint_used(wir_r);
      {
        u2_noun typ = j2_mcy(Pt6, ut, play)(wir_r, van, sut, gen);
        u2_noun ret = 
            u2_bc(wir_r,
                  _mint_nice(wir_r, van, gol, typ),
                  u2_bc(wir_r, _1, u2_rx(wir_r, q_gen)));

        return ret;
      }
      case c3__ktdt: u2_bi_cell(wir_r, u2_t(gen), &p_gen, &q_gen);
      _mint_used(wir_r);
      {
        u2_noun wit = j2_mcy(Pt6, ut, play)(wir_r, van, sut, p_gen);
        u2_noun nep = j2_mcy(Pt6, ut, snap)(wir_r, van, wit, q_gen);
        u2_noun ret = _mint_in(wir_r, van, sut, gol, nep);

        u2_rz(wir_r, nep);
        u2_rz(wir_r, wit);
        return ret;
      }
      case c3__ktbr: p_gen = u2_t(gen);
      _mint_used(wir_r);
      {
        u2_noun ryd = _mint_in(wir_r, van, sut, gol, p_gen);
        u2_noun tyf = j2_mcy(Pt6, ut, wrap)(wir_r, van, u2_h(ryd), c3__iron);
        u2_noun pro = u2_bc(wir_r, tyf, u2_rx(wir_r, u2_t(ryd)));

        u2_rz(wir_r, ryd);
        return pro;
      }
      case c3__ktpm: p_gen = u2_t(gen);
      _mint_used(wir_r);
      {
        u2_noun ryd = _mint_in(wir_r, van, sut, gol, p_gen);
        u2_noun tyf = j2_mcy(Pt6, ut, wrap)(wir_r, van, u2_h(ryd), c3__zinc);
        u2_noun pro = u2_bc(wir_r, tyf, u2_rx(wir_r, u2_t(ryd)));

        u2_rz(wir_r, ryd);
        return pro;
      }
      case c3__ktwt: p_gen = u2_t(gen);
      _mint_used(wir_r);
      {
        u2_noun ryd = _mint_in(wir_r, van, sut, gol, p_gen);
        u2_noun tyf = j2_mcy(Pt6, ut, wrap)(wir_r, van, u2_h(ryd), c3__lead);
        u2_noun pro = u2_bc(wir_r, tyf, u2_rx(wir_r, u2_t(ryd)));

        u2_rz(wir_r, ryd);
        return pro;
      }
      case c3__ktts: u2_bi_cell(wir_r, u2_t(gen), &p_gen, &q_gen);
      _mint_used(wir_r);
      {
        u2_noun vat = _mint_in(wir_r, van, sut, gol, q_gen);
     
        ret = u2_bc
          (wir_r,
           u2_bt(wir_r, c3__face,
                        u2_rx(wir_r, p_gen), 
                        u2_rx(wir_r, u2_h(vat))),
           u2_rx(wir_r, u2_t(vat)));

        u2_rl_lose(wir_r, vat);
        return ret;
      }
      case c3__ktsg: p_gen = u2_t(gen);
      _mint_used(wir_r);
      {
        u2_noun nef = _mint_in(wir_r, van, sut, gol, p_gen);
        u2_noun p_nef = u2_h(nef);
        u2_noun q_nef = u2_t(nef);
        u2_noun fom;

        {
          u2_noun cag = j2_mcy(Pt6, ut, burn)(wir_r, van, sut);
          u2_noun wim = u2_cn_moch(cag, u2k(q_nef));

          if ( 0 == u2h(wim) ) {
            fom = u2nc(1, u2k(u2t(wim)));
          } else {
            fom = u2k(q_nef);
          }
          u2z(wim);
        }
        ret = u2_bc(wir_r, u2_rx(wir_r, p_nef), fom);
 
        u2_rz(wir_r, nef);
        return ret;
      }
      case c3__ktls: u2_bi_cell(wir_r, u2_t(gen), &p_gen, &q_gen);
      _mint_used(wir_r);
      {
        u2_noun hif = j2_mcy(Pt6, ut, play)(wir_r, van, sut, p_gen);
        u2_noun zel = _mint_in(wir_r, van, sut, hif, q_gen);
        u2_noun ret = u2_bc(wir_r, hif, u2_rx(wir_r, u2_t(zel)));

        u2_rz(wir_r, zel);
        return ret;
      }
      case c3__tsgr: u2_bi_cell(wir_r, u2_t(gen), &p_gen, &q_gen);
      _mint_used(wir_r);
      {
        u2_noun fid = _mint_in(wir_r, van, sut, c3__noun, p_gen);
        u2_noun p_fid = u2_h(fid);
        u2_noun q_fid = u2_t(fid);
        u2_noun dov = _mint_in(wir_r, van, p_fid, gol, q_gen);
        u2_noun p_dov = u2_h(dov);
        u2_noun q_dov = u2_t(dov);

        ret = u2_bc
          (wir_r, u2_rx(wir_r, p_dov), 
                  j2_mbc(Pt6, comb)(wir_r, q_fid, q_dov));

        u2_rl_lose(wir_r, fid); 
        u2_rl_lose(wir_r, dov);
        return ret;
      }
      case c3__cnts: u2_bi_cell(wir_r, u2_t(gen), &p_gen, &q_gen);
      _mint_used(wir_r);
      {
        u2_noun sec = j2_mcy(Pt6, ut, seek)(wir_r, van, sut, c3__read, p_gen);
        u2_noun lar = _mint_foil(wir_r, sec);
        u2_noun p_lar = u2_h(lar);
        u2_noun q_lar = u2_t(lar);
        u2_noun pq_lar = u2_h(q_lar);
        u2_noun qq_lar = u2_t(q_lar);
        u2_noun mew = j2_mcy(Pt6, ut, swab)(wir_r, van, sut, qq_lar, q_gen);
        u2_noun yom = _mint_edit
          (wir_r, van, sut, mew, p_lar, u2_rx(wir_r, qq_lar), u2_nul);
        u2_noun p_yom = u2_h(yom);
        u2_noun q_yom = u2_t(yom);
        u2_noun ret = u2_bc
          (wir_r, _mint_nice(wir_r, van, gol, u2_rx(wir_r, p_yom)),
                  (_0 == pq_lar) ? u2_rx(wir_r, q_yom)
                                 : u2_bt(wir_r, _9,
                                                u2_rx(wir_r, pq_lar),
                                                u2_rx(wir_r, q_yom)));
                  
        u2_rz(wir_r, yom);
        u2_rz(wir_r, mew);
        u2_rz(wir_r, lar);

        return ret;
      }
      case c3__pmcl: u2_bi_cell(wir_r, u2_t(gen), &p_gen, &q_gen);
      _mint_used(wir_r);
      {
        u2_noun ruf = u2_bt
          (wir_r, c3__clhp, 
                  u2_bc(wir_r, u2_nul, _1),
                  u2_rx(wir_r, p_gen));
        u2_noun ret = _mint_grow(wir_r, van, sut, gol, c3__zinc, ruf, q_gen);

        u2_rz(wir_r, ruf);
        return ret;
      }
      case c3__brcn: p_gen = u2_t(gen);
      _mint_used(wir_r);
      {
        u2_noun ruf = u2_bc(wir_r, u2_nul, _1);

        ret = _mint_grow(wir_r, van, sut, gol, c3__gold, ruf, p_gen);
        u2_rz(wir_r, ruf);

        return ret;
      }
      case c3__pmcn: p_gen = u2_t(gen);
      _mint_used(wir_r);
      {
        u2_noun ruf = u2_bc(wir_r, u2_nul, _1);

        ret = _mint_grow(wir_r, van, sut, gol, c3__lead, ruf, p_gen);
        u2_rz(wir_r, ruf);

        return ret;
      }
      case c3__pmls: u2_bi_cell(wir_r, u2_t(gen), &p_gen, &q_gen);
      _mint_used(wir_r);
      {
        u2_noun ruf = u2_bt
          (wir_r, c3__clhp, 
                  u2_bc(wir_r, u2_nul, _1),
                  u2_rx(wir_r, p_gen));
        u2_noun ret = _mint_grow(wir_r, van, sut, gol, c3__iron, ruf, q_gen);

        u2_rz(wir_r, ruf);
        return ret;
      }
      case c3__sggr: u2_bi_cell(wir_r, u2_t(gen), &p_gen, &q_gen);
      _mint_used(wir_r);
      {
        u2_noun hum = _mint_in(wir_r, van, sut, gol, q_gen);
        u2_noun bez;
      
          if ( u2_yes == u2_stud(p_gen) ) {
            bez = u2_rx(wir_r, p_gen);
          } else {
            bez = u2_bc(wir_r, u2_rx(wir_r, u2_h(p_gen)),
                               _mint_corn(wir_r, van, sut, u2_t(p_gen)));
          }
          ret = u2_bc(wir_r, 
                      u2_rx(wir_r, u2_h(hum)),
                      u2_bt(wir_r, _10, bez, u2_rx(wir_r, u2_t(hum))));
        
        u2_rl_lose(wir_r, hum);
        return ret;
      }
      case c3__zpts: p_gen = u2_t(gen);
      _mint_used(wir_r);
      {
        u2_noun von = u2_bn_molt(wir_r, van, j2_ut_van_vet, u2_no, 0);
        u2_noun sev = _mint_corn(wir_r, von, sut, p_gen);

        u2_rz(wir_r, von);
        return u2_bc(wir_r, c3__noun, u2_bc(wir_r, _1, sev));
      }
      case c3__zpcm: u2_bi_cell(wir_r, u2_t(gen), &p_gen, &q_gen);
      _mint_used(wir_r);
      {
        return u2_bc
          (wir_r, 
           _mint_nice(wir_r, van, 
                             gol, 
                             j2_mcy(Pt6, ut, play)(wir_r, van, sut, p_gen)),
           u2_bc(wir_r, 1, u2_rx(wir_r, q_gen)));
      }
      case c3__zpcb: u2_bi_cell(wir_r, u2_t(gen), &p_gen, &q_gen);
      {
        u2_bl_push(wir_r, u2_bc(wir_r, c3__mean, _mint_loc(wir_r, van, p_gen)));
        {
          u2_noun hum = _mint_in(wir_r, van, sut, gol, q_gen);
          u2_noun bez = u2_bt(wir_r, c3__spot, _1, u2_rx(wir_r, p_gen));

          ret = u2_bc(wir_r, 
                      u2_rx(wir_r, u2_h(hum)),
                      u2_bt(wir_r, _10, bez, u2_rx(wir_r, u2_t(hum))));

          u2_rz(wir_r, hum);
        }
        u2_bl_drop(wir_r);
        return ret;
      }
      case c3__zpcn:
      _mint_used(wir_r);
      {
        u2_noun pet   = u2_bn_hook(wir_r, van, "seed");
        u2_noun p_pet = u2_h(pet);
        u2_noun q_pet = u2_t(pet);
        u2_noun ret;

        ret = u2_bc(wir_r, _mint_nice(wir_r, van, gol, u2_rx(wir_r, p_pet)),
                           u2_bc(wir_r, _1, u2_rx(wir_r, q_pet)));

        u2_rz(wir_r, pet);
        return ret;
      }
      case c3__zpsm: u2_bi_cell(wir_r, u2_t(gen), &p_gen, &q_gen);
      _mint_used(wir_r);
      {
        u2_noun vos   = _mint_in(wir_r, van, sut, c3__noun, q_gen);
        u2_noun zur   = j2_mcy(Pt6, ut, play)(wir_r, van, sut, p_gen);
        u2_noun p_vos = u2_h(vos);
        u2_noun q_vos = u2_t(vos);
        u2_noun waz   = u2_bc(wir_r, _1, u2_rx(wir_r, p_vos));
        u2_noun cig   = j2_mby(Pt6, cell)(wir_r, zur, p_vos);
        u2_noun ret;

        ret = u2_bc(wir_r,
                    _mint_nice(wir_r, van, gol, cig),
                    j2_mby(Pt6, cons)(wir_r, waz, q_vos));

        u2_rz(wir_r, waz);
        u2_rz(wir_r, zur);
        u2_rz(wir_r, vos);

        return ret;
      }
      case c3__zpfs: p_gen = u2_t(gen);
      _mint_used(wir_r);
      {
        if ( u2_yes == _mint_vet(wir_r, van) ) {
          u2_noun zur = j2_mcy(Pt6, ut, play)(wir_r, van, sut, p_gen);
          u2_noun dun = j2_mcy(Pt6, ut, dunq)(wir_r, van, "lost", zur);

          u2_bl_push(wir_r, u2_bc(wir_r, c3__mean, dun));
          return u2_bl_error(wir_r, "mint-lost");
        }
        else {
          return u2_bt(wir_r, c3__void, _0, _0);
        }
      }
      case c3__zpzp:
      _mint_used(wir_r);
      {
        return u2_bt(wir_r, c3__void, _0, _0);
      }
    }
  }
Пример #28
0
/* nock_mool(): fast internal mink interface.  Arguments transferred.
*/
u2_noun
_nock_mool(u2_noun  bus,
           u2_noun  fol,
           u2_kode* pon)
{
    u2_noun hib, gal;

    c3_assert(u2_yes == *pon);

    while ( 1 ) {
        u2_tx_did_hop(u2_Wire, 1);

        if ( u2_no == u2du(fol) ) {
            *pon = 2;
            u2z(bus);
            u2z(fol);
            return u2_cm_wail();
        }
        else {
            hib = u2fh(fol);
            gal = u2ft(fol);
        }

        if ( u2_yes == u2du(hib) ) {
            u2_noun poz, riv;
            u2_kode h_pon = 0, t_pon = 0;

            poz = _nock_mool(u2k(bus), u2k(hib), &h_pon);
            if ( 2 == h_pon ) {
                *pon = 2;
                u2z(bus);
                u2z(fol);
                return poz;
            }

            riv = _nock_mool(bus, u2k(gal), &t_pon);
            u2z(fol);
            if ( 2 == t_pon ) {
                *pon = 2;
                u2z(poz);
                return riv;
            }

            if ( (1 == h_pon) || (1 == t_pon) ) {
                u2_noun lal;

                *pon = 1;

                if ( 0 == h_pon ) {
                    u2z(poz);
                    lal = riv;
                } else if ( 0 == t_pon ) {
                    u2z(riv);
                    lal = poz;
                } else {
                    lal = u2_ckb_weld(poz, riv);
                }
                return lal;
            }
            return u2_cn_cell(poz, riv);
        }
        else switch ( hib ) {
            default:
                *pon = 2;
                u2z(bus);
                u2z(fol);
                return u2_cm_wail();

            case 0: {
                if ( u2_no == u2_cr_ud(gal) ) {
                    *pon = 2;
                    u2z(bus);
                    u2z(fol);
                    return u2_cm_wail();
                }
                else {
                    u2_weak pro = u2_cr_at(gal, bus);

                    if ( u2_none == pro ) {
                        *pon = 2;
                        u2z(bus);
                        u2z(fol);
                        return u2_cm_wail();
                    }
                    else {
                        pro = u2k(pro);
                        u2z(bus);
                        u2z(fol);

                        return pro;
                    }
                }
            }
            case 1: {
                u2_noun pro = u2k(gal);

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

            case 2: {
                if ( (u2_no == u2du(gal)) || (u2_no == u2du(u2fh(gal))) ) {
                    *pon = 2;
                    u2z(bus);
                    u2z(fol);
                    return u2_cm_wail();
                }
                else {
                    u2_noun neb;

                    neb = _nock_mool(bus, u2k(gal), pon);
                    u2z(fol);
                    if ( 0 != *pon ) {
                        return neb;
                    }

                    bus = u2k(u2fh(neb));
                    fol = u2k(u2ft(neb));
                    u2z(neb);
                    continue;
                }
            }
            c3_assert(!"not reached");

            case 3: {
                u2_noun gof, pro;

                gof = _nock_mool(bus, u2k(gal), pon);
                u2z(fol);
                if ( 0 != *pon ) {
                    return gof;
                }

                pro = u2du(gof);
                u2z(gof);

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

            case 4: {
                u2_noun gof, pro;

                gof = _nock_mool(bus, u2k(gal), pon);
                u2z(fol);
                if ( 0 != *pon ) {
                    return gof;
                }

                if ( u2_none == (pro = u2_rl_vint(u2_Wire, gof)) ) {
                    *pon = 2;
                    u2z(gof);
                    return u2_cm_wail();
                }
                u2z(gof);

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

            case 5: {
                u2_noun gof, pro;

                gof = _nock_mool(bus, u2k(gal), pon);
                u2z(fol);
                if ( 0 != *pon ) {
                    return gof;
                }

                if ( u2_no == u2du(gof) ) {
                    *pon = 2;
                    u2z(gof);
                    return u2_cm_wail();
                }
                pro = u2_cr_sing(u2h(gof), u2t(gof));
                u2z(gof);

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

            case 6: {
                u2_noun b_gal, cd_gal, c_gal, d_gal;

                if ( u2_no == u2_cr_cell(gal, &b_gal, &cd_gal) ) {
                    *pon = 2;
                    u2z(bus);
                    u2z(fol);
                    return u2_cm_wail();
                }
                else {
                    u2_noun tys, nex;

                    tys = _nock_mool(u2k(bus), u2k(b_gal), pon);
                    if ( 0 != *pon ) {
                        u2z(bus);
                        u2z(fol);
                        return tys;
                    }

                    if ( u2_no == u2_cr_cell(cd_gal, &c_gal, &d_gal) ) {
                        *pon = 2;
                        u2z(bus);
                        u2z(fol);
                        return u2_cm_wail();
                    }

                    if ( 0 == tys ) {
                        nex = u2k(c_gal);
                    } else if ( 1 == tys ) {
                        nex = u2k(d_gal);
                    } else {
                        *pon = 2;
                        u2z(bus);
                        u2z(fol);
                        return u2_cm_wail();
                    }

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

            case 7: {
                u2_noun b_gal, c_gal;

                if ( u2_no == u2_cr_cell(gal, &b_gal, &c_gal) ) {
                    *pon = 2;
                    u2z(bus);
                    u2z(fol);
                    return u2_cm_wail();
                }
                else {
                    u2_noun bod, nex;

                    bod = _nock_mool(bus, u2k(b_gal), pon);
                    if ( 0 != *pon ) {
                        u2z(fol);
                        return bod;
                    }

                    nex = u2k(c_gal);
                    u2z(fol);

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

            case 8: {
                u2_noun b_gal, c_gal;

                // c3_assert(!"got 8 (mink)!");
                if ( u2_no == u2_cr_cell(gal, &b_gal, &c_gal) ) {
                    *pon = 2;
                    u2z(bus);
                    u2z(fol);
                    return u2_cm_wail();
                }
                else {
                    u2_noun wib, bod, nex;

                    wib = _nock_mool(u2k(bus), u2k(b_gal), pon);
                    if ( 0 != *pon ) {
                        u2z(bus);
                        u2z(fol);
                        return wib;
                    }

                    bod = u2nc(wib, bus);
                    nex = u2k(c_gal);
                    u2z(fol);

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

            case 9: {
                u2_noun b_gal, c_gal;

                if ( (u2_no == u2_cr_cell(gal, &b_gal, &c_gal)) ||
                        (u2_no == u2ud(b_gal)) )
                {
                    *pon = 2;
                    u2z(bus);
                    u2z(fol);
                    return u2_cm_wail();
                }
                else {
                    u2_noun seb;
                    u2_weak xip;

                    seb = _nock_mool(bus, u2k(c_gal), pon);
                    u2z(fol);
                    if ( 0 != *pon ) {
                        return seb;
                    }

                    u2_tx_sys_bit(u2_Wire, u2_yes);
                    xip = u2_ds_find(u2_Wire, seb);
                    u2_tx_sys_bit(u2_Wire, u2_no);

                    if ( u2_none != xip ) {
                        u2_noun pro;

                        u2_tx_sys_bit(u2_Wire, u2_yes);
                        pro = u2_ho_kicq(u2_Wire, xip, seb, b_gal, pon);
                        u2_tx_sys_bit(u2_Wire, u2_no);
                        u2z(seb);

                        if ( u2_none == pro ) {
                            *pon = 2;
                            return u2_cm_wail();
                        }
                        else return pro;
                    }
                    else {
                        u2_noun nex = u2_cr_at(b_gal, seb);

                        if ( u2_none == nex ) {
                            *pon = 2;
                            u2z(seb);
                            return u2_cm_wail();
                        }
                        bus = seb;
                        fol = u2k(nex);
                        continue;
                    }
                }
            }
            c3_assert(!"not reached");

            case 10: {
                u2_noun p_gal, q_gal;

                if ( u2_no == u2_cr_cell(gal, &p_gal, &q_gal) ) {
                    *pon = 2;
                    u2z(bus);
                    u2z(fol);
                    return u2_cm_wail();
                }
                else {
                    u2_noun zep, hod, nex;

                    if ( u2_yes == u2du(p_gal) ) {
                        u2_noun b_gal = u2fh(p_gal);
                        u2_noun c_gal = u2ft(p_gal);
                        u2_noun d_gal = q_gal;

                        hod = _nock_mool(u2k(bus), u2_ct(c_gal), pon);
                        if ( 0 != *pon ) {
                            u2z(fol);
                            return hod;
                        }

                        zep = u2k(b_gal);
                        nex = u2k(d_gal);
                        u2z(fol);
                    }
                    else {
                        u2_noun b_gal = p_gal;
                        u2_noun c_gal = q_gal;

                        zep = u2k(b_gal);
                        hod = u2_nul;
                        nex = u2k(c_gal);

                        u2z(fol);
                    }

                    return _nock_hint(zep, hod, bus, nex, pon);
                }
            }

            case 11: {
                u2_noun gof;

                gof = _nock_mool(bus, u2k(gal), pon);
                u2z(fol);
                if ( 0 != *pon ) {
                    return gof;
                }

                return _nock_pray_mool(gof, pon);
            }
            c3_assert(!"not reached");
            }
    }
}
Пример #29
0
/* _nock_cool(): nock, transferring arguments.
*/
static u2_noun
_nock_cool(u2_noun bus,
           u2_noun fol)
{
    u2_noun hib, gal;

    while ( 1 ) {
        u2_tx_did_hop(u2_Wire, 1);

        if ( u2_no == u2du(fol) ) {
            return u2_cm_bail(c3__exit);
        }
        else {
            hib = u2fh(fol);
            gal = u2ft(fol);
        }

        if ( u2_yes == u2du(hib) ) {
            u2_noun poz, riv;

            poz = _nock_cool(u2k(bus), u2k(hib));
            riv = _nock_cool(bus, u2k(gal));

            u2z(fol);
            return u2_cn_cell(poz, riv);
        }
        else switch ( hib ) {
            default:
                return u2_cm_bail(c3__exit);

            case 0: {
                if ( u2_no == u2_cr_ud(gal) ) {
                    return u2_cm_bail(c3__exit);
                }
                else {
                    u2_noun pro = u2k(u2at(gal, bus));

                    u2z(bus);
                    u2z(fol);
                    return pro;
                }
            }
            case 1: {
                u2_noun pro = u2k(gal);

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

            case 2: {
                if ( u2_no == u2du(gal) ) {
                    return u2_cm_bail(c3__exit);
                }
                else {
                    u2_noun nex = _nock_cool(u2k(bus), u2k(u2ft(gal)));
                    u2_noun seb = _nock_cool(bus, u2k(u2fh(gal)));

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

            case 3: {
                u2_noun gof, pro;

                gof = _nock_cool(bus, u2k(gal));
                pro = u2du(gof);

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

            case 4: {
                u2_noun gof, pro;

                gof = _nock_cool(bus, u2k(gal));
                if ( (u2_none == (pro = u2_rl_vint(u2_Wire, gof))) ) {
                    return u2_cm_bail(c3__exit);
                }

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

            case 5: {
                if ( u2_no == u2du(gal) ) {
                    return u2_cm_bail(c3__exit);
                }
                else {
                    u2_noun wim = _nock_cool(bus, u2k(gal));
                    u2_noun pro;

                    if ( u2_no == u2du(wim) ) {
                        return u2_cm_bail(c3__exit);
                    }
                    else pro = u2_cr_sing(u2h(wim), u2t(wim));

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

            case 6: {
                u2_noun b_gal, c_gal, d_gal;

                u2_cx_trel(gal, &b_gal, &c_gal, &d_gal);
                {
                    u2_noun tys = _nock_cool(u2k(bus), u2k(b_gal));
                    u2_noun nex;

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

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

            case 7: {
                u2_noun b_gal, c_gal;

                u2_cx_cell(gal, &b_gal, &c_gal);
                {
                    u2_noun bod = _nock_cool(bus, u2k(b_gal));
                    u2_noun nex = u2k(c_gal);

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

            case 8: {
                u2_noun b_gal, c_gal;

                // c3_assert(!"got 8 (nock)!");
                u2_cx_cell(gal, &b_gal, &c_gal);
                {
                    u2_noun bod = u2nc(_nock_cool(u2k(bus), u2k(b_gal)), bus);
                    u2_noun nex = u2k(c_gal);

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

            case 9: {
                u2_noun b_gal, c_gal;

                u2_cx_cell(gal, &b_gal, &c_gal);
                if ( u2_no == u2ud(b_gal) ) {
                    return u2_cm_bail(c3__exit);
                }
                else {
                    u2_noun seb = _nock_cool(bus, u2k(c_gal));
                    u2_weak xip;

                    u2_tx_sys_bit(u2_Wire, u2_yes);
                    xip = u2_ds_find(u2_Wire, seb);

                    if ( u2_none != xip ) {
                        u2_noun pro = u2_ho_kick(u2_Wire, xip, seb, b_gal);

                        u2_tx_sys_bit(u2_Wire, u2_no);
                        if ( u2_none == pro ) {
                            return u2_cm_bail(c3__exit);
                        }
                        else {
                            u2z(seb);
                            u2z(fol);
                            return pro;
                        }
                    }
                    else {
                        u2_tx_sys_bit(u2_Wire, u2_no);
                        {
                            u2_noun nex = u2_ct(u2at(b_gal, seb));

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

            case 10: {
                u2_noun p_gal, q_gal;

                u2_cx_cell(gal, &p_gal, &q_gal);
                {
                    u2_noun zep, hod, nex, pro;

                    if ( u2_yes == u2du(p_gal) ) {
                        u2_noun b_gal = u2fh(p_gal);
                        u2_noun c_gal = u2ft(p_gal);
                        u2_noun d_gal = q_gal;

                        zep = u2k(b_gal);
                        hod = _nock_cool(u2k(bus), u2_ct(c_gal));
                        nex = u2_ct(d_gal);
                    }
                    else {
                        u2_noun b_gal = p_gal;
                        u2_noun c_gal = q_gal;

                        zep = u2k(b_gal);
                        hod = u2_nul;
                        nex = u2_ct(c_gal);
                    }

                    u2_cz(fol);
                    pro = _nock_hint(zep, hod, bus, nex, 0);
                    return pro;
                }
            }

            case 11: {
                u2_noun gof, pro;

                gof = _nock_cool(bus, u2k(gal));
                pro = _nock_pray_cool(gof);

                u2z(fol);
                return pro;
            }
            c3_assert(!"not reached");
            }
    }
}
Пример #30
0
/* _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;
        }
    }
    }
}