Skip to content

Commit

Permalink
retrieve_tests work through h
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-levan committed Sep 5, 2024
1 parent dc43203 commit f8cd976
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 22 deletions.
11 changes: 4 additions & 7 deletions pkg/noun/imprison.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ u3i_slab_init(u3i_slab* sab_u, c3_g met_g, c3_d len_d)
u3i_slab_bare(sab_u, met_g, len_d);

u3t_on(mal_o);
memset(sab_u->buf_y, 0, (size_t)sab_u->len_w * 4);
memset(sab_u->buf_y, 0, (size_t)sab_u->len_w * sizeof(c3_w));
u3t_off(mal_o);
}

Expand Down Expand Up @@ -227,8 +227,7 @@ u3i_slab_free(u3i_slab* sab_u)
}
else {
c3_w* tav_w = (sab_u->buf_w - c3_wiseof(u3a_atom));
// XX
// u3_assert( tav_w == (c3_w*)vat_u );
u3_assert( tav_w == (c3_w*)vat_u );
u3a_wfree(vat_u);
}

Expand Down Expand Up @@ -258,8 +257,7 @@ u3i_slab_mint(u3i_slab* sab_u)
else {
u3a_atom* vat_u = sab_u->_._vat_u;
c3_w* tav_w = (sab_u->buf_w - c3_wiseof(u3a_atom));
// XX
// u3_assert( tav_w == (c3_w*)vat_u );
u3_assert( tav_w == (c3_w*)vat_u );

// trim trailing zeros
//
Expand Down Expand Up @@ -297,8 +295,7 @@ u3i_slab_moot(u3i_slab* sab_u)
else {
u3a_atom* vat_u = sab_u->_._vat_u;
c3_w* tav_w = (sab_u->buf_w - c3_wiseof(u3a_atom));
// XX
// u3_assert( tav_w == (c3_w*)vat_u );
u3_assert( tav_w == (c3_w*)vat_u );

pro = _ci_atom_mint(vat_u, len_w);
}
Expand Down
10 changes: 10 additions & 0 deletions pkg/noun/jets/c/bex.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@ u3qc_bex(u3_atom a)
c3_d a_d;
u3i_slab sab_u;

#ifdef VERE_64
if ( a < 63 ) {
return 1ULL << a;
#else
if ( a < 31 ) {
return 1 << a;
#endif
}

if ( c3y == u3a_is_cat(a) ) {
Expand All @@ -24,6 +29,7 @@ u3qc_bex(u3_atom a)
return u3m_bail(c3__fail);
}

// XX
// We don't currently support atoms 2GB or larger (fails while
// mugging). The extra term of 16 is experimentally determined.
if ( a_d >= ((c3_d)1 << (c3_d)34) - 16 ) {
Expand All @@ -34,7 +40,11 @@ u3qc_bex(u3_atom a)

u3i_slab_init(&sab_u, 0, a_d + 1);

#ifdef VERE_64
sab_u.buf_w[a_d >> 6] = 1 << (a_d & 63);
#else
sab_u.buf_w[a_d >> 5] = 1 << (a_d & 31);
#endif

return u3i_slab_moot(&sab_u);
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/noun/jets/c/lsh.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ u3qc_lsh(u3_atom a,
u3_atom b,
u3_atom c)
{
#ifdef VERE_64
if ( !_(u3a_is_cat(a)) || (a >= 64) ) {
#else
if ( !_(u3a_is_cat(a)) || (a >= 32) ) {
#endif
return u3m_bail(c3__fail);
}
else if ( !_(u3a_is_cat(b)) ) {
Expand Down
5 changes: 5 additions & 0 deletions pkg/noun/jets/c/mix.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@
u3qc_mix(u3_atom a,
u3_atom b)
{
#ifdef VERE_64
c3_w lna_w = u3r_met(6, a);
c3_w lnb_w = u3r_met(6, b);
#else
c3_w lna_w = u3r_met(5, a);
c3_w lnb_w = u3r_met(5, b);
#endif

if ( (lna_w == 0) && (lnb_w == 0) ) {
return 0;
Expand Down
38 changes: 38 additions & 0 deletions pkg/noun/retrieve.c
Original file line number Diff line number Diff line change
Expand Up @@ -1414,8 +1414,13 @@ u3r_chop_bits(c3_g bif_g,
c3_w* dst_w,
const c3_w* src_w)
{
#ifdef VERE_64
c3_y fib_y = 64 - bif_g;
c3_y tib_y = 64 - bit_g;
#else
c3_y fib_y = 32 - bif_g;
c3_y tib_y = 32 - bit_g;
#endif

// we need to chop words
//
Expand All @@ -1433,13 +1438,23 @@ u3r_chop_bits(c3_g bif_g,

wid_d -= tib_y;
bif_g += tib_y;
#ifdef VERE_64
src_w += !!(bif_g >> 6);
bif_g &= 63;
fib_y = 64 - bif_g;
#else
src_w += !!(bif_g >> 5);
bif_g &= 31;
fib_y = 32 - bif_g;
#endif
}

{
#ifdef VERE_64
size_t i_i, byt_i = wid_d >> 6;
#else
size_t i_i, byt_i = wid_d >> 5;
#endif

if ( !bif_g ) {
for ( i_i = 0; i_i < byt_i; i_i++ ) {
Expand All @@ -1454,7 +1469,11 @@ u3r_chop_bits(c3_g bif_g,

src_w += byt_i;
dst_w += byt_i;
#ifdef VERE_64
wid_d &= 63;
#else
wid_d &= 31;
#endif
bit_g = 0;
}
}
Expand Down Expand Up @@ -1491,11 +1510,19 @@ u3r_chop_words(c3_g met_g,
{
// operate on words
//
#ifdef VERE_64
if ( met_g >= 6 ) {
#else
if ( met_g >= 5 ) {
#endif
size_t i_i, wid_i;

{
#ifdef VERE_64
c3_g hut_g = met_g - 6;
#else
c3_g hut_g = met_g - 5;
#endif
size_t fum_i = (size_t)fum_w << hut_g;
size_t tou_i = (size_t)tou_w << hut_g;
size_t tot_i;
Expand Down Expand Up @@ -1533,7 +1560,11 @@ u3r_chop_words(c3_g met_g,
c3_g bif_g, bit_g;

{
#ifdef VERE_64
c3_d len_d = (c3_d)len_w << 6;
#else
c3_d len_d = (c3_d)len_w << 5;
#endif
c3_d fum_d = (c3_d)fum_w << met_g;
c3_d tou_d = (c3_d)tou_w << met_g;
c3_d tot_d = fum_d + wid_d;
Expand All @@ -1552,10 +1583,17 @@ u3r_chop_words(c3_g met_g,
wid_d -= tot_d - len_d;
}

#ifdef VERE_64
src_w += fum_d >> 6;
dst_w += tou_d >> 6;
bif_g = fum_d & 63;
bit_g = tou_d & 63;
#else
src_w += fum_d >> 5;
dst_w += tou_d >> 5;
bif_g = fum_d & 31;
bit_g = tou_d & 31;
#endif
}

u3r_chop_bits(bif_g, wid_d, bit_g, dst_w, src_w);
Expand Down
28 changes: 17 additions & 11 deletions pkg/noun/retrieve_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ _test_mug(void)
}
}

fprintf(stderr, "f\r\n");
{
u3_noun a = u3i_string("xxxxxxxxxxxxxxxxxxxxxxxxxxxx");

Expand All @@ -110,19 +109,19 @@ _test_mug(void)

u3z(a);
}
fprintf(stderr, "g\r\n");

{
u3_noun a = u3qc_bex(32);

if ( 0x7cefb7f != u3r_mug_cell(0, a) ) {
fprintf(stderr, "fail (g)\r\n");
gud = 0x7cefb7f;
res = u3r_mug_cell(0, a);
if ( gud != res ) {
fprintf(stderr, "fail (g) %x %x\r\n", gud, res);
ret_i = 0;
}

u3z(a);
}
fprintf(stderr, "h\r\n");

{
u3_noun a = u3ka_dec(u3qc_bex(128));
Expand All @@ -134,19 +133,26 @@ _test_mug(void)

u3z(a);
}
fprintf(stderr, "i\r\n");

{
// stick some zero bytes in a string
//
u3m_p("(bex 212)", u3qc_bex(212));
u3m_p("u3i_string", u3i_string("abcdefjhijklmnopqrstuvwxyz"));
u3_noun str = u3kc_lsh(3, 1,
u3kc_mix(u3qc_bex(212),
u3i_string("abcdefjhijklmnopqrstuvwxyz")));
u3m_p("lsh", str);

c3_w byt_w = u3r_met(3, str);
#ifdef VERE_64
c3_w wor_w = u3r_met(6, str);
c3_w* str_w = c3_malloc(8 * wor_w);
#else
c3_w wor_w = u3r_met(5, str);
c3_y* str_y = c3_malloc(byt_w);
c3_w* str_w = c3_malloc(4 * wor_w);
#endif
c3_y* str_y = c3_malloc(byt_w);
c3_d str_d = 0;

u3r_bytes(0, byt_w, str_y, str);
Expand All @@ -155,8 +161,10 @@ _test_mug(void)
str_d |= str_w[0];
str_d |= ((c3_d)str_w[1] << 32ULL);

if ( 0x34d08717 != u3r_mug(str) ) {
fprintf(stderr, "fail (i) (1) \r\n");
gud = 0x34d08717;
res = u3r_mug(str);
if ( gud != res ) {
fprintf(stderr, "fail (i) (1) %x %x\r\n", gud, res);
ret_i = 0;
}
if ( 0x34d08717 != u3r_mug_bytes(str_y, byt_w) ) {
Expand All @@ -176,7 +184,6 @@ _test_mug(void)
c3_free(str_w);
u3z(str);
}
fprintf(stderr, "j\r\n");

{
c3_w som_w[4] = { 0, 0, 0, 1 };
Expand All @@ -194,7 +201,6 @@ _test_mug(void)

u3z(som);
}
fprintf(stderr, "k\r\n");

{
c3_w som_w[4] = { 0, 1, 0, 1 };
Expand Down
20 changes: 16 additions & 4 deletions pkg/noun/serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,7 @@ _cs_jam_fib_mat(struct _cs_jam_fib* fib_u, u3_noun a)
{
c3_d dat_d = (c3_d)1 << b_w;
src_w[0] = (c3_w)dat_d;
#ifdef VERE_64
src_w[1] = dat_d >> 64;
#else
src_w[1] = dat_d >> 32;
#endif

u3r_chop_words(0, 0, b_w + 1, bit_w, buf_w, 2, src_w);
bit_w += b_w + 1;
Expand Down Expand Up @@ -503,7 +499,11 @@ typedef struct _cue_frame_s {
static inline ur_cue_res_e
_cs_cue_xeno_next(u3a_pile* pil_u,
ur_bsr_t* red_u,
#ifdef VERE_64
ur_dict64_t* dic_u,
#else
ur_dict32_t* dic_u,
#endif
u3_noun* out)
{
ur_root_t* rot_u = 0;
Expand Down Expand Up @@ -539,7 +539,11 @@ _cs_cue_xeno_next(u3a_pile* pil_u,
c3_d bak_d = ur_bsr64_any(red_u, len_d);
c3_w bak_w;

#ifdef VERE_64
if ( !ur_dict64_get(rot_u, dic_u, bak_d, &bak_w) ) {
#else
if ( !ur_dict32_get(rot_u, dic_u, bak_d, &bak_w) ) {
#endif
return ur_cue_back;
}

Expand All @@ -560,7 +564,11 @@ _cs_cue_xeno_next(u3a_pile* pil_u,
c3_d byt_d = (len_d + 0x7) >> 3;
u3i_slab sab_u;

#ifdef VERE_64
if ( 0xffffffffffffffffULL < byt_d) {
#else
if ( 0xffffffffULL < byt_d) {
#endif
return ur_cue_meme;
}
else {
Expand All @@ -570,7 +578,11 @@ _cs_cue_xeno_next(u3a_pile* pil_u,
}
}

#ifdef VERE_64
ur_dict64_put(rot_u, dic_u, bit_d, *out);
#else
ur_dict32_put(rot_u, dic_u, bit_d, *out);
#endif
return ur_cue_good;
}
}
Expand Down

0 comments on commit f8cd976

Please sign in to comment.