Skip to content

Commit

Permalink
loom: v3 migration
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-levan committed Sep 19, 2023
1 parent 174f910 commit 70ec094
Show file tree
Hide file tree
Showing 28 changed files with 333 additions and 110 deletions.
8 changes: 5 additions & 3 deletions pkg/noun/allocate.c
Original file line number Diff line number Diff line change
Expand Up @@ -2159,6 +2159,7 @@ u3a_rewrite_compact(void)
u3a_rewrite_noun(u3R->pro.day);
u3a_rewrite_noun(u3R->pro.trace);
u3h_rewrite(u3R->cax.har_p);
u3h_rewrite(u3R->cax.per_p);

u3R->ski.gul = u3a_rewritten_noun(u3R->ski.gul);
u3R->bug.tax = u3a_rewritten_noun(u3R->bug.tax);
Expand All @@ -2167,6 +2168,7 @@ u3a_rewrite_compact(void)
u3R->pro.day = u3a_rewritten_noun(u3R->pro.day);
u3R->pro.trace = u3a_rewritten_noun(u3R->pro.trace);
u3R->cax.har_p = u3a_rewritten(u3R->cax.har_p);
u3R->cax.per_p = u3a_rewritten(u3R->cax.per_p);
}

/* _ca_print_box(): heuristically print the contents of an allocation box.
Expand Down Expand Up @@ -2268,9 +2270,9 @@ _ca_print_leak(c3_c* cap_c, u3a_box* box_u, c3_ws use_ws)
u3a_print_memory(stderr, " size", box_u->siz_w);

{
c3_c* dat_c = _ca_print_box(box_u);
fprintf(stderr, " data: %s\r\n", dat_c);
c3_free(dat_c);
// c3_c* dat_c = _ca_print_box(box_u);
// fprintf(stderr, " data: %s\r\n", dat_c);
// c3_free(dat_c);
}
}

Expand Down
8 changes: 5 additions & 3 deletions pkg/noun/allocate.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,11 @@
u3_noun day; // doss, only in u3H (moveme)
} pro;

struct { // transient/persistent memoization
u3p(u3h_root) har_p; // (map (pair term noun) noun)
u3p(u3h_root) per_p; // (map (pair term noun) noun)
struct { // memoization caches
u3p(u3h_root) har_p; // transient
u3p(u3h_root) per_p; // persistent
// u3p(u3h_root) fod_p; // ford
// u3p(u3h_root) sam_p; // ames
} cax;
} u3a_road;
typedef u3a_road u3_road;
Expand Down
65 changes: 28 additions & 37 deletions pkg/noun/jets.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,6 @@
#include "vortex.h"
#include "xtract.h"

/** Data structures.
**/

/* _cj_hank: cached hook information.
*/
typedef struct {
u3_weak hax; // axis of hooked inner core
u3j_site sit_u; // call-site data
} _cj_hank;

