Various fixes and improvements.

This commit is contained in:
C. Guy Yarvin 2014-10-09 18:27:02 -07:00
parent 69a669fb66
commit ae6aa44695
19 changed files with 216 additions and 70 deletions

90
g/a.c
View File

@ -181,10 +181,10 @@ u3_ca_sane(void)
}
}
/* u3_ca_walloc(): allocate storage words on hat_w.
/* _ca_walloc(): u3_ca_walloc() internals.
*/
void*
u3_ca_walloc(c3_w len_w)
static void*
_ca_walloc(c3_w len_w)
{
c3_w siz_w = c3_max(u3_cc_minimum, u3_co_boxed(len_w));
c3_w sel_w = _box_slot(siz_w);
@ -263,6 +263,27 @@ u3_ca_walloc(c3_w len_w)
}
}
int FOO;
/* u3_ca_walloc(): allocate storage words on hat_w.
*/
void*
u3_ca_walloc(c3_w len_w)
{
void* ptr_v = _ca_walloc(len_w);
#if 0
if ( u3_co_botox(ptr_v) == (u3_cs_box*)(void *) 0x200ce0ed4 ) {
static int xuc_i;
printf("xuc_i %d; u3_Code %d\r\n", xuc_i, u3_Code);
if ( 4 == xuc_i ) { FOO = 1; }
xuc_i++;
}
#endif
return ptr_v;
}
/* u3_ca_malloc(): allocate storage measured in bytes.
*/
void*
@ -1050,6 +1071,8 @@ u3_ca_sweep(c3_c* cap_c)
c3_ws use_ws = (c3_ws)box_u->use_w;
if ( use_ws > 0 ) {
printf("leak %p %d\r\n", box_u, box_u->cod_w);
leq_w += box_u->siz_w;
box_u->use_w = 0;
@ -1073,8 +1096,8 @@ u3_ca_sweep(c3_c* cap_c)
c3_assert((pos_w + leq_w) == neg_w);
// _ca_print_memory("available", (tot_w - pos_w));
// _ca_print_memory("allocated", pos_w);
_ca_print_memory("available", (tot_w - pos_w));
_ca_print_memory("allocated", pos_w);
_ca_print_memory("volatile", caf_w);
_ca_print_memory("leaked", leq_w);
}
@ -1150,6 +1173,45 @@ u3_ca_moot(c3_w* sal_w)
return u3_co_to_pug(u3_co_outa(nov_w));
}
/* _ca_detect(): in u3_ca_detect().
*/
static c3_o
_ca_detect(u3_ch_root* har_u, u3_noun fum, u3_noun som)
{
while ( 1 ) {
if ( som == fum ) {
return u3_yes;
}
else if ( u3_ne(u3du(fum)) || (u3_none != u3_ch_get(har_u, fum)) ) {
return u3_no;
}
else {
u3_ch_put(har_u, fum, 0);
if ( u3_so(_ca_detect(har_u, u3h(fum), som)) ) {
return u3_yes;
}
else fum = u3t(fum);
}
}
}
/* u3_ca_detect(): for debugging, check if (som) is referenced from (fum).
**
** (som) and (fum) are both RETAINED.
*/
c3_o
u3_ca_detect(u3_noun fum, u3_noun som)
{
u3_ch_root* har_u = u3_ch_new();
c3_o ret_o;
ret_o = _ca_detect(har_u, fum, som);
u3_ch_free(har_u);
return ret_o;
}
/* u3_ca_mint(): finish a measured proto-atom.
*/
u3_noun
@ -1197,3 +1259,21 @@ u3_ca_mint(c3_w* sal_w, c3_w len_w)
return u3_co_to_pug(u3_co_outa(nov_w));
}
/* u3_ca_lush(): leak push.
*/
c3_w
u3_ca_lush(c3_w lab_w)
{
c3_w cod_w = u3_Code;
u3_Code = lab_w;
return cod_w;
}
/* u3_ca_lop(): leak pop.
*/
void
u3_ca_lop(c3_w lab_w)
{
u3_Code = 0;
}

