/* zuse_boot(): create the zuse engine. */ struct zuse_state* zuse_boot(const c3_c* src_c) { struct zuse_state* fod_f = malloc(sizeof(struct zuse_state)); u2_ray wir_r; u2_boot(); wir_r = u2_wr_init(c3__rock, u2_ray_of(0, 0), u2_ray_of(1, 0)); fod_f->wir_r = wir_r; { u2_ray jub_r = u2_bl_open(wir_r); fprintf(stderr, "boot: %s\n", src_c); if ( u2_bl_set(wir_r) ) { u2_bl_done(wir_r, jub_r); fprintf(stderr, "boot failed\n"); free(fod_f); return 0; } else { u2_bx_boot(wir_r); if ( u2_yes == u2_ux_fresh(src_c, "watt", "noun") ) { _zuse_load_rock(fod_f, src_c); } else { _zuse_load_cold(fod_f, src_c); } _zuse_gates(fod_f); u2_bl_done(wir_r, jub_r); u2_bx_spot(wir_r, u2_nul); u2_bx_show(wir_r); return fod_f; } } }
/* hill_boot(): create the hill engine. */ struct hill_state* // produce hill_boot(void) { struct hill_state* hil_h = malloc(sizeof(struct hill_state)); u2_ray wir_r; u2_boot(); wir_r = u2_wr_init(c3__rock, u2_ray_of(0, 0), u2_ray_of(1, 0)); Hill = hil_h; Hill->wir_r = wir_r; Hill->soa = u2_none; Hill->sob = u2_none; Hill->soc = u2_none; /* Mint the shoes. Impeccable memory practices. */ { u2_noun soa = u2_none; u2_noun sob = u2_none; u2_noun soc = u2_none; do { /* Boot shoe A. */ if ( u2_no == u2_rl_leap(wir_r, c3__rock) ) { c3_assert(0); } u2_bx_boot(wir_r); { u2_ray kit_r = u2_bl_open(wir_r); if ( u2_bl_set(wir_r) ) { u2_bl_done(wir_r, kit_r); u2_rl_fall(wir_r); fprintf(stderr, "{no boot, a}\n"); break; } else { soa = _hill_z_boot(wir_r, FileA); u2_bl_done(wir_r, kit_r); u2_bx_spot(wir_r, u2_nul); u2_bx_show(wir_r); } } fprintf(stderr, "{cold boot: %s, with %s jets: %x}\n", FileA, FileZ, u2_mug(soa)); Hill->soa = u2_rl_take(u2_wire_bas_r(wir_r), soa); u2_rl_fall(wir_r); /* Boot shoe B. */ if ( u2_no == u2_rl_leap(wir_r, c3__rock) ) { c3_assert(0); } u2_bx_boot(wir_r); { u2_ray kit_r = u2_bl_open(wir_r); if ( u2_bl_set(wir_r) ) { u2_bl_done(wir_r, kit_r); u2_rl_fall(wir_r); fprintf(stderr, "{no boot, b}\n"); break; } else { sob = _hill_a_boot(wir_r, soa, FileB); u2_bl_done(wir_r, kit_r); u2_bx_spot(wir_r, u2_nul); u2_bx_show(wir_r); } } fprintf(stderr, "{warm boot: %s, with %s: %x}\n", FileB, FileA, u2_mug(sob)); Hill->sob = u2_rl_take(u2_wire_bas_r(wir_r), sob); u2_rl_fall(wir_r); /* Boot shoe C. */ if ( u2_no == u2_rl_leap(wir_r, c3__rock) ) { c3_assert(0); } u2_bx_boot(wir_r); { u2_ray kit_r = u2_bl_open(wir_r); if ( u2_bl_set(wir_r) ) { u2_bl_done(wir_r, kit_r); u2_rl_fall(wir_r); fprintf(stderr, "{no boot, c}\n"); u2_bx_show(wir_r); break; } else { soc = _hill_b_eyre(wir_r, soa, sob, FileC); u2_bl_done(wir_r, kit_r); u2_bx_spot(wir_r, u2_nul); u2_bx_show(wir_r); } } fprintf(stderr, "{last boot: %s, with %s: %x}\n", FileC, FileB, u2_mug(soc)); Hill->soc = u2_rl_take(u2_wire_bas_r(wir_r), soc); u2_rl_fall(wir_r); /* Testing basics of soc. */ printf("testing eyre...\n"); { u2_noun foo = u2_rl_string(wir_r, "|!(a=@ (dec a))"); u2_noun bar = u2_nk_nock(wir_r, foo, Hill->soc); if ( u2_none == bar ) { printf("no bar\n"); } else { u2_noun moo = u2_nk_nock(wir_r, _0, bar); if ( u2_none == moo ) { printf("no moo\n"); } else { u2_noun zor = u2_nk_mung(wir_r, moo, 13); u2_err(wir_r, "zor", zor); } } } printf("tested.\n"); #if 1 { u2_noun soa = Hill->soa; u2_noun sob = Hill->sob; u2_noun dat = Hill->soc; u2_noun pak, bag; fprintf(stderr, "jam test: jam\n"); u2_bx_boot(wir_r); pak = _hill_b_jam(wir_r, soa, sob, dat); u2_bx_show(wir_r); fprintf(stderr, "jam test: %d bits\n", u2_met(0, pak)); u2_ux_write(wir_r, pak, "watt/264", "noun"); fprintf(stderr, "jam test: cue\n"); u2_bx_boot(wir_r); bag = _hill_b_cue(wir_r, soa, sob, pak); u2_bx_show(wir_r); if ( u2_yes == u2_sing(bag, dat) ) { fprintf(stderr, "jam test: match\n"); } else { fprintf(stderr, "jam test: NO MATCH\n"); } } #endif return Hill; } while (0); free(Hill); return 0; } }
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; }