/** Functions.
**/
Expand Down Expand Up @@ -1069,18 +1060,18 @@ _cj_prog(u3_weak loc, u3_noun fol)
/* cj_hank_find(): find cached hook information, keyed by arbitrary
* prefix and term cords. RETAIN.
*/
static _cj_hank*
static u3j_hank*
_cj_hank_find(u3_noun pre, u3_noun tam)
{
u3_noun key = u3nc(u3k(pre), u3k(tam));
u3_noun got = u3h_git(u3R->jed.han_p, key);

if ( u3_none != got ) {
u3z(key);
return u3to(_cj_hank, got);
return u3to(u3j_hank, got);
}
else {
_cj_hank* new_u = u3a_walloc(c3_wiseof(_cj_hank));
u3j_hank* new_u = u3a_walloc(c3_wiseof(u3j_hank));
u3a_road* rod_u = u3R;

while ( rod_u->par_p && u3_none == got ) {
Expand All @@ -1092,7 +1083,7 @@ _cj_hank_find(u3_noun pre, u3_noun tam)
new_u->hax = u3_none;
}
else {
_cj_hank* old_u = u3to(_cj_hank, got);
u3j_hank* old_u = u3to(u3j_hank, got);
if ( u3_none != (new_u->hax = old_u->hax) ) {
// it's unusual but safe to "take" here, because
// u3a_take will no-op on senior nouns (just as u3k would)
Expand All @@ -1101,7 +1092,7 @@ _cj_hank_find(u3_noun pre, u3_noun tam)
}
}

u3h_put(u3R->jed.han_p, key, u3of(_cj_hank, new_u));
u3h_put(u3R->jed.han_p, key, u3of(u3j_hank, new_u));
u3z(key);
return new_u;
}
Expand All @@ -1112,7 +1103,7 @@ _cj_hank_find(u3_noun pre, u3_noun tam)
* core on return if valid. RETAIN.
*/
static c3_o
_cj_hank_fine(_cj_hank* han_u, u3_noun cor, u3_noun *inn)
_cj_hank_fine(u3j_hank* han_u, u3_noun cor, u3_noun *inn)
{
u3_noun hax = han_u->hax;
if ( u3_none == hax ) {
Expand All @@ -1134,7 +1125,7 @@ _cj_hank_fine(_cj_hank* han_u, u3_noun cor, u3_noun *inn)
/* _cj_hank_lose(): release memory maintained in a hook cache.
*/
static void
_cj_hank_lose(_cj_hank* han_u)
_cj_hank_lose(u3j_hank* han_u)
{
if ( u3_none != han_u->hax ) {
u3z(han_u->hax);
Expand All @@ -1145,7 +1136,7 @@ _cj_hank_lose(_cj_hank* han_u)
/* _cj_hank_fill(): slow path, populate han_u.
*/
static u3_noun
_cj_hank_fill(_cj_hank* han_u, u3_noun tam, u3_noun cor)
_cj_hank_fill(u3j_hank* han_u, u3_noun tam, u3_noun cor)
{
u3_weak loc, col;
u3_noun got, pat, nam, huc;
Expand Down Expand Up @@ -1642,7 +1633,7 @@ u3j_cook(const c3_c* key_c,
const c3_c* tam_c)
{
u3_noun pro, key, tam, inn;
_cj_hank* han_u;
u3j_hank* han_u;

u3t_on(glu_o);
key = u3i_string(key_c);
Expand Down Expand Up @@ -1992,11 +1983,11 @@ u3j_rite_mine(u3j_rite* rit_u, u3_noun clu, u3_noun cor)

/* _cj_take_hank_cb(): u3h_take_with cb for taking hanks
*/
static u3p(_cj_hank)
_cj_take_hank_cb(u3p(_cj_hank) nah_p)
static u3p(u3j_hank)
_cj_take_hank_cb(u3p(u3j_hank) nah_p)
{
_cj_hank* nah_u = u3to(_cj_hank, nah_p);
_cj_hank* han_u = u3a_walloc(c3_wiseof(_cj_hank));
u3j_hank* nah_u = u3to(u3j_hank, nah_p);
u3j_hank* han_u = u3a_walloc(c3_wiseof(u3j_hank));

if ( u3_none == nah_u->hax ) {
han_u->hax = u3_none;
Expand All @@ -2007,7 +1998,7 @@ _cj_take_hank_cb(u3p(_cj_hank) nah_p)
u3j_site_take(&(han_u->sit_u), &(nah_u->sit_u));
}

return u3of(_cj_hank, han_u);
return u3of(u3j_hank, han_u);
}

/* u3j_take(): copy junior jet state.
Expand All @@ -2029,25 +2020,25 @@ static void
_cj_merge_hank_cb(u3_noun kev, void* wit)
{
u3p(u3h_root) han_p = *(u3p(u3h_root)*)wit;
_cj_hank* nah_u;
u3j_hank* nah_u;
u3_noun key;
u3p(_cj_hank) nah_p;
u3p(u3j_hank) nah_p;
u3x_cell(kev, &key, &nah_p);

nah_u = u3to(_cj_hank, nah_p);
nah_u = u3to(u3j_hank, nah_p);

if ( u3_none == nah_u->hax ) {
u3a_wfree(nah_u);
}
else {
_cj_hank* han_u;
u3j_hank* han_u;
u3_weak got = u3h_git(u3R->jed.han_p, key);

if ( u3_none == got ) {
han_u = nah_u;
}
else {
han_u = u3to(_cj_hank, got);
han_u = u3to(u3j_hank, got);

if ( u3_none != han_u->hax ) {
u3z(han_u->hax);
Expand All @@ -2058,7 +2049,7 @@ _cj_merge_hank_cb(u3_noun kev, void* wit)
u3a_wfree(nah_u);
}

u3h_put(han_p, key, u3of(_cj_hank, han_u));
u3h_put(han_p, key, u3of(u3j_hank, han_u));
}
}

Expand Down Expand Up @@ -2170,7 +2161,7 @@ _cj_warm_tap(u3_noun kev, void* wit)
static void
_cj_ream_hank(u3_noun kev)
{
u3j_site_ream(&(u3to(_cj_hank, u3t(kev))->sit_u));
u3j_site_ream(&(u3to(u3j_hank, u3t(kev))->sit_u));
}

/* u3j_ream(): rebuild warm state
Expand Down Expand Up @@ -2304,7 +2295,7 @@ static void
_cj_mark_hank(u3_noun kev, void* dat)
{
c3_w* tot_w = (c3_w*) dat;
_cj_hank* han_u = u3to(_cj_hank, u3t(kev));
u3j_hank* han_u = u3to(u3j_hank, u3t(kev));
*tot_w += u3a_mark_ptr(han_u);
if ( u3_none != han_u->hax ) {
*tot_w += u3a_mark_noun(han_u->hax);
Expand Down Expand Up @@ -2337,12 +2328,12 @@ u3j_mark(FILE* fil_u)
return u3a_maid(fil_u, "total jet stuff", tot_w);
}

/* _cj_free_hank(): free an entry from the hank cache.
/* u3j_free_hank(): free an entry from the hank cache.
*/
static void
_cj_free_hank(u3_noun kev)
void
u3j_free_hank(u3_noun kev)
{
_cj_hank* han_u = u3to(_cj_hank, u3t(kev));
u3j_hank* han_u = u3to(u3j_hank, u3t(kev));
if ( u3_none != han_u->hax ) {
u3z(han_u->hax);
u3j_site_lose(&(han_u->sit_u));
Expand All @@ -2355,7 +2346,7 @@ _cj_free_hank(u3_noun kev)
void
u3j_free(void)
{
u3h_walk(u3R->jed.han_p, _cj_free_hank);
u3h_walk(u3R->jed.han_p, u3j_free_hank);
u3h_free(u3R->jed.war_p);
u3h_free(u3R->jed.cod_p);
u3h_free(u3R->jed.han_p);
Expand All @@ -2379,7 +2370,7 @@ u3j_reclaim(void)
// }
// clear the jet hank cache
//
u3h_walk(u3R->jed.han_p, _cj_free_hank);
u3h_walk(u3R->jed.han_p, u3j_free_hank);
u3h_free(u3R->jed.han_p);
u3R->jed.han_p = u3h_new();
}
Expand Down
12 changes: 12 additions & 0 deletions pkg/noun/jets.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@
u3p(u3j_fink) fin_p; // fine check
} u3j_site;

/* u3j_hank: cached hook information.
*/
typedef struct {
u3_weak hax; // axis of hooked inner core
u3j_site sit_u; // call-site data
} u3j_hank;

/** Globals.
**/
/* u3_Dash: jet dashboard.
Expand Down Expand Up @@ -297,6 +304,11 @@
void
u3j_free(void);

/* u3j_free_hank(): free an entry from the hank cache.
*/
void
u3j_free_hank(u3_noun kev);

/* u3j_reclaim(): clear ad-hoc persistent caches to reclaim memory.
*/
void
Expand Down
9 changes: 5 additions & 4 deletions pkg/noun/manage.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/// @file

#include "manage.h"
#include "pkg/noun/manage.h"
#include "pkg/noun/v2/manage.h"
#include "pkg/noun/v3/manage.h"

#include <ctype.h>
#include <errno.h>
Expand All @@ -23,7 +25,6 @@
#include "urcrypt/urcrypt.h"
#include "vortex.h"
#include "xtract.h"
#include "zave.h"

// XX stack-overflow recovery should be gated by -a
//
Expand Down Expand Up @@ -597,7 +598,8 @@ _find_home(void)

switch ( ver_w ) {
case 1: u3m_v2_migrate();
case 2: break;
case 2: u3m_v3_migrate();
case 3: break;
default: {
fprintf(stderr, "loom: checkpoint version mismatch: "
"have %u, need %u\r\n",
Expand Down Expand Up @@ -2128,7 +2130,6 @@ u3m_boot(c3_c* dir_c, size_t len_i)
if ( c3n == nuu_o ) {
u3j_ream();
u3n_ream();
// u3z_ream();
return u3A->eve_d;
}
else {
Expand Down
17 changes: 8 additions & 9 deletions pkg/noun/nock.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include "vortex.h"
#include "xtract.h"
#include "zave.h"
#include "log.h"

// define to have each opcode printed as it executes,
// along with some other debugging info
Expand Down Expand Up @@ -1128,9 +1127,11 @@ _n_bint(u3_noun* ops, u3_noun hif, u3_noun nef, c3_o los_o, c3_o tel_o)

op_y = (c3y == los_o) ? SLIB : SKIB; // overflows to SLIS / SKIS
u3z_cid cid = u3z_memo_toss;
hod = u3r_skip(hod);
if ( c3y == u3du(hod) ) {
cid = u3z_memo_keep;
{
u3_weak con = u3r_skip(hod);
if ( (u3_none != con) && (c3y == u3du(con)) ) {
cid = u3z_memo_keep;
}
}
++tot_w; _n_emit(ops, u3nq(op_y, cid, mem_w, u3k(nef)));
tot_w += mem_w; _n_apen(ops, mem);
Expand Down Expand Up @@ -2634,13 +2635,11 @@ _n_burn(u3n_prog* pog_u, u3_noun bus, c3_ys mov, c3_ys off)
o = *top;
if ( ( u3z_memo_toss == u3h(o) )
? ( &(u3H->rod_u) != u3R )
// : ( 0 == u3R->ski.gul ) ) { // prevents userspace from persistence
: ( 1 ) ) { // prevents userspace from persistence
: ( 0 == u3R->ski.gul ) ) { // prevents userspace from persistence
u3z_save_m(u3h(o), 144 + c3__nock, u3t(o), x);
}
else if ( ( u3z_memo_keep == u3h(o) ) &&
( 0 != u3R->ski.gul ) ) {
u3l_log("nock: userspace can't save to persistent cache\r\n");
else if ( u3z_memo_keep == u3h(o) ) {
fprintf(stderr, "\r\nnock: userspace can't save to persistent cache\r\n");
}
*top = x;
u3z(o);
Expand Down
29 changes: 10 additions & 19 deletions pkg/noun/retrieve.c
Original file line number Diff line number Diff line change
Expand Up @@ -1908,32 +1908,23 @@ u3r_mug(u3_noun veb)
**
** Extract a constant from a formula, ignoring
** safe/static hints, doing no computation.
**
*/
u3_weak u3r_skip(u3_noun fol) {
while ( 1 ) {
if ( c3n == u3du(fol) ) {
return u3_none;
}
else switch ( u3h(fol) ) {
default:
return u3_none;
case 1:
return u3k(u3t(fol));
u3_weak
u3r_skip(u3_noun fol) {
while ( c3y == u3du(fol) ) {
switch ( u3h(fol) ) {
default: return u3_none;
case 1: return u3t(fol);
case 11: {
u3_noun arg = u3t(fol),
hod = u3h(arg);

if ( c3y == u3du(hod) ) {
u3_weak dug = u3r_skip(u3t(hod));
if ( u3_none == dug ) {
return u3_none;
}
u3z(dug);
if ( (c3y == u3du(hod)) && (u3_none == u3r_skip(u3t(hod))) ) {
return u3_none;
}
fol = u3t(arg);
continue;
}
}
}
}
return u3_none;
}
Loading

0 comments on commit 70ec094

Please sign in to comment.