Skip to content

Commit

Permalink
wip: working with aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-levan committed Sep 14, 2023
1 parent b2151d2 commit 94e7801
Show file tree
Hide file tree
Showing 12 changed files with 12 additions and 98 deletions.
10 changes: 0 additions & 10 deletions pkg/noun/allocate.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,6 @@ u3_road* u3a_Road;
c3_w u3_Code;
#endif

// declarations of inline functions
//
void *u3a_into(c3_w x);
c3_w u3a_outa(void *p);
c3_w u3a_to_off(c3_w som);
void *u3a_to_ptr(c3_w som);
c3_w *u3a_to_wtr(c3_w som);
c3_w u3a_to_pug(c3_w off);
c3_w u3a_to_pom(c3_w off);

void
u3a_drop(const u3a_pile* pil_u);
void*
Expand Down
31 changes: 7 additions & 24 deletions pkg/noun/allocate.h
Original file line number Diff line number Diff line change
Expand Up @@ -384,48 +384,31 @@
**/
/* u3a_into(): convert loom offset [x] into generic pointer.
*/
inline void *u3a_into(c3_w x) {
return u3_Loom + x;
}
# define u3a_into(x) (u3_Loom + (x))

/* u3a_outa(): convert pointer [p] into word offset into loom.
*/
inline c3_w u3a_outa(void *p) {
return ((c3_w *)p) - u3_Loom;
}
# define u3a_outa(p) ((c3_w *)(void *)(p) - u3_Loom)

/* u3a_to_off(): mask off bits 30 and 31 from noun [som].
*/
inline c3_w u3a_to_off(c3_w som) {
return (som & 0x3fffffff) << u3a_vits;
}
# define u3a_to_off(som) (((som) & 0x3fffffff) << u3a_vits)

/* u3a_to_ptr(): convert noun [som] into generic pointer into loom.
*/
inline void *u3a_to_ptr(c3_w som) {
return u3a_into(u3a_to_off(som));
}
# define u3a_to_ptr(som) (u3a_into(u3a_to_off(som)))

/* u3a_to_wtr(): convert noun [som] into word pointer into loom.
*/
inline c3_w *u3a_to_wtr(c3_w som) {
return (c3_w *)u3a_to_ptr(som);
}
# define u3a_to_wtr(som) ((c3_w *)u3a_to_ptr(som))

/* u3a_to_pug(): set bit 31 of [off].
*/
inline c3_w u3a_to_pug(c3_w off) {
c3_dessert((off & u3a_walign-1) == 0);
return (off >> u3a_vits) | 0x80000000;
}
# define u3a_to_pug(off) ((off >> u3a_vits) | 0x80000000)

/* u3a_to_pom(): set bits 30 and 31 of [off].
*/
/* # define u3a_to_pom(off) (off | 0xc0000000) */
inline c3_w u3a_to_pom(c3_w off) {
c3_dessert((off & u3a_walign-1) == 0);
return (off >> u3a_vits) | 0xc0000000;
}
# define u3a_to_pom(off) ((off >> u3a_vits) | 0xc0000000)

/** road stack.
**/
Expand Down
2 changes: 0 additions & 2 deletions pkg/noun/manage.c
Original file line number Diff line number Diff line change
Expand Up @@ -650,8 +650,6 @@ _find_home(void)
u3a_loom_sane();

_rod_vaal(u3R);
// u3m_pack();
fprintf(stderr, "hi\r\n");
}

/* u3m_pave(): instantiate or activate image.
Expand Down
4 changes: 2 additions & 2 deletions pkg/noun/v1/hashtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ u3h_v1_free(u3p(u3h_v1_root) har_p)
u3a_v1_lose(u3h_v1_slot_to_noun(sot_w));
}
else if ( _(u3h_v1_slot_is_node(sot_w)) ) {
u3h_v1_node* han_u = u3h_v1_slot_to_node(sot_w);
u3h_v1_node* han_u = (u3h_v1_node*) u3h_v1_slot_to_node(sot_w);

_ch_v1_free_node(han_u, 25);
}
Expand Down Expand Up @@ -145,7 +145,7 @@ u3h_v1_walk_with(u3p(u3h_v1_root) har_p,
fun_f(kev, wit);
}
else if ( _(u3h_v1_slot_is_node(sot_w)) ) {
u3h_v1_node* han_u = u3h_v1_slot_to_node(sot_w);
u3h_v1_node* han_u = (u3h_v1_node*) u3h_v1_slot_to_node(sot_w);

_ch_v1_walk_node(han_u, 25, fun_f, wit);
}
Expand Down
2 changes: 0 additions & 2 deletions pkg/noun/v1/hashtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@
/** Aliases.
**/
# define u3h_v1_buck u3h_v2_buck
# define u3h_v1_free u3h_free
# define u3h_v1_new u3h_new
# define u3h_v1_node u3h_v2_node
# define u3h_v1_root u3h_v2_root
# define u3h_v1_slot_is_node u3h_v2_slot_is_node
# define u3h_v1_slot_is_noun u3h_v2_slot_is_noun
# define u3h_v1_slot_to_noun u3h_v2_slot_to_noun
# define u3h_v1_walk u3h_v2_walk