2
g/e.c
View File

@ -794,5 +794,7 @@ u3_ce_boot(c3_o nuu_o, c3_c* cpu_c)
else {
u3_cj_clear();
}
u3_leak_on(c3__jack);
u3_cv_jack();
u3_leak_off;
}

10
g/i.c
View File

@ -192,6 +192,8 @@ u3_ci_vint(u3_noun a)
}
}
extern int FOO;
/* u3_ci_cell():
**
** Produce the cell `[a b]`.
@ -213,7 +215,13 @@ u3_ci_cell(u3_noun a, u3_noun b)
nov_u->hed = a;
nov_u->tel = b;
return u3_co_to_pom(u3_co_outa(nov_w));
if ( !FOO ) return u3_co_to_pom(u3_co_outa(nov_w));
else {
u3_noun pro = u3_co_to_pom(u3_co_outa(nov_w));
printf("pro %u, %x\r\n", pro, u3_cr_mug(pro));
abort();
}
}
}

10
g/j.c
View File

@ -199,7 +199,13 @@ _cj_kick_b(u3_noun cor, c3_l jax_l, c3_l axe_l)
while ( 1 ) {
if ( 0 == hud_u ) { break; }
if ( mug_l != hud_u->mug_l ) { hud_u = hud_u->nex_u; continue; }
return _cj_kick_a(cor, hud_u, axe_l);
{
c3_w lab_w = u3_ca_lush(jax_l);
u3_noun pro = _cj_kick_a(cor, hud_u, axe_l);
u3_ca_lop(lab_w);
return pro;
}
}
return u3_none;
}
@ -625,7 +631,7 @@ u3_cj_mine(u3_noun clu,
u3D.ray_u[jax_l].par_u = par_u;
c3_assert(0 != jax_l);
free(nam_c);
#if 0
#if 1
fprintf(stderr, "mine: bound jet %d/%s/%s\r\n",
cop_u->jax_l,
cop_u->cos_c,

5
g/m.c
View File

@ -336,7 +336,7 @@ u3_cm_mark(void)
u3_ch_mark(u3R->jed.har_u);
u3_ca_mark_noun(u3R->ski.flu);
u3_ca_mark_noun(u3R->bug.tax);
u3_ca_mark_noun(u3R->bug.tax);
u3_ca_mark_noun(u3R->bug.mer);
u3_ca_mark_noun(u3R->pro.don);
u3_ca_mark_noun(u3R->pro.day);
u3_ch_mark(u3R->cax.har_u);
@ -457,7 +457,8 @@ u3_cm_bail(u3_noun how)
// _cm_punt();
// u3_cm_signal(c3__exit);
u3_Code = 0;
if ( c3__exit != how ) {
// u3_lo_sway(2, u3k(u3R->bug.tax));
abort();

3
g/n.c
View File

@ -14,6 +14,7 @@ _cn_hint(u3_noun zep,
{
switch ( zep ) {
default: {
// u3_cm_p("weird zep", zep);
u3_ca_lose(zep);
u3_ca_lose(hod);
@ -79,6 +80,8 @@ _cn_hint(u3_noun zep,
u3_cz_save_2(c3__nock, bus, nex, pro);
u3z(bus); u3z(nex);
return pro;
}
#endif
}

1
g/v.c
View File

@ -29,6 +29,7 @@ u3_cv_make(c3_c* pas_c)
printf("cv_make: kernel %x, core %x\n",
u3_cr_mug(u3A->ken), u3_cr_mug(u3A->roc));
u3z(sys);
}
/* u3_cv_jack(): execute kernel formula to bind jets.

View File

@ -257,6 +257,7 @@
# define c3__cstg c3_s4('c','s','t','g')
# define c3__cstr c3_s4('c','s','t','r')
# define c3__cszp c3_s4('c','s','z','p')
# define c3__cttp c3_s4('c','t','t','p')
# define c3__cube c3_s4('c','u','b','e')
# define c3__cull c3_s4('c','u','l','l')
# define c3__curd c3_s4('c','u','r','d')
@ -531,6 +532,7 @@
# define c3__iron c3_s4('i','r','o','n')
# define c3__is c3_s2('i','s')
# define c3__ix c3_s2('i','x')
# define c3__jack c3_s4('j','a','c','k')
# define c3__jamx c3_s4('j','a','m','x')
# define c3__jamz c3_s4('j','a','m','z')
# define c3__jato c3_s4('j','a','t','o')

View File

@ -75,6 +75,16 @@
void
u3_ca_sane(void);
/* u3_ca_lush(): leak push.
*/
c3_w
u3_ca_lush(c3_w lab_w);
/* u3_ca_lop(): leak pop.
*/
void
u3_ca_lop(c3_w lab_w);
/* Atoms from proto-atoms.
*/
/* u3_ca_slab(): create a length-bounded proto-atom.

View File

@ -8,8 +8,8 @@
# define U3_MEMORY_DEBUG
# ifdef U3_MEMORY_DEBUG
# define u3_leak_on(x) (u2_Code = x)
# define u3_leak_off (u2_Code = 0)
# define u3_leak_on(x) (u3_Code = x)
# define u3_leak_off (u3_Code = 0)
# endif
# define u3_cc_bits U2_OS_LoomBits // 28, max 29

View File

@ -20,8 +20,7 @@ _al_core(u3_noun van,
/* ~(bunt al gen)
*/
u3_noun
u3_cqfl_bunt(u3_noun van,
u3_noun gen)
u3_cqfl_bunt(u3_noun van, u3_noun gen)
{
u3_noun cor = _al_core(van, gen);

View File

@ -33,6 +33,17 @@
return u3_ci_molt(gat, u3_cv_sam, u3k(gen), 0);
}
/* van is transferred, gen is retained
*/
static u3_noun
_ap_bunt(u3_noun van, u3_noun gen)
{
u3_noun pro = u3_cqfl_bunt(van, gen);
u3z(van);
return pro;
}
/** open cases
**/
@ -60,7 +71,7 @@
{
return
u3nt(c3__tsls,
u3_cqfl_bunt(
_ap_bunt(
_al_core(ter, p_gen), p_gen),
u3k(q_gen));
}
@ -125,13 +136,13 @@
***/
_open_do_p(bccb) // $_
{
return u3_cqfl_bunt(_al_core(ter, p_gen), p_gen);
return _ap_bunt(_al_core(ter, p_gen), p_gen);
}
_open_do_p(bctr) // $*
{
return
u3nc(c3__ktsg,
u3_cqfl_bunt(
_ap_bunt(
_al_core(ter, p_gen),
p_gen));
}
@ -492,7 +503,7 @@
{
return u3nt
(c3__ktls,
u3_cqfl_bunt(_al_core(ter, p_gen), p_gen),
_ap_bunt(_al_core(ter, p_gen), p_gen),
u3k(q_gen));
}
/***

View File

@ -733,9 +733,7 @@ int FOO;
u3_noun ret = u3nc
(_mint_nice(van, gol, u3k(p_yom)),
(0 == pq_lar) ? u3k(q_yom)
: u3nt(9,
u3k(pq_lar),
u3k(q_yom)));
: u3nt(9, u3k(pq_lar), u3k(q_yom)));
u3z(yom);
u3z(mew);

View File

@ -37,9 +37,7 @@
: (u3_no == u3_cr_sing(p_geq, u3t(p_mox)))
? u3_cm_bail(c3__exit)
: u3k(p_mox) ),
u3nc(u3nc(u3k(q_geq),
u3k(qi_men)),
u3k(q_mox)));
u3nc(u3nc(u3k(q_geq), u3k(qi_men)), u3k(q_mox)));
u3z(mox);
u3z(geq);
@ -63,8 +61,7 @@
if ( u3_nul == p_wib ) {
return u3_cm_bail(c3__exit);
} else {
u3_noun ret = u3nc(u3k(u3t(p_wib)),
u3k(q_wib));
u3_noun ret = u3nc(u3k(u3t(p_wib)), u3k(q_wib));
u3z(wib);
return ret;

View File

@ -283,7 +283,8 @@ static u3_cs_harm _mood__hoon__ut_tock_a[] = {{".2", u3_cwfu_tock}, {}};
static u3_cs_harm _mood__hoon__ut_wrap_a[] = {{".2", u3_cwfu_wrap}, {}};
static u3_cs_core _mood__hoon__ut_d[] =
{ { "busk", _mood__hoon__ut_busk_a },
{
{ "busk", _mood__hoon__ut_busk_a },
{ "bust", _mood__hoon__ut_bust_a },
{ "conk", _mood__hoon__ut_conk_a },
{ "crop", _mood__hoon__ut_crop_a },

View File

@ -328,11 +328,13 @@ u3_ames_io_init()
add_u.sin_port = htons(por_s);
int ret;
if ( (ret = uv_udp_bind(&sam_u->wax_u, (const struct sockaddr*) & add_u, 0)) != 0 ) {
if ( (ret = uv_udp_bind(&sam_u->wax_u,
(const struct sockaddr*) & add_u, 0)) != 0 ) {
uL(fprintf(uH, "ames: bind: %s\n",
uv_strerror(ret)));
if (UV_EADDRINUSE == ret){
uL(fprintf(uH, " ...perhaps you've got two copies of vere running?\n"));
uL(fprintf(uH,
" ...perhaps you've got two copies of vere running?\n"));
}
exit(1);
}
@ -342,11 +344,13 @@ u3_ames_io_init()
sam_u->por_s = ntohs(add_u.sin_port);
}
u3_leak_on(3);
// Timer too.
{
uv_timer_init(u3L, &sam_u->tim_u);
}
u3_leak_off;
}
/* u3_ames_io_talk(): start receiving ames traffic.

View File

@ -349,7 +349,7 @@ u3_lo_open(void)
void
u3_lo_shut(u3_bean inn)
{
u3_ce_grab("lo_shut a");
// u3_ce_grab("lo_shut a");
// process actions
//

102
v/main.c
View File

@ -230,6 +230,43 @@ overflow_handler(int emergency, stackoverflow_context_t scp)
}
}
// 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.
//
u3_lo_sway(0, u3k(u3_wire_tax(u3_Wire)));
u3_lo_bail(u3A);
exit(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);
}
static void
interrupt_handler(int x)
{
@ -238,6 +275,8 @@ interrupt_handler(int x)
}
#endif
// #define GRAB
c3_i
main(c3_i argc,
c3_c** argv)
@ -272,6 +311,7 @@ main(c3_i argc,
/* Start Arvo.
*/
#if 0
{
struct timeval tim_tv;
u3_noun now;
@ -281,7 +321,7 @@ main(c3_i argc,
u3_cv_start(now);
}
#endif
#if 0
/* Initial checkpoint.
*/
@ -294,50 +334,32 @@ main(c3_i argc,
#endif
}
#if 0
// 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.
#ifdef GRAB
{
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;
u3_noun fur = u3_cv_wish("(dec 199)");
signal(SIGINT, SIG_DFL);
stackoverflow_deinstall_handler();
// Print the trace, do a GC, etc.
//
// This is half-assed at present, so we exit.
//
u3_lo_sway(0, u3k(u3_wire_tax(u3_Wire)));
u3_lo_bail(u3A);
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
u3_cm_p("fur", fur);
u3z(fur);
}
u3_lo_grab("main", u3_none);
#endif
u3_ce_grab("main");
#else
#if 1
u3_lo_loop();
#else
{
u3_noun imp, num;
u3_leak_on(1);
imp = u3_ci_string(u3_Host.ops_u.imp_c);
u3_leak_on(2);
num = u3_dc("slaw", 'p', imp);
u3z(num);
u3_leak_off;
u3_ce_grab("init");
}
#endif
#endif
return 0;
}

View File

@ -1789,6 +1789,7 @@ u3_raft_work(void)
}
_raft_kick_all(vir);
egg_u->did = u3_yes;
egg_u->vir = 0;
}
}
}