예제 #1
0
파일: nock.c 프로젝트: sillsm/urbit
/* _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;
                }
            }
        }
    }
}
예제 #2
0
파일: nock.c 프로젝트: sillsm/urbit
/* _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;
}
/* _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;
    }

#if 0
    case c3__leap: {
      u2z(hod);
      fprintf(stderr, "leaping!!\r\n");
      {
        u2_noun hoe, tax;
        
        tax = u2_wire_tax(u2_Wire);
        u2_wire_tax(u2_Wire) = u2_nul;

        u2_rl_leap(u2_Wire, c3__rock);

        if ( 0 != (hoe = u2_cm_trap()) ) {
          u2_noun cod;

          u2_rl_fall(u2_Wire);
          hoe = u2_rl_take(u2_Wire, hoe);
          u2_rl_flog(u2_Wire);

          u2_wire_tax(u2_Wire) = u2_ckb_weld(u2k(u2t(hoe)), tax);
          cod = u2k(u2h(hoe));

          fprintf(stderr, "error in leap: %s\r\n", u2_cr_string(cod));
          return u2_cm_bail(cod);
        }
        else {
          u2_noun pro = pon ? _nock_mool(bus, nex, pon) : _nock_cool(bus, nex); 

          u2_cm_done();
          u2_rl_fall(u2_Wire);
          pro = u2_rl_take(u2_Wire, pro);
          u2_rl_flog(u2_Wire);
          u2_wire_tax(u2_Wire) = tax;

          fprintf(stderr, "leapt!!\r\n");
          u2z(bus); u2z(nex); return pro;
        }
      }
    }
#endif

    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;
      }
    }
  }
}
예제 #4
0
파일: loop.c 프로젝트: gunnarahlberg/urbit
/* u2_lo_soft(): standard soft wrapper.  unifies unix and nock errors.
**
**  Produces [%$ result] or [%error (list tank)].
*/
u2_noun
u2_lo_soft(u2_reck* rec_u, c3_w sec_w, u2_funk fun_f, u2_noun arg)
{
  u2_noun hoe, pro, rop;

  u2_rl_leap(u2_Wire, c3__rock);

  //  system level setjmp, for signals
  //
  c3_assert(u2_nul == u2_wire_tax(u2_Wire));
  c3_assert(0 == u2_wire_kit_r(u2_Wire));

  //  stop signals
  //
  u2_unix_ef_hold();
  _lo_signal_deep(sec_w);

  if ( 0 != sigsetjmp(Signal_buf, 1) ) {
    u2_noun tax, pre, mok;

    //  return to blank state
    //
    _lo_signal_done();

    //  acquire trace and reset memory
    //
    tax = u2_wire_tax(u2_Wire);
    u2_rl_fall(u2_Wire);
    u2z(arg);

    tax = u2_rl_take(u2_Wire, tax);
    u2_wire_tax(u2_Wire) = u2_nul;
    mok = u2_dc("mook", 2, tax);

    //  other ugly disgusting cleanups
    {
      u2_wire_kit_r(u2_Wire) = 0;

      u2_hevx_be(u2_wire_hev_r(u2_Wire), u2_pryr, god) = 0;
      u2_hevx_at(u2_wire_hev_r(u2_Wire), lad) = 0;
    }

    switch ( Sigcause ) {
      default:            pre = c3__wyrd; break;
      case sig_none:      pre = c3__none; break;
      case sig_overflow:  pre = c3__over; break;
      case sig_interrupt: pre = c3__intr; break;
      case sig_terminate: pre = c3__term; break;
      case sig_memory:    pre = c3__full; break;
      case sig_assert:    pre = c3__lame; break;
      case sig_timer:     fprintf(stderr, "timer!!\r\n"); pre = c3__slow; break;
    }
    rop = u2nc(pre, u2k(u2t(mok)));
    u2z(mok);
    fprintf(stderr, "error computed\r\n");
    return rop;
  }

  if ( 0 != (hoe = u2_cm_trap()) ) {
    u2_noun mok;

    u2_rl_fall(u2_Wire);
    hoe = u2_rl_take(u2_Wire, hoe);
    u2_rl_flog(u2_Wire);

    mok = u2_dc("mook", 2, u2k(u2t(hoe)));
    rop = u2nc(u2k(u2h(hoe)), u2k(u2t(mok)));

    u2z(arg);
    u2z(hoe);
    u2z(mok);
  }
  else {
    u2_noun pro = fun_f(rec_u, arg);

    _lo_signal_done();
    u2_cm_done();

    u2_rl_fall(u2_Wire);
    pro = u2_rl_take(u2_Wire, pro);
    u2_rl_flog(u2_Wire);

    u2z(arg);
    rop = u2nc(u2_blip, pro);
  }
  pro = rop;

  return pro;
}
c3_i
main(c3_i   argc,
     c3_c** argv)
{
  // set both logging systems to unit-ed
  //
  u2K->inited_t = c3_false;

  c3_w kno_w;

  _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON);
  _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON);

  //  Parse options.
  //
  if ( u2_no == _main_getopt(argc, argv) ) {
    u2_ve_usage(argc, argv);
    return 1;
  }


  u2_ve_sysopt();

  printf("~\n");
  printf("welcome.\n");
  printf("vere: urbit home is %s\n", u2_Host.cpu_c);
  printf("vere: hostname is %s\n", u2_Host.ops_u.nam_c);

  if ( u2_yes == u2_Host.ops_u.dem && u2_no == u2_Host.ops_u.bat ) {
    printf("Starting daemon\n");
  }

  //  Seed prng. Don't panic -- just for fuzz testing and election timeouts.
  //
  srand(getpid());

  //  Instantiate process globals.
  {
    u2_wr_check_init(u2_Host.cpu_c);
    u2_Host.xit_i = 0;

    if ( (u2_no == u2_Host.ops_u.nuu) &&
          (u2_yes == u2_loom_load()) )
    {
      u2_Host.wir_r = u2_ray_of(0, 0);
      u2_Wire = u2_Host.wir_r;

      u2_Host.arv_u = u2_Arv;

      u2_Arv->ova.egg_u = u2_Arv->ova.geg_u = 0;

      u2_lo_grab("init", u2_none);

      //  Horrible ancient stuff.
      //
      kno_w = u2_Host.arv_u->kno_w;
      u2_Host.kno_w = kno_w;

      u2_ho_push();
    }
    else {
      u2_loom_boot();
      u2_Host.wir_r = u2_wr_init(c3__rock, u2_ray_of(0, 0), u2_ray_of(1, 0));
      u2_Wire = u2_Host.wir_r;

      u2_Host.arv_u = u2_Arv;
    }
  }

  //  If we have not loaded from checkpoint, build kernel.
  //
  if ( 0 != u2_Host.arv_u->ent_d ) {
    u2_reck_time(u2_Host.arv_u);
    u2_reck_numb(u2_Host.arv_u);
    {
      c3_c* dyt_c = u2_cr_string(u2_Host.arv_u->wen);

      printf("time: %s\n", dyt_c);
      free(dyt_c);
    }
  }
  else {
    //  Set outside bail trap.  Should not be used, but you never know...
    //
    if ( 0 != u2_cm_trap() ) {
      u2_ve_panic(argc, argv);
    }
    else {
      //  Set boot and goal stages.
      {
        if ( (0 == u2_Host.ops_u.kno_w) || (u2_Host.ops_u.kno_w > 255) ) {
          kno_w = DefaultKernel;
        } else {
          kno_w = u2_Host.ops_u.kno_w;
        }
      }

      //  Load the system.
      //
      {
        u2_Host.kno_w = u2_Host.ops_u.kno_w;

        u2_reck_boot(u2_Host.arv_u);
      }
      u2_cm_done();
    }
  }

  //  Install signal handlers and set buffers.
  //
  //  Note that we use the sigmask-restoring variant.  Essentially, when
  //  we get a signal, we force the system back into the just-booted state.
  //  If anything goes wrong during boot (above), it's curtains.
  {
    if ( 0 != sigsetjmp(Signal_buf, 1) ) {
      switch ( Sigcause ) {
        case sig_overflow: printf("[stack overflow]\r\n"); break;
        case sig_interrupt: printf("[interrupt]\r\n"); break;
        default: printf("[signal error!]\r\n"); break;
      }
      Sigcause = sig_none;

      signal(SIGINT, SIG_DFL);
      stackoverflow_deinstall_handler();

      //  Print the trace, do a GC, etc.
      //
      //  This is half-assed at present, so we exit.
      //
      u2_lo_sway(0, u2k(u2_wire_tax(u2_Wire)));

      u2_lo_bail(u2_Host.arv_u);

      exit(1);
    }
#if 1
    if ( -1 == stackoverflow_install_handler
        (overflow_handler, Sigstk, SIGSTKSZ) )
    {
      fprintf(stderr, "overflow_handler: install failed\n");
      exit(1);
    }
    signal(SIGINT, interrupt_handler);
    signal(SIGIO, SIG_IGN);
#endif
  }

  u2_lo_grab("main", u2_none);

  // booted in admin mode: do a task, then exit
  // booted in user mode: do command loop

  if (u2_Host.ops_u.adm_c != 0) {
    if      (strcmp(u2_Host.ops_u.adm_c, "edmp") ==0) { u2_egz_admin_dump_egz(); }
    else if (strcmp(u2_Host.ops_u.adm_c, "etok") ==0) { u2_kafka_admin_egz_to_kafka(); }
    else if (strcmp(u2_Host.ops_u.adm_c, "ktoe") ==0) { u2_kafka_admin_kafka_to_egz(); }
    else if (strcmp(u2_Host.ops_u.adm_c, "kcnf") ==0) { u2_lo_loop(); } // do it in the app
    else                                              { fprintf(stderr, "unsupported admin mode command %s\n", u2_Host.ops_u.adm_c); exit(1); }
  } else {
    u2_lo_loop();
  }

  return 0;
}