From 5f299fc5cef130022e1f76fb191f5739c02e06cc Mon Sep 17 00:00:00 2001 From: Matthew LeVan Date: Wed, 20 Sep 2023 14:38:53 -0400 Subject: [PATCH] wip: set globals only in funcs that need it --- pkg/noun/v1/nock.c | 14 +++++++------- pkg/noun/v2/jets.c | 13 ++++++++++--- pkg/noun/v2/nock.c | 19 +++++++++++++++++++ pkg/noun/v2/nock.h | 6 +++++- pkg/noun/v3/allocate.h | 1 + pkg/noun/v3/hashtable.c | 33 +++++++++++++++++++++++++++++++++ pkg/noun/v3/hashtable.h | 12 +++++++++++- pkg/noun/v3/jets.h | 12 ++++++++++++ pkg/noun/v3/manage.c | 6 ------ pkg/noun/v3/nock.h | 1 + 10 files changed, 99 insertions(+), 18 deletions(-) create mode 100644 pkg/noun/v3/hashtable.c create mode 100644 pkg/noun/v3/jets.h diff --git a/pkg/noun/v1/nock.c b/pkg/noun/v1/nock.c index 743ac8e916..86aa07a921 100644 --- a/pkg/noun/v1/nock.c +++ b/pkg/noun/v1/nock.c @@ -26,6 +26,13 @@ u3n_v1_reclaim(void) static void _cn_v1_prog_free(u3n_v1_prog* pog_u) { + // fix up pointers for loom portability + pog_u->byc_u.ops_y = (c3_y*) ((void*) pog_u) + sizeof(u3n_v1_prog); + pog_u->lit_u.non = (u3_noun*) (pog_u->byc_u.ops_y + pog_u->byc_u.len_w); + pog_u->mem_u.sot_u = (u3n_v1_memo*) (pog_u->lit_u.non + pog_u->lit_u.len_w); + pog_u->cal_u.sit_u = (u3j_v1_site*) (pog_u->mem_u.sot_u + pog_u->mem_u.len_w); + pog_u->reg_u.rit_u = (u3j_v1_rite*) (pog_u->cal_u.sit_u + pog_u->cal_u.len_w); + c3_w dex_w; for (dex_w = 0; dex_w < pog_u->lit_u.len_w; ++dex_w) { u3a_v1_lose(pog_u->lit_u.non[dex_w]); @@ -40,13 +47,6 @@ _cn_v1_prog_free(u3n_v1_prog* pog_u) u3j_v1_rite_lose(&(pog_u->reg_u.rit_u[dex_w])); } - // fix up pointers for loom portability - pog_u->byc_u.ops_y = (c3_y*) ((void*) pog_u) + sizeof(u3n_v1_prog); - pog_u->lit_u.non = (u3_noun*) (pog_u->byc_u.ops_y + pog_u->byc_u.len_w); - pog_u->mem_u.sot_u = (u3n_v1_memo*) (pog_u->lit_u.non + pog_u->lit_u.len_w); - pog_u->cal_u.sit_u = (u3j_v1_site*) (pog_u->mem_u.sot_u + pog_u->mem_u.len_w); - pog_u->reg_u.rit_u = (u3j_v1_rite*) (pog_u->cal_u.sit_u + pog_u->cal_u.len_w); - u3a_v1_free(pog_u); } diff --git a/pkg/noun/v2/jets.c b/pkg/noun/v2/jets.c index 47596ed60f..dfa38febdc 100644 --- a/pkg/noun/v2/jets.c +++ b/pkg/noun/v2/jets.c @@ -9,16 +9,23 @@ #include "pkg/noun/v2/hashtable.h" #include "pkg/noun/v2/vortex.h" +#include "pkg/noun/v3/hashtable.h" +#include "pkg/noun/v3/jets.h" + /* u3j_v2_reclaim(): clear ad-hoc persistent caches to reclaim memory. */ void u3j_v2_reclaim(void) { + // set globals (required for aliased functions) + u3H = (u3v_home*) u3H_v2; + u3R = (u3a_road*) u3R_v2; + // clear the jet hank cache // - u3h_v2_walk(u3R_v2->jed.han_p, u3j_v2_free_hank); - u3h_v2_free(u3R_v2->jed.han_p); - u3R_v2->jed.han_p = u3h_v2_new(); + u3h_v3_walk(u3R->jed.han_p, u3j_v3_free_hank); + u3h_v3_free(u3R->jed.han_p); + u3R->jed.han_p = u3h_v3_new(); } /* u3j_v2_rewrite_compact(): rewrite jet state for compaction. diff --git a/pkg/noun/v2/nock.c b/pkg/noun/v2/nock.c index d8e447a417..d03e56a5bd 100644 --- a/pkg/noun/v2/nock.c +++ b/pkg/noun/v2/nock.c @@ -2,8 +2,27 @@ #include "pkg/noun/v2/nock.h" +#include "pkg/noun/vortex.h" + #include "pkg/noun/v2/allocate.h" #include "pkg/noun/v2/hashtable.h" +#include "pkg/noun/v2/vortex.h" + +#include "pkg/noun/v3/hashtable.h" + +/* u3n_v2_reclaim(): clear ad-hoc persistent caches to reclaim memory. +*/ +void +u3n_v2_reclaim(void) +{ + // set globals (required for aliased functions) + u3H = (u3v_home*) u3H_v2; + u3R = (u3a_road*) u3R_v2; + + // clear the bytecode cache + u3n_v3_free(); + u3R->byc.har_p = u3h_v3_new(); +} /* u3n_v2_rewrite_compact(): rewrite the bytecode cache for compaction. * diff --git a/pkg/noun/v2/nock.h b/pkg/noun/v2/nock.h index c8dda8badc..c05e05da8a 100644 --- a/pkg/noun/v2/nock.h +++ b/pkg/noun/v2/nock.h @@ -11,7 +11,11 @@ **/ # define u3n_v2_memo u3n_v3_memo # define u3n_v2_prog u3n_v3_prog -# define u3n_v2_reclaim u3n_v3_reclaim + + /* u3n_v2_reclaim(): clear ad-hoc persistent caches to reclaim memory. + */ + void + u3n_v2_reclaim(void); /* u3n_v2_rewrite_compact(): rewrite bytecode cache for compaction. */ diff --git a/pkg/noun/v3/allocate.h b/pkg/noun/v3/allocate.h index fb9fa73015..bacc79e174 100644 --- a/pkg/noun/v3/allocate.h +++ b/pkg/noun/v3/allocate.h @@ -12,5 +12,6 @@ # define u3a_v3_balign u3a_balign # define u3a_v3_road u3a_road # define u3a_v3_walign u3a_walign +# define u3a_v3_walloc u3a_walloc #endif /* ifndef U3_ALLOCATE_V3_H */ diff --git a/pkg/noun/v3/hashtable.c b/pkg/noun/v3/hashtable.c new file mode 100644 index 0000000000..b17d7b6e78 --- /dev/null +++ b/pkg/noun/v3/hashtable.c @@ -0,0 +1,33 @@ +/// @file + +#include "pkg/noun/v3/hashtable.h" + +#include "pkg/noun/allocate.h" +#include "pkg/noun/vortex.h" + +#include "pkg/noun/v3/allocate.h" +#include "pkg/noun/v3/vortex.h" + +/* u3h_v3_new_cache(): create hashtable with bounded size. +*/ +u3p(u3h_v3_root) +u3h_v3_new_cache(c3_w max_w) +{ + // set globals (required for aliased functions) + u3H = (u3v_home*) u3H_v3; + u3R = (u3a_road*) u3R_v3; + + u3h_v3_root* har_u = u3a_v3_walloc(c3_wiseof(u3h_v3_root)); + u3p(u3h_v3_root) har_p = u3of(u3h_v3_root, har_u); + c3_w i_w; + + har_u->max_w = max_w; + har_u->use_w = 0; + har_u->arm_u.mug_w = 0; + har_u->arm_u.inx_w = 0; + + for ( i_w = 0; i_w < 64; i_w++ ) { + har_u->sot_w[i_w] = 0; + } + return har_p; +} diff --git a/pkg/noun/v3/hashtable.h b/pkg/noun/v3/hashtable.h index 7ad854b91c..14e0e47753 100644 --- a/pkg/noun/v3/hashtable.h +++ b/pkg/noun/v3/hashtable.h @@ -1,8 +1,18 @@ #ifndef U3_HASHTABLE_V3_H #define U3_HASHTABLE_V3_H -#define u3h_v3_new_cache u3h_new_cache +#define u3h_v3_free u3h_free +#define u3h_v3_new u3h_new +#define u3h_v3_root u3h_root +#define u3h_v3_walk u3h_walk #include "pkg/noun/hashtable.h" + /** Functions. + **/ + /* u3h_v3_new_cache(): create hashtable with bounded size. + */ + u3p(u3h_v3_root) + u3h_v3_new_cache(c3_w clk_w); + #endif /* U3_HASHTABLE_V3_H */ diff --git a/pkg/noun/v3/jets.h b/pkg/noun/v3/jets.h new file mode 100644 index 0000000000..a0fe54f9d7 --- /dev/null +++ b/pkg/noun/v3/jets.h @@ -0,0 +1,12 @@ +/// @file + +#ifndef U3_JETS_V3_H +#define U3_JETS_V3_H + +#include "pkg/noun/jets.h" + + /** Aliases. + **/ +# define u3j_v3_free_hank u3j_free_hank + +#endif /* ifndef U3_JETS_V3_H */ diff --git a/pkg/noun/v3/manage.c b/pkg/noun/v3/manage.c index ff31ba1b05..a15d5ad9be 100644 --- a/pkg/noun/v3/manage.c +++ b/pkg/noun/v3/manage.c @@ -35,8 +35,6 @@ u3m_v3_migrate() u3H_v2 = (void *)mut_w; u3R_v2 = &u3H_v2->rod_u; u3R_v2->cap_p = u3R_v2->mat_p = u3a_v2_outa(u3H_v2); - u3H = (u3v_home*)u3H_v2; - u3R = (u3a_road*)u3R_v2; // free bytecode caches in old road u3j_v2_reclaim(); @@ -100,10 +98,6 @@ u3m_v3_migrate() // set globals u3H_v3 = (void*)mat_w; u3R_v3 = &u3H_v3->rod_u; - u3H = (u3v_home*)u3H_v3; - u3R = (u3a_road*)u3R_v3; - - // update the version u3H_v3->ver_w = U3V_VER3; // initialize persistent cache diff --git a/pkg/noun/v3/nock.h b/pkg/noun/v3/nock.h index 1f35bef918..a7b208ba99 100644 --- a/pkg/noun/v3/nock.h +++ b/pkg/noun/v3/nock.h @@ -9,6 +9,7 @@ /** Aliases. **/ +# define u3n_v3_free u3n_free # define u3n_v3_memo u3n_memo # define u3n_v3_prog u3n_prog # define u3n_v3_reclaim u3n_reclaim