/* functions */ u3_noun u3qb_murn(u3_noun a, u3_noun b) { if ( 0 == a ) { return a; } else if ( c3n == u3du(a) ) { return u3m_bail(c3__exit); } else { u3_noun one = u3n_slam_on(u3k(b), u3k(u3h(a))); u3_noun two = u3qb_murn(u3t(a), b); u3_noun nex; switch ( u3ud(one) ) { case c3y: u3z(one); return two; case c3n: nex = u3nc(u3k(u3t(one)), two); u3z(one); return nex; default: u3z(one); u3z(two); return u3_none; } } }
/* functions */ u3_noun u3qb_roll(u3_noun a, u3_noun b) { if ( 0 == a ) { return u3k(u3r_at(u3x_sam_3, b)); } else if ( c3n == u3du(a) ) { return u3m_bail(c3__exit); } else { u3_noun gim = u3k(u3h(a)); u3_noun zor = u3k(u3r_at(u3x_sam_3, b)); u3_noun daz = u3n_slam_on(u3k(b), u3nc(gim, zor)); u3_noun vel = u3i_molt(u3k(b), u3x_sam_3, daz, 0); if ( u3_none == vel ) { return u3m_bail(c3__exit); } else { u3_noun hox = u3qb_roll(u3t(a), vel); u3z(vel); return hox; } } }
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); } } }
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; }
static u3_noun _mint_brew( u3_noun van, u3_noun sut, u3_noun tov, u3_noun gen) { u3_noun von; switch ( tov ) { default: return u3m_bail(c3__fail); case c3y: von = u3k(van); break; case c3n: von = u3i_molt(u3k(van), u3qfu_van_vet, c3n, 0); break; } { u3_noun mil = u3qfu_mint(von, sut, c3__noun, gen); u3_noun fol = u3k(u3t(mil)); u3z(mil); u3z(von); return fol; } }
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; }
/* 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)); } } } }
/* pfix */ u3_noun _cqe_pfix(u3_noun vex, u3_noun sab) { u3_noun p_vex, q_vex; u3x_cell(vex, &p_vex, &q_vex); if ( c3n == u3du(q_vex) ) { return u3k(vex); } else { u3_noun uq_vex = u3t(q_vex); u3_noun puq_vex, quq_vex; u3_noun yit, p_yit, q_yit; u3_noun ret; u3x_cell(uq_vex, &puq_vex, &quq_vex); yit = u3x_good(u3n_slam_on(u3k(sab), u3k(quq_vex))); u3x_cell(yit, &p_yit, &q_yit); ret = u3nc(_last(p_vex, p_yit), u3k(q_yit)); u3z(yit); return ret; } }
/* cold */ u3_noun _cqe_cold_fun(u3_noun cus, u3_noun sef, u3_noun tub) { u3_noun vex = u3x_good(u3n_slam_on(u3k(sef), u3k(tub))); u3_noun p_vex, q_vex; u3x_cell(vex, &p_vex, &q_vex); if ( c3n == u3du(q_vex) ) { return vex; } else { u3_noun uq_vex = u3t(q_vex); u3_noun quq_vex; u3_noun ret; u3x_cell(uq_vex, 0, &quq_vex); ret = u3nq(u3k(p_vex), u3_nul, u3k(cus), u3k(quq_vex)); u3z(vex); return ret; } }
/* 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); }
/* boilerplate */ u3_noun _ap_core(u3_noun ter, u3_noun gen) { u3_noun gat = u3j_hook(u3k(ter), "ap"); return u3i_molt(gat, u3x_sam, u3k(gen), 0); }
/* ~(. al gen) */ static u3_noun _al_bore(u3_noun ter, u3_noun gen) { u3_noun gat = u3j_hook(u3k(ter), "al"); return u3i_molt(gat, u3x_sam, u3nc(c3__herb, u3k(gen)), 0); }
/* u3_sist_boot(): restore or create. */ void u3_sist_boot(void) { // uL(fprintf(uH, "sist: booting\n")); if ( c3y == u3_Host.ops_u.nuu ) { u3_noun pig = u3_none; if ( 0 == u3_Host.ops_u.imp_c ) { c3_c get_c[2049]; snprintf(get_c, 2048, "%s/.urb/get", u3_Host.dir_c); if ( 0 == access(get_c, 0) ) { uL(fprintf(uH, "pier: already built\n")); u3_lo_bail(); } u3_noun ten = _sist_zen(); uL(fprintf(uH, "generating 2048-bit RSA pair...\n")); pig = u3nq(c3__make, u3_nul, 11, u3nc(ten, u3_Host.ops_u.fak)); } else { u3_noun imp = u3i_string(u3_Host.ops_u.imp_c); u3_noun whu = u3dc("slaw", 'p', u3k(imp)); if ( (u3_nul == whu) ) { fprintf(stderr, "czar: incorrect format\r\n"); u3_lo_bail(); } else { u3_noun gen = u3_nul; u3_noun gun = u3_nul; if (c3n == u3_Host.ops_u.fak) { gen = _sist_text("generator"); gun = u3dc("slaw", c3__uw, gen); if ( u3_nul == gun ) { fprintf(stderr, "czar: incorrect format\r\n"); u3_lo_bail(); } } else { gun = u3nc(u3_nul, u3_nul); } pig = u3nq(c3__sith, u3k(u3t(whu)), u3k(u3t(gun)), u3_Host.ops_u.fak); u3z(whu); u3z(gun); } u3z(imp); } _sist_make(pig); } else { _sist_rest(); } }
/* _unix_sync_change(): sync single change to unix */ static void _unix_sync_change(u3_udir* dir_u, u3_noun pax, u3_noun mim) { c3_assert( c3y == dir_u->dir ); if ( c3n == u3du(pax) ) { if ( u3_nul == pax ) { uL(fprintf(uH,"can't sync out file as top-level, strange\r\n")); } else { uL(fprintf(uH,"sync out: bad path\r\n")); } u3z(pax); u3z(mim); return; } else if ( c3n == u3du(u3t(pax)) ) { uL(fprintf(uH,"can't sync out file as top-level, strangely\r\n")); u3z(pax); u3z(mim); } else { u3_noun i_pax = u3h(pax); u3_noun t_pax = u3t(pax); u3_noun it_pax = u3h(t_pax); u3_noun tt_pax = u3t(t_pax); if ( u3_nul == tt_pax ) { _unix_sync_file(dir_u, u3k(i_pax), u3k(it_pax), mim); } else { c3_c* nam_c = u3r_string(i_pax); c3_w pax_w = strlen(dir_u->pax_c); u3_unod* nod_u; for ( nod_u = dir_u->kid_u; ( nod_u && ( c3n == nod_u->dir || 0 != strcmp(nod_u->pax_c + pax_w + 1, nam_c) ) ); nod_u = nod_u->nex_u ) { } if ( !nod_u ) { nod_u = c3_malloc(sizeof(u3_udir)); _unix_create_dir((u3_udir*) nod_u, dir_u, u3k(i_pax)); } if ( c3n == nod_u->dir ) { uL(fprintf(uH, "weird, we got a file when we weren't expecting to\r\n")); c3_assert(0); } _unix_sync_change((u3_udir*) nod_u, u3k(t_pax), mim); } } u3z(pax); }
/* 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)); } } } }
static u3_noun _ar_core(u3_noun van, u3_noun ref, u3_noun syn) { u3_noun gat = u3j_hook(u3k(van), "ar"); return u3i_molt(gat, u3x_sam, u3nc(u3k(ref), u3k(syn)), 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))); }
/* u3z_save*(): save in memo cache. */ u3_noun u3z_save(c3_m fun, u3_noun one, u3_noun val) { u3_noun key = u3nc(fun, u3k(one)); u3h_put(u3R->cax.har_p, key, u3k(val)); u3z(key); return val; }
u3_noun u3z_save_3(c3_m fun, u3_noun one, u3_noun two, u3_noun tri, u3_noun val) { u3_noun key = u3nq(fun, u3k(one), u3k(two), u3k(tri)); u3h_put(u3R->cax.har_p, key, u3k(val)); u3z(key); return val; }
u3_noun u3qfu_lose(u3_noun van, u3_noun sut, u3_noun gen) { u3_noun von = u3i_molt(u3k(van), u3x_sam, u3k(sut), 0); u3_noun gat = u3j_cook("u3qfu_lose-lose", von, "lose"); return u3n_kick_on(u3i_molt(gat, u3x_sam, u3k(gen), 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; }
u3_weak u3z_find_4(c3_m fun, u3_noun one, u3_noun two, u3_noun tri, u3_noun qua) { u3_noun key = u3nc(fun, u3nq(u3k(one), u3k(two), u3k(tri), u3k(qua))); u3_noun val; val = u3h_get(u3R->cax.har_p, key); u3z(key); return val; }
u3_noun _cqe_stew_fun(u3_noun hel, u3_noun tub) { u3_noun p_tub, q_tub; u3x_cell(tub, &p_tub, &q_tub); if ( c3n == u3du(q_tub) ) { return _fail(tub); } else { u3_noun iq_tub = u3h(q_tub); if ( !_(u3a_is_cat(iq_tub)) ) { return u3m_bail(c3__fail); } else while ( 1 ) { if ( c3n == u3du(hel) ) { return _fail(tub); } else { u3_noun n_hel, l_hel, r_hel; u3_noun pn_hel, qn_hel; c3_o bit_o; u3x_trel(hel, &n_hel, &l_hel, &r_hel); u3x_cell(n_hel, &pn_hel, &qn_hel); if ( (c3n == u3du(pn_hel)) ) { bit_o = __((iq_tub == pn_hel)); } else { u3_noun hpn_hel = u3h(pn_hel); u3_noun tpn_hel = u3t(pn_hel); if ( !_(u3a_is_cat(hpn_hel)) || !_(u3a_is_cat(tpn_hel)) ) { return _fail(tub); } else bit_o = __((iq_tub >= hpn_hel) && (iq_tub <= tpn_hel)); } if ( c3y == bit_o ) { return u3x_good (u3n_slam_on(u3k(qn_hel), u3k(tub))); } else { if ( c3y == _stew_wor(iq_tub, pn_hel) ) { hel = l_hel; } else hel = r_hel; } } } } }
/* u3_term_ef_bake(): initial effects for new terminal. */ void u3_term_ef_bake(u3_noun fav) { u3_noun pax = u3nq(u3_blip, c3__term, '1', u3_nul); u3v_plan(u3k(pax), u3nc(c3__boot, fav)); u3v_plan(u3k(pax), u3nc(c3__blew, u3_term_get_blew(1))); u3v_plan(u3k(pax), u3nc(c3__hail, u3_nul)); u3z(pax); }
/* 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)); }
/* 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)); }
/* 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); } } }
u3_noun u3qdb_bif(u3_noun a, u3_noun b) { u3_noun c, n_c, l_c, r_c; u3_noun d; c = _b_bif_putroot(a, b); u3r_trel(c, &n_c, &l_c, &r_c); d = u3nc(u3k(l_c), u3k(r_c)); u3z(c); return d; }
/* functions */ u3_noun u3qf_hint(u3_noun sag, u3_noun tip) { if ( c3__void == tip ) { return c3__void; } if ( c3__noun == tip ) { return c3__noun; } else return u3nt(c3__hint, u3k(sag), u3k(tip)); }
/* 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; } } }