Skip to content

Commit

Permalink
wip: working v2 migration
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-levan committed Sep 8, 2023
1 parent d4d061a commit f35cd83
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 89 deletions.
6 changes: 3 additions & 3 deletions pkg/noun/v1/allocate.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ u3a_v1_rewritten_noun(u3_noun som)
if ( c3y == u3a_is_cat(som) ) {
return som;
}
u3_post som_p = u3a_v1_rewritten(u3a_v1_to_off(som));
u3_post som_p = u3a_rewritten(u3a_v1_to_off(som));

if ( c3y == u3a_is_pug(som) ) {
som_p = u3a_v1_to_pug(som_p); // XX alias?
Expand Down Expand Up @@ -60,8 +60,8 @@ u3a_v1_rewrite_compact(void)
u3R->bug.mer = u3a_v1_rewritten_noun(u3R->bug.mer);
u3R->pro.don = u3a_v1_rewritten_noun(u3R->pro.don);
u3R->pro.day = u3a_v1_rewritten_noun(u3R->pro.day);
u3R->pro.trace = u3a_v1_rewritten_noun(u3R->pro.trace);
u3R->cax.har_p = u3a_v1_rewritten(u3R->cax.har_p);
u3R->pro.trace = u3a_rewritten_noun(u3R->pro.trace);
u3R->cax.har_p = u3a_rewritten(u3R->cax.har_p);
}
void
u3a_v1_rewrite_noun(u3_noun som)
Expand Down
68 changes: 34 additions & 34 deletions pkg/noun/v1/hashtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@
#include "xtract.h"


/* _ch_popcount(): number of bits set in word. A standard intrinsic.
** NB: copy of _ch_popcount in pkg/noun/hashtable.c
/* _ch_v1_popcount(): number of bits set in word. A standard intrinsic.
** NB: copy of _ch_v1_popcount in pkg/noun/hashtable.c
*/
static c3_w
_ch_popcount(c3_w num_w)
_ch_v1_popcount(c3_w num_w)
{
return __builtin_popcount(num_w);
}

/* _ch_free_buck(): free bucket
** NB: copy of _ch_free_buck in pkg/noun/hashtable.c
/* _ch_v1_free_buck(): free bucket
** NB: copy of _ch_v1_free_buck in pkg/noun/hashtable.c
*/
static void
_ch_free_buck(u3h_buck* hab_u)
_ch_v1_free_buck(u3h_buck* hab_u)
{
c3_w i_w;

Expand All @@ -33,12 +33,12 @@ _ch_free_buck(u3h_buck* hab_u)
u3a_wfree(hab_u);
}

/* _ch_free_node(): free node.
/* _ch_v1_free_node(): free node.
*/
static void
_ch_free_node(u3h_node* han_u, c3_w lef_w)
_ch_v1_free_node(u3h_node* han_u, c3_w lef_w)
{
c3_w len_w = _ch_popcount(han_u->map_w);
c3_w len_w = _ch_v1_popcount(han_u->map_w);
c3_w i_w;

lef_w -= 5;
Expand All @@ -53,9 +53,9 @@ _ch_free_node(u3h_node* han_u, c3_w lef_w)
void* hav_v = u3h_v1_slot_to_node(sot_w);

if ( 0 == lef_w ) {
_ch_free_buck(hav_v);
_ch_v1_free_buck(hav_v);
} else {
_ch_free_node(hav_v, lef_w);
_ch_v1_free_node(hav_v, lef_w);
}
}
}
Expand All @@ -79,17 +79,17 @@ u3h_v1_free(u3p(u3h_root) har_p)
else if ( _(u3h_slot_is_node(sot_w)) ) {
u3h_node* han_u = u3h_slot_to_node(sot_w);

_ch_free_node(han_u, 25);
_ch_v1_free_node(han_u, 25);
}
}
u3a_free(har_u);
}

