Skip to content

Commit

Permalink
wip: fix up pointers in u3n_v2_reclaim
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-levan committed Sep 22, 2023
1 parent 3c8d8fe commit c4830c0
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
51 changes: 49 additions & 2 deletions pkg/noun/v2/nock.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,55 @@ u3n_v2_reclaim(void)
u3R = (u3a_road*) u3R_v2;

// clear the bytecode cache
u3n_v3_free();
u3R->byc.har_p = u3h_v3_new();
u3n_v2_free();
u3R->byc.har_p = u3h_v2_new();
}

/* _cn_v2_prog_free(): free memory retained by program pog_u
*/
static void
_cn_v2_prog_free(u3n_v2_prog* pog_u)
{
// fix up pointers for loom portability
pog_u->byc_u.ops_y = (c3_y*) ((void*) pog_u) + sizeof(u3n_v2_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_v2_memo*) (pog_u->lit_u.non + pog_u->lit_u.len_w);
pog_u->cal_u.sit_u = (u3j_v2_site*) (pog_u->mem_u.sot_u + pog_u->mem_u.len_w);
pog_u->reg_u.rit_u = (u3j_v2_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_v2_lose(pog_u->lit_u.non[dex_w]);
}
for (dex_w = 0; dex_w < pog_u->mem_u.len_w; ++dex_w) {
u3a_v2_lose(pog_u->mem_u.sot_u[dex_w].key);
}
for (dex_w = 0; dex_w < pog_u->cal_u.len_w; ++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_v2_rite_lose(&(pog_u->reg_u.rit_u[dex_w]));
}
u3a_v2_free(pog_u);
}

/* _n_v2_feb(): u3h_v2_walk helper for u3n_v2_free
*/
static void
_n_v2_feb(u3_noun kev)
{
u3a_v2_cell *cel_u = (u3a_v2_cell*) u3a_v2_to_ptr(kev);
_cn_v2_prog_free(u3to(u3n_v2_prog, cel_u->tel));
}

/* u3n_v2_free(): free bytecode cache
*/
void
u3n_v2_free()
{
u3p(u3h_v2_root) har_p = u3R_v2->byc.har_p;
u3h_v2_walk(har_p, _n_v2_feb);
u3h_v2_free(har_p);
}

/* u3n_v2_mig_rewrite_compact(): rewrite the bytecode cache for compaction.
Expand Down
5 changes: 5 additions & 0 deletions pkg/noun/v2/nock.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@
void
u3n_v2_reclaim(void);

/* u3n_v2_free(): free bytecode cache.
*/
void
u3n_v2_free(void);

/* u3n_v2_mig_rewrite_compact(): rewrite bytecode cache for compaction.
*/
void
Expand Down

0 comments on commit c4830c0

Please sign in to comment.