From 18ff192e3e30d16fcb6a93a084896686256d4b00 Mon Sep 17 00:00:00 2001 From: "C. Guy Yarvin" Date: Fri, 3 Oct 2014 10:44:08 -0700 Subject: [PATCH] Various fixes and improvements. --- g/a.c | 82 +++++++++++++++------------- g/e.c | 2 +- g/i.c | 4 +- g/j.c | 136 +++++++++++++++++++++++++++++++++-------------- g/m.c | 89 ++++++++++++++++++++----------- g/v.c | 23 +++++--- include/n/road.h | 67 +++++++++++++---------- j/6/ut_fink.c | 9 ++-- j/6/ut_mint.c | 4 ++ v/sist.c | 2 +- v/term.c | 2 +- w/test.c | 8 +-- 12 files changed, 272 insertions(+), 156 deletions(-) diff --git a/g/a.c b/g/a.c index 79d211c14..3b200f427 100644 --- a/g/a.c +++ b/g/a.c @@ -102,11 +102,11 @@ _box_detach(u3_cs_box* box_u) static c3_w* _me_road_all_hat(c3_w len_w) { - if ( len_w > u3_co_open ) { + if ( len_w > u3_co_open(u3R) ) { u3_cm_bail(c3__meme); return 0; } - if ( u3_yes == u3_co_is_north ) { + if ( u3_yes == u3_co_is_north(u3R) ) { c3_w* all_w; all_w = u3R->hat_w; @@ -125,11 +125,11 @@ _me_road_all_hat(c3_w len_w) static c3_w* _me_road_all_cap(c3_w len_w) { - if ( len_w > u3_co_open ) { + if ( len_w > u3_co_open(u3R) ) { u3_cm_bail(c3__meme); return 0; } - if ( u3_yes == u3_co_is_north ) { + if ( u3_yes == u3_co_is_north(u3R) ) { u3R->cap_w -= len_w; return u3R->cap_w; } @@ -316,7 +316,7 @@ u3_ca_free(void* tox_v) } #endif - if ( u3_yes == u3_co_is_north ) { + if ( u3_yes == u3_co_is_north(u3R) ) { /* Try to coalesce with the block below. */ if ( box_w != u3R->rut_w ) { @@ -378,7 +378,7 @@ u3_ca_free(void* tox_v) } } -#if 0 +#if 1 /* _me_wash_north(): clean up mug slots after copy. */ static void _me_wash_north(u3_noun dog); @@ -386,7 +386,7 @@ static void _me_wash_north_in(u3_noun som) { if ( u3_so(u3_co_is_cat(som)) ) return; - if ( u3_ne(u3_co_north_is_junior(som)) ) return; + if ( u3_ne(u3_co_north_is_junior(u3R, som)) ) return; _me_wash_north(som); } @@ -394,7 +394,7 @@ static void _me_wash_north(u3_noun dog) { c3_assert(u3_yes == u3_co_is_dog(dog)); - // c3_assert(u3_yes == u3_co_north_is_junior(dog)); + // c3_assert(u3_yes == u3_co_north_is_junior(u3R, dog)); { u3_cs_noun* dog_u = u3_co_to_ptr(dog); @@ -417,7 +417,7 @@ static void _me_wash_south_in(u3_noun som) { if ( u3_so(u3_co_is_cat(som)) ) return; - if ( u3_ne(u3_co_south_is_junior(som)) ) return; + if ( u3_ne(u3_co_south_is_junior(u3R, som)) ) return; _me_wash_south(som); } @@ -425,7 +425,7 @@ static void _me_wash_south(u3_noun dog) { c3_assert(u3_yes == u3_co_is_dog(dog)); - // c3_assert(u3_yes == u3_co_south_is_junior(dog)); + // c3_assert(u3_yes == u3_co_south_is_junior(u3R, dog)); { u3_cs_noun* dog_u = u3_co_to_ptr(dog); @@ -446,7 +446,7 @@ _me_wash_south(u3_noun dog) void u3_cm_wash(u3_noun som) { - if ( u3_so(u3_co_is_north) ) { + if ( u3_so(u3_co_is_north(u3R)) ) { _me_wash_north(som); } else { _me_wash_south(som); @@ -483,10 +483,10 @@ _me_copy_north_in(u3_noun som) else { u3_noun dog = som; - if ( u3_so(u3_co_north_is_senior(dog)) ) { + if ( u3_so(u3_co_north_is_senior(u3R, dog)) ) { return dog; } - else if ( u3_so(u3_co_north_is_junior(dog)) ) { + else if ( u3_so(u3_co_north_is_junior(u3R, dog)) ) { return _me_copy_north(dog); } else { @@ -500,10 +500,10 @@ _me_copy_north_in(u3_noun som) static u3_noun _me_copy_north(u3_noun dog) { - c3_assert(u3_yes == u3_co_north_is_junior(dog)); + c3_assert(u3_yes == u3_co_north_is_junior(u3R, dog)); - if ( u3_ne(u3_co_north_is_junior(dog)) ) { - if ( u3_ne(u3_co_north_is_senior(dog)) ) { + if ( u3_ne(u3_co_north_is_junior(u3R, dog)) ) { + if ( u3_ne(u3_co_north_is_senior(u3R, dog)) ) { _me_gain_use(dog); } return dog; @@ -516,7 +516,7 @@ _me_copy_north(u3_noun dog) if ( dog_u->mug_w >> 31 ) { u3_noun nov = (u3_noun) dog_u->mug_w; - c3_assert(u3_so(u3_co_north_is_normal(nov))); + c3_assert(u3_so(u3_co_north_is_normal(u3R, nov))); _me_gain_use(nov); return nov; @@ -575,10 +575,10 @@ _me_copy_south_in(u3_noun som) else { u3_noun dog = som; - if ( u3_so(u3_co_south_is_senior(dog)) ) { + if ( u3_so(u3_co_south_is_senior(u3R, dog)) ) { return dog; } - else if ( u3_so(u3_co_south_is_junior(dog)) ) { + else if ( u3_so(u3_co_south_is_junior(u3R, dog)) ) { return _me_copy_south(dog); } else { @@ -592,10 +592,10 @@ _me_copy_south_in(u3_noun som) static u3_noun _me_copy_south(u3_noun dog) { - c3_assert(u3_yes == u3_co_south_is_junior(dog)); + c3_assert(u3_yes == u3_co_south_is_junior(u3R, dog)); - if ( u3_ne(u3_co_south_is_junior(dog)) ) { - if ( u3_ne(u3_co_south_is_senior(dog)) ) { + if ( u3_ne(u3_co_south_is_junior(u3R, dog)) ) { + if ( u3_ne(u3_co_south_is_senior(u3R, dog)) ) { _me_gain_use(dog); } return dog; @@ -608,7 +608,9 @@ _me_copy_south(u3_noun dog) if ( dog_u->mug_w >> 31 ) { u3_noun nov = (u3_noun) dog_u->mug_w; - c3_assert(u3_so(u3_co_south_is_normal(nov))); + // printf("south: %p is already %p\r\n", dog_u, u3_co_to_ptr(nov)); + + c3_assert(u3_so(u3_co_south_is_normal(u3R, nov))); _me_gain_use(nov); return nov; @@ -620,6 +622,8 @@ _me_copy_south(u3_noun dog) u3_noun new = u3_co_de_twin(dog, new_w); u3_cs_cell* new_u = (u3_cs_cell*)(void *)new_w; + // printf("south: cell %p to %p\r\n", old_u, new_u); + new_u->mug_w = old_u->mug_w; new_u->hed = _me_copy_south_in(old_u->hed); new_u->tel = _me_copy_south_in(old_u->tel); @@ -635,6 +639,8 @@ _me_copy_south(u3_noun dog) u3_noun new = u3_co_de_twin(dog, new_w); u3_cs_atom* new_u = (u3_cs_atom*)(void *)new_w; + // printf("south: atom %p to %p\r\n", old_u, new_u); + new_u->mug_w = old_u->mug_w; new_u->len_w = old_u->len_w; { @@ -659,17 +665,17 @@ _me_copy_south(u3_noun dog) static u3_noun _me_take_north(u3_noun dog) { - if ( u3_yes == u3_co_north_is_senior(dog) ) { + if ( u3_yes == u3_co_north_is_senior(u3R, dog) ) { /* senior pointers are not refcounted */ return dog; } - else if ( u3_yes == u3_co_north_is_junior(dog) ) { + else if ( u3_yes == u3_co_north_is_junior(u3R, dog) ) { /* junior pointers are copied */ u3_noun mos = _me_copy_north(dog); - // _me_wash_north(dog); + // printf("north: %p to %p\r\n", u3_co_to_ptr(dog), u3_co_to_ptr(mos)); return mos; } else { @@ -685,17 +691,17 @@ _me_take_north(u3_noun dog) static u3_noun _me_take_south(u3_noun dog) { - if ( u3_yes == u3_co_south_is_senior(dog) ) { + if ( u3_yes == u3_co_south_is_senior(u3R, dog) ) { /* senior pointers are not refcounted */ return dog; } - else if ( u3_yes == u3_co_south_is_junior(dog) ) { + else if ( u3_yes == u3_co_south_is_junior(u3R, dog) ) { /* junior pointers are copied */ u3_noun mos = _me_copy_south(dog); - // _me_wash_south(dog); + // printf("south: %p to %p\r\n", u3_co_to_ptr(dog), u3_co_to_ptr(mos)); return mos; } else { @@ -717,7 +723,7 @@ u3_ca_take(u3_noun som) return som; } else { - return u3_so(u3_co_is_north) + return u3_so(u3_co_is_north(u3R)) ? _me_take_north(som) : _me_take_south(som); } @@ -728,7 +734,7 @@ u3_ca_take(u3_noun som) static u3_noun _me_gain_north(u3_noun dog) { - if ( u3_yes == u3_co_north_is_senior(dog) ) { + if ( u3_yes == u3_co_north_is_senior(u3R, dog) ) { /* senior pointers are not refcounted */ return dog; @@ -736,7 +742,7 @@ _me_gain_north(u3_noun dog) else { /* junior nouns are disallowed */ - c3_assert(u3_ne(u3_co_north_is_junior(dog))); + c3_assert(u3_ne(u3_co_north_is_junior(u3R, dog))); /* normal pointers are refcounted */ @@ -750,7 +756,7 @@ _me_gain_north(u3_noun dog) static u3_noun _me_gain_south(u3_noun dog) { - if ( u3_yes == u3_co_south_is_senior(dog) ) { + if ( u3_yes == u3_co_south_is_senior(u3R, dog) ) { /* senior pointers are not refcounted */ return dog; @@ -758,7 +764,7 @@ _me_gain_south(u3_noun dog) else { /* junior nouns are disallowed */ - c3_assert(u3_ne(u3_co_south_is_junior(dog))); + c3_assert(u3_ne(u3_co_south_is_junior(u3R, dog))); /* normal nouns are refcounted */ @@ -773,7 +779,7 @@ static void _me_lose_north(u3_noun dog) { top: - if ( u3_yes == u3_co_north_is_normal(dog) ) { + if ( u3_yes == u3_co_north_is_normal(u3R, dog) ) { c3_w* dog_w = u3_co_to_ptr(dog); u3_cs_box* box_u = u3_co_botox(dog_w); @@ -813,7 +819,7 @@ static void _me_lose_south(u3_noun dog) { top: - if ( u3_yes == u3_co_south_is_normal(dog) ) { + if ( u3_yes == u3_co_south_is_normal(u3R, dog) ) { c3_w* dog_w = u3_co_to_ptr(dog); u3_cs_box* box_u = u3_co_botox(dog_w); @@ -858,7 +864,7 @@ u3_ca_gain(u3_noun som) return som; } else { - return u3_so(u3_co_is_north) + return u3_so(u3_co_is_north(u3R)) ? _me_gain_north(som) : _me_gain_south(som); } @@ -870,7 +876,7 @@ void u3_ca_lose(u3_noun som) { if ( u3_ne(u3_co_is_cat(som)) ) { - if ( u3_so(u3_co_is_north) ) { + if ( u3_so(u3_co_is_north(u3R)) ) { _me_lose_north(som); } else { _me_lose_south(som); diff --git a/g/e.c b/g/e.c index ff9804a0f..4bc957f86 100644 --- a/g/e.c +++ b/g/e.c @@ -666,7 +666,7 @@ void u3_ce_init(c3_o chk_o) { _ce_limits(); - // _ce_signals(); + _ce_signals(); /* Map at fixed address. */ diff --git a/g/i.c b/g/i.c index 0dc7fd6df..6df84624d 100644 --- a/g/i.c +++ b/g/i.c @@ -202,8 +202,8 @@ u3_ci_cell(u3_noun a, u3_noun b) c3_assert(u3_none != a); c3_assert(u3_none != b); - c3_assert(u3_ne(u3_co_is_junior(a))); - c3_assert(u3_ne(u3_co_is_junior(b))); + c3_assert(u3_ne(u3_co_is_junior(u3R, a))); + c3_assert(u3_ne(u3_co_is_junior(u3R, b))); { c3_w* nov_w = u3_ca_walloc(c3_wiseof(u3_cs_cell)); diff --git a/g/j.c b/g/j.c index d90a41ba8..edf4f1b75 100644 --- a/g/j.c +++ b/g/j.c @@ -56,7 +56,7 @@ u3_cj_boot(void) memset(u3D.ray_u, 0, (u3D.all_l * sizeof(u3_cs_core))); jax_l = _cj_install(u3D.ray_u, 1, u3D.dev_u); - printf("boot: installed %d jets\n", jax_l); + fprintf(stderr, "boot: installed %d jets\n", jax_l); } /* _cj_insert(): append copy of core driver to jet table. For dummies. @@ -75,19 +75,40 @@ _cj_insert(u3_cs_core* cop_u) return jax_l; } -/* u3_cj_find(): search for jet. `cor` is RETAINED. +/* u3_cj_find(): search for jet. `bat` is RETAINED. */ c3_l u3_cj_find(u3_noun bat) { - u3_weak jax = u3_ch_get(u3R->jed.har_u, bat); + u3_cs_road* rod_u = u3R; - if ( u3_none == jax ) { - return 0; - } else { - u3_assure(u3_co_is_cat(jax)); + while ( rod_u->par_u ) { + if ( u3_so(u3_co_is_senior(rod_u, bat)) ) { + rod_u = rod_u->par_u; + } + } + { + u3_weak jax = u3_ch_get(rod_u->jed.har_u, bat); - return (c3_l)jax; + if ( u3_none == jax ) { +#if 0 + if ( rod_u != u3R ) { + fprintf(stderr, "not: %x in %p, %d\r\n", bat, rod_u, jax); + } +#endif + return 0; + } + else { + u3_assure(u3_co_is_cat(jax)); + +#if 0 + if ( rod_u != u3R ) { + fprintf(stderr, "got: %x in %p/%p, %d\r\n", + bat, rod_u, rod_u->jed.har_u, jax); + } +#endif + return (c3_l)jax; + } } } @@ -148,7 +169,7 @@ _cj_kick_a(u3_noun cor, u3_cs_hood* hud_u, c3_l axe_l) ham_u->liv = u3_yes; if ( u3_no == u3_cr_sing(ame, pro) ) { - printf("test: %s %s: mismatch: good %x, bad %x\r\n", + fprintf(stderr, "test: %s %s: mismatch: good %x, bad %x\r\n", ham_u->cop_u->cos_c, (!strcmp(".2", ham_u->fcs_c)) ? "$" : ham_u->fcs_c, u3_cr_mug(ame), @@ -159,7 +180,7 @@ _cj_kick_a(u3_noun cor, u3_cs_hood* hud_u, c3_l axe_l) } else { #if 1 - printf("test: %s %s\r\n", + fprintf(stderr, "test: %s %s\r\n", ham_u->cop_u->cos_c, (!strcmp(".2", ham_u->fcs_c)) ? "$" : ham_u->fcs_c); #endif @@ -169,6 +190,8 @@ _cj_kick_a(u3_noun cor, u3_cs_hood* hud_u, c3_l axe_l) } } +extern int FOO; + /* _cj_kick_b(): try to kick by jet. If no kick, produce u3_none. ** ** `cor` is RETAINED iff there is no kick, TRANSFERRED if one. @@ -180,7 +203,15 @@ _cj_kick_b(u3_noun cor, c3_l jax_l, c3_l axe_l) u3_cs_core* cop_u = &u3D.ray_u[jax_l]; u3_cs_hood* hud_u = cop_u->hud_u; - // printf("kick: %s\r\n", cop_u->cos_c); + if ( FOO ) { + if ( 171 == jax_l ) { + fprintf(stderr, "kick: %s\r\n", cop_u->cos_c); + printf("core %x\r\n", cor); + printf("bat mug %x\r\n", u3_cr_mug(u3h(cor))); + printf("data mug %x\r\n", u3_cr_mug(u3t(cor))); + printf("core mug %x\r\n", u3_cr_mug(cor)); + } + } while ( 1 ) { if ( 0 == hud_u ) { break; } @@ -200,7 +231,7 @@ _cj_hook_in(u3_noun cor, u3_noun bat = u3h(cor); c3_l jax_l = u3_cj_find(bat); - // printf("hook: %s\n", tam_c); + // fprintf(stderr, "hook: %s\n", tam_c); if ( 0 == jax_l ) { return 0; } else { @@ -319,18 +350,18 @@ _cj_axis(u3_noun fol) (0 != p_fol) || (u3_ne(u3_co_is_cat(q_fol))) ) { - printf("axis: bad a\r\n"); + fprintf(stderr, "axis: bad a\r\n"); return 0; } return q_fol; } else { if ( 9 != p_fol ) - { printf("axis: bad b\r\n"); return 0; } + { fprintf(stderr, "axis: bad b\r\n"); return 0; } if ( u3_ne(u3_co_is_cat(q_fol)) ) - { printf("axis: bad c\r\n"); return 0; } + { fprintf(stderr, "axis: bad c\r\n"); return 0; } if ( u3_ne(u3du(r_fol)) || (0 != u3h(r_fol)) || (1 != u3t(r_fol)) ) - { printf("axis: bad d\r\n"); return 0; } + { fprintf(stderr, "axis: bad d\r\n"); return 0; } return q_fol; } @@ -350,7 +381,7 @@ _cj_activate(u3_cs_core* cop_u, u3_cs_hood* hud_u) while ( duh_u ) { if ( duh_u->mug_l == hud_u->mug_l ) { - printf("jets: mug collision!\r\n"); + fprintf(stderr, "jets: mug collision!\r\n"); return; } duh_u = duh_u->nex_u; @@ -379,7 +410,7 @@ _cj_activate(u3_cs_core* cop_u, u3_cs_hood* hud_u) ((1 << 31) & (axe_l = (c3_w)axe_d)) || (axe_l < 2) ) { - printf("jets: activate: bad fcs %s\r\n", jet_u->fcs_c); + fprintf(stderr, "jets: activate: bad fcs %s\r\n", jet_u->fcs_c); } } else { @@ -478,13 +509,37 @@ u3_cj_clear(void) u3R->jed.har_u = u3_ch_new(); } +/* cj_save(): save new jet binding. `bat` is RETAINED. +*/ +static void +_cj_save(u3_noun bat, + c3_l jax_l, + u3_cs_hood* hud_u) +{ + u3_cs_road* rod_u = u3R; + u3_cs_road* tmp_u; + + while ( rod_u->par_u ) { + if ( u3_so(u3_co_is_senior(rod_u, bat)) ) { + rod_u = rod_u->par_u; + } + } + + tmp_u = u3R; + u3R = rod_u; + u3_ch_put(rod_u->jed.har_u, bat, jax_l); + u3R = tmp_u; + + _cj_activate(&u3D.ray_u[jax_l], hud_u); +} + /* u3_cj_mine(): register core for jets. */ u3_noun u3_cj_mine(u3_noun clu, u3_noun cor) { - if ( u3_none != u3_ch_get(u3R->jed.har_u, u3h(cor)) ) { + if ( 0 != u3_cj_find(u3h(cor)) ) { u3z(clu); return cor; } @@ -497,46 +552,45 @@ u3_cj_mine(u3_noun clu, u3_noun pab; if ( u3_no == u3_cr_trel(clu, &p_clu, &q_clu, &r_clu) ) - { printf("mine: bad z\r\n"); u3z(clu); return cor; } + { fprintf(stderr, "mine: bad z\r\n"); u3z(clu); return cor; } if ( 0 == (nam_c = _cj_chum(p_clu)) ) - { printf("mine: bad a\r\n"); u3z(clu); return cor; } - - if ( !strcmp(nam_c, "rap") ) { - printf("mine: chum: %s (bat %x)\r\n", nam_c, u3_cr_mug(u3h(cor))); - } + { fprintf(stderr, "mine: bad a\r\n"); u3z(clu); return cor; } +#if 0 + fprintf(stderr, "mine: chum: %s (bat %x)\r\n", nam_c, u3_cr_mug(u3h(cor))); +#endif while ( u3_so(u3du(q_clu)) && (10 == u3h(q_clu)) ) { q_clu = u3t(u3t(q_clu)); } if ( u3_ne(u3du(q_clu)) ) - { printf("mine: bad b\r\n"); u3z(clu); return cor; } + { fprintf(stderr, "mine: bad b\r\n"); u3z(clu); return cor; } if ( (1 == u3h(q_clu)) && (0 == u3t(q_clu)) ) { axe_l = 0; } else { if ( (0 != u3h(q_clu)) ) - { printf("mine: bad c\r\n"); u3z(clu); return cor; c3_assert(0); } + { fprintf(stderr, "mine: c\r\n"); u3z(clu); return cor; c3_assert(0); } if ( u3_ne(u3_co_is_cat(axe_l = u3t(q_clu))) ) - { printf("mine: bad d\r\n"); u3z(clu); return cor; } + { fprintf(stderr, "mine: d\r\n"); u3z(clu); return cor; } } if ( 0 != axe_l ) { if ( (u3_none == (pab = u3_cr_at(axe_l, cor))) ) - { printf("mine: bad e\r\n"); u3z(clu); return cor; } + { fprintf(stderr, "mine: bad e\r\n"); u3z(clu); return cor; } if ( (0 == (par_l = u3_cj_find(u3h(pab)))) ) { - printf("mine: bad f\r\n"); - printf("parent battery mug %x\r\n", u3_cr_mug(u3h(pab))); + fprintf(stderr, "mine: bad f\r\n"); + fprintf(stderr, "parent battery mug %x\r\n", u3_cr_mug(u3h(pab))); u3z(clu); c3_assert(0); return cor; } else { - // printf("parent %d, mug %x\r\n", par_l, u3_cr_mug(u3h(pab))); + // fprintf(stderr, "parent %d, mug %x\r\n", par_l, u3_cr_mug(u3h(pab))); } } @@ -547,13 +601,13 @@ u3_cj_mine(u3_noun clu, c3_l kax_l; if ( u3_no == u3_cr_cell(r_clu, &ir_clu, &tr_clu) ) - { printf("mine: bad g\r\n"); u3z(clu); return cor; } + { fprintf(stderr, "mine: bad g\r\n"); u3z(clu); return cor; } if ( u3_no == u3_cr_cell(ir_clu, &pir_clu, &qir_clu) ) - { printf("mine: bad h\r\n"); u3z(clu); return cor; } + { fprintf(stderr, "mine: bad h\r\n"); u3z(clu); return cor; } if ( u3_ne(u3ud(pir_clu)) ) - { printf("mine: bad i\r\n"); u3z(clu); return cor; } + { fprintf(stderr, "mine: bad i\r\n"); u3z(clu); return cor; } if ( 0 == (kax_l = _cj_axis(qir_clu)) ) - { printf("mine: bad j\r\n"); u3z(clu); return cor; } + { fprintf(stderr, "mine: bad j\r\n"); u3z(clu); return cor; } kuh_u = malloc(sizeof(u3_cs_hook)); kuh_u->nam_c = u3_cr_string(pir_clu); @@ -591,7 +645,8 @@ u3_cj_mine(u3_noun clu, c3_assert(0 != jax_l); free(nam_c); - // printf("mine: bound jet %d/%s\r\n", cop_u->jax_l, cop_u->cos_c); + fprintf(stderr, "mine: bound jet %d/%s\r\n", + cop_u->jax_l, cop_u->cos_c); break; } i_l++; @@ -607,19 +662,18 @@ u3_cj_mine(u3_noun clu, fak_u.axe_l = axe_l; jax_l = _cj_insert(&fak_u); - // printf("mine: dummy jet %d/%s\r\n", jax_l, fak_u.cos_c); + fprintf(stderr, "mine: dummy jet %d/%s\r\n", jax_l, fak_u.cos_c); } - u3_ch_put(u3R->jed.har_u, u3h(cor), jax_l); u3z(clu); - _cj_activate(&u3D.ray_u[jax_l], hud_u); + _cj_save(u3h(cor), jax_l, hud_u); #if 0 { u3_cs_core* cop_u = &u3D.ray_u[jax_l]; u3_cs_core* par_u = cop_u->par_u; - printf("cop %s/%p/%d; par_u %p/%s/%d/%p; hud_u %p\n\n", + fprintf(stderr, "cop %s/%p/%d; par_u %p/%s/%d/%p; hud_u %p\n\n", cop_u->cos_c, cop_u, jax_l, par_u, par_u ? par_u->cos_c : "none", par_l, diff --git a/g/m.c b/g/m.c index 16d2d0f74..c293d810c 100644 --- a/g/m.c +++ b/g/m.c @@ -55,7 +55,7 @@ _find_north(c3_w* mem_w, c3_w siz_w, c3_w len_w) static u3_road* _find_south(c3_w* mem_w, c3_w siz_w, c3_w len_w) { - return (void *)(mem_w + siz_w); + return (void *)mem_w; } #endif @@ -68,6 +68,7 @@ _boot_north(c3_w* mem_w, c3_w siz_w, c3_w len_w) c3_w* cap_w = mat_w; u3_road* rod_u = (void*) mat_w; + // memset(mem_w, 0, 4 * len_w); // enable in case of corruption memset(rod_u, 0, 4 * siz_w); rod_u->rut_w = rut_w; @@ -86,10 +87,11 @@ _boot_south(c3_w* mem_w, c3_w siz_w, c3_w len_w) { c3_w* rut_w = (mem_w + len_w); c3_w* hat_w = rut_w; - c3_w* mat_w = mem_w + siz_w; - c3_w* cap_w = mat_w; + c3_w* mat_w = mem_w; + c3_w* cap_w = mat_w + siz_w; u3_road* rod_u = (void*) mat_w; + // memset(mem_w, 0, 4 * len_w); // enable in case of corruption memset(rod_u, 0, 4 * siz_w); rod_u->rut_w = rut_w; @@ -142,7 +144,7 @@ u3_cm_dump(void) c3_w fre_w = 0; c3_w i_w; - hat_w = u3_so(u3_co_is_north) ? u3R->hat_w - u3R->rut_w + hat_w = u3_so(u3_co_is_north(u3R)) ? u3R->hat_w - u3R->rut_w : u3R->rut_w - u3R->hat_w; for ( i_w = 0; i_w < u3_cc_fbox_no; i_w++ ) { @@ -153,14 +155,14 @@ u3_cm_dump(void) fre_u = fre_u->nex_u; } } - printf("dump: hat_w %x, fre_w %x, allocated %x\n", + fprintf(stderr, "dump: hat_w %x, fre_w %x, allocated %x\n", hat_w, fre_w, (hat_w - fre_w)); if ( 0 != (hat_w - fre_w) ) { - c3_w* box_w = u3_so(u3_co_is_north) ? u3R->rut_w : u3R->hat_w; + c3_w* box_w = u3_so(u3_co_is_north(u3R)) ? u3R->rut_w : u3R->hat_w; c3_w mem_w = 0; - while ( box_w < (u3_so(u3_co_is_north) ? u3R->hat_w : u3R->rut_w) ) { + while ( box_w < (u3_so(u3_co_is_north(u3R)) ? u3R->hat_w : u3R->rut_w) ) { u3_cs_box* box_u = (void *)box_w; if ( 0 != box_u->use_w ) { @@ -172,7 +174,7 @@ u3_cm_dump(void) box_w += box_u->siz_w; } - printf("second count: %x\n", mem_w); + fprintf(stderr, "second count: %x\n", mem_w); } } @@ -190,6 +192,9 @@ _cm_punt(void) } #endif +extern void +u3_lo_sway(c3_l tab_l, u3_noun tax); + /* u3_cm_bail(): bail out. Does not return. ** ** Bail motes: @@ -224,14 +229,17 @@ u3_cm_bail(u3_noun how) str_c[2] = ((how >> 16) & 0xff); str_c[3] = ((how >> 24) & 0xff); str_c[4] = 0; - printf("bail: %s (at %llu)\r\n", str_c, u3N); + fprintf(stderr, "bail: %s (at %llu)\r\n", str_c, u3N); } else { c3_assert(u3_so(u3ud(u3h(how)))); - printf("bail: %d (at %llu)\r\n", u3h(how), u3N); + fprintf(stderr, "bail: %d (at %llu)\r\n", u3h(how), u3N); + u3_cm_p("bail", u3t(how)); } } + // _cm_punt(); + // u3_lo_sway(2, u3k(u3R->bug.tax)); // abort(); /* Reconstruct a correct error ball. @@ -267,7 +275,7 @@ int c3_cooked() { return u3_cm_bail(c3__oops); } c3_i u3_cm_error(c3_c* str_c) { - printf("error: %s\r\n", str_c); // rong + fprintf(stderr, "error: %s\r\n", str_c); // rong return u3_cm_bail(c3__exit); } @@ -288,10 +296,10 @@ u3_cm_leap(c3_w pad_w) else { pad_w -= u3R->all.fre_w; } - if ( (pad_w + c3_wiseof(u3_cs_road)) >= u3_co_open ) { + if ( (pad_w + c3_wiseof(u3_cs_road)) >= u3_co_open(u3R) ) { u3_cm_bail(c3__meme); } - len_w = u3_co_open - (pad_w + c3_wiseof(u3_cs_road)); + len_w = u3_co_open(u3R) - (pad_w + c3_wiseof(u3_cs_road)); } /* Allocate a region on the cap. @@ -299,26 +307,29 @@ u3_cm_leap(c3_w pad_w) { c3_w* bot_w; - if ( u3_yes == u3_co_is_north ) { + if ( u3_yes == u3_co_is_north(u3R) ) { bot_w = (u3R->cap_w - len_w); u3R->cap_w -= len_w; rod_u = _boot_south(bot_w, c3_wiseof(u3_cs_road), len_w); - printf("leap: from north %p (cap %p), to south %p\r\n", +#if 0 + fprintf(stderr, "leap: from north %p (cap %p), to south %p\r\n", u3R, u3R->cap_w + len_w, rod_u); +#endif } else { bot_w = u3R->cap_w; u3R->cap_w += len_w; rod_u = _boot_north(bot_w, c3_wiseof(u3_cs_road), len_w); - - printf("leap: from north %p (cap %p), to south %p\r\n", +#if 0 + fprintf(stderr, "leap: from north %p (cap %p), to south %p\r\n", u3R, u3R->cap_w - len_w, rod_u); +#endif } } @@ -345,13 +356,15 @@ u3_cm_fall() { c3_assert(0 != u3R->par_u); - printf("fall: from %s %p, to %s %p (cap %p, was %p)\r\n", - u3_so(u3_co_is_north) ? "north" : "south", +#if 0 + fprintf(stderr, "fall: from %s %p, to %s %p (cap %p, was %p)\r\n", + u3_so(u3_co_is_north(u3R)) ? "north" : "south", u3R, - u3_so(u3_co_is_north) ? "north" : "south", + u3_so(u3_co_is_north(u3R)) ? "north" : "south", u3R->par_u, u3R->hat_w, u3R->rut_w); +#endif /* The new cap is the old hat - it's as simple as that. */ @@ -368,7 +381,7 @@ u3_cm_fall() c3_w u3_cm_golf(void) { - if ( u3_yes == u3_co_is_north ) { + if ( u3_yes == u3_co_is_north(u3R) ) { return u3R->mat_w - u3R->cap_w; } else { @@ -381,10 +394,21 @@ u3_cm_golf(void) void u3_cm_flog(c3_w gof_w) { - if ( u3_yes == u3_co_is_north ) { - u3R->cap_w = u3R->mat_w - gof_w; - } else { - u3R->cap_w = u3R->mat_w + gof_w; + // Enable memsets in case of memory corruption. + // + if ( u3_yes == u3_co_is_north(u3R) ) { + c3_w* bot_w = (u3R->mat_w - gof_w); + // c3_w len_w = (bot_w - u3R->cap_w); + + // memset(u3R->cap_w, 0, 4 * len_w); + u3R->cap_w = bot_w; + } + else { + c3_w* bot_w = u3R->mat_w + gof_w; + // c3_w len_w = (u3R->cap_w - bot_w); + + // memset(bot_w, 0, 4 * len_w); // + u3R->cap_w = bot_w; } } @@ -429,7 +453,9 @@ u3_cm_soft_top(c3_w pad_w, /* Trap for exceptions. */ if ( 0 == (why = u3_cm_trap()) ) { - u3_noun pro = fun_f(arg); + pro = fun_f(arg); + + u3_cm_wash(pro); /* Test stack correctness assertions, and restore. */ @@ -486,7 +512,10 @@ u3_cm_soft_run(u3_noun fly, { u3_noun why, pro; c3_w gof_w; - + + u3_cm_wash(aga); + u3_cm_wash(agb); + /* Record the cap, and leap. */ { @@ -505,7 +534,7 @@ u3_cm_soft_run(u3_noun fly, /* Trap for exceptions. */ if ( 0 == (why = u3_cm_trap()) ) { - u3_noun pro = fun_f(aga, agb); + pro = fun_f(aga, agb); /* Fall back to the old road, leaving temporary memory intact. */ @@ -645,7 +674,7 @@ u3_cm_soft(c3_w sec_w, u3_funk fun_f, u3_noun arg) { - u3_noun why = u3_cm_soft_top(0, fun_f, arg); + u3_noun why = u3_cm_soft_top((1 << 17), fun_f, arg); u3_noun pro; switch ( u3h(why) ) { @@ -816,7 +845,7 @@ u3_cm_p(const c3_c* cap_c, u3_noun som) { c3_c* pre_c = u3_cm_pretty(som); - printf("%s: %s\r\n", cap_c, pre_c); + fprintf(stderr, "%s: %s\r\n", cap_c, pre_c); free(pre_c); } diff --git a/g/v.c b/g/v.c index 4e25878da..1e073bea0 100644 --- a/g/v.c +++ b/g/v.c @@ -66,14 +66,23 @@ u3_cv_start(u3_noun now) u3_noun u3_cv_gate(const c3_c* txt_c) { - u3_noun txt = u3_ci_string(txt_c); - u3_weak gat = u3_ckdb_get(u3k(u3A->yot), u3k(txt)); + u3_cs_road* rod_u; + u3_noun gat; - if ( u3_none == gat ) { - gat = _cv_nock_wish(u3k(txt)); - u3A->yot = u3_ckdb_put(u3A->yot, u3k(txt), u3k(gat)); + rod_u = u3R; + u3R = &u3H->rod_u; + { + u3_noun txt = u3_ci_string(txt_c); + + gat = u3_ckdb_get(u3k(u3A->yot), u3k(txt)); + + if ( u3_none == gat ) { + gat = _cv_nock_wish(u3k(txt)); + u3A->yot = u3_ckdb_put(u3A->yot, u3k(txt), u3k(gat)); + } + u3z(txt); } - u3z(txt); + u3R = rod_u; return gat; } @@ -175,7 +184,7 @@ _cv_nock_poke(u3_noun ovo) #if 0 { c3_c* ovi_c = u3_cr_string(u3h(u3t(ovo))); - u3_noun tox = u3_do("spat", (u3k(u3h(ovo))); + u3_noun tox = u3_do("spat", u3k(u3h(ovo))); c3_c* tox_c = u3_cr_string(tox); printf("poke: %%%s on %s\r\n", ovi_c, tox_c); diff --git a/include/n/road.h b/include/n/road.h index b46ec67c9..62ad75642 100644 --- a/include/n/road.h +++ b/include/n/road.h @@ -175,43 +175,52 @@ /** Macros. **/ -# define u3_co_is_north ((u3R->cap_w > u3R->hat_w) ? u3_yes : u3_no) -# define u3_co_is_south ((u3_yes == u3_co_is_north) ? u3_no : u3_yes) - -# define u3_co_open ( (u3_yes == u3_co_is_north) \ - ? (c3_w)(u3R->cap_w - u3R->hat_w) \ - : (c3_w)(u3R->hat_w - u3R->cap_w) ) - # define u3_co_into(x) ((void *)(u3_Loom + (x))) # define u3_co_outa(p) (((c3_w*)(void*)(p)) - u3_Loom) -# define u3_co_north_is_senior(dog) \ - u3_say((u3_co_to_wtr(dog) < u3R->rut_w) || \ - (u3_co_to_wtr(dog) >= u3R->mat_w)) +# define u3to(type, x) ((type *) u3_co_into(x)) + +# define u3_co_is_north(r) ((r->cap_w > r->hat_w) ? u3_yes : u3_no) +# define u3_co_is_south(r) ((u3_so(u3_co_is_north(r))) ? u3_no : u3_yes) + +# define u3_co_open(r) ( (u3_yes == u3_co_is_north(r)) \ + ? (c3_w)(r->cap_w - r->hat_w) \ + : (c3_w)(r->hat_w - r->cap_w) ) + +# define u3_co_north_is_senior(r, dog) \ + u3_say((u3_co_to_wtr(dog) < r->rut_w) || \ + (u3_co_to_wtr(dog) >= r->mat_w)) -# define u3_co_north_is_junior(dog) \ - u3_say((u3_co_to_wtr(dog) >= u3R->cap_w) && \ - (u3_co_to_wtr(dog) < u3R->mat_w)) +# define u3_co_north_is_junior(r, dog) \ + u3_say((u3_co_to_wtr(dog) >= r->cap_w) && \ + (u3_co_to_wtr(dog) < r->mat_w)) -# define u3_co_north_is_normal(dog) \ - u3_and(u3_not(u3_co_north_is_senior(dog)), \ - u3_not(u3_co_north_is_junior(dog))) +# define u3_co_north_is_normal(r, dog) \ + u3_and(u3_not(u3_co_north_is_senior(r, dog)), \ + u3_not(u3_co_north_is_junior(r, dog))) -# define u3_co_south_is_senior(dog) \ - u3_say((u3_co_to_wtr(dog) < u3R->mat_w) || \ - (u3_co_to_wtr(dog) >= u3R->rut_w)) +# define u3_co_south_is_senior(r, dog) \ + u3_say((u3_co_to_wtr(dog) < r->mat_w) || \ + (u3_co_to_wtr(dog) >= r->rut_w)) -# define u3_co_south_is_junior(dog) \ - u3_say((u3_co_to_wtr(dog) >= u3R->cap_w) && \ - (u3_co_to_wtr(dog) < u3R->mat_w)) +# define u3_co_south_is_junior(r, dog) \ + u3_say((u3_co_to_wtr(dog) < r->cap_w) && \ + (u3_co_to_wtr(dog) >= r->mat_w)) -# define u3_co_south_is_normal(dog) \ - u3_and(u3_not(u3_co_south_is_senior(dog)), \ - u3_not(u3_co_south_is_junior(dog))) +# define u3_co_south_is_normal(r, dog) \ + u3_and(u3_not(u3_co_south_is_senior(r, dog)), \ + u3_not(u3_co_south_is_junior(r, dog))) -# define u3_co_is_junior(som) \ +# define u3_co_is_junior(r, som) \ ( u3_so(u3_co_is_cat(som)) \ ? u3_no \ - : u3_so(u3_co_is_north) \ - ? u3_co_north_is_junior(som) \ - : u3_co_south_is_junior(som) ) + : u3_so(u3_co_is_north(r)) \ + ? u3_co_north_is_junior(r, som) \ + : u3_co_south_is_junior(r, som) ) + +# define u3_co_is_senior(r, som) \ + ( u3_so(u3_co_is_cat(som)) \ + ? u3_no \ + : u3_so(u3_co_is_north(r)) \ + ? u3_co_north_is_senior(r, som) \ + : u3_co_south_is_senior(r, som) ) diff --git a/j/6/ut_fink.c b/j/6/ut_fink.c index 7607c9637..74d98ed5a 100644 --- a/j/6/ut_fink.c +++ b/j/6/ut_fink.c @@ -15,7 +15,7 @@ u3_noun way, u3_noun cog) { - // u3_noun dun = u3_cqfu_dunq(van, "type", sut); + u3_noun dun = u3_cqfu_dunq(van, "type", sut); u3_noun nuc = (u3_blip == cog) ? u3_cqfu_shew (van, @@ -26,13 +26,16 @@ (van, "find-limb", 'a', u3k(cog)); u3_noun pro; - // u3_ct_push(u3nc(c3__mean, dun)); + u3_ct_push(u3nc(c3__mean, dun)); u3_ct_push(u3nc(c3__mean, nuc)); { u3_noun hoq = u3_cqfu_find(van, sut, dep, way, cog); u3_noun fin = u3t(hoq); if ( u3_nul == fin ) { + u3_cm_p("cog", cog); + u3_cm_p("typ", u3h(sut)); + abort(); return u3_cm_error("find-none"); } else { @@ -41,7 +44,7 @@ } } u3_ct_drop(); - // u3_ct_drop(); + u3_ct_drop(); return pro; } diff --git a/j/6/ut_mint.c b/j/6/ut_mint.c index 0147346dd..947aa8bd5 100644 --- a/j/6/ut_mint.c +++ b/j/6/ut_mint.c @@ -934,6 +934,10 @@ int FOO; { u3_noun sut, gol, gen, van; + if ( FOO ) { + printf("mint: cor %x\r\n", cor); + printf("mint: core mug %x\r\n", u3_cr_mug(cor)); + } if ( (u3_no == u3_cr_mean(cor, u3_cv_sam_2, &gol, u3_cv_sam_3, &gen, u3_cv_con, &van, diff --git a/v/sist.c b/v/sist.c index 3afd9b2b9..ad56fc32b 100644 --- a/v/sist.c +++ b/v/sist.c @@ -307,7 +307,7 @@ _sist_home() } } -#if 0 +#if 1 // Copy zod files, if we're generating a carrier. // if ( u3_Host.ops_u.imp_c ) { diff --git a/v/term.c b/v/term.c index a21a4f897..dd9c3df08 100644 --- a/v/term.c +++ b/v/term.c @@ -418,7 +418,7 @@ _term_write_cb(uv_write_t* wri_u, c3_i sas_i) _u3_write_t* ruq_u = (void *)wri_u; if ( 0 != sas_i ) { - uL(fprintf(uH, "term: write: ERROR\n")); + // uL(fprintf(uH, "term: write: ERROR\n")); } free(ruq_u->buf_y); free(ruq_u); diff --git a/w/test.c b/w/test.c index c68ff9a77..2c130431a 100644 --- a/w/test.c +++ b/w/test.c @@ -206,16 +206,18 @@ _test_leap(void) { u3_noun pil; u3_noun cue, jam; + c3_w gof_w = u3_cm_golf(); - u3_cm_leap(0); pil = u3_walk_load("urb/urbit.pill"); + u3_cm_leap(0); printf("cueing pill - %d bytes\n", u3_cr_met(3, pil)); cue = u3_cke_cue(pil); - printf("cued - mug %x\n", u3_cr_mug(cue)); + printf("cued - %p, mug %x\n", u3_co_to_ptr(cue), u3_cr_mug(cue)); u3_cm_fall(); cue = u3_ca_take(cue); - printf("cued - mug %x\n", u3_cr_mug(cue)); + printf("taken - %p, mug %x\n", u3_co_to_ptr(cue), u3_cr_mug(cue)); + u3_cm_flog(gof_w); u3z(pil); #if 1