diff --git a/.gitignore b/.gitignore index 5669037173..08c9d4c4ee 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *.o +.DS_Store /bin/vere /urb/*/ !/urb/zod/ diff --git a/Makefile b/Makefile index 47955627bc..9622d4b35a 100644 --- a/Makefile +++ b/Makefile @@ -83,6 +83,7 @@ F_OFILES=\ f/wire.o \ f/chad.o \ f/cash.o \ + f/nash.o \ f/coal.o \ f/hevn.o \ f/host.o \ diff --git a/f/nash.c b/f/nash.c new file mode 100644 index 0000000000..84b0777455 --- /dev/null +++ b/f/nash.c @@ -0,0 +1,115 @@ +/* f/nash.c +** +** This file is in the public domain. +*/ +#include "all.h" + +struct u2_nair { + u2_noun key; + u2_noun val; +}; + +struct u2_buck { + c3_w con_w; + struct u2_nair* sto_u; +}; + +struct u2_nash { + c3_w cap_w; + struct u2_buck* sto_u; +}; + +/* u2_na_make(): create a new nounhash-table. +** +** nashtables live in C memory and do not take refs. +*/ +struct u2_nash* +u2_na_make() +{ + struct u2_nash* nas_u = c3_malloc(sizeof(struct u2_nash)); + nas_u->cap_w = 521; + nas_u->sto_u = calloc(nas_u->cap_w, sizeof(struct u2_buck)); + c3_assert(nas_u->sto_u); + // fprintf(stderr, "[%%nash-make %p]\r\n", nas_u); + return nas_u; +} + +/* u2_na_put(): put into nash, replacing. +**/ +void +u2_na_put(struct u2_nash* nash, u2_noun key, u2_noun val) +{ + struct u2_buck* buc_u = &(nash->sto_u[u2_mug(key) % nash->cap_w]); + + struct u2_nair* nuu_u; + c3_w sot_w; + c3_w i; + + if ( 0 == buc_u->con_w ) { + c3_assert(buc_u->sto_u == 0); + } + else { + for(i = 0; i < buc_u->con_w; i++) { + if (u2_sing(buc_u->sto_u[i].key, key) == u2_yes) { + buc_u->sto_u[i].val = val; +#if 0 + fprintf(stderr, "[%%nash-rep %p %p %d]\r\n", + (void*)key, (void*)val, i); +#endif + return; + } + } + } + + sot_w = buc_u->con_w; + buc_u->con_w++; + + nuu_u = realloc(buc_u->sto_u, buc_u->con_w * sizeof(struct u2_nair)); + c3_assert(nuu_u); + + nuu_u[sot_w].key = key; + nuu_u[sot_w].val = val; +#if 0 + fprintf(stderr, "[%%nash-put %p %p %d]\r\n", + (void*)key, (void*)val, sot_w); +#endif + buc_u->sto_u = nuu_u; +} + +/* u2_na_get(): get from a nounhash table +**/ +u2_weak +u2_na_get(struct u2_nash* nash, u2_noun key) +{ + struct u2_buck* buc_u = &(nash->sto_u[u2_mug(key) % nash->cap_w]); + c3_w i; + for(i = 0; i < buc_u->con_w; i++) { + if (u2_sing(buc_u->sto_u[i].key, key) == u2_yes) { +#if 0 + fprintf(stderr, "[%%nash-get %p %p %d]\r\n", + (void*)key, (void*)buc_u->sto_u[i].val, i); +#endif + return buc_u->sto_u[i].val; + } + } + return 0; +} + +/* u2_na_take(): destroy a nounhash table +**/ +void +u2_na_take(struct u2_nash* nash) +{ + c3_w i; + for(i=0; i < nash->cap_w; i++) { +#if 0 + fprintf(stderr, "%s%d%s", nash->sto_u[i].con_w, + 0==i? "[%%nash-pop " :"", + i+1==nash->cap_w? "]\r\n" :" "); +#endif + free(nash->sto_u[i].sto_u); + } + free(nash->sto_u); + free(nash); + // fprintf(stderr, "[%%nash-take %p]\r\n", nash); +} diff --git a/gen164/5/jam.c b/gen164/5/jam.c index 9fc15a29bf..836dc53492 100644 --- a/gen164/5/jam.c +++ b/gen164/5/jam.c @@ -4,30 +4,30 @@ */ #include "all.h" #include "../pit.h" - +#include "f/nash.h" /* functions */ + struct u2_nash* T_m; static u2_noun - _jam_in(u2_wire, u2_atom, u2_atom, u2_noun, u2_noun); + _jam_in(u2_wire, u2_atom, u2_atom, u2_noun); static u2_noun // produce _jam_in_pair(u2_wire wir_r, u2_atom h_a, // retain u2_atom t_a, // retain u2_atom b, // retain - u2_noun m, // retain u2_noun l) // retain { u2_noun w = u2_bc(wir_r, u2_bc(wir_r, _2, _1), u2_rx(wir_r, l)); u2_noun x = j2_mbc(Pt1, add)(wir_r, _2, b); - u2_noun d = _jam_in(wir_r, h_a, x, m, w); + u2_noun d = _jam_in(wir_r, h_a, x, w); u2_noun p_d, q_d, r_d; u2_noun r; u2_as_trel(d, &p_d, &q_d, &r_d); { u2_noun y = j2_mbc(Pt1, add)(wir_r, x, p_d); - u2_noun e = _jam_in(wir_r, t_a, y, r_d, q_d); + u2_noun e = _jam_in(wir_r, t_a, y, q_d); u2_noun p_e, q_e, r_e; u2_as_trel(e, &p_e, &q_e, &r_e); @@ -37,7 +37,7 @@ r = u2_bt (wir_r, j2_mbc(Pt1, add)(wir_r, _2, z), u2_rx(wir_r, q_e), - u2_rx(wir_r, r_e)); + 0); u2_rz(wir_r, z); } @@ -54,7 +54,6 @@ static u2_noun // produce _jam_in_flat(u2_wire wir_r, u2_atom a, // retain - u2_noun m, // retain u2_noun l) // retain { u2_noun d = j2_mby(Pt5, mat)(wir_r, a); @@ -65,7 +64,7 @@ x, j2_mbc(Pt3, lsh)(wir_r, _0, _1, u2_t(d))), u2_rx(wir_r, l)), - u2_rx(wir_r, m)); + 0); u2_rz(wir_r, d); @@ -75,7 +74,6 @@ static u2_noun // produce _jam_in_ptr(u2_wire wir_r, u2_atom u_c, // retain - u2_noun m, // retain u2_noun l) // retain { u2_noun d = j2_mby(Pt5, mat)(wir_r, u_c); @@ -85,7 +83,7 @@ (wir_r, u2_rx(wir_r, y), u2_bc(wir_r, u2_bc(wir_r, y, j2_mbc(Pt3, mix)(wir_r, _3, x)), u2_rx(wir_r, l)), - u2_rx(wir_r, m)); + 0); u2_rz(wir_r, d); u2_rz(wir_r, x); @@ -97,32 +95,27 @@ _jam_in(u2_wire wir_r, u2_noun a, // retain u2_atom b, // retain - u2_noun m, // retain u2_noun l) // retain { - u2_noun c = j2_mcc(Pt4, by, get)(wir_r, m, a); + u2_noun c = u2_na_get(T_m, a); u2_noun x; if ( u2_nul == c ) { - m = j2_mcc(Pt4, by, put)(wir_r, m, a, b); + u2_na_put(T_m, a, b); if ( u2_yes == u2_stud(a) ) { - x = _jam_in_flat(wir_r, a, m, l); + x = _jam_in_flat(wir_r, a, l); } else { - x = _jam_in_pair(wir_r, u2_h(a), u2_t(a), b, m, l); + x = _jam_in_pair(wir_r, u2_h(a), u2_t(a), b, l); } - u2_rz(wir_r, m); } else { - u2_noun u_c = u2_t(c); - - if ( u2_yes == u2_stud(a) && u2_met(0, a) <= u2_met(0, u_c) ) { - x = _jam_in_flat(wir_r, a, m, l); + if ( u2_yes == u2_stud(a) && u2_met(0, a) <= u2_met(0, c) ) { + x = _jam_in_flat(wir_r, a, l); } else { - x = _jam_in_ptr(wir_r, u_c, m, l); + x = _jam_in_ptr(wir_r, c, l); } - u2_rz(wir_r, c); } return x; } @@ -131,13 +124,15 @@ j2_mby(Pt5, jam)(u2_wire wir_r, u2_atom a) // retain { - u2_noun x = _jam_in(wir_r, a, _0, u2_nul, u2_nul); + T_m = u2_na_make(); + u2_noun x = _jam_in(wir_r, a, _0, u2_nul); u2_noun q = j2_mbc(Pt2, flop)(wir_r, u2_h(u2_t(x))); u2_noun r = j2_mbc(Pt3, can)(wir_r, _0, q); u2_rz(wir_r, x); u2_rz(wir_r, q); - + u2_na_take(T_m); + T_m = NULL; return r; } u2_noun // transfer @@ -157,6 +152,6 @@ */ u2_ho_jet j2_mbj(Pt5, jam)[] = { - { ".2", c3__hevy, j2_mb(Pt5, jam), Tier3, u2_none, u2_none }, + { ".2", c3__hevy, j2_mb(Pt5, jam), Tier5, u2_none, u2_none }, { } }; diff --git a/include/f/nash.h b/include/f/nash.h new file mode 100644 index 0000000000..ff4bf20f83 --- /dev/null +++ b/include/f/nash.h @@ -0,0 +1,11 @@ +/* include/f/nash.h +** +** This file is in the public domain. +*/ +struct u2_nash; + +struct u2_nash* u2_na_make(); +void u2_na_put(struct u2_nash* nash, u2_noun key, u2_noun val); +u2_weak u2_na_get(struct u2_nash* nash, u2_noun key); +void u2_na_take(struct u2_nash* nash); + diff --git a/include/v/vere.h b/include/v/vere.h index 2c70b52936..6d9c011f10 100644 --- a/include/v/vere.h +++ b/include/v/vere.h @@ -204,6 +204,7 @@ uv_udp_t wax_u; // socket state uv_timer_t tim_u; // network timer u2_bean alm; // alarm on + c3_w law_w; // last wakeup, unix time c3_s por_s; // public IPv4 port c3_w imp_w[256]; // imperial IPs } u2_ames; diff --git a/v/ames.c b/v/ames.c index a3a60beb06..ad8fac1ecb 100644 --- a/v/ames.c +++ b/v/ames.c @@ -228,7 +228,10 @@ u2_ames_ef_send(u2_noun lan, u2_noun pac) static void _ames_time_cb(uv_timer_t* tim_u, c3_i sas_i) { + u2_ames* sam_u = &u2_Host.sam_u; u2_lo_open(); + + sam_u->law_w = time(0); { u2_reck_plan (u2A, @@ -363,6 +366,10 @@ u2_ames_io_poll() (u2_yes == u2ud(u2t(wen))) ) { c3_d gap_d = u2_time_gap_ms(u2k(u2A->now), u2k(u2t(wen))); + c3_w lem_w = (time(0) - sam_u->law_w); + c3_w lef_w = (lem_w > 32) ? 0 : (32 - lem_w); + + gap_d = c3_min(gap_d, (c3_d)(1000 * lef_w)); if ( u2_yes == sam_u->alm ) { uv_timer_stop(&sam_u->tim_u); diff --git a/v/cttp.c b/v/cttp.c index 4fe95a0b45..bbb77c5dd5 100644 --- a/v/cttp.c +++ b/v/cttp.c @@ -1463,9 +1463,9 @@ _cttp_ccon_fire(u2_ccon* coc_u, u2_creq* ceq_u) snprintf(buf_c, 80, "content-length: %u\r\n", ceq_u->bod_u->len_w); _cttp_ccon_fire_str(coc_u, buf_c); - _cttp_ccon_fire_body(coc_u, ceq_u->bod_u); - _cttp_ccon_fire_str(coc_u, "\r\n"); + + _cttp_ccon_fire_body(coc_u, ceq_u->bod_u); } } diff --git a/v/sist.c b/v/sist.c index 291aa6e57d..06f9e3c87e 100644 --- a/v/sist.c +++ b/v/sist.c @@ -898,7 +898,7 @@ _sist_rest(u2_reck* rec_u) ent_d = 0; if ( -1 == lseek64(fid_i, 4ULL * end_d, SEEK_SET) ) { - fprintf(stderr, "end_d %llx\n", end_d); + fprintf(stderr, "end_d %llu\n", end_d); perror("lseek"); uL(fprintf(uH, "record (%s) is corrupt (c)\n", ful_c)); u2_lo_bail(rec_u);