From b2151d26709eb23e9dc59a6e697ebddc4a30e914 Mon Sep 17 00:00:00 2001 From: Matthew LeVan Date: Thu, 14 Sep 2023 16:09:43 -0400 Subject: [PATCH] wip: aliases, but doesn't build due to duplicate symbols --- pkg/noun/allocate.h | 3 +- pkg/noun/v1/allocate.c | 20 ++++---- pkg/noun/v1/allocate.h | 17 +++++-- pkg/noun/v1/hashtable.c | 52 ++++++++++---------- pkg/noun/v1/hashtable.h | 17 ++++++- pkg/noun/v1/jets.c | 59 ++++++----------------- pkg/noun/v1/jets.h | 49 ++++++++++++++----- pkg/noun/v1/manage.c | 5 -- pkg/noun/v1/manage.h | 4 ++ pkg/noun/v1/nock.c | 20 ++++---- pkg/noun/v1/nock.h | 7 +++ pkg/noun/v1/vortex.c | 4 +- pkg/noun/v1/vortex.h | 8 ++++ pkg/noun/v2/allocate.c | 51 ++++++++------------ pkg/noun/v2/allocate.h | 62 ++++++++++-------------- pkg/noun/v2/hashtable.c | 103 ++++++++++++++++++---------------------- pkg/noun/v2/hashtable.h | 13 +++-- pkg/noun/v2/jets.c | 34 ++++++------- pkg/noun/v2/jets.h | 18 ++++--- pkg/noun/v2/manage.c | 75 ++++++++++++++--------------- pkg/noun/v2/nock.c | 28 ++++++----- pkg/noun/v2/nock.h | 5 ++ pkg/noun/v2/options.h | 14 ++++++ pkg/noun/v2/vortex.c | 2 +- pkg/noun/v2/vortex.h | 8 ++++ 25 files changed, 357 insertions(+), 321 deletions(-) create mode 100644 pkg/noun/v2/options.h diff --git a/pkg/noun/allocate.h b/pkg/noun/allocate.h index c27e93234d..1ffe9934d9 100644 --- a/pkg/noun/allocate.h +++ b/pkg/noun/allocate.h @@ -380,8 +380,7 @@ # define u3_Loom ((c3_w *)(void *)U3_OS_LoomBase) - /** inline functions. - ** ;;: func-like-macros doing pointer conversion -> inline + /** Inline functions. **/ /* u3a_into(): convert loom offset [x] into generic pointer. */ diff --git a/pkg/noun/v1/allocate.c b/pkg/noun/v1/allocate.c index 487f989d9d..8155cf6071 100644 --- a/pkg/noun/v1/allocate.c +++ b/pkg/noun/v1/allocate.c @@ -13,7 +13,7 @@ u3a_v1_reclaim(void) // clear the memoization cache // u3h_v1_free(u3R->cax.har_p); - u3R->cax.har_p = u3h_new(); + u3R->cax.har_p = u3h_v1_new(); } /* _me_lose_north(): lose on a north road. @@ -24,32 +24,32 @@ _me_lose_north(u3_noun dog) top: { c3_w* dog_w = u3a_v1_to_ptr(dog); - u3a_box* box_u = u3a_botox(dog_w); + u3a_v1_box* box_u = u3a_v1_botox(dog_w); if ( box_u->use_w > 1 ) { box_u->use_w -= 1; } else { if ( 0 == box_u->use_w ) { - u3m_bail(c3__foul); + u3m_v1_bail(c3__foul); } else { - if ( _(u3a_is_pom(dog)) ) { - u3a_cell* dog_u = (void *)dog_w; + if ( _(u3a_v1_is_pom(dog)) ) { + u3a_v1_cell* dog_u = (void *)dog_w; u3_noun h_dog = dog_u->hed; u3_noun t_dog = dog_u->tel; - if ( !_(u3a_is_cat(h_dog)) ) { + if ( !_(u3a_v1_is_cat(h_dog)) ) { _me_lose_north(h_dog); } - u3a_wfree(dog_w); - if ( !_(u3a_is_cat(t_dog)) ) { + u3a_v1_wfree(dog_w); + if ( !_(u3a_v1_is_cat(t_dog)) ) { dog = t_dog; goto top; } } else { - u3a_wfree(dog_w); + u3a_v1_wfree(dog_w); } } } @@ -61,7 +61,7 @@ _me_lose_north(u3_noun dog) void u3a_v1_lose(u3_noun som) { - if ( !_(u3a_is_cat(som)) ) { + if ( !_(u3a_v1_is_cat(som)) ) { _me_lose_north(som); } } diff --git a/pkg/noun/v1/allocate.h b/pkg/noun/v1/allocate.h index 7bd5364213..e4bd90508c 100644 --- a/pkg/noun/v1/allocate.h +++ b/pkg/noun/v1/allocate.h @@ -2,9 +2,19 @@ #define U3_ALLOCATE_V1_H #include "pkg/noun/allocate.h" +#include "pkg/noun/v2/allocate.h" - /** Constants. + /** Aliases. **/ +# define u3R_v1 u3R_v2 +# define u3a_v1_botox u3a_v2_botox +# define u3a_v1_box u3a_v2_box +# define u3a_v1_cell u3a_v2_cell +# define u3a_v1_free u3a_v2_free +# define u3a_v1_into u3a_v2_into +# define u3a_v1_is_cat u3a_v2_is_cat +# define u3a_v1_is_pom u3a_is_pom +# define u3a_v1_wfree u3a_v2_wfree /** Structures. **/ @@ -12,14 +22,13 @@ **/ /* Inside a noun. */ - - /* u3a_to_off(): mask off bits 30 and 31 from noun [som]. + /* u3a_v1_to_off(): mask off bits 30 and 31 from noun [som]. */ # define u3a_v1_to_off(som) ((som) & 0x3fffffff) /* u3a_v1_to_ptr(): convert noun [som] into generic pointer into loom. */ -# define u3a_v1_to_ptr(som) (u3a_into(u3a_v1_to_off(som))) +# define u3a_v1_to_ptr(som) (u3a_v1_into(u3a_v1_to_off(som))) /* u3a_v1_to_wtr(): convert noun [som] into word pointer into loom. */ diff --git a/pkg/noun/v1/hashtable.c b/pkg/noun/v1/hashtable.c index 0396e8b6ab..9e6d004e16 100644 --- a/pkg/noun/v1/hashtable.c +++ b/pkg/noun/v1/hashtable.c @@ -20,20 +20,20 @@ _ch_v1_popcount(c3_w num_w) ** NB: copy of _ch_v1_free_buck in pkg/noun/hashtable.c */ static void -_ch_v1_free_buck(u3h_buck* hab_u) +_ch_v1_free_buck(u3h_v1_buck* hab_u) { c3_w i_w; for ( i_w = 0; i_w < hab_u->len_w; i_w++ ) { - u3a_v1_lose(u3h_slot_to_noun(hab_u->sot_w[i_w])); + u3a_v1_lose(u3h_v1_slot_to_noun(hab_u->sot_w[i_w])); } - u3a_wfree(hab_u); + u3a_v1_wfree(hab_u); } /* _ch_v1_free_node(): free node. */ static void -_ch_v1_free_node(u3h_node* han_u, c3_w lef_w) +_ch_v1_free_node(u3h_v1_node* han_u, c3_w lef_w) { c3_w len_w = _ch_v1_popcount(han_u->map_w); c3_w i_w; @@ -43,8 +43,8 @@ _ch_v1_free_node(u3h_node* han_u, c3_w lef_w) for ( i_w = 0; i_w < len_w; i_w++ ) { c3_w sot_w = han_u->sot_w[i_w]; - if ( _(u3h_slot_is_noun(sot_w)) ) { - u3a_v1_lose(u3h_slot_to_noun(sot_w)); + if ( _(u3h_v1_slot_is_noun(sot_w)) ) { + u3a_v1_lose(u3h_v1_slot_to_noun(sot_w)); } else { void* hav_v = u3h_v1_slot_to_node(sot_w); @@ -56,49 +56,49 @@ _ch_v1_free_node(u3h_node* han_u, c3_w lef_w) } } } - u3a_wfree(han_u); + u3a_v1_wfree(han_u); } /* u3h_v1_free(): free hashtable. */ void -u3h_v1_free(u3p(u3h_root) har_p) +u3h_v1_free(u3p(u3h_v1_root) har_p) { - u3h_root* har_u = u3to(u3h_root, har_p); + u3h_v1_root* har_u = u3to(u3h_v1_root, har_p); c3_w i_w; for ( i_w = 0; i_w < 64; i_w++ ) { c3_w sot_w = har_u->sot_w[i_w]; - if ( _(u3h_slot_is_noun(sot_w)) ) { - u3a_v1_lose(u3h_slot_to_noun(sot_w)); + if ( _(u3h_v1_slot_is_noun(sot_w)) ) { + u3a_v1_lose(u3h_v1_slot_to_noun(sot_w)); } - else if ( _(u3h_slot_is_node(sot_w)) ) { - u3h_node* han_u = u3h_v1_slot_to_node(sot_w); + else if ( _(u3h_v1_slot_is_node(sot_w)) ) { + u3h_v1_node* han_u = u3h_v1_slot_to_node(sot_w); _ch_v1_free_node(han_u, 25); } } - u3a_wfree(har_u); + u3a_v1_wfree(har_u); } /* _ch_v1_walk_buck(): walk bucket for gc. ** NB: copy of _ch_v1_walk_buck in pkg/noun/hashtable.c */ static void -_ch_v1_walk_buck(u3h_buck* hab_u, void (*fun_f)(u3_noun, void*), void* wit) +_ch_v1_walk_buck(u3h_v1_buck* hab_u, void (*fun_f)(u3_noun, void*), void* wit) { c3_w i_w; for ( i_w = 0; i_w < hab_u->len_w; i_w++ ) { - fun_f(u3h_slot_to_noun(hab_u->sot_w[i_w]), wit); + fun_f(u3h_v1_slot_to_noun(hab_u->sot_w[i_w]), wit); } } /* _ch_v1_walk_node(): walk node for gc. */ static void -_ch_v1_walk_node(u3h_node* han_u, c3_w lef_w, void (*fun_f)(u3_noun, void*), void* wit) +_ch_v1_walk_node(u3h_v1_node* han_u, c3_w lef_w, void (*fun_f)(u3_noun, void*), void* wit) { c3_w len_w = _ch_v1_popcount(han_u->map_w); c3_w i_w; @@ -108,8 +108,8 @@ _ch_v1_walk_node(u3h_node* han_u, c3_w lef_w, void (*fun_f)(u3_noun, void*), voi for ( i_w = 0; i_w < len_w; i_w++ ) { c3_w sot_w = han_u->sot_w[i_w]; - if ( _(u3h_slot_is_noun(sot_w)) ) { - u3_noun kev = u3h_slot_to_noun(sot_w); + if ( _(u3h_v1_slot_is_noun(sot_w)) ) { + u3_noun kev = u3h_v1_slot_to_noun(sot_w); fun_f(kev, wit); } @@ -129,23 +129,23 @@ _ch_v1_walk_node(u3h_node* han_u, c3_w lef_w, void (*fun_f)(u3_noun, void*), voi * argument; RETAINS. */ void -u3h_v1_walk_with(u3p(u3h_root) har_p, +u3h_v1_walk_with(u3p(u3h_v1_root) har_p, void (*fun_f)(u3_noun, void*), void* wit) { - u3h_root* har_u = u3to(u3h_root, har_p); + u3h_v1_root* har_u = u3to(u3h_v1_root, har_p); c3_w i_w; for ( i_w = 0; i_w < 64; i_w++ ) { c3_w sot_w = har_u->sot_w[i_w]; - if ( _(u3h_slot_is_noun(sot_w)) ) { - u3_noun kev = u3h_slot_to_noun(sot_w); + if ( _(u3h_v1_slot_is_noun(sot_w)) ) { + u3_noun kev = u3h_v1_slot_to_noun(sot_w); fun_f(kev, wit); } - else if ( _(u3h_slot_is_node(sot_w)) ) { - u3h_node* han_u = u3h_v1_slot_to_node(sot_w); + else if ( _(u3h_v1_slot_is_node(sot_w)) ) { + u3h_v1_node* han_u = u3h_v1_slot_to_node(sot_w); _ch_v1_walk_node(han_u, 25, fun_f, wit); } @@ -164,7 +164,7 @@ _ch_v1_walk_plain(u3_noun kev, void* wit) /* u3h_v1_walk(): u3h_v1_walk_with, but with no data argument */ void -u3h_v1_walk(u3p(u3h_root) har_p, void (*fun_f)(u3_noun)) +u3h_v1_walk(u3p(u3h_v1_root) har_p, void (*fun_f)(u3_noun)) { u3h_v1_walk_with(har_p, _ch_v1_walk_plain, fun_f); } diff --git a/pkg/noun/v1/hashtable.h b/pkg/noun/v1/hashtable.h index 2b325704c6..f37994f11e 100644 --- a/pkg/noun/v1/hashtable.h +++ b/pkg/noun/v1/hashtable.h @@ -2,6 +2,19 @@ #define U3_HASHTABLE_V1_H #include "pkg/noun/hashtable.h" +#include "pkg/noun/v2/hashtable.h" + + /** Aliases. + **/ +# define u3h_v1_buck u3h_v2_buck +# define u3h_v1_free u3h_free +# define u3h_v1_new u3h_new +# define u3h_v1_node u3h_v2_node +# define u3h_v1_root u3h_v2_root +# define u3h_v1_slot_is_node u3h_v2_slot_is_node +# define u3h_v1_slot_is_noun u3h_v2_slot_is_noun +# define u3h_v1_slot_to_noun u3h_v2_slot_to_noun +# define u3h_v1_walk u3h_v2_walk /** Data structures. **/ @@ -13,8 +26,8 @@ /* u3h_v1_slot_to_node(): slot to node pointer ** u3h_v1_node_to_slot(): node pointer to slot */ -# define u3h_v1_slot_to_node(sot) (u3a_into((sot) & 0x3fffffff)) -# define u3h_v1_node_to_slot(ptr) (u3a_outa(ptr) | 0x40000000) +# define u3h_v1_slot_to_node(sot) (u3a_v1_into((sot) & 0x3fffffff)) +# define u3h_v1_node_to_slot(ptr) (u3a_v1_outa(ptr) | 0x40000000) /** Functions. *** diff --git a/pkg/noun/v1/jets.c b/pkg/noun/v1/jets.c index 9de809860d..3318da8655 100644 --- a/pkg/noun/v1/jets.c +++ b/pkg/noun/v1/jets.c @@ -17,42 +17,32 @@ */ typedef struct { u3_weak hax; // axis of hooked inner core - u3j_site sit_u; // call-site data + u3j_v1_site sit_u; // call-site data } _cj_v1_hank; /** Functions. **/ -/* _cj_fink_free(): lose and free everything in a u3j_fink. +/* _cj_fink_free(): lose and free everything in a u3j_v1_fink. */ static void -_cj_v1_fink_free(u3p(u3j_fink) fin_p) +_cj_v1_fink_free(u3p(u3j_v1_fink) fin_p) { - fprintf(stderr, "_cj_v1_fink_free 1\r\n"); c3_w i_w; - u3j_fink* fin_u = u3to(u3j_fink, fin_p); - fprintf(stderr, "_cj_v1_fink_free 2 %p %u %x\r\n", fin_u, fin_u->len_w, fin_p); + u3j_v1_fink* fin_u = u3to(u3j_v1_fink, fin_p); u3a_v1_lose(fin_u->sat); - fprintf(stderr, "_cj_v1_fink_free 3\r\n"); for ( i_w = 0; i_w < fin_u->len_w; ++i_w ) { - u3j_fist* fis_u = &(fin_u->fis_u[i_w]); - fprintf(stderr, "_cj_v1_fink_free 4 %u\r\n", i_w); + u3j_v1_fist* fis_u = &(fin_u->fis_u[i_w]); u3a_v1_lose(fis_u->bat); - fprintf(stderr, "_cj_v1_fink_free 5 %u\r\n", i_w); u3a_v1_lose(fis_u->pax); - fprintf(stderr, "_cj_v1_fink_free 6 %u\r\n", i_w); } - - fprintf(stderr, "_cj_v1_fink_free 7\r\n"); - u3a_wfree(fin_u); - - fprintf(stderr, "_cj_v1_fink_free 8\r\n"); + u3a_v1_wfree(fin_u); } -/* u3j_v1_rite_lose(): lose references of u3j_rite (but do not free). +/* u3j_v1_rite_lose(): lose references of u3j_v1_rite (but do not free). */ void -u3j_v1_rite_lose(u3j_rite* rit_u) +u3j_v1_rite_lose(u3j_v1_rite* rit_u) { if ( (c3y == rit_u->own_o) && u3_none != rit_u->clu ) { u3a_v1_lose(rit_u->clu); @@ -61,37 +51,27 @@ u3j_v1_rite_lose(u3j_rite* rit_u) } -/* u3j_site_lose(): lose references of u3j_site (but do not free). +/* u3j_v1_site_lose(): lose references of u3j_v1_site (but do not free). */ void -u3j_v1_site_lose(u3j_site* sit_u) +u3j_v1_site_lose(u3j_v1_site* sit_u) { - fprintf(stderr, "u3j_v1_site_lose 1\r\n"); u3a_v1_lose(sit_u->axe); - fprintf(stderr, "u3j_v1_site_lose 2\r\n"); if ( u3_none != sit_u->bat ) { - fprintf(stderr, "u3j_v1_site_lose 3\r\n"); u3a_v1_lose(sit_u->bat); } if ( u3_none != sit_u->bas ) { - fprintf(stderr, "u3j_v1_site_lose 4\r\n"); u3a_v1_lose(sit_u->bas); } - fprintf(stderr, "u3j_v1_site_lose 5\r\n"); if ( u3_none != sit_u->loc ) { - fprintf(stderr, "u3j_v1_site_lose 6\r\n"); u3a_v1_lose(sit_u->loc); - fprintf(stderr, "u3j_v1_site_lose 7\r\n"); u3a_v1_lose(sit_u->lab); - fprintf(stderr, "u3j_v1_site_lose 8\r\n"); if ( c3y == sit_u->fon_o ) { - fprintf(stderr, "u3j_v1_site_lose 9\r\n"); if ( sit_u->fin_p ) { _cj_v1_fink_free(sit_u->fin_p); } } } - fprintf(stderr, "u3j_v1_site_lose 10\r\n"); } /* _cj_v1_free_hank(): free an entry from the hank cache. @@ -100,18 +80,13 @@ u3j_v1_site_lose(u3j_site* sit_u) static void _cj_v1_free_hank(u3_noun kev) { - fprintf(stderr, "_cj_v1_free_hank 1\r\n"); - u3a_cell* cel_u = u3a_v1_to_ptr(kev); + u3a_v1_cell* cel_u = u3a_v1_to_ptr(kev); _cj_v1_hank* han_u = u3to(_cj_v1_hank, cel_u->tel); - fprintf(stderr, "_cj_v1_free_hank 2\r\n"); if ( u3_none != han_u->hax ) { - fprintf(stderr, "_cj_v1_free_hank 3\r\n"); u3a_v1_lose(han_u->hax); - fprintf(stderr, "_cj_v1_free_hank 4\r\n"); u3j_v1_site_lose(&(han_u->sit_u)); } - // fprintf(stderr, "_cj_v1_free_hank 5 %x %x\r\n", u3h(kev), u3t(kev)); - u3a_wfree(han_u); + u3a_v1_wfree(han_u); } /* u3j_v1_reclaim(): clear ad-hoc persistent caches to reclaim memory. @@ -123,17 +98,13 @@ u3j_v1_reclaim(void) // // XX might this reduce fragmentation? // - // if ( &(u3H->rod_u) == u3R ) { - // u3j_ream(); + // if ( &(u3H_v1->rod_u) == u3R ) { + // u3j_v1_ream(); // } // clear the jet hank cache // - fprintf(stderr, "u3j_v1_reclaim 1 %x\r\n", u3R->jed.han_p); u3h_v1_walk(u3R->jed.han_p, _cj_v1_free_hank); - fprintf(stderr, "u3j_v1_reclaim 2 \r\n"); u3h_v1_free(u3R->jed.han_p); - fprintf(stderr, "u3j_v1_reclaim 3 \r\n"); - u3R->jed.han_p = u3h_new(); // XX maybe initialize these at end of migration - fprintf(stderr, "u3j_v1_reclaim 4 \r\n"); + u3R->jed.han_p = u3h_v1_new(); // XX maybe initialize these at end of migration } diff --git a/pkg/noun/v1/jets.h b/pkg/noun/v1/jets.h index 1fcbaa6b97..b32ce80ccb 100644 --- a/pkg/noun/v1/jets.h +++ b/pkg/noun/v1/jets.h @@ -1,23 +1,48 @@ /// @file +// u3a_v1_cell +// u3a_v1_wfree +// u3h_v1_new +// u3j_fink +// u3j_fist +// u3j_ream +// u3j_rite +// u3j_site +// u3j_site_lose +// u3H +// u3R + #ifndef U3_JETS_V1_H #define U3_JETS_V1_H #include "pkg/noun/jets.h" +#include "pkg/noun/v2/jets.h" + + /** Aliases. + **/ +# define u3j_v1_fink u3j_fink +# define u3j_v1_fist u3j_fist +# define u3j_v1_ream u3j_ream +# define u3j_v1_reclaim u3j_reclaim +# define u3j_v1_rite u3j_rite +# define u3j_v1_site u3j_v2_site +# define u3j_v1_site_lose u3j_v2_site_lose - /* u3j_v1_reclaim(): clear ad-hoc persistent caches to reclaim memory. - */ - void - u3j_v1_reclaim(void); + /** Functions. + **/ + /* u3j_v1_reclaim(): clear ad-hoc persistent caches to reclaim memory. + */ + void + u3j_v1_reclaim(void); - /* u3j_v1_rite_lose(): lose references of u3j_rite (but do not free). - */ - void - u3j_v1_rite_lose(u3j_rite* rit_u); + /* u3j_v1_rite_lose(): lose references of u3j_rite (but do not free). + */ + void + u3j_v1_rite_lose(u3j_rite* rit_u); - /* u3j_v1_site_lose(): lose references of u3j_site (but do not free). - */ - void - u3j_v1_site_lose(u3j_site* sit_u); + /* u3j_v1_site_lose(): lose references of u3j_site (but do not free). + */ + void + u3j_v1_site_lose(u3j_site* sit_u); #endif /* ifndef U3_JETS_V1_H */ diff --git a/pkg/noun/v1/manage.c b/pkg/noun/v1/manage.c index df0e3a0baf..0eac6a8d7b 100644 --- a/pkg/noun/v1/manage.c +++ b/pkg/noun/v1/manage.c @@ -13,13 +13,8 @@ void u3m_v1_reclaim(void) { - fprintf(stderr, "u3m_v1_reclaim 1\r\n"); u3v_v1_reclaim(); - fprintf(stderr, "u3m_v1_reclaim 2\r\n"); u3j_v1_reclaim(); - fprintf(stderr, "u3m_v1_reclaim 3\r\n"); u3n_v1_reclaim(); - fprintf(stderr, "u3m_v1_reclaim 4\r\n"); u3a_v1_reclaim(); - fprintf(stderr, "u3m_v1_reclaim 5\r\n"); } diff --git a/pkg/noun/v1/manage.h b/pkg/noun/v1/manage.h index f369d92044..669d69ea36 100644 --- a/pkg/noun/v1/manage.h +++ b/pkg/noun/v1/manage.h @@ -3,6 +3,10 @@ #ifndef U3_MANAGE_V1_H #define U3_MANAGE_V1_H + /** Aliases. + **/ +# define u3m_v1_bail u3m_bail + /** System management. **/ /* u3m_v1_reclaim: clear persistent caches to reclaim memory diff --git a/pkg/noun/v1/nock.c b/pkg/noun/v1/nock.c index 75cd0746d0..8619c300a5 100644 --- a/pkg/noun/v1/nock.c +++ b/pkg/noun/v1/nock.c @@ -15,18 +15,18 @@ u3n_v1_reclaim(void) { // clear the bytecode cache // - // We can't just u3h_free() -- the value is a post to a u3n_v1_prog. - // Note that the hank cache *must* also be freed (in u3j_reclaim()) + // We can't just u3h_v1_free() -- the value is a post to a u3n_v1_prog. + // Note that the hank cache *must* also be freed (in u3j_v1_reclaim()) // u3n_v1_free(); - u3R->byc.har_p = u3h_new(); + u3R->byc.har_p = u3h_v1_new(); } /* _cn_prog_free(): free memory retained by program pog_u ** NB: copy of _cn_prog_free in pkg/noun/nock.c */ static void -_cn_prog_free(u3n_prog* pog_u) +_cn_prog_free(u3n_v1_prog* pog_u) { c3_w dex_w; for (dex_w = 0; dex_w < pog_u->lit_u.len_w; ++dex_w) { @@ -41,17 +41,17 @@ _cn_prog_free(u3n_prog* pog_u) for (dex_w = 0; dex_w < pog_u->reg_u.len_w; ++dex_w) { u3j_v1_rite_lose(&(pog_u->reg_u.rit_u[dex_w])); } - u3a_free(pog_u); + u3a_v1_free(pog_u); } -/* _n_feb(): u3h_walk helper for u3n_free +/* _n_feb(): u3h_v1_walk helper for u3n_v1_free */ static void _n_feb(u3_noun kev) { - u3a_cell *cel_u = u3a_v1_to_ptr(kev); - _cn_prog_free(u3to(u3n_prog, cel_u->tel)); + u3a_v1_cell *cel_u = u3a_v1_to_ptr(kev); + _cn_prog_free(u3to(u3n_v1_prog, cel_u->tel)); } /* u3n_v1_free(): free bytecode cache @@ -59,9 +59,7 @@ _n_feb(u3_noun kev) void u3n_v1_free() { - u3p(u3h_root) har_p = u3R->byc.har_p; - fprintf(stderr, "u3n_v1_free walking\r\n"); + u3p(u3h_v1_root) har_p = u3R->byc.har_p; u3h_v1_walk(har_p, _n_feb); - fprintf(stderr, "u3n_v1_free walked\r\n"); u3h_v1_free(har_p); } diff --git a/pkg/noun/v1/nock.h b/pkg/noun/v1/nock.h index fd472919f4..3fff04a4bd 100644 --- a/pkg/noun/v1/nock.h +++ b/pkg/noun/v1/nock.h @@ -3,6 +3,13 @@ #ifndef U3_NOCK_V1_H #define U3_NOCK_V1_H +#include "pkg/noun/v2/nock.h" + + /** Aliases. + **/ +# define u3n_v1_free u3n_v2_free +# define u3n_v1_prog u3n_v2_prog + /** Functions. **/ /* u3n_v1_reclaim(): clear ad-hoc persistent caches to reclaim memory. diff --git a/pkg/noun/v1/vortex.c b/pkg/noun/v1/vortex.c index 5ee41722ba..e1ec21b22d 100644 --- a/pkg/noun/v1/vortex.c +++ b/pkg/noun/v1/vortex.c @@ -12,6 +12,6 @@ u3v_v1_reclaim(void) { // clear the u3v_wish cache // - u3a_v1_lose(u3A->yot); - u3A->yot = u3_nul; + u3a_v1_lose(u3A_v1->yot); + u3A_v1->yot = u3_nul; } diff --git a/pkg/noun/v1/vortex.h b/pkg/noun/v1/vortex.h index 2a97c7d5ae..ac3114065c 100644 --- a/pkg/noun/v1/vortex.h +++ b/pkg/noun/v1/vortex.h @@ -3,6 +3,14 @@ #ifndef U3_VORTEX_V1_H #define U3_VORTEX_V1_H +#include "pkg/noun/allocate.h" +#include "pkg/noun/v2/vortex.h" + + /** Aliases. + **/ +# define u3H_v1 u3H_v2 +# define u3A_v1 u3A + /** Functions. **/ /* u3v_v1_reclaim(): clear ad-hoc persistent caches to reclaim memory. diff --git a/pkg/noun/v2/allocate.c b/pkg/noun/v2/allocate.c index bd9a511963..907a602d52 100644 --- a/pkg/noun/v2/allocate.c +++ b/pkg/noun/v2/allocate.c @@ -25,27 +25,18 @@ c3_w u3a_v2_to_pom(c3_w off); u3_noun u3a_v2_rewritten_noun(u3_noun som) { - if ( c3y == u3a_is_cat(som) ) { + if ( c3y == u3a_v2_is_cat(som) ) { return som; } - u3_post som_p = u3a_rewritten(u3a_v1_to_off(som)); + u3_post som_p = u3a_v2_rewritten(u3a_v1_to_off(som)); - // /* If this is being called during a migration, one-bit pointer compression - // needs to be temporarily enabled so the rewritten reference is compressed */ - // if (u3C.migration_state == MIG_REWRITE_COMPRESSED) - // u3C.vits_w = 1; - - if ( c3y == u3a_is_pug(som) ) { + if ( c3y == u3a_v2_is_pug(som) ) { som_p = u3a_v2_to_pug(som_p); } else { som_p = u3a_v2_to_pom(som_p); } - // /* likewise, pointer compression is disabled until migration is complete */ - // if (u3C.migration_state == MIG_REWRITE_COMPRESSED) - // u3C.vits_w = 0; - return som_p; } @@ -54,33 +45,33 @@ u3a_v2_rewritten_noun(u3_noun som) void u3a_v2_rewrite_compact(void) { - u3a_v2_rewrite_noun(u3R->ski.gul); - u3a_v2_rewrite_noun(u3R->bug.tax); - u3a_v2_rewrite_noun(u3R->bug.mer); - u3a_v2_rewrite_noun(u3R->pro.don); - u3a_v2_rewrite_noun(u3R->pro.day); - u3a_v2_rewrite_noun(u3R->pro.trace); - u3h_v2_rewrite(u3R->cax.har_p); - - u3R->ski.gul = u3a_v2_rewritten_noun(u3R->ski.gul); - u3R->bug.tax = u3a_v2_rewritten_noun(u3R->bug.tax); - u3R->bug.mer = u3a_v2_rewritten_noun(u3R->bug.mer); - u3R->pro.don = u3a_v2_rewritten_noun(u3R->pro.don); - u3R->pro.day = u3a_v2_rewritten_noun(u3R->pro.day); - u3R->pro.trace = u3a_v2_rewritten_noun(u3R->pro.trace); - u3R->cax.har_p = u3a_rewritten(u3R->cax.har_p); + u3a_v2_rewrite_noun(u3R_v2->ski.gul); + u3a_v2_rewrite_noun(u3R_v2->bug.tax); + u3a_v2_rewrite_noun(u3R_v2->bug.mer); + u3a_v2_rewrite_noun(u3R_v2->pro.don); + u3a_v2_rewrite_noun(u3R_v2->pro.day); + u3a_v2_rewrite_noun(u3R_v2->pro.trace); + u3h_v2_rewrite(u3R_v2->cax.har_p); + + u3R_v2->ski.gul = u3a_v2_rewritten_noun(u3R_v2->ski.gul); + u3R_v2->bug.tax = u3a_v2_rewritten_noun(u3R_v2->bug.tax); + u3R_v2->bug.mer = u3a_v2_rewritten_noun(u3R_v2->bug.mer); + u3R_v2->pro.don = u3a_v2_rewritten_noun(u3R_v2->pro.don); + u3R_v2->pro.day = u3a_v2_rewritten_noun(u3R_v2->pro.day); + u3R_v2->pro.trace = u3a_v2_rewritten_noun(u3R_v2->pro.trace); + u3R_v2->cax.har_p = u3a_v2_rewritten(u3R_v2->cax.har_p); } void u3a_v2_rewrite_noun(u3_noun som) { - if ( c3n == u3a_is_cell(som) ) { + if ( c3n == u3a_v2_is_cell(som) ) { return; } - if ( c3n == u3a_rewrite_ptr(u3a_v1_to_ptr((som))) ) return; + if ( c3n == u3a_v2_rewrite_ptr(u3a_v1_to_ptr((som))) ) return; - u3a_cell* cel = u3a_v1_to_ptr(som); + u3a_v2_cell* cel = u3a_v1_to_ptr(som); u3a_v2_rewrite_noun(cel->hed); u3a_v2_rewrite_noun(cel->tel); diff --git a/pkg/noun/v2/allocate.h b/pkg/noun/v2/allocate.h index 7c1ddcd60a..f1faec715a 100644 --- a/pkg/noun/v2/allocate.h +++ b/pkg/noun/v2/allocate.h @@ -1,49 +1,37 @@ #ifndef U3_ALLOCATE_V2_H #define U3_ALLOCATE_V2_H -#define VITS_W 1 - #include "pkg/noun/allocate.h" #include "pkg/noun/v2/manage.h" #include "options.h" - /** Constants. - **/ - - /** inline functions. + /** Aliases. **/ - /* u3a_v2_to_off(): mask off bits 30 and 31 from noun [som]. - */ - inline c3_w u3a_v2_to_off(c3_w som) { - return (som & 0x3fffffff) << VITS_W; - } - - /* u3a_v2_to_ptr(): convert noun [som] into generic pointer into loom. - */ - inline void *u3a_v2_to_ptr(c3_w som) { - return u3a_into(u3a_v2_to_off(som)); - } - - /* u3a_v2_to_wtr(): convert noun [som] into word pointer into loom. - */ - inline c3_w *u3a_v2_to_wtr(c3_w som) { - return (c3_w *)u3a_v2_to_ptr(som); - } - - /* u3a_v2_to_pug(): set bit 31 of [off]. - */ - inline c3_w u3a_v2_to_pug(c3_w off) { - c3_dessert((off & u3a_walign-1) == 0); - return (off >> VITS_W) | 0x80000000; - } - - /* u3a_v2_to_pom(): set bits 30 and 31 of [off]. - */ - inline c3_w u3a_v2_to_pom(c3_w off) { - c3_dessert((off & u3a_walign-1) == 0); - return (off >> VITS_W) | 0xc0000000; - } +# define u3R_v2 u3R +# define u3a_v2_botox u3a_botox +# define u3a_v2_box u3a_box +# define u3a_v2_cell u3a_cell +# define u3a_v2_fbox_no u3a_fbox_no +# define u3a_v2_free u3a_free +# define u3a_v2_heap u3a_heap +# define u3a_v2_into u3a_into +# define u3a_v2_is_cat u3a_is_cat +# define u3a_v2_is_cell u3a_is_cell +# define u3a_v2_is_pug u3a_is_pug +# define u3a_v2_malloc u3a_malloc +# define u3a_v2_outa u3a_outa +# define u3a_v2_pack_seek u3a_pack_seek +# define u3a_v2_rewrite u3a_rewrite +# define u3a_v2_rewrite_ptr u3a_rewrite_ptr +# define u3a_v2_rewritten u3a_rewritten +# define u3a_v2_road u3a_road +# define u3a_v2_wfree u3a_wfree +# define u3a_v2_to_off u3a_to_off +# define u3a_v2_to_ptr u3a_to_ptr +# define u3a_v2_to_wtr u3a_to_wtr +# define u3a_v2_to_pug u3a_to_pug +# define u3a_v2_to_pom u3a_to_pom /** Functions. **/ diff --git a/pkg/noun/v2/hashtable.c b/pkg/noun/v2/hashtable.c index d085a15f03..6cab9bc24d 100644 --- a/pkg/noun/v2/hashtable.c +++ b/pkg/noun/v2/hashtable.c @@ -21,20 +21,20 @@ _ch_v2_popcount(c3_w num_w) ** NB: copy of _ch_v2_free_buck in pkg/noun/hashtable.c */ static void -_ch_v2_free_buck(u3h_buck* hab_u) +_ch_v2_free_buck(u3h_v2_buck* hab_u) { c3_w i_w; for ( i_w = 0; i_w < hab_u->len_w; i_w++ ) { - u3z(u3h_slot_to_noun(hab_u->sot_w[i_w])); + u3z(u3h_v2_slot_to_noun(hab_u->sot_w[i_w])); } - u3a_wfree(hab_u); + u3a_v2_wfree(hab_u); } /* _ch_v2_free_node(): free node. */ static void -_ch_v2_free_node(u3h_node* han_u, c3_w lef_w) +_ch_v2_free_node(u3h_v2_node* han_u, c3_w lef_w) { c3_w len_w = _ch_v2_popcount(han_u->map_w); c3_w i_w; @@ -44,8 +44,8 @@ _ch_v2_free_node(u3h_node* han_u, c3_w lef_w) for ( i_w = 0; i_w < len_w; i_w++ ) { c3_w sot_w = han_u->sot_w[i_w]; - if ( _(u3h_slot_is_noun(sot_w)) ) { - u3z(u3h_slot_to_noun(sot_w)); + if ( _(u3h_v2_slot_is_noun(sot_w)) ) { + u3z(u3h_v2_slot_to_noun(sot_w)); } else { // NB: u3h_v2_slot_to_node() @@ -58,49 +58,49 @@ _ch_v2_free_node(u3h_node* han_u, c3_w lef_w) } } } - u3a_wfree(han_u); + u3a_v2_wfree(han_u); } /* u3h_v2_free(): free hashtable. */ void -u3h_v2_free(u3p(u3h_root) har_p) +u3h_v2_free(u3p(u3h_v2_root) har_p) { - u3h_root* har_u = u3to(u3h_root, har_p); + u3h_v2_root* har_u = u3to(u3h_v2_root, har_p); c3_w i_w; for ( i_w = 0; i_w < 64; i_w++ ) { c3_w sot_w = har_u->sot_w[i_w]; - if ( _(u3h_slot_is_noun(sot_w)) ) { - u3z(u3h_slot_to_noun(sot_w)); + if ( _(u3h_v2_slot_is_noun(sot_w)) ) { + u3z(u3h_v2_slot_to_noun(sot_w)); } - else if ( _(u3h_slot_is_node(sot_w)) ) { - u3h_node* han_u = u3h_v2_slot_to_node(sot_w); + else if ( _(u3h_v2_slot_is_node(sot_w)) ) { + u3h_v2_node* han_u = u3h_v2_slot_to_node(sot_w); _ch_v2_free_node(han_u, 25); } } - u3a_wfree(har_u); + u3a_v2_wfree(har_u); } /* _ch_v2_walk_buck(): walk bucket for gc. ** NB: copy of _ch_v2_walk_buck in pkg/noun/hashtable.c */ static void -_ch_v2_walk_buck(u3h_buck* hab_u, void (*fun_f)(u3_noun, void*), void* wit) +_ch_v2_walk_buck(u3h_v2_buck* hab_u, void (*fun_f)(u3_noun, void*), void* wit) { c3_w i_w; for ( i_w = 0; i_w < hab_u->len_w; i_w++ ) { - fun_f(u3h_slot_to_noun(hab_u->sot_w[i_w]), wit); + fun_f(u3h_v2_slot_to_noun(hab_u->sot_w[i_w]), wit); } } /* _ch_v2_walk_node(): walk node for gc. */ static void -_ch_v2_walk_node(u3h_node* han_u, c3_w lef_w, void (*fun_f)(u3_noun, void*), void* wit) +_ch_v2_walk_node(u3h_v2_node* han_u, c3_w lef_w, void (*fun_f)(u3_noun, void*), void* wit) { c3_w len_w = _ch_v2_popcount(han_u->map_w); c3_w i_w; @@ -110,8 +110,8 @@ _ch_v2_walk_node(u3h_node* han_u, c3_w lef_w, void (*fun_f)(u3_noun, void*), voi for ( i_w = 0; i_w < len_w; i_w++ ) { c3_w sot_w = han_u->sot_w[i_w]; - if ( _(u3h_slot_is_noun(sot_w)) ) { - u3_noun kev = u3h_slot_to_noun(sot_w); + if ( _(u3h_v2_slot_is_noun(sot_w)) ) { + u3_noun kev = u3h_v2_slot_to_noun(sot_w); fun_f(kev, wit); } @@ -131,23 +131,23 @@ _ch_v2_walk_node(u3h_node* han_u, c3_w lef_w, void (*fun_f)(u3_noun, void*), voi * argument; RETAINS. */ void -u3h_v2_walk_with(u3p(u3h_root) har_p, +u3h_v2_walk_with(u3p(u3h_v2_root) har_p, void (*fun_f)(u3_noun, void*), void* wit) { - u3h_root* har_u = u3to(u3h_root, har_p); + u3h_v2_root* har_u = u3to(u3h_v2_root, har_p); c3_w i_w; for ( i_w = 0; i_w < 64; i_w++ ) { c3_w sot_w = har_u->sot_w[i_w]; - if ( _(u3h_slot_is_noun(sot_w)) ) { - u3_noun kev = u3h_slot_to_noun(sot_w); + if ( _(u3h_v2_slot_is_noun(sot_w)) ) { + u3_noun kev = u3h_v2_slot_to_noun(sot_w); fun_f(kev, wit); } - else if ( _(u3h_slot_is_node(sot_w)) ) { - u3h_node* han_u = u3h_v2_slot_to_node(sot_w); + else if ( _(u3h_v2_slot_is_node(sot_w)) ) { + u3h_v2_node* han_u = u3h_v2_slot_to_node(sot_w); _ch_v2_walk_node(han_u, 25, fun_f, wit); } @@ -166,7 +166,7 @@ _ch_v2_walk_plain(u3_noun kev, void* wit) /* u3h_v2_walk(): u3h_v2_walk_with, but with no data argument */ void -u3h_v2_walk(u3p(u3h_root) har_p, void (*fun_f)(u3_noun)) +u3h_v2_walk(u3p(u3h_v2_root) har_p, void (*fun_f)(u3_noun)) { u3h_v2_walk_with(har_p, _ch_v2_walk_plain, fun_f); } @@ -174,14 +174,14 @@ u3h_v2_walk(u3p(u3h_root) har_p, void (*fun_f)(u3_noun)) /* _ch_v2_rewrite_buck(): rewrite buck for compaction. */ void -_ch_v2_rewrite_buck(u3h_buck* hab_u) +_ch_v2_rewrite_buck(u3h_v2_buck* hab_u) { - if ( c3n == u3a_rewrite_ptr(hab_u) ) return; + if ( c3n == u3a_v2_rewrite_ptr(hab_u) ) return; c3_w i_w; for ( i_w = 0; i_w < hab_u->len_w; i_w++ ) { - u3_noun som = u3h_slot_to_noun(hab_u->sot_w[i_w]); - hab_u->sot_w[i_w] = u3h_noun_to_slot(u3a_v2_rewritten_noun(som)); + u3_noun som = u3h_v2_slot_to_noun(hab_u->sot_w[i_w]); + hab_u->sot_w[i_w] = u3h_v2_noun_to_slot(u3a_v2_rewritten_noun(som)); u3a_v2_rewrite_noun(som); } } @@ -189,9 +189,9 @@ _ch_v2_rewrite_buck(u3h_buck* hab_u) /* _ch_v2_rewrite_node(): rewrite node for compaction. */ void -_ch_v2_rewrite_node(u3h_node* han_u, c3_w lef_w) +_ch_v2_rewrite_node(u3h_v2_node* han_u, c3_w lef_w) { - if ( c3n == u3a_rewrite_ptr(han_u) ) return; + if ( c3n == u3a_v2_rewrite_ptr(han_u) ) return; c3_w len_w = _ch_v2_popcount(han_u->map_w); c3_w i_w; @@ -201,24 +201,18 @@ _ch_v2_rewrite_node(u3h_node* han_u, c3_w lef_w) for ( i_w = 0; i_w < len_w; i_w++ ) { c3_w sot_w = han_u->sot_w[i_w]; - if ( _(u3h_slot_is_noun(sot_w)) ) { - u3_noun kev = u3h_slot_to_noun(sot_w); - han_u->sot_w[i_w] = u3h_noun_to_slot(u3a_v2_rewritten_noun(kev)); + if ( _(u3h_v2_slot_is_noun(sot_w)) ) { + u3_noun kev = u3h_v2_slot_to_noun(sot_w); + han_u->sot_w[i_w] = u3h_v2_noun_to_slot(u3a_v2_rewritten_noun(kev)); u3a_v2_rewrite_noun(kev); } else { void* hav_v = u3h_v1_slot_to_node(sot_w); - u3h_node* nod_u = u3to(u3h_node, u3a_rewritten(u3of(u3h_node,hav_v))); - - // if (u3C.migration_state == MIG_REWRITE_COMPRESSED) - // u3C.vits_w = 1; + u3h_v2_node* nod_u = u3to(u3h_v2_node, u3a_v2_rewritten(u3of(u3h_v2_node,hav_v))); han_u->sot_w[i_w] = u3h_v2_node_to_slot(nod_u); - // if (u3C.migration_state == MIG_REWRITE_COMPRESSED) - // u3C.vits_w = 0; - if ( 0 == lef_w ) { _ch_v2_rewrite_buck(hav_v); } else { @@ -231,35 +225,28 @@ _ch_v2_rewrite_node(u3h_node* han_u, c3_w lef_w) /* u3h_v2_rewrite(): rewrite pointers during compaction. */ void -u3h_v2_rewrite(u3p(u3h_root) har_p) +u3h_v2_rewrite(u3p(u3h_v2_root) har_p) { - u3h_root* har_u = u3to(u3h_root, har_p); + u3h_v2_root* har_u = u3to(u3h_v2_root, har_p); c3_w i_w; - if ( c3n == u3a_rewrite_ptr(har_u) ) return; + if ( c3n == u3a_v2_rewrite_ptr(har_u) ) return; for ( i_w = 0; i_w < 64; i_w++ ) { c3_w sot_w = har_u->sot_w[i_w]; - if ( _(u3h_slot_is_noun(sot_w)) ) { - u3_noun kev = u3h_slot_to_noun(sot_w); - har_u->sot_w[i_w] = u3h_noun_to_slot(u3a_v2_rewritten_noun(kev)); + if ( _(u3h_v2_slot_is_noun(sot_w)) ) { + u3_noun kev = u3h_v2_slot_to_noun(sot_w); + har_u->sot_w[i_w] = u3h_v2_noun_to_slot(u3a_v2_rewritten_noun(kev)); u3a_v2_rewrite_noun(kev); } - else if ( _(u3h_slot_is_node(sot_w)) ) { - // XX check for correctness - u3h_node* han_u = u3h_v1_slot_to_node(sot_w); - u3h_node* nod_u = u3to(u3h_node, u3a_rewritten(u3of(u3h_node,han_u))); - - // if (u3C.migration_state == MIG_REWRITE_COMPRESSED) - // u3C.vits_w = 1; + else if ( _(u3h_v2_slot_is_node(sot_w)) ) { + u3h_v2_node* han_u = u3h_v1_slot_to_node(sot_w); + u3h_v2_node* nod_u = u3to(u3h_v2_node, u3a_v2_rewritten(u3of(u3h_v2_node,han_u))); har_u->sot_w[i_w] = u3h_v2_node_to_slot(nod_u); - // if (u3C.migration_state == MIG_REWRITE_COMPRESSED) - // u3C.vits_w = 0; - _ch_v2_rewrite_node(han_u, 25); } } diff --git a/pkg/noun/v2/hashtable.h b/pkg/noun/v2/hashtable.h index 121ee31ef0..e225ccbd76 100644 --- a/pkg/noun/v2/hashtable.h +++ b/pkg/noun/v2/hashtable.h @@ -1,7 +1,14 @@ #ifndef U3_HASHTABLE_V2_H #define U3_HASHTABLE_V2_H -#define VITS_W 1 +#define u3h_v2_buck u3h_buck +#define u3h_v2_node u3h_node +#define u3h_v2_noun_to_slot u3h_noun_to_slot +#define u3h_v2_root u3h_root +#define u3h_v2_slot_is_node u3h_slot_is_node +#define u3h_v2_slot_is_noun u3h_slot_is_noun +#define u3h_v2_slot_to_noun u3h_slot_to_noun +#define u3h_v2_walk u3h_walk #include "pkg/noun/hashtable.h" @@ -18,8 +25,8 @@ /* u3h_v2_slot_to_node(): slot to node pointer ** u3h_v2_node_to_slot(): node pointer to slot */ -# define u3h_v2_slot_to_node(sot) (u3a_into(((sot) & 0x3fffffff) << VITS_W)) -# define u3h_v2_node_to_slot(ptr) ((u3a_outa((ptr)) >> VITS_W) | 0x40000000) +# define u3h_v2_slot_to_node(sot) (u3a_v2_into(((sot) & 0x3fffffff) << u3a_vits)) +# define u3h_v2_node_to_slot(ptr) ((u3a_v2_outa((ptr)) >> u3a_vits) | 0x40000000) /** Functions. *** diff --git a/pkg/noun/v2/jets.c b/pkg/noun/v2/jets.c index c3653b7283..237c22d03e 100644 --- a/pkg/noun/v2/jets.c +++ b/pkg/noun/v2/jets.c @@ -5,7 +5,9 @@ #include "pkg/noun/jets.h" #include "pkg/noun/v2/jets.h" +#include "pkg/noun/v2/allocate.h" #include "pkg/noun/v2/hashtable.h" +#include "pkg/noun/v2/vortex.h" /** Data structures. **/ @@ -15,7 +17,7 @@ */ typedef struct { u3_weak hax; // axis of hooked inner core - u3j_site sit_u; // call-site data + u3j_v2_site sit_u; // call-site data } _cj_hank; /** Functions. @@ -30,14 +32,14 @@ _cj_v2_free_hank(u3_noun kev) _cj_hank* han_u = u3to(_cj_hank, u3t(kev)); if ( u3_none != han_u->hax ) { u3z(han_u->hax); - u3j_site_lose(&(han_u->sit_u)); + u3j_v2_site_lose(&(han_u->sit_u)); } - u3a_wfree(han_u); + u3a_v2_wfree(han_u); } /* u3j_v2_rewrite_compact(): rewrite jet state for compaction. * - * NB: u3R->jed.han_p *must* be cleared (currently via u3j_v2_reclaim above) + * NB: u3R_v2->jed.han_p *must* be cleared (currently via u3j_v2_reclaim above) * since it contains hanks which are not nouns but have loom pointers. * Alternately, rewrite the entries with u3h_v2_walk, using u3j_v2_mark as a * template for how to walk. There's an untested attempt at this in git @@ -46,18 +48,18 @@ _cj_v2_free_hank(u3_noun kev) void u3j_v2_rewrite_compact() { - u3h_v2_rewrite(u3R->jed.war_p); - u3h_v2_rewrite(u3R->jed.cod_p); - u3h_v2_rewrite(u3R->jed.han_p); - u3h_v2_rewrite(u3R->jed.bas_p); - - if ( u3R == &(u3H->rod_u) ) { - u3h_v2_rewrite(u3R->jed.hot_p); - u3R->jed.hot_p = u3a_rewritten(u3R->jed.hot_p); + u3h_v2_rewrite(u3R_v2->jed.war_p); + u3h_v2_rewrite(u3R_v2->jed.cod_p); + u3h_v2_rewrite(u3R_v2->jed.han_p); + u3h_v2_rewrite(u3R_v2->jed.bas_p); + + if ( u3R_v2 == &(u3H_v2->rod_u) ) { + u3h_v2_rewrite(u3R_v2->jed.hot_p); + u3R_v2->jed.hot_p = u3a_v2_rewritten(u3R_v2->jed.hot_p); } - u3R->jed.war_p = u3a_rewritten(u3R->jed.war_p); - u3R->jed.cod_p = u3a_rewritten(u3R->jed.cod_p); - u3R->jed.han_p = u3a_rewritten(u3R->jed.han_p); - u3R->jed.bas_p = u3a_rewritten(u3R->jed.bas_p); + u3R_v2->jed.war_p = u3a_v2_rewritten(u3R_v2->jed.war_p); + u3R_v2->jed.cod_p = u3a_v2_rewritten(u3R_v2->jed.cod_p); + u3R_v2->jed.han_p = u3a_v2_rewritten(u3R_v2->jed.han_p); + u3R_v2->jed.bas_p = u3a_v2_rewritten(u3R_v2->jed.bas_p); } diff --git a/pkg/noun/v2/jets.h b/pkg/noun/v2/jets.h index 7fc16b3c66..69c3a95d76 100644 --- a/pkg/noun/v2/jets.h +++ b/pkg/noun/v2/jets.h @@ -3,11 +3,17 @@ #ifndef U3_JETS_V2_H #define U3_JETS_V2_H - /** Functions. - **/ - /* u3j_v2_rewrite_compact(): rewrite jet state for compaction. - */ - void - u3j_v2_rewrite_compact(); + /** Aliases. + **/ +# define u3j_v2_rite_lose u3j_rite_lose +# define u3j_v2_site u3j_site +# define u3j_v2_site_lose u3j_site_lose + + /** Functions. + **/ + /* u3j_v2_rewrite_compact(): rewrite jet state for compaction. + */ + void + u3j_v2_rewrite_compact(); #endif /* ifndef U3_JETS_V2_H */ \ No newline at end of file diff --git a/pkg/noun/v2/manage.c b/pkg/noun/v2/manage.c index 6a426331ff..2790048b2b 100644 --- a/pkg/noun/v2/manage.c +++ b/pkg/noun/v2/manage.c @@ -6,6 +6,7 @@ #include "pkg/noun/v2/hashtable.h" #include "pkg/noun/v2/jets.h" #include "pkg/noun/v2/nock.h" +#include "pkg/noun/v2/options.h" #include "pkg/noun/vortex.h" #include "pkg/noun/v2/vortex.h" @@ -15,11 +16,11 @@ static void _cm_pack_rewrite(void) { - // XX fix u3a_rewrite* to support south roads + // XX fix u3a_v2_rewrite* to support south roads // - u3_assert( &(u3H->rod_u) == u3R ); + u3_assert( &(u3H_v2->rod_u) == u3R_v2 ); - // NB: these implementations must be kept in sync with u3m_reclaim(); + // NB: these implementations must be kept in sync with u3m_v2_reclaim(); // anything not reclaimed must be rewritable // u3v_v2_rewrite_compact(); @@ -34,23 +35,22 @@ _migrate_reclaim() // XX update this and similar printfs fprintf(stderr, "loom: migration reclaim\r\n"); u3m_v1_reclaim(); - fprintf(stderr, "loom: migration reclaim done\r\n"); } static void -_migrate_seek(const u3a_road *rod_u) +_migrate_seek(const u3a_v2_road *rod_u) { /* - very much like u3a_pack_seek with the following changes: + very much like u3a_v2_pack_seek with the following changes: - there is no need to account for free space as |pack is performed before the migration - odd sized boxes will be padded by one word to achieve an even size - rut will be moved from one word ahead of u3_Loom to two words ahead */ - c3_w * box_w = u3a_into(rod_u->rut_p); - c3_w * end_w = u3a_into(rod_u->hat_p); - u3_post new_p = (rod_u->rut_p + 1 + c3_wiseof(u3a_box)); - u3a_box * box_u = (void *)box_w; + c3_w * box_w = u3a_v2_into(rod_u->rut_p); + c3_w * end_w = u3a_v2_into(rod_u->hat_p); + u3_post new_p = (rod_u->rut_p + 1 + c3_wiseof(u3a_v2_box)); + u3a_v2_box * box_u = (void *)box_w; fprintf(stderr, "loom: migration seek\r\n"); @@ -72,39 +72,36 @@ _migrate_rewrite() { fprintf(stderr, "loom: migration rewrite\r\n"); - // /* So that rewritten pointers are compressed, this flag is set */ - // u3C.migration_state = MIG_REWRITE_COMPRESSED; _cm_pack_rewrite(); - // u3C.migration_state = MIG_NONE; } static void -_migrate_move(u3a_road *rod_u) +_migrate_move(u3a_v2_road *rod_u) { fprintf(stderr, "loom: migration move\r\n"); - c3_z hiz_z = u3a_heap(rod_u) * sizeof(c3_w); + c3_z hiz_z = u3a_v2_heap(rod_u) * sizeof(c3_w); /* calculate required shift distance to prevent write head overlapping read head */ - c3_w off_w = 1; /* at least 1 word because u3R->rut_p migrates from 1 to 2 */ - for (u3a_box *box_u = u3a_into(rod_u->rut_p) - ; (void *)box_u < u3a_into(rod_u->hat_p) + c3_w off_w = 1; /* at least 1 word because u3R_v2->rut_p migrates from 1 to 2 */ + for (u3a_v2_box *box_u = u3a_v2_into(rod_u->rut_p) + ; (void *)box_u < u3a_v2_into(rod_u->hat_p) ; box_u = (void *)((c3_w *)box_u + box_u->siz_w)) off_w += box_u->siz_w & 1; /* odd-sized boxes are padded by one word */ /* shift */ - memmove(u3a_into(u3H->rod_u.rut_p + off_w), - u3a_into(u3H->rod_u.rut_p), + memmove(u3a_v2_into(u3H_v2->rod_u.rut_p + off_w), + u3a_v2_into(u3H_v2->rod_u.rut_p), hiz_z); /* manually zero the former rut */ - *(c3_w *)u3a_into(rod_u->rut_p) = 0; + *(c3_w *)u3a_v2_into(rod_u->rut_p) = 0; /* relocate boxes to DWORD-aligned addresses stored in trailing size word */ - c3_w *box_w = u3a_into(rod_u->rut_p + off_w); - c3_w *end_w = u3a_into(rod_u->hat_p + off_w); - u3a_box *old_u = (void *)box_w; + c3_w *box_w = u3a_v2_into(rod_u->rut_p + off_w); + c3_w *end_w = u3a_v2_into(rod_u->hat_p + off_w); + u3a_v2_box *old_u = (void *)box_w; c3_w siz_w = old_u->siz_w; - u3p(c3_w) new_p = rod_u->rut_p + 1 + c3_wiseof(u3a_box); + u3p(c3_w) new_p = rod_u->rut_p + 1 + c3_wiseof(u3a_v2_box); c3_w *new_w; for (; box_w < end_w @@ -116,7 +113,7 @@ _migrate_move(u3a_road *rod_u) if (!old_u->use_w) continue; - new_w = (void *)u3a_botox(u3a_into(new_p)); + new_w = (void *)u3a_v2_botox(u3a_v2_into(new_p)); u3_assert(box_w[siz_w - 1] == new_p); u3_assert(new_w <= box_w); @@ -138,14 +135,14 @@ _migrate_move(u3a_road *rod_u) /* restore proper heap state */ rod_u->rut_p = 2; - rod_u->hat_p = new_p - c3_wiseof(u3a_box); + rod_u->hat_p = new_p - c3_wiseof(u3a_v2_box); /* like |pack, clear the free lists and cell allocator */ - for (c3_w i_w = 0; i_w < u3a_fbox_no; i_w++) - u3R->all.fre_p[i_w] = 0; + for (c3_w i_w = 0; i_w < u3a_v2_fbox_no; i_w++) + u3R_v2->all.fre_p[i_w] = 0; - u3R->all.fre_w = 0; - u3R->all.cel_p = 0; + u3R_v2->all.fre_w = 0; + u3R_v2->all.cel_p = 0; } @@ -154,30 +151,30 @@ _migrate_move(u3a_road *rod_u) void u3m_v2_migrate() { - c3_w len_w = u3C.wor_i - 1; + c3_w len_w = u3C_v2.wor_i - 1; c3_w ver_w = *(u3_Loom + len_w); u3_assert( U3V_VER1 == ver_w ); c3_w* mem_w = u3_Loom + 1; - c3_w siz_w = c3_wiseof(u3v_home); + c3_w siz_w = c3_wiseof(u3v_v2_home); c3_w* mat_w = (mem_w + len_w) - siz_w; - u3H = (void *)mat_w; - u3R = &u3H->rod_u; + u3H_v2 = (void *)mat_w; + u3R_v2 = &u3H_v2->rod_u; - u3R->cap_p = u3R->mat_p = u3a_outa(u3H); + u3R_v2->cap_p = u3R_v2->mat_p = u3a_v2_outa(u3H_v2); fprintf(stderr, "loom: pointer compression migration running...\r\n"); /* perform the migration in a pattern similar to |pack */ _migrate_reclaim(); - _migrate_seek(&u3H->rod_u); + _migrate_seek(&u3H_v2->rod_u); _migrate_rewrite(); - _migrate_move(&u3H->rod_u); + _migrate_move(&u3H_v2->rod_u); /* finally update the version and commit to disk */ - u3H->ver_w = U3V_VER2; + u3H_v2->ver_w = U3V_VER2; fprintf(stderr, "loom: pointer compression migration done\r\n"); } diff --git a/pkg/noun/v2/nock.c b/pkg/noun/v2/nock.c index d64d1d48fc..4df7d32037 100644 --- a/pkg/noun/v2/nock.c +++ b/pkg/noun/v2/nock.c @@ -3,13 +3,15 @@ #include "pkg/noun/nock.h" #include "pkg/noun/v2/nock.h" +#include "pkg/noun/v2/allocate.h" #include "pkg/noun/v2/hashtable.h" +#include "pkg/noun/v2/vortex.h" /* _cn_prog_free(): free memory retained by program pog_u ** NB: copy of _cn_prog_free in pkg/noun/nock.c */ static void -_cn_prog_free(u3n_prog* pog_u) +_cn_prog_free(u3n_v2_prog* pog_u) { c3_w dex_w; for (dex_w = 0; dex_w < pog_u->lit_u.len_w; ++dex_w) { @@ -19,21 +21,21 @@ _cn_prog_free(u3n_prog* pog_u) u3z(pog_u->mem_u.sot_u[dex_w].key); } for (dex_w = 0; dex_w < pog_u->cal_u.len_w; ++dex_w) { - u3j_site_lose(&(pog_u->cal_u.sit_u[dex_w])); + u3j_v2_site_lose(&(pog_u->cal_u.sit_u[dex_w])); } for (dex_w = 0; dex_w < pog_u->reg_u.len_w; ++dex_w) { - u3j_rite_lose(&(pog_u->reg_u.rit_u[dex_w])); + u3j_v2_rite_lose(&(pog_u->reg_u.rit_u[dex_w])); } - u3a_free(pog_u); + u3a_v2_free(pog_u); } -/* _n_feb(): u3h_walk helper for u3n_free +/* _n_feb(): u3h_v2_walk helper for u3n_v2_free */ static void _n_feb(u3_noun kev) { - _cn_prog_free(u3to(u3n_prog, u3t(kev))); + _cn_prog_free(u3to(u3n_v2_prog, u3t(kev))); } /* u3n_v2_free(): free bytecode cache @@ -41,20 +43,20 @@ _n_feb(u3_noun kev) void u3n_v2_free() { - u3p(u3h_root) har_p = u3R->byc.har_p; + u3p(u3h_v2_root) har_p = u3R_v2->byc.har_p; u3h_v2_walk(har_p, _n_feb); u3h_v2_free(har_p); } /* u3n_v2_rewrite_compact(): rewrite the bytecode cache for compaction. * - * NB: u3R->byc.har_p *must* be cleared (currently via u3n_v2_reclaim above), + * NB: u3R_v2->byc.har_p *must* be cleared (currently via u3n_v2_reclaim above), * since it contains things that look like nouns but aren't. * Specifically, it contains "cells" where the tail is a - * pointer to a u3a_malloc'ed block that contains loom pointers. + * pointer to a u3a_v2_malloc'ed block that contains loom pointers. * - * You should be able to walk this with u3h_walk and rewrite the - * pointers, but you need to be careful to handle that u3a_malloc + * You should be able to walk this with u3h_v2_walk and rewrite the + * pointers, but you need to be careful to handle that u3a_v2_malloc * pointers can't be turned into a box by stepping back two words. You * must step back one word to get the padding, step then step back that * many more words (plus one?). @@ -62,6 +64,6 @@ u3n_v2_free() void u3n_v2_rewrite_compact() { - u3h_v2_rewrite(u3R->byc.har_p); - u3R->byc.har_p = u3a_rewritten(u3R->byc.har_p); + u3h_v2_rewrite(u3R_v2->byc.har_p); + u3R_v2->byc.har_p = u3a_v2_rewritten(u3R_v2->byc.har_p); } diff --git a/pkg/noun/v2/nock.h b/pkg/noun/v2/nock.h index 82fbe707bf..57f358eeca 100644 --- a/pkg/noun/v2/nock.h +++ b/pkg/noun/v2/nock.h @@ -3,6 +3,11 @@ #ifndef U3_NOCK_V2_H #define U3_NOCK_V2_H + /** Aliases. + **/ +#define u3n_v2_free u3n_free +#define u3n_v2_prog u3n_prog + /** Functions. **/ /* u3n_v2_free(): free bytecode cache. diff --git a/pkg/noun/v2/options.h b/pkg/noun/v2/options.h new file mode 100644 index 0000000000..4af573f20d --- /dev/null +++ b/pkg/noun/v2/options.h @@ -0,0 +1,14 @@ +/// @file + +#ifndef U3_OPTIONS_V2_H +#define U3_OPTIONS_V2_H + +#include "pkg/noun/options.h" + + /** Globals. + **/ + /* u3_Config / u3C: global memory control. + */ +# define u3C_v2 u3C + +#endif /* ifndef U3_OPTIONS_H */ diff --git a/pkg/noun/v2/vortex.c b/pkg/noun/v2/vortex.c index f00628f333..5a0d7cc4e2 100644 --- a/pkg/noun/v2/vortex.c +++ b/pkg/noun/v2/vortex.c @@ -10,7 +10,7 @@ void u3v_v2_rewrite_compact() { - u3v_arvo* arv_u = &(u3H->arv_u); + u3v_v2_arvo* arv_u = &(u3H_v2->arv_u); u3a_v2_rewrite_noun(arv_u->roc); u3a_v2_rewrite_noun(arv_u->now); diff --git a/pkg/noun/v2/vortex.h b/pkg/noun/v2/vortex.h index bc3fba8d59..7fa6a41b4d 100644 --- a/pkg/noun/v2/vortex.h +++ b/pkg/noun/v2/vortex.h @@ -3,6 +3,14 @@ #ifndef U3_VORTEX_V2_H #define U3_VORTEX_V2_H +#include "pkg/noun/vortex.h" + + /** Aliases. + **/ +# define u3H_v2 u3H +# define u3v_v2_arvo u3v_arvo +# define u3v_v2_home u3v_home + /** Functions. **/ /* u3v_v2_rewrite_compact(): rewrite arvo kernel for compaction.