Skip to content

Commit

Permalink
wip: aliases, but doesn't build due to duplicate symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-levan committed Sep 14, 2023
1 parent 591ea02 commit b2151d2
Show file tree
Hide file tree
Showing 25 changed files with 357 additions and 321 deletions.
3 changes: 1 addition & 2 deletions pkg/noun/allocate.h
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,7 @@

# define u3_Loom ((c3_w *)(void *)U3_OS_LoomBase)

/** inline functions.
** ;;: func-like-macros doing pointer conversion -> inline
/** Inline functions.
**/
/* u3a_into(): convert loom offset [x] into generic pointer.
*/
Expand Down
20 changes: 10 additions & 10 deletions pkg/noun/v1/allocate.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ u3a_v1_reclaim(void)
// clear the memoization cache
//
u3h_v1_free(u3R->cax.har_p);
u3R->cax.har_p = u3h_new();
u3R->cax.har_p = u3h_v1_new();
}

/* _me_lose_north(): lose on a north road.
Expand All @@ -24,32 +24,32 @@ _me_lose_north(u3_noun dog)
top:
{
c3_w* dog_w = u3a_v1_to_ptr(dog);
u3a_box* box_u = u3a_botox(dog_w);
u3a_v1_box* box_u = u3a_v1_botox(dog_w);

if ( box_u->use_w > 1 ) {
box_u->use_w -= 1;
}
else {
if ( 0 == box_u->use_w ) {
u3m_bail(c3__foul);
u3m_v1_bail(c3__foul);
}
else {
if ( _(u3a_is_pom(dog)) ) {
u3a_cell* dog_u = (void *)dog_w;
if ( _(u3a_v1_is_pom(dog)) ) {
u3a_v1_cell* dog_u = (void *)dog_w;
u3_noun h_dog = dog_u->hed;
u3_noun t_dog = dog_u->tel;

if ( !_(u3a_is_cat(h_dog)) ) {
if ( !_(u3a_v1_is_cat(h_dog)) ) {
_me_lose_north(h_dog);
}
u3a_wfree(dog_w);
if ( !_(u3a_is_cat(t_dog)) ) {
u3a_v1_wfree(dog_w);
if ( !_(u3a_v1_is_cat(t_dog)) ) {
dog = t_dog;
goto top;
}
}
else {
u3a_wfree(dog_w);
u3a_v1_wfree(dog_w);
}
}
}
Expand All @@ -61,7 +61,7 @@ _me_lose_north(u3_noun dog)
void
u3a_v1_lose(u3_noun som)
{
if ( !_(u3a_is_cat(som)) ) {
if ( !_(u3a_v1_is_cat(som)) ) {
_me_lose_north(som);
}
}
17 changes: 13 additions & 4 deletions pkg/noun/v1/allocate.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,33 @@
#define U3_ALLOCATE_V1_H

#include "pkg/noun/allocate.h"
#include "pkg/noun/v2/allocate.h"

/** Constants.
/** Aliases.
**/
# define u3R_v1 u3R_v2
# define u3a_v1_botox u3a_v2_botox
# define u3a_v1_box u3a_v2_box
# define u3a_v1_cell u3a_v2_cell
# define u3a_v1_free u3a_v2_free
# define u3a_v1_into u3a_v2_into
# define u3a_v1_is_cat u3a_v2_is_cat
# define u3a_v1_is_pom u3a_is_pom
# define u3a_v1_wfree u3a_v2_wfree

/** Structures.
**/
/** Macros. Should be better commented.
**/
/* Inside a noun.
*/

/* u3a_to_off(): mask off bits 30 and 31 from noun [som].
/* u3a_v1_to_off(): mask off bits 30 and 31 from noun [som].
*/
# define u3a_v1_to_off(som) ((som) & 0x3fffffff)

/* u3a_v1_to_ptr(): convert noun [som] into generic pointer into loom.
*/
# define u3a_v1_to_ptr(som) (u3a_into(u3a_v1_to_off(som)))
# define u3a_v1_to_ptr(som) (u3a_v1_into(u3a_v1_to_off(som)))

/* u3a_v1_to_wtr(): convert noun [som] into word pointer into loom.
*/
Expand Down
52 changes: 26 additions & 26 deletions pkg/noun/v1/hashtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ _ch_v1_popcount(c3_w num_w)
** NB: copy of _ch_v1_free_buck in pkg/noun/hashtable.c
*/
static void
_ch_v1_free_buck(u3h_buck* hab_u)
_ch_v1_free_buck(u3h_v1_buck* hab_u)
{
c3_w i_w;

for ( i_w = 0; i_w < hab_u->len_w; i_w++ ) {
u3a_v1_lose(u3h_slot_to_noun(hab_u->sot_w[i_w]));
u3a_v1_lose(u3h_v1_slot_to_noun(hab_u->sot_w[i_w]));
}
u3a_wfree(hab_u);
u3a_v1_wfree(hab_u);
}

/* _ch_v1_free_node(): free node.
*/
static void
_ch_v1_free_node(u3h_node* han_u, c3_w lef_w)
_ch_v1_free_node(u3h_v1_node* han_u, c3_w lef_w)
{
c3_w len_w = _ch_v1_popcount(han_u->map_w);
c3_w i_w;
Expand All @@ -43,8 +43,8 @@ _ch_v1_free_node(u3h_node* han_u, c3_w lef_w)
for ( i_w = 0; i_w < len_w; i_w++ ) {
c3_w sot_w = han_u->sot_w[i_w];

if ( _(u3h_slot_is_noun(sot_w)) ) {
u3a_v1_lose(u3h_slot_to_noun(sot_w));
if ( _(u3h_v1_slot_is_noun(sot_w)) ) {
u3a_v1_lose(u3h_v1_slot_to_noun(sot_w));
}
else {
void* hav_v = u3h_v1_slot_to_node(sot_w);
Expand All @@ -56,49 +56,49 @@ _ch_v1_free_node(u3h_node* han_u, c3_w lef_w)
}
}
}
u3a_wfree(han_u);
u3a_v1_wfree(han_u);
}