/* _ch_walk_buck(): walk bucket for gc.
** NB: copy of _ch_walk_buck in pkg/noun/hashtable.c
/* _ch_v1_walk_buck(): walk bucket for gc.
** NB: copy of _ch_v1_walk_buck in pkg/noun/hashtable.c
*/
static void
_ch_walk_buck(u3h_buck* hab_u, void (*fun_f)(u3_noun, void*), void* wit)
_ch_v1_walk_buck(u3h_buck* hab_u, void (*fun_f)(u3_noun, void*), void* wit)
{
c3_w i_w;

Expand All @@ -98,12 +98,12 @@ _ch_walk_buck(u3h_buck* hab_u, void (*fun_f)(u3_noun, void*), void* wit)
}
}

/* _ch_walk_node(): walk node for gc.
/* _ch_v1_walk_node(): walk node for gc.
*/
static void
_ch_walk_node(u3h_node* han_u, c3_w lef_w, void (*fun_f)(u3_noun, void*), void* wit)
_ch_v1_walk_node(u3h_node* han_u, c3_w lef_w, void (*fun_f)(u3_noun, void*), void* wit)
{
c3_w len_w = _ch_popcount(han_u->map_w);
c3_w len_w = _ch_v1_popcount(han_u->map_w);
c3_w i_w;

lef_w -= 5;
Expand All @@ -120,9 +120,9 @@ _ch_walk_node(u3h_node* han_u, c3_w lef_w, void (*fun_f)(u3_noun, void*), void*
void* hav_v = u3h_slot_to_node(sot_w);

if ( 0 == lef_w ) {
_ch_walk_buck(hav_v, fun_f, wit);
_ch_v1_walk_buck(hav_v, fun_f, wit);
} else {
_ch_walk_node(hav_v, lef_w, fun_f, wit);
_ch_v1_walk_node(hav_v, lef_w, fun_f, wit);
}
}
}
Expand Down Expand Up @@ -150,15 +150,15 @@ u3h_v1_walk_with(u3p(u3h_root) har_p,
else if ( _(u3h_slot_is_node(sot_w)) ) {
u3h_node* han_u = u3h_slot_to_node(sot_w);

_ch_walk_node(han_u, 25, fun_f, wit);
_ch_v1_walk_node(han_u, 25, fun_f, wit);
}
}
}

/* _ch_v1_walk_plain(): use plain u3_noun fun_f for each node
/* _ch_v1_v1_walk_plain(): use plain u3_noun fun_f for each node
*/
static void
_ch_v1_walk_plain(u3_noun kev, void* wit)
_ch_v1_v1_walk_plain(u3_noun kev, void* wit)
{
void (*fun_f)(u3_noun) = wit;
fun_f(kev);
Expand All @@ -169,13 +169,13 @@ _ch_v1_walk_plain(u3_noun kev, void* wit)
void
u3h_v1_walk(u3p(u3h_root) har_p, void (*fun_f)(u3_noun))
{
u3h_v1_walk_with(har_p, _ch_v1_walk_plain, fun_f);
u3h_v1_walk_with(har_p, _ch_v1_v1_walk_plain, fun_f);
}

/* _ch_rewrite_buck(): rewrite buck for compaction.
/* _ch_v1_rewrite_buck(): rewrite buck for compaction.
*/
void
_ch_rewrite_buck(u3h_buck* hab_u)
_ch_v1_rewrite_buck(u3h_buck* hab_u)
{
if ( c3n == u3a_rewrite_ptr(hab_u) ) return;
c3_w i_w;
Expand All @@ -187,14 +187,14 @@ _ch_rewrite_buck(u3h_buck* hab_u)
}
}

