Now boots and runs a clean :solid.

This commit is contained in:
C. Guy Yarvin 2014-10-08 15:16:24 -07:00
parent 3c6398c106
commit b64ee70c24
13 changed files with 320 additions and 52 deletions

23
g/a.c
View File

@ -54,6 +54,18 @@ _box_attach(u3_cs_box* box_u)
{
c3_assert(box_u->siz_w >= (1 + c3_wiseof(u3_cs_fbox)));
#if 0
// For debugging, fill the box with beef.
{
c3_w* box_w = (void *)box_u;
c3_w i_w;
for ( i_w = c3_wiseof(u3_cs_box); (i_w + 1) < box_u->siz_w; i_w++ ) {
box_w[i_w] = 0xdeadbeef;
}
}
#endif
u3R->all.fre_w += box_u->siz_w;
{
c3_w sel_w = _box_slot(box_u->siz_w);
@ -466,6 +478,9 @@ _me_gain_use(u3_noun dog)
u3_cm_bail(c3__fail);
}
else {
if ( box_u->use_w == 0 ) {
u3_cm_bail(c3__foul);
}
box_u->use_w += 1;
}
}
@ -900,7 +915,7 @@ u3_ca_use(u3_noun som)
}
}
/* u3_ca_audit(): investigate object.
/* u3_ca_audit(): anticipate zero usecounts.
*/
c3_o
u3_ca_audit(u3_noun som)
@ -908,12 +923,16 @@ u3_ca_audit(u3_noun som)
if ( u3_so(u3_co_is_cat(som)) ) {
return u3_yes;
}
if ( u3_so(u3_co_is_senior(u3R, som)) ) {
return u3_yes;
}
if ( 0 == u3_ca_use(som) ) {
u3_cm_p("som", som);
printf("zero: %x/%x\r\n", u3_cr_mug(som), som);
abort();
return u3_no;
}
else if ( u3_so(u3du(som)) ) {
else if ( u3_so(u3du(som)) && (1 == u3_ca_use(som)) ) {
return u3_and(u3_ca_audit(u3h(som)), u3_ca_audit(u3t(som)));
}
else return u3_yes;

90
g/h.c
View File

@ -298,7 +298,6 @@ u3_ch_hum(u3_ch_root* har_u, c3_w mug_w)
}
}
/* _ch_buck_get(): read in bucket.
*/
static u3_weak
@ -387,6 +386,95 @@ u3_ch_get(u3_ch_root* har_u, u3_noun key)
}
}
/* _ch_buck_gut(): read in bucket, unifying key nouns.
*/
static u3_weak
_ch_buck_gut(u3_ch_buck* hab_u, u3_noun key)
{
c3_w i_w;
for ( i_w = 0; i_w < hab_u->len_w; i_w++ ) {
if ( u3_so(u3_cr_sung(key, u3h(hab_u->kev[i_w]))) ) {
return u3_ca_gain(u3t(hab_u->kev[i_w]));
}
}
return u3_none;
}
/* _ch_node_gut(): read in node, unifying key nouns.
*/
static u3_weak
_ch_node_gut(u3_ch_node* han_u, c3_w lef_w, c3_w rem_w, u3_noun key)
{
c3_w bit_w, map_w;
lef_w -= 5;
bit_w = (rem_w >> lef_w);
rem_w = (rem_w & ((1 << lef_w) - 1));
map_w = han_u->map_w;
if ( !(map_w & (1 << bit_w)) ) {
return u3_none;
}
else {
c3_w inx_w = _ch_popcount(map_w & ((1 << bit_w) - 1));
c3_w sot_w = han_u->sot_w[inx_w];
if ( u3_so(u3_ch_slot_is_noun(sot_w)) ) {
u3_noun kev = u3_ch_slot_to_noun(sot_w);
if ( u3_so(u3_cr_sung(key, u3h(kev))) ) {
return u3_ca_gain(u3t(kev));
}
else {
return u3_none;
}
}
else {
void* hav_v = u3_ch_slot_to_node(sot_w);
if ( 0 == lef_w ) {
return _ch_buck_gut(hav_v, key);
}
else return _ch_node_gut(hav_v, lef_w, rem_w, key);
}
}
}
/* u3_ch_gut(): read from hashtable, unifying key nouns.
**
** `key` is RETAINED.
*/
u3_weak
u3_ch_gut(u3_ch_root* har_u, u3_noun key)
{
c3_w mug_w = u3_cr_mug(key);
c3_w inx_w = (mug_w >> 25);
c3_w rem_w = (mug_w & ((1 << 25) - 1));
c3_w sot_w = har_u->sot_w[inx_w];
if ( u3_so(u3_ch_slot_is_null(sot_w)) ) {
return u3_none;
}
else if ( u3_so(u3_ch_slot_is_noun(sot_w)) ) {
u3_noun kev = u3_ch_slot_to_noun(sot_w);
if ( u3_so(u3_cr_sung(key, u3h(kev))) ) {
har_u->sot_w[inx_w] = u3_ch_noun_be_warm(sot_w);
return u3_ca_gain(u3t(kev));
}
else {
return u3_none;
}
}
else {
u3_ch_node* han_u = u3_ch_slot_to_node(sot_w);
return _ch_node_gut(han_u, 25, rem_w, key);
}
}
/* _ch_free_buck(): free bucket
*/
static void

