Various fixes and improvements.

This commit is contained in:
C. Guy Yarvin 2014-10-28 10:36:22 -07:00
parent 9eb236eeda
commit 109053ecf1
18 changed files with 439 additions and 517 deletions

View File

@ -58,7 +58,7 @@ endif
INCLUDE=include
MDEFINES=-DU2_OS_$(OS) -DU2_OS_ENDIAN_$(ENDIAN) -D U2_LIB=\"$(LIB)\"
# NOTFORCHECKIN - restore -O2
# NOTFORCHECKIN - restore -O3
CFLAGS= $(COSFLAGS) -O3 -msse3 -ffast-math \
-funsigned-char \
-I/usr/local/include \

122
g/a.c
View File

@ -39,9 +39,11 @@ _box_make(void* box_v, c3_w siz_w, c3_w use_w)
box_w[0] = siz_w;
box_w[siz_w - 1] = siz_w;
box_u->use_w = use_w;
c3_assert(2 != use_w);
# ifdef U3_MEMORY_DEBUG
box_u->cod_w = u3_Code;
box_u->eus_w = 0;
# endif
return box_u;
@ -272,12 +274,18 @@ 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 *)0x2006a4b38 ) {
#if 1
if ( (703 == u3_Code) &&
u3_co_botox(ptr_v) == (u3_cs_box*)(void *)0x200dfe3e4 ) {
static int xuc_i;
printf("xuc_i %d\r\n", xuc_i);
if ( 31 == xuc_i ) { abort(); }
if ( 1 == xuc_i ) {
u3_cs_box* box_u = u3_co_botox(ptr_v);
box_u->cod_w = 999;
FOO = 1;
}
// if ( 9 == xuc_i ) { FOO = 1; }
xuc_i++;
}
@ -496,6 +504,8 @@ u3_ca_wash(u3_noun som)
}
#endif
extern u3_noun BDA, BDB;
/* _me_gain_use(): increment use count.
*/
static void
@ -512,6 +522,37 @@ _me_gain_use(u3_noun dog)
u3_cm_bail(c3__foul);
}
box_u->use_w += 1;
#ifdef U3_MEMORY_DEBUG
// if ( u3_Code && !box_u->cod_w ) { box_u->cod_w = u3_Code; }
#if 0
{
static c3_w bug_w = 0;
if ( BDA == dog ) {
printf("BDA %d %d\r\n", bug_w, box_u->use_w);
// if ( bug_w == 0 ) { abort(); }
bug_w++;
}
}
#endif
#if 0
{
static c3_w bug_w = 0;
if ( FOO && u3_co_botox(u3_co_to_ptr(dog)) == (void *)0x200dfe3e4 ) {
u3_cs_box* box_u = u3_co_botox(u3_co_to_ptr(dog));
printf("GAIN %d %d\r\n", bug_w, box_u->use_w);
if ( bug_w == 8 ) { abort(); }
bug_w++;
}
}
#endif
#endif
}
}
@ -905,17 +946,6 @@ u3_ca_gain(u3_noun som)
{
c3_assert(u3_none != som);
#if 0
if ( FOO && (som == 3221949559) ) {
static int xuc_i;
printf("gain %d\r\n", xuc_i);
if ( 5 == xuc_i ) {
abort();
}
xuc_i++;
}
#endif
if ( u3_so(u3_co_is_cat(som)) ) {
return som;
}
@ -956,7 +986,7 @@ u3_ca_use(u3_noun som)
}
}
/* u3_ca_mark_ptr(): mark a pointer for gc. Produce size.
/* u3_ca_mark_ptr(): mark a pointer for gc. Produce size if first mark.
*/
c3_w
u3_ca_mark_ptr(void* ptr_v)
@ -969,9 +999,19 @@ u3_ca_mark_ptr(void* ptr_v)
}
{
u3_cs_box* box_u = u3_co_botox(ptr_v);
c3_ws use_ws = (c3_ws)box_u->use_w;
c3_w siz_w;
#ifdef U3_MEMORY_DEBUG
if ( box_u->eus_w == 0 ) {
siz_w = box_u->siz_w;
}
else {
siz_w = 0;
}
box_u->eus_w += 1;
#else
c3_ws use_ws = (c3_ws)box_u->use_w;
if ( use_ws == 0 ) {
fprintf(stderr, "%p is bogus\r\n", ptr_v);
siz_w = 0;
@ -989,6 +1029,7 @@ u3_ca_mark_ptr(void* ptr_v)
}
box_u->use_w = (c3_w)use_ws;
}
#endif
return siz_w;
}
}
@ -1056,7 +1097,7 @@ _ca_print_memory(c3_c* cap_c, c3_w wor_w)
void
u3_ca_sweep(c3_c* cap_c)
{
c3_w neg_w, pos_w, leq_w, tot_w, caf_w;
c3_w neg_w, pos_w, leq_w, weq_w, tot_w, caf_w;
/* Measure allocated memory by counting the free list.
*/
@ -1082,21 +1123,47 @@ u3_ca_sweep(c3_c* cap_c)
/* Sweep through the arena, repairing and counting leaks.
*/
pos_w = leq_w = 0;
pos_w = leq_w = weq_w = 0;
{
c3_w* box_w = u3_so(u3_co_is_north(u3R)) ? u3R->rut_w : u3R->hat_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;
c3_ws use_ws = (c3_ws)box_u->use_w;
if ( use_ws > 0 ) {
#ifdef U3_MEMORY_DEBUG
printf("leak %p\r\n", box_u);
if ( box_u->use_w != box_u->eus_w ) {
if ( box_u->eus_w != 0 ) {
if ( box_u->use_w == 0 ) {
printf("dank %p (%d, %d)\r\n", box_u, box_u->use_w, box_u->eus_w);
}
else {
printf("weak %p (%d, %d)\r\n", box_u, box_u->use_w, box_u->eus_w);
printf("weak %x %x\r\n",
((u3_cs_noun *)(u3_co_boxto(box_w)))->mug_w,
u3_cr_mug(u3_co_to_pom(u3_co_outa(u3_co_boxto(box_w)))));
}
weq_w += box_u->siz_w;
}
else {
printf("leak %p (%d)\r\n", box_u, box_u->use_w);
leq_w += box_u->siz_w;
}
if ( box_u->cod_w ) {
u3_cm_p(" code", box_u->cod_w);
}
#endif
box_u->use_w = box_u->eus_w;
}
else {
if ( box_u->use_w ) {
pos_w += box_u->siz_w;
}
}
box_u->eus_w = 0;
#else
c3_ws use_ws = (c3_ws)box_u->use_w;
if ( use_ws > 0 ) {
printf("leak %p\r\n", box_u);
leq_w += box_u->siz_w;
box_u->use_w = 0;
@ -1106,7 +1173,7 @@ u3_ca_sweep(c3_c* cap_c)
pos_w += box_u->siz_w;
box_u->use_w = (c3_w)(0 - use_ws);
}
#endif
box_w += box_u->siz_w;
}
}
@ -1118,14 +1185,15 @@ u3_ca_sweep(c3_c* cap_c)
? u3R->mat_w - u3R->cap_w
: u3R->cap_w - u3R->mat_w;
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("volatile", caf_w);
// _ca_print_memory("volatile", caf_w);
_ca_print_memory("leaked", leq_w);
_ca_print_memory("weaked", weq_w);
if ( 0 != leq_w ) {
c3_assert((pos_w + leq_w + weq_w) == neg_w);
if ( 0 != leq_w || (0 != weq_w) ) {
c3_assert(0);
}
}

8
g/e.c
View File

@ -703,6 +703,9 @@ u3_ce_init(c3_o chk_o)
void
u3_ce_grab(c3_c* cap_c, u3_noun som, ...) // terminate with u3_none
{
// u3_ch_free(u3R->cax.har_u);
// u3R->cax.har_u = u3_ch_new();
u3_cv_mark();
u3_cm_mark();
{
@ -805,9 +808,10 @@ u3_ce_boot(c3_o nuu_o, c3_c* cpu_c)
snprintf(pas_c, 2048, "%s/.urb/urbit.pill", cpu_c);
printf("boot: loading %s\r\n", pas_c);
u3_cv_make(pas_c);
u3_cv_jack();
}
else {
u3_cj_clear();
u3_cj_ream();
}
u3_cv_jack();
}

17
g/i.c
View File

@ -194,6 +194,9 @@ u3_ci_vint(u3_noun a)
extern int FOO;
u3_noun BDA;
u3_noun BDB;
/* u3_ci_cell():
**
** Produce the cell `[a b]`.
@ -210,13 +213,25 @@ u3_ci_cell(u3_noun a, u3_noun b)
{
c3_w* nov_w = u3_ca_walloc(c3_wiseof(u3_cs_cell));
u3_cs_cell* nov_u = (void *)nov_w;
u3_noun pro;
nov_u->mug_w = 0;
nov_u->hed = a;
nov_u->tel = b;
pro = u3_co_to_pom(u3_co_outa(nov_w));
#if 0
if ( 0x2aa8e7aa == u3_cr_mug(pro) ) {
fprintf(stderr, "BDA %x\r\n", pro);
BDA = pro;
}
if ( 0x47645a83 == u3_cr_mug(pro) ) {
fprintf(stderr, "BDB %x\r\n", pro);
BDB = pro;
}
#endif
#if 1
return u3_co_to_pom(u3_co_outa(nov_w));
return pro;
#else
if ( !FOO ) return u3_co_to_pom(u3_co_outa(nov_w));
else {

647
g/j.c
View File

@ -42,16 +42,6 @@
return jax_l;
}
struct _cj_dash {
u3_noun sys;
u3_noun haw;
};
struct _cj_cope {
u3_noun soh;
u3_noun hud;
u3_noun mop;
};
/* _cj_axis(): axis from formula, or 0. `fol` is RETAINED.
*/
static c3_l
@ -84,7 +74,7 @@ _cj_axis(u3_noun fol)
}
}
/* _cj_by_gut(): (~(get by a) b), unifying; RETAINS a, b, and result.
/* _cj_by_gut(): (~(get by a) b), unifying; RETAINS a, b, AND result.
*/
static u3_weak
_cj_by_gut(u3_noun a, u3_noun b)
@ -99,7 +89,7 @@ _cj_by_gut(u3_noun a, u3_noun b)
u3_cx_trel(a, &n_a, &l_a, &r_a);
u3_cx_cell(n_a, &pn_a, &qn_a);
{
if ( (u3_yes == u3_cr_sung(b, pn_a)) ) {
if ( (u3_yes == u3_cr_sing(b, pn_a)) ) {
return qn_a;
}
else {
@ -112,149 +102,6 @@ _cj_by_gut(u3_noun a, u3_noun b)
}
}
/* _cj_insert(): append copy of core driver to jet table. For dummies.
*/
static c3_l
_cj_insert(u3_cs_core* cop_u)
{
c3_l jax_l = u3D.len_l;
u3D.len_l += 1;
c3_assert(u3D.len_l < u3D.all_l);
memcpy(&u3D.ray_u[jax_l], cop_u, sizeof(u3_cs_core));
cop_u->jax_l = jax_l;
return jax_l;
}
/* _cj_x_dash(): export dash. RETAIN.
*/
static void
_cj_x_dash(u3_noun das, struct _cj_dash* das_u)
{
u3_cx_cell(das, &(das_u->sys), &(das_u->haw));
u3k(das_u->sys); u3k(das_u->haw);
}
/* _cj_m_dash(): import dash.
*/
static u3_noun
_cj_m_dash(struct _cj_dash* das_u)
{
return u3nc(das_u->sys, das_u->haw);
}
/* _cj_f_dash(): release dash.
*/
static void
_cj_f_dash(struct _cj_dash* das_u)
{
u3z(das_u->sys);
u3z(das_u->haw);
}
/* _cj_x_cope(): export cope. RETAIN.
*/
static void
_cj_x_cope(u3_noun coe, struct _cj_cope* coe_u)
{
u3_cx_trel(coe, &(coe_u->soh),
&(coe_u->hud),
&(coe_u->mop));
u3k(coe_u->soh);
u3k(coe_u->hud);
u3k(coe_u->mop);
}
/* _cj_m_cope(): import cope.
*/
static u3_noun
_cj_m_cope(struct _cj_cope* coe_u)
{
return u3nt(coe_u->soh, coe_u->hud, coe_u->mop);
}
/* _cj_f_cope(): release cope.
*/
static void
_cj_f_cope(struct _cj_cope* coe_u)
{
u3z(coe_u->soh);
u3z(coe_u->hud);
u3z(coe_u->mop);
}
#if 0
/* _cj_je_fine(): fine:je. RETAINS args.
*/
static c3_o
_cj_je_fine(struct _cj_dash* das_u, struct _cj_cope* coe_u, u3_noun cor)
{
u3_noun p_mop, q_mop, r_mop, h_mop, t_mop;
u3_cx_trel(coe_u->mop, &p_mop, &q_mop, &r_mop);
u3_cx_cell(r_mop, &h_mop, &t_mop);
{
u3_weak rah = u3_cr_at(q_mop, cor);
if ( u3_none == rah ) {
return u3_no;
}
else {
if ( u3_no == h_mop ) {
return u3_cr_sing(t_mop, rah);
}
else {
u3_noun eco;
eco = u3_ckdb_got(u3k(das_u->haw), u3k(t_mop));
{
struct _cj_cope eco_u;
c3_o pro_o;
_cj_x_cope(eco, &eco_u);
pro_o = _cj_je_fine(das_u, &eco_u, rah);
_cj_f_cope(&eco_u);
u3z(eco);
return pro_o;
}
}
}
}
}
/* _cj_je_fill: fill:je. RETAINS args, PRODUCES result.
*/
static u3_noun
_cj_je_fill(struct _cj_dash* das_u, u3_noun cor)
{
u3_noun bus = _cj_je_find(das_u, cor);
if ( u3_nul == bus ) {
return u3_nul;
}
else {
u3_noun soh = u3t(bus);
u3_noun coe;
coe = u3_ckdb_got(u3k(das_u->haw), u3k(soh));
{
struct _cj_cope coe_u;
c3_o pro_o;
_cj_x_cope(coe, &coe_u);
pro_o = _cj_je_fine(das_u, &coe_u, cor);
_cj_f_cope(&coe_u);
}
return u3nc(u3_nul, soh);
}
}
#endif
/* _cj_chum(): decode chum as string.
*/
static c3_c*
@ -330,6 +177,7 @@ _cj_je_fsck(u3_noun clu)
r_clu = tr_clu;
}
}
u3z(clu);
return u3nt(u3_ci_string(nam_c), axe_l, huk);
}
@ -346,86 +194,25 @@ _cj_sham(u3_noun som) // XX wrong, does not match ++sham
return haf;
}
/* _cj_je_fuel: install battery and core pattern.
*/
static void
_cj_je_fuel(struct _cj_dash* das_u, u3_noun bat, u3_noun coe)
{
struct _cj_cope coe_u;
_cj_x_cope(coe, &coe_u);
{
das_u->sys = u3_ckdb_put(das_u->sys, u3k(bat), u3k(coe_u.soh));
das_u->haw = u3_ckdb_put(das_u->haw, u3k(coe_u.soh), u3k(coe));
}
u3z(bat);
u3z(coe);
_cj_f_cope(&coe_u);
}
/* _cj_cold_find_bash(): in cold, find identity hash by battery.
**
** RETAINS `bat` AND result.
/* _cj_cold_find_sys: search `sys` in dashboard. RETAINS `bat` AND result.
*/
static u3_weak
_cj_cold_find_bash(u3_noun bat)
_cj_cold_find_sys(u3_noun bat)
{
u3_cs_road* rod_u = u3R;
u3_weak pro = u3_none;
while ( 1 ) {
if ( u3_ne(u3_co_is_senior(u3R, bat)) ) {
struct _cj_dash das_u;
_cj_x_dash(u3R->jed.das, &das_u);
{
pro = _cj_by_gut(das_u.sys, bat);
}
_cj_f_dash(&das_u);
if ( u3_ne(u3_co_is_senior(rod_u, bat)) ) {
u3_noun pro = _cj_by_gut(u3h(rod_u->jed.das), bat);
if ( pro != u3_none ) {
break;
return pro;
}
}
if ( !u3R->par_u ) { break; }
else u3R = u3R->par_u;
if ( !rod_u->par_u ) break;
rod_u = rod_u->par_u;
}
u3R = rod_u;
return pro;
}
/* _cj_cold_find_cope(): in cold, find core pattern by battery.
**
** RETAINS `bat` AND result.
*/
static u3_weak
_cj_cold_find_cope(u3_noun bat)
{
u3_cs_road* rod_u = u3R;
u3_weak pro = u3_none;
while ( 1 ) {
if ( u3_ne(u3_co_is_senior(u3R, bat)) ) {
struct _cj_dash das_u;
_cj_x_dash(u3R->jed.das, &das_u);
{
pro = _cj_by_gut(das_u.sys, bat);
if ( u3_none != pro ) {
pro = _cj_by_gut(das_u.haw, pro);
}
}
_cj_f_dash(&das_u);
if ( pro != u3_none ) {
break;
}
}
if ( !u3R->par_u ) { break; }
else u3R = u3R->par_u;
}
u3R = rod_u;
return pro;
return u3_none;
}
/* _cj_road(): find the proper road for a battery. RETAIN.
@ -441,115 +228,69 @@ _cj_road(u3_noun bat)
return rod_u;
}
/* _cj_cold_mine(): in cold mode, declare a core. RETAIN.
/* _cj_cold_mine(): in cold mode, declare a core. RETAINS.
*/
static c3_o
static u3_weak
_cj_cold_mine(u3_noun cey, u3_noun cor)
{
struct _cj_dash das_u;
u3_noun coe;
u3_noun bat = u3h(cor);
u3_noun p_cey, q_cey, r_cey;
u3_cr_trel(cey, &p_cey, &q_cey, &r_cey);
_cj_x_dash(u3R->jed.das, &das_u);
{
u3_noun mop, soh;
/* Calculate semantic identity (mop).
*/
{
if ( 0 == q_cey ) {
mop = u3nq(u3k(p_cey), 3, u3_no, u3k(bat));
u3_noun mop;
if ( 0 == q_cey ) {
mop = u3nq(u3k(p_cey), 3, u3_no, u3k(bat));
}
else {
u3_weak rah = u3_cr_at(q_cey, cor);
if ( (u3_none == rah) || u3_ne(u3du(rah)) ) {
fprintf(stderr, "fund: %s is bogus\r\n", u3_cr_string(p_cey));
return u3_none;
}
else {
u3_weak rah = u3_cr_at(q_cey, cor);
u3_noun soh = _cj_cold_find_sys(u3h(rah));
if ( (u3_none == rah) || u3_ne(u3du(rah)) ) {
fprintf(stderr, "fund: %s is bogus\r\n", u3_cr_string(p_cey));
return u3_no;
if ( u3_none == soh ) {
fprintf(stderr, "fund: in %s, parent %x not found at %d\r\n",
u3_cr_string(p_cey),
u3_cr_mug(u3h(rah)),
q_cey);
return u3_none;
}
else {
u3_noun bah = _cj_cold_find_bash(u3h(rah));
if ( u3_none == bah ) {
fprintf(stderr, "fund: in %s, parent %x not found at %d\r\n",
u3_cr_string(p_cey),
u3_cr_mug(u3h(rah)),
q_cey);
abort();
return u3_no;
}
else {
mop = u3nq(u3k(p_cey), u3k(q_cey), u3_yes, u3k(bah));
}
mop = u3nq(u3k(p_cey), u3k(q_cey), u3_yes, u3k(soh));
}
}
}
// Assemble new core pattern in this road.
//
{
soh = _cj_sham(u3k(mop));
coe = u3_ckdb_get(u3k(das_u.haw), u3k(soh));
// Assemble new core pattern in this road.
//
{
u3_noun soh = _cj_sham(u3k(mop));
u3_noun hoe = u3_ckdb_get(u3k(u3t(u3R->jed.das)), u3k(soh));
u3_noun sab, sad;
if ( u3_none != coe ) {
fprintf(stderr, "fund: old %s\r\n", u3_cr_string(p_cey));
{
struct _cj_cope coe_u;
_cj_x_cope(coe, &coe_u);
coe_u.hud = u3_ckdb_put(coe_u.hud, u3k(bat), u3k(r_cey));
u3z(coe);
coe = _cj_m_cope(&coe_u);
}
}
else {
// fprintf(stderr, "fund: new %s\r\n", u3_cr_string(p_cey));
coe = u3nt(u3k(soh),
u3nt(u3nc(u3k(bat), u3k(r_cey)), u3_nul, u3_nul),
u3k(mop));
}
das_u.haw = u3_ckdb_put(das_u.haw, u3k(soh), coe);
das_u.sys = u3_ckdb_put(das_u.sys, u3k(bat), u3k(soh));
if ( u3_none == hoe ) {
sab = u3nt(u3nc(u3k(bat), u3k(r_cey)), u3_nul, u3_nul);
}
u3z(mop);
u3z(soh);
}
}
u3z(u3R->jed.das);
u3R->jed.das = _cj_m_dash(&das_u);
return u3_yes;
}
/* _cj_warm_find(): in warm state, return 0 or the battery index. RETAINS.
*/
c3_l
_cj_warm_find(u3_noun bat)
{
u3_cs_road* rod_u = u3R;
while ( 1 ) {
if ( u3_ne(u3_co_is_senior(rod_u, bat)) ) {
u3_weak jaw = u3_ch_gut(rod_u->jed.har_u, bat);
if ( u3_none != jaw ) {
u3_assure(u3_co_is_cat(u3h(jaw)));
#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)u3h(jaw);
else {
sab = u3_ckdb_put(u3k(u3t(hoe)), u3k(bat), u3k(r_cey));
u3z(hoe);
}
sad = u3nc
(u3_ckdb_put(u3k(u3h(u3R->jed.das)), u3k(bat), soh),
u3_ckdb_put(u3k(u3t(u3R->jed.das)), u3k(soh), u3nc(u3k(mop), sab)));
u3z(u3R->jed.das);
u3R->jed.das = sad;
return mop;
}
if ( rod_u->par_u ) {
rod_u = rod_u->par_u;
}
else return 0;
}
}
@ -580,12 +321,12 @@ _cj_warm_fend(u3_noun bat)
static u3_noun
_cj_warm_hump(c3_l jax_l, u3_noun huc)
{
u3_cs_core* cop_u = &u3D.ray_u[jax_l];
u3_noun hap = u3_nul;
u3_noun hap = u3_nul;
u3_cs_core* cop_u;
/* Compute axes of all correctly declared arms.
*/
if ( cop_u->arm_u ) {
if ( jax_l && (cop_u = &u3D.ray_u[jax_l])->arm_u ) {
u3_cs_harm* jet_u;
c3_l i_l;
@ -610,7 +351,10 @@ _cj_warm_hump(c3_l jax_l, u3_noun huc)
if ( u3_none == fol ) {
fprintf(stderr, "jets: activate: bad fcs %s\r\n", jet_u->fcs_c);
}
axe_l = _cj_axis(fol);
else {
axe_l = _cj_axis(fol);
u3z(fol);
}
}
if ( 0 != axe_l ) {
hap = u3_ckdb_put(hap, axe_l, i_l);
@ -620,99 +364,167 @@ _cj_warm_hump(c3_l jax_l, u3_noun huc)
return hap;
}
/* _cj_boil_mine(): in boiling state, declare a core. RETAINS.
**
/* _cj_boil_mean(): in parent, declare a core. RETAINS.
*/
static c3_l
_cj_boil_mine(u3_noun cor)
_cj_boil_mean(c3_l par_l, u3_noun mop)
{
u3_noun bat = u3h(cor);
u3_weak coe = _cj_cold_find_cope(bat);
struct _cj_cope coe_u;
c3_l jax_l = 0;
c3_assert(u3_none != coe);
_cj_x_cope(coe, &coe_u);
u3_cs_core* par_u;
u3_cs_core* dev_u;
if ( 0 != par_l ) {
par_u = &u3D.ray_u[par_l];
dev_u = par_u->dev_u;
}
else {
par_u = 0;
dev_u = u3D.dev_u;
}
{
u3_noun p_mop, q_mop, r_mop, hr_mop, tr_mop;
c3_w i_l = 0;
u3_cs_core* cop_u;
u3_cx_trel(coe_u.mop, &p_mop, &q_mop, &r_mop);
u3_cx_cell(r_mop, &hr_mop, &tr_mop);
{
u3_noun nam = p_mop;
u3_noun axe_l = q_mop;
u3_noun par_l;
// Calculate parent axis.
//
if ( u3_yes == hr_mop ) {
par_l = _cj_warm_find(u3h(u3_cr_at(axe_l, cor)));
c3_assert(0 != par_l);
}
else par_l = 0;
// Link into parent.
//
{
u3_cs_core* par_u = par_l ? &u3D.ray_u[par_l] : 0;
u3_cs_core* dev_u = par_u ? par_u->dev_u : u3_Dash.dev_u;
c3_w i_l = 0;
if ( dev_u ) {
u3_cs_core* cop_u;
while ( (cop_u = &dev_u[i_l])->cos_c ) {
if ( u3_so(u3_cr_sing_c(cop_u->cos_c, nam)) ) {
jax_l = cop_u->jax_l;
u3D.ray_u[jax_l].axe_l = axe_l;
u3D.ray_u[jax_l].par_u = par_u;
c3_assert(0 != jax_l);
while ( (cop_u = &dev_u[i_l])->cos_c ) {
if ( u3_so(u3_cr_sing_c(cop_u->cos_c, u3h(mop))) ) {
#if 1
fprintf(stderr, "boil: bound jet %d/%s/%s/%x\r\n",
cop_u->jax_l,
cop_u->cos_c,
par_u ? par_u->cos_c : "~",
u3_cr_mug(bat));
fprintf(stderr, "boil: bound jet %d/%s/%s\r\n",
cop_u->jax_l,
cop_u->cos_c,
par_u ? par_u->cos_c : "~");
#endif
break;
}
i_l++;
}
}
if ( 0 == jax_l ) {
u3_cs_core fak_u;
memset(&fak_u, 0, sizeof(u3_cs_core));
fak_u.cos_c = u3_cr_string(nam);
fak_u.par_u = par_u;
fak_u.axe_l = axe_l;
jax_l = _cj_insert(&fak_u);
#if 1
fprintf(stderr, "boil: dummy jet %d/%s\r\n", jax_l, fak_u.cos_c);
#endif
}
return cop_u->jax_l;
}
i_l++;
}
}
_cj_f_cope(&coe_u);
return 0;
}
/* _cj_boil_mine(): in boiling state, declare a core. RETAINS.
*/
static c3_l
_cj_boil_mine(u3_noun mop, u3_noun cor)
{
u3_noun p_mop, q_mop, r_mop, hr_mop, tr_mop;
u3_cx_trel(mop, &p_mop, &q_mop, &r_mop);
u3_cx_cell(r_mop, &hr_mop, &tr_mop);
{
c3_l par_l;
// Calculate parent axis.
//
if ( u3_yes == hr_mop ) {
u3_noun cax = _cj_warm_fend(u3h(u3_cr_at(q_mop, cor)));
par_l = u3h(cax);
u3z(cax);
}
else par_l = 0;
return _cj_boil_mean(par_l, mop);
}
}
static c3_l _cj_warm_fresh_at(u3_noun soh, u3_noun cag);
/* _cj_warm_fresh_be(): install battery; RETAINS.
*/
static void
_cj_warm_fresh_be(c3_l jax_l,
u3_noun pax,
u3_noun bat,
u3_noun huc)
{
u3_ch_put(u3R->jed.har_u,
bat,
u3nq(jax_l,
u3k(pax),
_cj_warm_hump(jax_l, huc),
u3k(huc)));
}
/* _cj_warm_fresh_is(): refresh battery; RETAINS.
*/
static void
_cj_warm_fresh_is(c3_l jax_l,
u3_noun pax,
u3_noun sab)
{
if ( u3_nul != sab ) {
u3_noun n_sab, l_sab, r_sab, pn_sab, qn_sab;
u3_cx_trel(sab, &n_sab, &l_sab, &r_sab);
u3_cx_cell(n_sab, &pn_sab, &qn_sab);
_cj_warm_fresh_be(jax_l, pax, pn_sab, qn_sab);
_cj_warm_fresh_is(jax_l, pax, l_sab);
_cj_warm_fresh_is(jax_l, pax, r_sab);
}
}
/* _cj_warm_fresh_un(): refresh under `soh`; RETAINS.
*/
static c3_l
_cj_warm_fresh_un(u3_noun soh)
{
u3_noun cag = u3_ckdb_got(u3k(u3t(u3R->jed.das)), u3k(soh));
u3_noun sab = u3t(cag);
u3_noun cax;
c3_l jax_l;
if ( u3_none != (cax = u3_ch_get(u3R->jed.har_u, u3h(u3h(sab)))) ) {
jax_l = u3h(cax);
u3z(cax);
}
else {
jax_l = _cj_warm_fresh_at(soh, cag);
}
u3z(cag);
return jax_l;
}
/* _cj_warm_fresh_in(): refresh in `tys`; RETAINS.
/* _cj_warm_fresh_at(): refresh at `soh` and `cag`; RETAINS.
*/
static c3_l
_cj_warm_fresh_at(u3_noun soh, u3_noun cag)
{
u3_noun mop = u3h(cag);
u3_noun sab = u3t(cag);
u3_noun p_mop, q_mop, r_mop, hr_mop, tr_mop;
u3_cx_trel(mop, &p_mop, &q_mop, &r_mop);
u3_cx_cell(r_mop, &hr_mop, &tr_mop);
{
c3_l par_l, jax_l;
if ( u3_yes == hr_mop ) {
par_l = _cj_warm_fresh_un(tr_mop);
}
else par_l = 0;
jax_l = _cj_boil_mean(par_l, mop);
_cj_warm_fresh_is(jax_l, q_mop, sab);
return jax_l;
}
}
/* _cj_warm_fresh_in(): refresh in `taw`; RETAINS.
*/
static void
_cj_warm_fresh_in(struct _cj_dash* das_u, u3_noun tys)
_cj_warm_fresh_in(u3_noun taw)
{
if ( u3_nul == tys ) {
u3_noun n_tys, l_tys, r_tys, pn_tys, qn_tys;
if ( u3_nul != taw ) {
u3_noun n_taw, l_taw, r_taw, pn_taw, qn_taw;
u3_cx_trel(tys, &n_tys, &l_tys, &r_tys);
u3_cx_cell(n_tys, &pn_tys, &qn_tys);
u3_cx_trel(taw, &n_taw, &l_taw, &r_taw);
u3_cx_cell(n_taw, &pn_taw, &qn_taw);
_cj_warm_fresh_in(das_u, l_tys);
_cj_warm_fresh_in(das_u, r_tys);
_cj_warm_fresh_at(pn_taw, qn_taw);
_cj_warm_fresh_in(l_taw);
_cj_warm_fresh_in(r_taw);
}
}
@ -721,24 +533,37 @@ _cj_warm_fresh_in(struct _cj_dash* das_u, u3_noun tys)
static void
_cj_warm_fresh(void)
{
struct _cj_dash das_u;
_cj_x_dash(u3R->jed.das, &das_u);
c3_assert(u3R == &(u3H->rod_u));
{
_cj_warm_boot_in(&das_u, das_u.sys);
_cj_warm_fresh_in(u3t(u3R->jed.das));
}
_cj_f_dash(&das_u);
}
/* u3_cj_ream(): refresh after restoring from checkpoint.
*/
void
u3_cj_ream(void)
{
u3_ch_free(u3R->jed.har_u);
u3R->jed.har_u = u3_ch_new();
_cj_warm_fresh();
}
/* _cj_warm_mine(): in warm mode, declare a core.
*/
static void
_cj_warm_mine(u3_noun clu, u3_noun cor)
{
u3_noun bat = u3h(cor);
u3_noun cax;
if ( u3_ne(u3du(cor)) || (0 != _cj_warm_find(bat)) ) {
if ( u3_ne(u3du(cor)) ) {
u3z(clu);
}
else if ( u3_none != (cax = _cj_warm_fend(bat)) ) {
u3z(cax); u3z(clu);
}
else {
u3_noun cey = _cj_je_fsck(clu);
@ -752,16 +577,18 @@ _cj_warm_mine(u3_noun clu, u3_noun cor)
u3_noun yec = u3_ca_take(cey);
u3_noun huc = u3t(u3t(yec));
u3_noun pax = u3h(u3t(yec));
u3_noun mop;
if ( u3_so(_cj_cold_mine(yec, cor)) ) {
c3_l jax_l = _cj_boil_mine(cor);
if ( u3_none != (mop = _cj_cold_mine(yec, cor)) ) {
c3_l jax_l = _cj_boil_mine(mop, cor);
u3_ch_put(u3R->jed.har_u,
bat,
u3nq(jax_l,
u3k(pax),
_cj_warm_hump(jax_l, u3k(huc)),
_cj_warm_hump(jax_l, huc),
u3k(huc)));
u3z(mop);
}
u3z(yec);
}
@ -972,7 +799,10 @@ u3_noun
u3_cj_soft(u3_noun cor,
const c3_c* tam_c)
{
return _cj_hook_in(cor, tam_c, u3_no);
u3_noun pro;
pro = _cj_hook_in(cor, tam_c, u3_no);
return pro;
}
/* u3_cj_hook(): execute hook from core, or fail.
@ -981,7 +811,10 @@ u3_noun
u3_cj_hook(u3_noun cor,
const c3_c* tam_c)
{
return _cj_hook_in(cor, tam_c, u3_yes);
u3_noun pro;
pro = _cj_hook_in(cor, tam_c, u3_yes);
return pro;
}
/* u3_cj_kick(): new kick.
@ -1010,9 +843,12 @@ u3_cj_kick(u3_noun cor, u3_noun axe)
u3_cs_core* cop_u = &u3D.ray_u[jax_l];
c3_l inx_l = inx;
u3_cs_harm* ham_u = &cop_u->arm_u[inx_l];
u3_noun pro;
u3z(cax);
return _cj_kick_z(cor, cop_u, ham_u, axe);
pro = _cj_kick_z(cor, cop_u, ham_u, axe);
return pro;
}
}
}
@ -1033,15 +869,6 @@ u3_cj_kink(u3_noun cor,
}
}
/* u3_cj_clear(): clear jet table to re-register.
*/
void
u3_cj_clear(void)
{
u3_ch_free(u3R->jed.har_u);
u3R->jed.har_u = u3_ch_new();
}
/* u3_cj_mine(): register core for jets. Produce registered core.
*/
void

11
g/m.c
View File

@ -383,6 +383,7 @@ u3_cm_boot(c3_o nuu_o)
void
u3_cm_clear(void)
{
u3_ch_free(u3R->cax.har_u);
u3_ch_free(u3R->jed.har_u);
u3_ca_lose(u3R->jed.das);
}
@ -680,6 +681,7 @@ u3_cm_water(c3_w* low_w, c3_w* hig_w)
u3_noun
u3_cm_soft_top(c3_w sec_w, // timer seconds
c3_w pad_w, // base memory pad
c3_o gab_o, // garbage-collect result
u3_funk fun_f,
u3_noun arg)
{
@ -711,11 +713,10 @@ u3_cm_soft_top(c3_w sec_w, // timer seconds
/* Trap for ordinary nock exceptions.
*/
if ( 0 == (why = u3_cm_trap()) ) {
#if 0
#if 1
{
u3_ce_grab("before", u3_none);
pro = fun_f(arg);
u3_ce_grab("after", pro, u3_none);
u3_ce_grab("top", pro, u3_none);
}
#else
pro = fun_f(arg);
@ -931,7 +932,9 @@ u3_cm_soft(c3_w sec_w,
u3_funk fun_f,
u3_noun arg)
{
u3_noun why = u3_cm_soft_top(sec_w, (1 << 17), fun_f, arg); // 512K pad
u3_noun why;
why = u3_cm_soft_top(sec_w, (1 << 17), u3_no, fun_f, arg); // 512K pad
if ( 0 == u3h(why) ) {
return why;

4
g/n.c
View File

@ -4,6 +4,8 @@
*/
#include "all.h"
extern int FOO;
/* _cn_hint(): process hint.
*/
static u3_noun
@ -31,7 +33,7 @@ _cn_hint(u3_noun zep,
u3_ct_push(tac);
#if 0
if ( c3__spot == zep ) {
printf("spot %d/%d : %d/%d\n",
printf("spot %d/%d : %d/%d\r\n",
u3h(u3h(u3t(hod))),
u3t(u3h(u3t(hod))),
u3h(u3t(u3t(hod))),

18
g/v.c
View File

@ -67,12 +67,9 @@ u3_cv_start(u3_noun now)
u3_noun
u3_cv_wish(const c3_c* str_c)
{
u3_cs_road* rod_u;
u3_noun exp;
u3_noun exp;
rod_u = u3R;
u3R = &u3H->rod_u;
{
if ( u3R == &u3H->rod_u ) {
u3_noun txt = u3_ci_string(str_c);
exp = u3_ckdb_get(u3k(u3A->yot), u3k(txt));
@ -82,9 +79,14 @@ u3_cv_wish(const c3_c* str_c)
u3A->yot = u3_ckdb_put(u3A->yot, u3k(txt), u3k(exp));
}
u3z(txt);
return exp;
}
else {
// It's probably not a good idea to use u3_cv_wish()
// outside the top level...
//
return _cv_nock_wish(u3_ci_string(str_c));
}
u3R = rod_u;
return exp;
}
/* _cv_mung(): formula wrapper with gate and sample.
@ -193,7 +195,9 @@ _cv_nock_poke(u3_noun ovo)
}
#endif
// u3_leak_on(1);
pro = u3_cn_slam_on(fun, sam);
// u3_leak_off;
#if 0
{

View File

@ -57,3 +57,8 @@
void
u3_cj_mine(u3_noun clu,
u3_noun cor);
/* u3_cj_ream(): refresh after restoring from checkpoint.
*/
void
u3_cj_ream(void);

View File

@ -111,6 +111,7 @@
u3_noun
u3_cm_soft_top(c3_w sec_w, // timer seconds
c3_w pad_w, // base memory pad
c3_o gab_o, // gc result
u3_funk fun_f,
u3_noun arg);

View File

@ -2,7 +2,7 @@
**
** This file is in the public domain.
*/
/** Noun specifications.
/** Noun structures.
**/
#if 0
++ bane ,@tas :: battery name
@ -13,40 +13,16 @@
$: jax=,@ud :: jet index
pax=,@ud :: parent axis or 0
hap=(map ,@ud ,@ud) :: axis/jet
huc=(map ,@tas nock) :: name/tool
huc=(map term nock) :: name/tool
== ::
++ dash :: jet engine
++ clog (pair cope (map batt (map term nock))) :: identity record
++ cope (trel bane axis (each bash noun)) :: core pattern
++ dash :: jet system
$: sys=(map batt bash) :: battery/identity
haw=(map bash cope) :: identity/core
haw=(map bash clog) :: identity/core
== ::
++ cope :: core pattern
$: soh=bash :: identity
hud=(map batt (map ,@tas nock)) :: instances
mop=(trel bane axis (each bash ,*)) :: ancestry
== ::
++ je !: :: dashboard door
|_ dash
++ fill :: validated match
|= cor=*
^- (unit bash)
%+ biff (find cor)
|= soh=bash
^- (unit bash)
?.((fine cor (~(got by haw) soh)) ~ `soh)
::
++ find :: simple match
|= cor=*
`(unit bash)`?@(cor ~ (~(get by sys) -.cor))
::
++ fine :: validate context
|= [cor=* coe=cope]
^- ?
=+ rah=.*(cor [0 q.mop.coe])
?- -.r.mop.coe
| =(rah p.r.mop.coe)
& $(cor rah, coe (~(got by haw) p.r.mop.coe))
==
::
++ fsck :: parse classic clue
|= clu=clue
^- [p=term q=axis r=(map term nock)]
@ -59,13 +35,6 @@
?> ?=([0 @] q.clu) +.q.clu
(~(gas by *(map term nock)) r.jlu)
::
++ fuel :: attach battery
|= [bat=* coe=cope]
%_ +>
sys (~(put by sys) bat soh.coe)
haw (~(put by haw) soh.coe coe)
==
::
++ fund :: register battery
|= [clu=clue cor=*] ::
^+ +>
@ -77,13 +46,15 @@
[3 %| -.cor]
[q.cey %& (~(got by sys) -:.*([0 q.cey] cor))]
=+ soh=(sham mop)
=+ cup=(~(get by haw) soh)
?^ cup
%= +>.$
sys (~(put by sys) -.cor soh))
haw (~(put by haw) soh u.cup(hud (~(put by hud.u.cup) -.cor r.cey)))
==
(fuel -.cor `cope`[soh [[-.cor r.cey] ~ ~] mop])
=+ cag=(~(get by haw) soh)
%= +>.$
sys (~(put by sys) -.cor [soh r.cey])
haw %+ ~(put by haw) soh
:- mop
?~ cag
[[-.cor r.cey] ~ ~]
(~(put by q.u.cag) -.cor r.cey)
==
--
#endif
/** Data structures.

View File

@ -23,6 +23,7 @@
c3_w siz_w; // size of this box
c3_w use_w; // reference count; free if 0
# ifdef U3_MEMORY_DEBUG
c3_w eus_w; // recomputed refcount
c3_w cod_w; // tracing code
# endif
} u3_cs_box;

View File

@ -6,7 +6,7 @@
**/
# define u3_cc_fbox_no 28
# undef U3_MEMORY_DEBUG
# define U3_MEMORY_DEBUG
# ifdef U3_MEMORY_DEBUG
# define u3_leak_on(x) (u3_Code = x)
# define u3_leak_off (u3_Code = 0)

View File

@ -8,9 +8,7 @@
/* functions
*/
u3_noun
u3_cqf_cell(
u3_noun hed,
u3_noun tal)
u3_cqf_cell(u3_noun hed, u3_noun tal)
{
if ( (c3__void == hed) || (c3__void == tal) ) {
return c3__void;

View File

@ -8,10 +8,7 @@
/* logic
*/
u3_bean
_cqfu_conk(
u3_noun van,
u3_noun sut,
u3_noun got)
_cqfu_conk(u3_noun van, u3_noun sut, u3_noun got)
{
if ( u3_yes == u3ud(got) ) {
return u3_cqf_face(got, sut);
@ -29,7 +26,7 @@
}
case 2: {
u3_bean vet = u3_cr_at(u3_cqfu_van_vet, van);
u3_noun hed, tal, ret;
u3_noun hed, tal, deh, lat, ret;
if ( u3_yes == vet ) {
u3_noun cel = u3nt(c3__cell, c3__noun, c3__noun);
@ -41,14 +38,15 @@
}
hed = u3_cqfu_peek(van, sut, c3__both, 2);
tal = u3_cqfu_peek(van, sut, c3__both, 3);
deh = _cqfu_conk(van, hed, u3h(u3t(got)));
lat = _cqfu_conk(van, tal, u3t(u3t(got)));
ret = u3_cqf_cell
(
_cqfu_conk(van, hed, u3h(u3t(got))),
_cqfu_conk(van, tal, u3t(u3t(got))));
ret = u3_cqf_cell(deh, lat);
u3z(hed);
u3z(lat);
u3z(deh);
u3z(tal);
u3z(hed);
return ret;
}

View File

@ -393,6 +393,7 @@ u3_lo_shut(u3_bean inn)
//
_lo_poll();
}
u3_leak_off;
}
#if 0

View File

@ -329,12 +329,11 @@ main(c3_i argc,
printf("about to save.\r\n");
u3_ce_save();
printf("saved.\r\n");
exit(1);
}
#endif
}
// u3_ce_grab("main", u3_none);
u3_ce_grab("main", u3_none);
u3_lo_loop();
return 0;

View File

@ -836,6 +836,29 @@ _unix_dir_ankh(u3_udir* dir_u)
return u3_do("cosh", u3nt(0, u3_nul, pam));
}
/* _find_mug(): find a noun with a given mug. retain. DELETEME
*/
#if 0
static u3_weak
_find_mug(u3_noun som, c3_l mug_l)
{
if ( mug_l == u3_cr_mug(som) ) {
return som;
}
else {
u3_weak pro;
if ( u3_so(u3du(som)) ) {
if ( (pro = _find_mug(u3h(som), mug_l)) != u3_none ) {
return pro;
}
else return _find_mug(u3t(som), mug_l);
}
else return u3_none;
}
}
#endif
/* _unix_desk_peek(): peek for ankh.
*/
static u3_noun
@ -843,13 +866,16 @@ _unix_desk_peek(u3_noun hox,
u3_noun syd,
u3_noun lok)
{
u3_noun arg;
u3_noun cay;
cay = u3_cv_peek(u3nc(c3_s2('c','z'), u3nq(hox, syd, lok, u3_nul)));
arg = u3nc(c3_s2('c','z'), u3nq(hox, syd, lok, u3_nul));
cay = u3_cv_peek(arg);
if ( u3_nul == cay ) {
return u3nt(0, u3_nul, u3_nul);
} else {
}
else {
u3_noun ank = u3k(u3t(cay));
u3z(cay); return ank;
@ -943,8 +969,7 @@ _unix_desk_sync_into(u3_noun who,
xun = _unix_dir_ankh(dir_u);
bur = _unix_desk_peek(hox, u3k(syd), u3k(u3A->wen));
if ( (u3_no == u3_cr_sing(u3h(xun), u3h(bur)))) //&&
// (u3_no == _unix_ankh_sing(xun, bur)) )
if ( (u3_no == u3_cr_sing(u3h(xun), u3h(bur))))
{
doz = u3_dc("cost", xun, bur);