Skip to content

Commit

Permalink
wip: set globals only in funcs that need it
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-levan committed Sep 20, 2023
1 parent 774e9bf commit 5f299fc
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 18 deletions.
14 changes: 7 additions & 7 deletions pkg/noun/v1/nock.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand All @@ -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);
}

Expand Down
13 changes: 10 additions & 3 deletions pkg/noun/v2/jets.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
19 changes: 19 additions & 0 deletions pkg/noun/v2/nock.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
6 changes: 5 additions & 1 deletion pkg/noun/v2/nock.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
1 change: 1 addition & 0 deletions pkg/noun/v3/allocate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
33 changes: 33 additions & 0 deletions pkg/noun/v3/hashtable.c
Original file line number Diff line number Diff line change
@@ -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;
}
12 changes: 11 additions & 1 deletion pkg/noun/v3/hashtable.h
Original file line number Diff line number Diff line change
@@ -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 */
12 changes: 12 additions & 0 deletions pkg/noun/v3/jets.h
Original file line number Diff line number Diff line change
@@ -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 */
6 changes: 0 additions & 6 deletions pkg/noun/v3/manage.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pkg/noun/v3/nock.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5f299fc

Please sign in to comment.