/* _ch_rewrite_node(): rewrite node for compaction.
/* _ch_v1_rewrite_node(): rewrite node for compaction.
*/
void
_ch_rewrite_node(u3h_node* han_u, c3_w lef_w)
_ch_v1_rewrite_node(u3h_node* han_u, c3_w lef_w)
{
if ( c3n == u3a_rewrite_ptr(han_u) ) return;

c3_w len_w = _ch_popcount(han_u->map_w);
c3_w len_w = _ch_v1_popcount(han_u->map_w);
c3_w i_w;

lef_w -= 5;
Expand All @@ -210,14 +210,14 @@ _ch_rewrite_node(u3h_node* han_u, c3_w lef_w)
}
else {
void* hav_v = u3h_v1_slot_to_node(sot_w);
u3h_node* nod_u = u3to(u3h_node, u3a_v1_rewritten(u3of(u3h_node,hav_v)));
u3h_node* nod_u = u3to(u3h_node, u3a_rewritten(u3of(u3h_node,hav_v)));

han_u->sot_w[i_w] = u3h_v1_node_to_slot(nod_u);

if ( 0 == lef_w ) {
_ch_rewrite_buck(hav_v);
_ch_v1_rewrite_buck(hav_v);
} else {
_ch_rewrite_node(hav_v, lef_w);
_ch_v1_rewrite_node(hav_v, lef_w);
}
}
}
Expand All @@ -244,11 +244,11 @@ u3h_v1_rewrite(u3p(u3h_root) har_p)
}
else if ( _(u3h_slot_is_node(sot_w)) ) {
u3h_node* han_u = u3h_v1_slot_to_node(sot_w);
u3h_node* nod_u = u3to(u3h_node, u3a_v1_rewritten(u3of(u3h_node,han_u)));
u3h_node* nod_u = u3to(u3h_node, u3a_rewritten(u3of(u3h_node,han_u)));

har_u->sot_w[i_w] = u3h_v1_node_to_slot(nod_u);

_ch_rewrite_node(han_u, 25);
_ch_v1_rewrite_node(han_u, 25);
}
}
}
16 changes: 8 additions & 8 deletions pkg/noun/v1/jets.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,24 @@
/** Data structures.
**/

/* _cj_hank: cached hook information.
** NB: copy of _cj_hank from pkg/noun/jets.c
/* _cj_v1_hank: cached hook information.
** NB: copy of _cj_v1_hank from pkg/noun/jets.c
*/
typedef struct {
u3_weak hax; // axis of hooked inner core
u3j_site sit_u; // call-site data
} _cj_hank;
} _cj_v1_hank;

/** Functions.
**/

/* _cj_free_hank(): free an entry from the hank cache.
** NB: copy of _cj_free_hank() from pkg/noun/jets.c
/* _cj_v1_free_hank(): free an entry from the hank cache.
** NB: copy of _cj_v1_free_hank() from pkg/noun/jets.c
*/
static void
_cj_free_hank(u3_noun kev)
_cj_v1_free_hank(u3_noun kev)
{
_cj_hank* han_u = u3to(_cj_hank, u3t(kev));
_cj_v1_hank* han_u = u3to(_cj_v1_hank, u3t(kev));
if ( u3_none != han_u->hax ) {
u3z(han_u->hax);
u3j_site_lose(&(han_u->sit_u));
Expand All @@ -51,7 +51,7 @@ u3j_v1_reclaim(void)

// clear the jet hank cache
//
u3h_v1_walk(u3R->jed.han_p, _cj_free_hank);
u3h_v1_walk(u3R->jed.han_p, _cj_v1_free_hank);
u3h_v1_free(u3R->jed.han_p);
u3R->jed.han_p = u3h_new();
}
Expand Down
20 changes: 20 additions & 0 deletions pkg/noun/v1/nock.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,23 @@ u3n_v1_free()
u3h_v1_walk(har_p, _n_feb);
u3h_v1_free(har_p);
}

/* u3n_v1_rewrite_compact(): rewrite the bytecode cache for compaction.
*
* NB: u3R->byc.har_p *must* be cleared (currently via u3n_v1_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.
*
* 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
* 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?).
*/
void
u3n_v1_rewrite_compact()
{
u3h_v1_rewrite(u3R->byc.har_p);
u3R->byc.har_p = u3a_rewritten(u3R->byc.har_p);
}
4 changes: 2 additions & 2 deletions pkg/noun/v2/allocate.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ u3a_v2_rewrite_compact(void)
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_v2_rewritten(u3R->cax.har_p);
u3R->pro.trace = u3a_rewritten_noun(u3R->pro.trace);
u3R->cax.har_p = u3a_rewritten(u3R->cax.har_p);
}

void
Expand Down
Loading

0 comments on commit f35cd83

Please sign in to comment.