62
g/j.c
View File

@ -82,32 +82,26 @@ u3_cj_find(u3_noun bat)
{
u3_cs_road* rod_u = u3R;
while ( rod_u->par_u && u3_so(u3_co_is_senior(rod_u, bat)) ) {
rod_u = rod_u->par_u;
}
while ( 1 ) {
if ( u3_ne(u3_co_is_senior(rod_u, bat)) ) {
u3_weak jax = u3_ch_gut(rod_u->jed.har_u, bat);
{
u3_weak jax = u3_ch_get(rod_u->jed.har_u, bat);
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 ( u3_none != jax ) {
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);
}
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;
return (c3_l)jax;
}
}
if ( rod_u->par_u ) {
rod_u = rod_u->par_u;
}
else return 0;
}
}
@ -189,8 +183,6 @@ _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.
@ -202,15 +194,7 @@ _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;
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));
}
}
// fprintf(stderr, "kick: %s, %d, %d\r\n", cop_u->cos_c, jax_l, axe_l);
while ( 1 ) {
if ( 0 == hud_u ) { break; }
@ -230,7 +214,7 @@ _cj_hook_in(u3_noun cor,
u3_noun bat = u3h(cor);
c3_l jax_l = u3_cj_find(bat);
// fprintf(stderr, "hook: %s\n", tam_c);
// fprintf(stderr, "hook: %s\r\n", tam_c);
if ( 0 == jax_l ) { return 0; }
else {
@ -242,7 +226,7 @@ _cj_hook_in(u3_noun cor,
while ( 1 ) {
if ( 0 == hud_u ) { break; }
if ( mug_l != hud_u->mug_l ) { break; hud_u = hud_u->nex_u; continue; }
if ( mug_l != hud_u->mug_l ) { hud_u = hud_u->nex_u; continue; }
{
u3_cs_hook* huk_u = hud_u->huk_u;
@ -642,8 +626,10 @@ u3_cj_mine(u3_noun clu,
c3_assert(0 != jax_l);
free(nam_c);
#if 0
fprintf(stderr, "mine: bound jet %d/%s\r\n",
cop_u->jax_l, cop_u->cos_c);
fprintf(stderr, "mine: bound jet %d/%s/%s\r\n",
cop_u->jax_l,
cop_u->cos_c,
par_u ? par_u->cos_c : "~");
#endif
break;
}
@ -660,7 +646,9 @@ u3_cj_mine(u3_noun clu,
fak_u.axe_l = axe_l;
jax_l = _cj_insert(&fak_u);
// fprintf(stderr, "mine: dummy jet %d/%s\r\n", jax_l, fak_u.cos_c);
#if 1
fprintf(stderr, "mine: dummy jet %d/%s\r\n", jax_l, fak_u.cos_c);
#endif
}
u3z(clu);

6
g/m.c
View File

@ -394,6 +394,8 @@ u3_cm_dump(void)
}
}
c3_w Exit;
/* u3_cm_bail(): bail out. Does not return.
**
** Bail motes:
@ -443,10 +445,12 @@ u3_cm_bail(u3_noun how)
// u3_cm_signal(c3__exit);
if ( c3__exit != how ) {
u3_lo_sway(2, u3k(u3R->bug.tax));
// u3_lo_sway(2, u3k(u3R->bug.tax));
abort();
}
// if ( c3__exit == how ) { fprintf(stderr, "Exit: %d\n", Exit); Exit++; }
if ( &(u3H->rod_u) == u3R ) {
// For top-level errors, which shouln't happen often, we have no
// choice but to use the signal process; and we require the flat

1
g/n.c
View File

@ -379,7 +379,6 @@ u3_noun
u3_cn_nock_an(u3_noun bus, u3_noun fol)
{
u3_noun fly = u3nt(u3nc(1, 0), 0, 0); // |=(a=* ~)
u3_noun pro;
return u3_cn_nock_in(fly, bus, fol);
}

148
g/r.c
View File

@ -458,7 +458,8 @@ u3_cr_mug_trel(u3_noun a,
u3_noun b,
u3_noun c)
{
return u3_cr_mug_both(u3_cr_mug(a), u3_cr_mug_both(u3_cr_mug(b), u3_cr_mug(c)));
return u3_cr_mug_both
(u3_cr_mug(a), u3_cr_mug_both(u3_cr_mug(b), u3_cr_mug(c)));
}
/* u3_cr_mug_qual():
@ -477,6 +478,142 @@ u3_cr_mug_qual(u3_noun a,
u3_cr_mug_both(u3_cr_mug(c), u3_cr_mug(d))));
}
/* _sung_one(): pick a unified pointer for identical (a) and (b).
*/
static void
_sung_one(u3_noun* a, u3_noun* b)
{
if ( *a == *b ) {
return;
}
else {
c3_o asr_o = u3_co_is_senior(u3R, *a);
c3_o bsr_o = u3_co_is_senior(u3R, *b);
if ( u3_so(asr_o) && u3_so(bsr_o) ) {
// You shouldn't have let this happen. We don't want to
// descend down to a lower road and free there, because
// synchronization - though this could be revisited under
// certain circumstances.
//
return;
}
if ( u3_so(asr_o) && !u3_so(bsr_o) ){
u3z(*b);
*b = *a;
}
if ( u3_so(bsr_o) && !u3_so(asr_o) ) {
u3z(*a);
*a = *b;
}
if ( u3_co_is_north(u3R) ) {
if ( *a <= *b ) {
u3k(*a);
u3z(*b);
*b = *a;
} else {
u3k(*b);
u3z(*a);
*a = *b;
}
}
else {
if ( *a >= *b ) {
u3k(*a);
u3z(*b);
*b = *a;
} else {
u3k(*b);
u3z(*a);
*a = *b;
}
}
}
}
/* _sung_x(): yes if a and b are the same noun, unifying.
*/
static u3_bean
_sung_x(u3_noun a, u3_noun b)
{
if ( a == b ) {
return u3_yes;
}
else {
if ( u3_so(u3_co_is_atom(a)) ) {
u3_cs_atom* a_u = u3_co_to_ptr(a);
if ( !u3_so(u3_co_is_atom(b)) ||
u3_so(u3_co_is_cat(a)) ||
u3_so(u3_co_is_cat(b)) )
{
return u3_no;
}
else {
u3_cs_atom* b_u = u3_co_to_ptr(b);
if ( a_u->mug_w &&
b_u->mug_w &&
(a_u->mug_w != b_u->mug_w) )
{
return u3_no;
}
else {
c3_w w_rez = a_u->len_w;
c3_w w_mox = b_u->len_w;
if ( w_rez != w_mox ) {
return u3_no;
}
else {
c3_w i_w;
for ( i_w = 0; i_w < w_rez; i_w++ ) {
if ( a_u->buf_w[i_w] != b_u->buf_w[i_w] ) {
return u3_no;
}
}
return u3_yes;
}
}
}
}
else {
if ( u3_so(u3_co_is_atom(b)) ) {
return u3_no;
}
else {
u3_cs_cell* a_u = u3_co_to_ptr(a);
u3_cs_cell* b_u = u3_co_to_ptr(b);
if ( a_u->mug_w &&
b_u->mug_w &&
(a_u->mug_w != b_u->mug_w) )
{
return u3_no;
}
else {
if ( u3_no == _sung_x(a_u->hed, b_u->hed) ) {
return u3_no;
}
else {
_sung_one(&a_u->hed, &b_u->hed);
if ( u3_no == _sung_x(a_u->tel, b_u->tel) ) {
return u3_no;
}
else {
_sung_one(&a_u->tel, &b_u->tel);
return u3_yes;
}
}
}
}
}
}
}
/* _sing_x():
**
** Yes iff (a) and (b) are the same noun.
@ -569,6 +706,15 @@ u3_cr_sing(u3_noun a,
return _sing_x(a, b);
}
/* u3_cr_sung(): yes iff (a) and (b) are the same noun, unifying equals.
*/
u3_bean
u3_cr_sung(u3_noun a,
u3_noun b)
{
return _sung_x(a, b);
}
u3_bean
u3_cr_fing(u3_noun a,
u3_noun b)

View File

@ -27,6 +27,13 @@
u3_weak
u3_ch_get(u3_ch_root* har_u, u3_noun key);
/* u3_ch_gut(): read from hashtable, unifying key nouns.
**
** `key` is RETAINED.
*/
u3_weak
u3_ch_gut(u3_ch_root* har_u, u3_noun key);
/* u3_ch_free(): free hashtable.
*/
void

View File

@ -147,6 +147,15 @@
u3_cr_sing(u3_noun a,
u3_noun b);
/* u3_cr_sung(): yes iff (a) and (b) are the same noun, unifying equals.
**
** Make sure you have no live, uncounted pointers to any noun
** within (a) or (b)!
*/
u3_bean
u3_cr_sung(u3_noun a,
u3_noun b);
/* u3_cr_sing_c():
**
** Yes iff (b) is the same noun as the C string [a].

View File

@ -217,7 +217,7 @@
# define u3_co_is_senior(r, som) \
( u3_so(u3_co_is_cat(som)) \
? u3_no \
? u3_yes \
: u3_so(u3_co_is_north(r)) \
? u3_co_north_is_senior(r, som) \
: u3_co_south_is_senior(r, som) )

View File

@ -479,7 +479,8 @@
(u3_no == u3_cr_mean(van, u3_cv_sam_2, &hez, u3_cv_sam_3, &sef, 0)) )
{
return u3_cm_bail(c3__fail);
} else {
}
else {
return _cqe_here_fun(hez, sef, tub);
}
}

View File

@ -6,12 +6,20 @@
u3_noun
u3_cqfu_gain(u3_noun van,
u3_noun sut,
u3_noun gen)
u3_cqfu_gain(u3_noun van, u3_noun sut, u3_noun gen)
{
u3_noun von = u3_ci_molt(u3k(van), u3_cv_sam, u3k(sut), 0);
u3_noun gat = u3_cj_hook(u3k(von), "gain");
u3_noun dun = u3_cqfu_dunq(van, "type", sut);
u3_noun pro;
return u3_cn_kick_on(u3_ci_molt(gat, u3_cv_sam, u3k(gen), 0));
if ( u3_ne(u3_ca_audit(gen)) ){
printf("bad gene!\r\n");
}
u3_ct_push(u3nc(c3__mean, dun));
pro = u3_cn_kick_on(u3_ci_molt(gat, u3_cv_sam, u3k(gen), 0));
u3_ct_drop();
return pro;
}

View File

@ -378,7 +378,7 @@
u3_noun nob = u3_cqfl_bunt(van, p_gen);
u3_noun p_waz = u3_cqfu_play(van, sut, nob);
u3_noun q_waz = u3_cqfu_play(van, dox, nob);
u3_noun dok = u3nc(c3__cnzz, q_gen);
u3_noun dok = u3nc(c3__cnzz, u3k(q_gen));
u3_noun p_syx = _mull_doke(van, sut, dok);
u3_noun q_syx = _mull_doke(van, dox, dok);
u3_noun p_pov = u3_cqfu_fish(van, p_waz, p_syx);

View File

@ -285,8 +285,7 @@
}
case c3__hold: p_sut = u3t(sut);
{
u3_noun hud = u3nc(u3k(sut),
u3k(ref));
u3_noun hud = u3nc(u3k(sut), u3k(ref));
if ( (u3_yes == u3_cqdi_has(gil, hud)) ) {
u3z(hud);