/** Data structures.
**/
Expand Down
2 changes: 1 addition & 1 deletion pkg/noun/v1/jets.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ u3j_v1_site_lose(u3j_v1_site* sit_u)
static void
_cj_v1_free_hank(u3_noun kev)
{
u3a_v1_cell* cel_u = u3a_v1_to_ptr(kev);
u3a_v1_cell* cel_u = (u3a_v1_cell*) u3a_v1_to_ptr(kev);
_cj_v1_hank* han_u = u3to(_cj_v1_hank, cel_u->tel);
if ( u3_none != han_u->hax ) {
u3a_v1_lose(han_u->hax);
Expand Down
2 changes: 0 additions & 2 deletions pkg/noun/v1/jets.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@
# define u3j_v1_fink u3j_fink
# define u3j_v1_fist u3j_fist
# define u3j_v1_ream u3j_ream
# define u3j_v1_reclaim u3j_reclaim
# define u3j_v1_rite u3j_rite
# define u3j_v1_site u3j_v2_site
# define u3j_v1_site_lose u3j_v2_site_lose

/** Functions.
**/
Expand Down
2 changes: 1 addition & 1 deletion pkg/noun/v1/nock.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ _cn_prog_free(u3n_v1_prog* pog_u)
static void
_n_feb(u3_noun kev)
{
u3a_v1_cell *cel_u = u3a_v1_to_ptr(kev);
u3a_v1_cell *cel_u = (u3a_v1_cell*) u3a_v1_to_ptr(kev);
_cn_prog_free(u3to(u3n_v1_prog, cel_u->tel));
}

Expand Down
1 change: 0 additions & 1 deletion pkg/noun/v1/nock.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

/** Aliases.
**/
# define u3n_v1_free u3n_v2_free
# define u3n_v1_prog u3n_v2_prog

/** Functions.
Expand Down
12 changes: 1 addition & 11 deletions pkg/noun/v2/allocate.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,6 @@
#include "trace.h"
#include "vortex.h"

// declarations of inline functions
//
void *u3a_v2_into(c3_w x);
c3_w u3a_v2_outa(void *p);
c3_w u3a_v2_to_off(c3_w som);
void *u3a_v2_to_ptr(c3_w som);
c3_w *u3a_v2_to_wtr(c3_w som);
c3_w u3a_v2_to_pug(c3_w off);
c3_w u3a_v2_to_pom(c3_w off);

u3_noun
u3a_v2_rewritten_noun(u3_noun som)
{
Expand Down Expand Up @@ -71,7 +61,7 @@ u3a_v2_rewrite_noun(u3_noun som)

if ( c3n == u3a_v2_rewrite_ptr(u3a_v1_to_ptr((som))) ) return;

u3a_v2_cell* cel = u3a_v1_to_ptr(som);
u3a_v2_cell* cel = (u3a_v2_cell*) u3a_v1_to_ptr(som);

u3a_v2_rewrite_noun(cel->hed);
u3a_v2_rewrite_noun(cel->tel);
Expand Down
1 change: 0 additions & 1 deletion pkg/noun/v2/hashtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#define u3h_v2_slot_is_node u3h_slot_is_node
#define u3h_v2_slot_is_noun u3h_slot_is_noun
#define u3h_v2_slot_to_noun u3h_slot_to_noun
#define u3h_v2_walk u3h_walk

#include "pkg/noun/hashtable.h"

Expand Down
41 changes: 0 additions & 41 deletions pkg/noun/v2/nock.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,47 +7,6 @@
#include "pkg/noun/v2/hashtable.h"
#include "pkg/noun/v2/vortex.h"

/* _cn_prog_free(): free memory retained by program pog_u
** NB: copy of _cn_prog_free in pkg/noun/nock.c
*/
static void
_cn_prog_free(u3n_v2_prog* pog_u)
{
c3_w dex_w;
for (dex_w = 0; dex_w < pog_u->lit_u.len_w; ++dex_w) {
u3z(pog_u->lit_u.non[dex_w]);
}
for (dex_w = 0; dex_w < pog_u->mem_u.len_w; ++dex_w) {
u3z(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_feb(): u3h_v2_walk helper for u3n_v2_free
*/
static void
_n_feb(u3_noun kev)
{
_cn_prog_free(u3to(u3n_v2_prog, u3t(kev)));
}

/* 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_feb);
u3h_v2_free(har_p);
}

/* u3n_v2_rewrite_compact(): rewrite the bytecode cache for compaction.
*
* NB: u3R_v2->byc.har_p *must* be cleared (currently via u3n_v2_reclaim above),
Expand Down

0 comments on commit 94e7801

Please sign in to comment.