/* u3h_v1_free(): free hashtable.
*/
void
u3h_v1_free(u3p(u3h_root) har_p)
u3h_v1_free(u3p(u3h_v1_root) har_p)
{
u3h_root* har_u = u3to(u3h_root, har_p);
u3h_v1_root* har_u = u3to(u3h_v1_root, har_p);
c3_w i_w;

for ( i_w = 0; i_w < 64; i_w++ ) {
c3_w sot_w = har_u->sot_w[i_w];

if ( _(u3h_slot_is_noun(sot_w)) ) {
u3a_v1_lose(u3h_slot_to_noun(sot_w));
if ( _(u3h_v1_slot_is_noun(sot_w)) ) {
u3a_v1_lose(u3h_v1_slot_to_noun(sot_w));
}
else if ( _(u3h_slot_is_node(sot_w)) ) {
u3h_node* han_u = u3h_v1_slot_to_node(sot_w);
else if ( _(u3h_v1_slot_is_node(sot_w)) ) {
u3h_v1_node* han_u = u3h_v1_slot_to_node(sot_w);

_ch_v1_free_node(han_u, 25);
}
}
u3a_wfree(har_u);
u3a_v1_wfree(har_u);
}

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

for ( i_w = 0; i_w < hab_u->len_w; i_w++ ) {
fun_f(u3h_slot_to_noun(hab_u->sot_w[i_w]), wit);
fun_f(u3h_v1_slot_to_noun(hab_u->sot_w[i_w]), wit);
}
}

/* _ch_v1_walk_node(): walk node for gc.
*/
static void
_ch_v1_walk_node(u3h_node* han_u, c3_w lef_w, void (*fun_f)(u3_noun, void*), void* wit)
_ch_v1_walk_node(u3h_v1_node* han_u, c3_w lef_w, void (*fun_f)(u3_noun, void*), void* wit)
{
c3_w len_w = _ch_v1_popcount(han_u->map_w);
c3_w i_w;
Expand All @@ -108,8 +108,8 @@ _ch_v1_walk_node(u3h_node* han_u, c3_w lef_w, void (*fun_f)(u3_noun, void*), voi
for ( i_w = 0; i_w < len_w; i_w++ ) {
c3_w sot_w = han_u->sot_w[i_w];

if ( _(u3h_slot_is_noun(sot_w)) ) {
u3_noun kev = u3h_slot_to_noun(sot_w);
if ( _(u3h_v1_slot_is_noun(sot_w)) ) {
u3_noun kev = u3h_v1_slot_to_noun(sot_w);

fun_f(kev, wit);
}
Expand All @@ -129,23 +129,23 @@ _ch_v1_walk_node(u3h_node* han_u, c3_w lef_w, void (*fun_f)(u3_noun, void*), voi
* argument; RETAINS.
*/
void
u3h_v1_walk_with(u3p(u3h_root) har_p,
u3h_v1_walk_with(u3p(u3h_v1_root) har_p,
void (*fun_f)(u3_noun, void*),
void* wit)
{
u3h_root* har_u = u3to(u3h_root, har_p);
u3h_v1_root* har_u = u3to(u3h_v1_root, har_p);
c3_w i_w;

for ( i_w = 0; i_w < 64; i_w++ ) {
c3_w sot_w = har_u->sot_w[i_w];

if ( _(u3h_slot_is_noun(sot_w)) ) {
u3_noun kev = u3h_slot_to_noun(sot_w);
if ( _(u3h_v1_slot_is_noun(sot_w)) ) {
u3_noun kev = u3h_v1_slot_to_noun(sot_w);

fun_f(kev, wit);
}
else if ( _(u3h_slot_is_node(sot_w)) ) {
u3h_node* han_u = u3h_v1_slot_to_node(sot_w);
else if ( _(u3h_v1_slot_is_node(sot_w)) ) {
u3h_v1_node* han_u = u3h_v1_slot_to_node(sot_w);

_ch_v1_walk_node(han_u, 25, fun_f, wit);
}
Expand All @@ -164,7 +164,7 @@ _ch_v1_walk_plain(u3_noun kev, void* wit)
/* u3h_v1_walk(): u3h_v1_walk_with, but with no data argument
*/
void
u3h_v1_walk(u3p(u3h_root) har_p, void (*fun_f)(u3_noun))
u3h_v1_walk(u3p(u3h_v1_root) har_p, void (*fun_f)(u3_noun))
{
u3h_v1_walk_with(har_p, _ch_v1_walk_plain, fun_f);
}
17 changes: 15 additions & 2 deletions pkg/noun/v1/hashtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@
#define U3_HASHTABLE_V1_H

#include "pkg/noun/hashtable.h"
#include "pkg/noun/v2/hashtable.h"

/** 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 All @@ -13,8 +26,8 @@
/* u3h_v1_slot_to_node(): slot to node pointer
** u3h_v1_node_to_slot(): node pointer to slot
*/
# define u3h_v1_slot_to_node(sot) (u3a_into((sot) & 0x3fffffff))
# define u3h_v1_node_to_slot(ptr) (u3a_outa(ptr) | 0x40000000)
# define u3h_v1_slot_to_node(sot) (u3a_v1_into((sot) & 0x3fffffff))
# define u3h_v1_node_to_slot(ptr) (u3a_v1_outa(ptr) | 0x40000000)

/** Functions.
***
Expand Down
Loading

0 comments on commit b2151d2

Please sign in to comment.