diff --git a/pkg/urbit/Makefile b/pkg/urbit/Makefile index be4b9e684..33c339f71 100644 --- a/pkg/urbit/Makefile +++ b/pkg/urbit/Makefile @@ -15,9 +15,9 @@ worker_objs = $(shell echo $(worker) | sed 's/\.c/.o/g') all_objs = $(common_objs) $(daemon_objs) $(worker_objs) all_srcs = $(common) $(daemon) $(worker) -all_exes = ./build/mug_tests ./build/jam_tests ./build/hashtable_tests \ - ./build/urbit ./build/urbit-worker - +all_exes = ./build/mug_tests ./build/jam_tests \ + ./build/noun_tests ./build/hashtable_tests \ + ./build/urbit ./build/urbit-worker # -Werror promotes all warnings that are enabled into errors (this is on) # -Wall issues all types of errors. This is off (for now) @@ -31,10 +31,11 @@ CFLAGS := $(CFLAGS) all: $(all_exes) -test: build/hashtable_tests build/jam_tests build/mug_tests +test: build/hashtable_tests build/jam_tests build/mug_tests build/noun_tests ./build/hashtable_tests ./build/jam_tests ./build/mug_tests + ./build/noun_tests clean: rm -f ./tags $(all_objs) $(all_exes) @@ -59,6 +60,11 @@ build/mug_tests: $(common_objs) tests/mug_tests.o @mkdir -p ./build @$(CC) $^ $(LDFLAGS) -o $@ +build/noun_tests: $(common_objs) tests/noun_tests.o + @echo CC -o $@ + @mkdir -p ./build + @$(CC) $^ $(LDFLAGS) -o $@ + build/urbit: $(common_objs) $(daemon_objs) @echo CC -o $@ @mkdir -p ./build diff --git a/pkg/urbit/tests/hashtable_tests.c b/pkg/urbit/tests/hashtable_tests.c index f97687305..071d05cf3 100644 --- a/pkg/urbit/tests/hashtable_tests.c +++ b/pkg/urbit/tests/hashtable_tests.c @@ -1,69 +1,45 @@ #include "all.h" -static void _setup(void); -static void _test_bit_manipulation(); -static void _test_cache_replace_value(void); -static void _test_cache_trimming(void); -static void _test_no_cache(void); -static void _test_skip_slot(void); - // defined in noun/hashtable.c c3_w _ch_skip_slot(c3_w mug_w, c3_w lef_w); - -/* main(): run all test cases. -*/ -int -main(int argc, char* argv[]) -{ - _setup(); - - _test_bit_manipulation(); - _test_no_cache(); - _test_skip_slot(); - _test_cache_trimming(); - _test_cache_replace_value(); - - return 0; -} - /* _setup(): prepare for tests. */ static void _setup(void) { u3m_init(); - u3m_pave(c3y, c3n); + u3m_pave(c3y, c3n); } +/* _test_bit_manipulation(): +*/ static void -_test_bit_manipulation() +_test_bit_manipulation() { - if (8 != sizeof(u3h_slot)){ - printf("wrong size\n"); + if ( sizeof(u3_noun) != sizeof(u3h_slot) ){ + c3_assert(!"wrong size\n"); } u3h_slot a = 0; if (u3h_slot_is_null(a) != c3y){ - printf("nullity\n"); + c3_assert(!"nullity\n"); } - + a = u3h_noun_be_warm(a); if (u3h_slot_is_warm(a) != c3y){ - printf("warmth\n"); + c3_assert(!"warmth\n"); } if (u3h_slot_is_null(a) != c3n){ - printf("nullity 2\n"); - } - - a = u3h_noun_be_cold(a); - if (u3h_slot_is_warm(a) != c3n){ - printf("coldness\n"); + c3_assert(!"nullity 2\n"); } - + a = u3h_noun_be_cold(a); + if (u3h_slot_is_warm(a) != c3n){ + c3_assert(!"coldness\n"); + } } /* _test_no_cache(): test a hashtable without caching. @@ -72,12 +48,12 @@ static void _test_no_cache(void) { c3_w i_w; - c3_w max_w = 3; // NOTFORCHECKIN + c3_w max_w = 1000; u3p(u3h_root) har_p = u3h_new(); for ( i_w = 0; i_w < max_w; i_w++ ) { - u3h_put(har_p, i_w, i_w + max_w); + u3h_put(har_p, i_w, i_w + max_w); } for ( i_w = 0; i_w < max_w; i_w++ ) { @@ -147,6 +123,8 @@ _test_cache_trimming(void) fprintf(stderr, "test_cache_trimming: ok\n"); } +/* _test_cache_replace_value(): +*/ static void _test_cache_replace_value(void) { @@ -174,3 +152,21 @@ _test_cache_replace_value(void) } fprintf(stderr, "test_cache_replace_value: ok\r\n"); } + +/* main(): run all test cases. +*/ +int +main(int argc, char* argv[]) +{ + _setup(); + + _test_bit_manipulation(); + _test_no_cache(); + _test_skip_slot(); + _test_cache_trimming(); + _test_cache_replace_value(); + + fprintf(stderr, "test_hashtable: ok\r\n"); + + return 0; +} diff --git a/pkg/urbit/tests/jam_tests.c b/pkg/urbit/tests/jam_tests.c index e87bd5e46..bc557c857 100644 --- a/pkg/urbit/tests/jam_tests.c +++ b/pkg/urbit/tests/jam_tests.c @@ -96,8 +96,181 @@ _test_jam(void) exit(1); } } +} - fprintf(stderr, "test_jam: ok\n"); +/* _test_cue_jam(): more jam/cue spot-checking, ported from the 64-bit effort +*/ +static void +_test_cue_jam() +{ + // the boot msg from the worker + { + u3_noun dat = u3_nul; + u3_noun in_1 = u3nc(c3__play, dat); + u3_atom jam_1 = u3ke_jam(in_1); + + u3_noun out_1 = u3ke_cue(jam_1); + u3_noun head_out = u3h(out_1); + u3_noun tail_out = u3t(out_1); + + if (c3__play != head_out){ + printf("*** cue_jam 0 out head \n"); + } + + if (u3_nul != tail_out){ + printf("*** cue_jam 0 out tail \n"); + } + + } + + // the boot msg from the worker, again, + // but this time torn apart into bytes and rebuilt + { + u3_noun dat = u3_nul; + u3_noun in_1 = u3nc(c3__play, dat); + u3_atom jam_1 = u3ke_jam(in_1); + + c3_y buf_y[1024]; + memset(buf_y, 0, 1024); + c3_w len_w = u3r_met(3, jam_1); + + u3r_bytes(0, // start byte + len_w, // len + buf_y, // buffer + jam_1 ); // input noun + + /// zip ....zap ... communicate between serf and king + + u3_noun jam_2 = u3i_bytes(len_w, buf_y); + + if ( c3n == u3r_sing(jam_1, jam_2) ) { + printf("*** error in 6 byte message\n"); + } + + u3_noun out_1 = u3ke_cue(jam_2); + + u3_noun head_out = u3h(out_1); + u3_noun tail_out = u3t(out_1); + + if (c3__play != head_out){ + printf("*** cue_jam 0 out head \n"); + } + + if (u3_nul != tail_out){ + printf("*** cue_jam 0 out tail \n"); + } + + } + + // 1 + { + + u3_atom in_1 = 1; + u3_atom jam_1 = u3ke_jam(in_1); + + if (12 != jam_1){ + printf("*** cue_jam 1a \n"); + } + + u3_noun out_1 = u3ke_cue(jam_1); + + if (1 != out_1){ + printf("*** cue_jam 1b \n"); + } + } + + // [ 1 1 ] + { + + u3_noun in_1 = u3i_cell(1, 1); + u3_atom jam_1 = u3ke_jam(in_1); + + if (817 != jam_1){ + printf("*** cue_jam 2 in \n"); + } + + u3_noun out_1 = u3ke_cue(jam_1); + + + u3_noun head_out = u3h(out_1); + u3_noun tail_out = u3t(out_1); + + if (1 != head_out){ + printf("*** cue_jam 2 out head \n"); + } + + if (1 != tail_out){ + printf("*** cue_jam 2 out tail \n"); + } + } + + // [ 1 2 ] + { + + u3_noun in_1 = u3i_cell(1, 2); + u3_atom jam_1 = u3ke_jam(in_1); + + if (4657 != jam_1){ + printf("*** cue_jam 2 in \n"); + } + + u3_noun out_1 = u3ke_cue(jam_1); + + u3_noun head_out = u3h(out_1); + u3_noun tail_out = u3t(out_1); + + if (1 != head_out){ + printf("*** cue_jam 2 out head \n"); + } + + if (2 != tail_out){ + printf("*** cue_jam 2 out tail \n"); + } + } + + // medium complicated cell + // q + // / \ + // a1 r + // / \ + // b2 s + // / \ + // c3 d4 + { + u3_noun a = (u3_noun) 0x1; + u3_noun b = (u3_noun) 0x2; + u3_noun c = (u3_noun) 0x3; + u3_noun d = (u3_noun) 0x4; + + u3_noun s = u3i_cell(c, d); + u3_noun r = u3i_cell(b, s); + u3_noun q = u3i_cell(a, r); + + u3_atom jam_1 = u3ke_jam(q); + u3_noun out_1 = u3ke_cue(jam_1); + + u3_noun a2 = u3h(out_1); + u3_noun r2 = u3t(out_1); + if (a2 != a){ + printf("*** _cue_jam: complicated a\n"); + } + + u3_noun b2 = u3h(r2); + u3_noun s2 = u3t(r2); + if (b2 != b){ + printf("*** _cue_jam: complicated b\n"); + } + + u3_noun c2 = u3h(s2); + u3_noun d2 = u3t(s2); + if (c2 != c){ + printf("*** _cue_jam: complicated c\n"); + } + + if (d2 != d){ + printf("*** _cue_jam: complicated d\n"); + } + } } /* main(): run all test cases. @@ -108,6 +281,9 @@ main(int argc, char* argv[]) _setup(); _test_jam(); + _test_cue_jam(); + + fprintf(stderr, "test_jam: ok\n"); return 0; } diff --git a/pkg/urbit/tests/noun_tests.c b/pkg/urbit/tests/noun_tests.c index 5dd778277..3e0c9276d 100644 --- a/pkg/urbit/tests/noun_tests.c +++ b/pkg/urbit/tests/noun_tests.c @@ -3,7 +3,6 @@ #define TRUE 1 #define FALSE 0 - /* _setup(): prepare for tests. */ static void @@ -13,160 +12,154 @@ _setup(void) u3m_pave(c3y, c3n); } -// malloc space and fill with a random string of length len_w -// -static c3_y * util_rand_string(c3_w len_w) +/* _util_rand_string(): dynamically allocated len_w random string +*/ +static c3_y* +_util_rand_string(c3_w len_w) { - c3_y * choice_y = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; - c3_w choice_len_w = c3_sizet_to_w(strlen( choice_y)); + c3_c* choice_c = + "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; + c3_w choice_len_w = strlen(choice_c); - c3_y * out_y = malloc(len_w + 1); + c3_y* out_y = c3_malloc(len_w + 1); c3_w i_w; for (i_w = 0; i_w < len_w; i_w ++){ - out_y[i_w] = choice_y[ (c3_w) rand() % choice_len_w ]; + out_y[i_w] = choice_c[ (c3_w) rand() % choice_len_w ]; } out_y[i_w] = 0; - return(out_y); + return out_y; } +/* _test_noun_bits_helper(): +*/ static void -_test_noun_bits_helper(u3_noun a, int direct_o, int indirect_o, int indirect_atom_o, int cell_o) +_test_noun_bits_helper(u3_noun a, int direct_o, + int indirect_o, + int indirect_atom_o, + int cell_o) { - c3_w verbose_w = 0; - if (verbose_w){ - printf("=========== %lx\n", (uint64_t) a); - printf(" 63 bit %lx\n", (uint64_t) a & ( ((c3_d) 1) << 63)); - printf(" 62 bit %lx\n", (uint64_t) a & ( ((c3_d) 1) << 62)); - printf(" dir %x\n", u3a_is_direct_b(a)); - printf(" ind %x\n", u3a_is_indirect_b(a)); - printf(" i cell %x\n", u3a_is_cell_b(a)); - printf(" i atom %x\n", u3a_is_indirect_atom_b(a)); - } +#if 0 + printf("=========== %u\n", a); + printf(" 31 bit %u\n", a & ( ((c3_w)1) << 31)); + printf(" 30 bit %u\n", a & ( ((c3_w)1) << 30)); + printf(" dir %x\n", c3y == u3a_is_cat(a)); + printf(" ind %x\n", c3y == u3a_is_dog(a)); + printf(" i cell %x\n", c3y == u3a_is_cell(a)); + printf(" i atom %x\n", c3y == u3a_is_pug(a)); +#endif - // level 1 - direct testing of flags (boolean) - - if ( direct_o != u3a_is_direct_b(a) ) { + if ( direct_o != (c3y == u3a_is_cat(a)) ) { printf("*** _test_noun_bits_one() fail: u3a_is_direct\r\n"); } - if ( indirect_o != u3a_is_indirect_b(a) ) { - printf("*** fail-2 u3a_is_indirect %d\r\n", u3a_is_indirect_b(a)); + if ( indirect_o != (c3y == u3a_is_dog(a)) ) { + printf("*** fail-2 u3a_is_indirect %d\r\n", c3n == u3a_is_cat(a)); } - if ( cell_o != u3a_is_cell_b(a) ) { + if ( cell_o != (c3y == u3a_is_cell(a)) ) { printf("*** fail-4 u3a_is_cell\r\n"); } - if ( indirect_atom_o != u3a_is_indirect_atom_b(a) ) { + if ( indirect_atom_o != (c3y == u3a_is_pug(a)) ) { printf("*** fail-3 u3a_is_indirect_atom\r\n"); } - - } + +/* _test_noun_bits_set(): allocate.h level 1a +*/ static void _test_noun_bits_set() { u3_noun a = 1; // flip indirect bit on - - a = u3a_to_indirect(a); - if ( ! u3a_is_indirect_b(a) ) { + a |= (1 << 31); + if ( c3n == u3a_is_dog(a) ) { printf("*** fail-5a turn indirect bit on\r\n"); } - if ( u3a_is_cell_b(a) ) { + if ( c3y == u3a_is_cell(a) ) { printf("*** fail-5b turn indirect bit on\r\n"); } - if (! u3a_is_indirect_atom_b(a)) { + if ( c3n == u3a_is_pug(a) ) { printf("*** fail-5c turn indirect bit on\r\n"); } // flip all bits off a = u3a_to_off(a); - if ( u3a_is_indirect_b(a) ) { - printf("*** fail-6 turn indirect bit off\r\n"); + if ( c3y == u3a_is_dog(a) ) { + printf("*** fail-5d turn indirect bit off\r\n"); } - if ( u3a_is_cell_b(a) ) { - printf("*** fail-5b turn indirect bit on\r\n"); - } - - if ( u3a_is_indirect_atom_b(a)) { - printf("*** fail-5c turn indirect bit on\r\n"); - } - - // flip indirect & cell bit on - - a = u3a_to_indirect_cell(a); - - if ( ! u3a_is_indirect_b(a) ) { - printf("*** fail-5d turn indirect bit on\r\n"); - } - - if ( ! u3a_is_cell_b(a) ) { + if ( c3y == u3a_is_cell(a) ) { printf("*** fail-5e turn indirect bit on\r\n"); } - if (u3a_is_indirect_atom_b(a)) { + if ( c3y == u3a_is_pug(a)) { printf("*** fail-5f turn indirect bit on\r\n"); } + // flip indirect & cell bit on + a = u3a_to_pom(a); + if ( c3n == u3a_is_dog(a) ) { + printf("*** fail-5g turn indirect bit on\r\n"); + } + + if ( c3n == u3a_is_cell(a) ) { + printf("*** fail-5h turn indirect bit on\r\n"); + } + + if ( c3y == u3a_is_pug(a) ) { + printf("*** fail-5i turn indirect bit on\r\n"); + } } -// flip +/* _test_noun_bits_read(): allocate.h level 1 +*/ static void _test_noun_bits_read() { - u3_noun a = ((u3_noun) 0x1); // no bits set -> direct + u3_noun a = (u3_noun)0x1; // direct atom + u3_noun b = u3a_to_pug(0x2); // indirect atom + u3_noun c = u3a_to_pom(0x3); // indirect cell - u3_noun b = ((u3_noun) 0x2) | u3_noun_indirectbit; // indirect, not a cell - - u3_noun c = ((u3_noun) 0x3) | u3_noun_indirectbit | u3_noun_cellbit; // indirect, a cell - - - - // direct indirect indirect-atom indirect-cell - //---------------------------------------- - - _test_noun_bits_helper(a, TRUE, FALSE, FALSE, FALSE); - - _test_noun_bits_helper(b, FALSE, TRUE, TRUE, FALSE); - - _test_noun_bits_helper(c, FALSE, TRUE, FALSE, TRUE); + // direct indirect indirect-atom indirect-cell + //---------------------------------------- + _test_noun_bits_helper(a, TRUE, FALSE, FALSE, FALSE); + _test_noun_bits_helper(b, FALSE, TRUE, TRUE, FALSE); + _test_noun_bits_helper(c, FALSE, TRUE, FALSE, TRUE); } - -// insert and retrieve bytes in a noun -// u3_i_bytes() <--> u3r_bytes +/* _test_imprison(): test basic data into / out of nouns +** insert and retrieve bytes with u3i_bytes()/u3r_bytes() +*/ static void _test_imprison() { - - c3_y * input_y = "abcdefghij"; + c3_c* input_c = "abcdefghij"; c3_w out_len_w = 300; - c3_y * output_y = malloc(out_len_w); + c3_y * output_y = c3_malloc(out_len_w); u3_noun a; // size 1, direct - a = u3i_bytes(1, input_y); - bzero(output_y, out_len_w); + a = u3i_bytes(1, (c3_y*)input_c); + memset(output_y, 0, out_len_w); u3r_bytes(0, 1, output_y, a); - if (0 != strcmp(output_y, "a")) { + if (0 != memcmp(output_y, "a", 1)) { printf("*** _test_imprison: fail-1\n"); } // size 2, direct - a = u3i_bytes(2, input_y); - bzero(output_y, out_len_w); + a = u3i_bytes(2, (c3_y*)input_c); + memset(output_y, 0, out_len_w); u3r_bytes(0, 2, output_y, a); - if (0 != strcmp(output_y, "ab")) { + if (0 != memcmp(output_y, "ab", 2)) { printf("*** _test_imprison: fail-2\n"); } @@ -174,58 +167,57 @@ _test_imprison() { c3_y data_y[] = { 0x1, 0x1f, 0x8e, 0x2d, 0x2c, 0x2f }; a = u3i_bytes(6, data_y); - bzero(output_y, out_len_w); + memset(output_y, 0, out_len_w); u3r_bytes(0, 6, output_y, a); int ret; ret = memcmp(output_y, data_y, 6); if (0 != ret) { printf("*** _test_imprison: fail-2.5 %x\n", ret); - printf(" %x %x %x %x %x %x\n", output_y[0], output_y[1], output_y[2], output_y[3], output_y[4], output_y[5]); + printf(" %x %x %x %x %x %x\n", output_y[0], + output_y[1], + output_y[2], + output_y[3], + output_y[4], + output_y[5]); } } // size 8, direct - a = u3i_bytes(8, input_y); - bzero(output_y, out_len_w); + a = u3i_bytes(8, (c3_y*)input_c); + memset(output_y, 0, out_len_w); u3r_bytes(0, 8, output_y, a); - if (0 != strcmp(output_y, "abcdefgh")) { + if (0 != memcmp(output_y, "abcdefgh", 8)) { printf("*** _test_imprison: fail-3\n"); } // size 10, indirect - a = u3i_bytes(10, input_y); - bzero(output_y, out_len_w); + a = u3i_bytes(10, (c3_y*)input_c); + memset(output_y, 0, out_len_w); u3r_bytes(0, 10, output_y, a); - if (0 != strcmp(output_y, "abcdefghij")) { + if (0 != memcmp(output_y, "abcdefghij", 10)) { printf("*** _test_imprison: fail-4\n"); } // size 200, indirect - c3_y * rand_y = util_rand_string(200); + c3_y * rand_y = _util_rand_string(200); a = u3i_bytes(200, rand_y); - bzero(output_y, out_len_w); + memset(output_y, 0, out_len_w); u3r_bytes(0, 200, output_y, a); - if (0 != strcmp(output_y, rand_y)) { + if (0 != memcmp(output_y, rand_y, 200)) { printf("*** _test_imprison: fail-5\n"); } - free(rand_y); - - free(output_y); + c3_free(rand_y); + c3_free(output_y); } - -// test u3i_cell(), u3h(), u3t() -// +/* _test_cells(): build and inspect cells: u3i_cell(), u3h(), u3t() +*/ static void _test_cells() { - - c3_w verbose_w = 0; - // very simple cell { - u3_noun a = (u3_noun) 0x1; u3_noun b = (u3_noun) 0x2; u3_noun c = u3i_cell(a, b); @@ -243,50 +235,41 @@ _test_cells() // very simple cell with indirect atoms { - c3_w out_len_w = 200; - c3_y * rand_a = util_rand_string(out_len_w); - c3_y * rand_b = util_rand_string(out_len_w); + c3_y * rand_a = _util_rand_string(out_len_w); + c3_y * rand_b = _util_rand_string(out_len_w); u3_noun a = u3i_bytes(200, rand_a); u3_noun b = u3i_bytes(200, rand_b); u3_noun c = u3i_cell(a, b); - if (verbose_w){ - printf("a = %x\n", a); - printf("b = %x\n", b); - printf("c = %x\n", c); - printf("a_rand = %s\n", rand_a); - printf("b_rand = %s\n", rand_b); - } +#if 0 + printf("a = %x\n", a); + printf("b = %x\n", b); + printf("c = %x\n", c); + printf("a_rand = %s\n", rand_a); + printf("b_rand = %s\n", rand_b); +#endif u3_noun a2 = u3h(c); - c3_y * output_y = malloc(out_len_w + 1); - bzero(output_y, out_len_w + 1); + c3_y * output_y = c3_malloc(out_len_w + 1); + memset(output_y, 0, out_len_w + 1); u3r_bytes(0, out_len_w, output_y, a); - if (verbose_w){ - printf("a_rand_out = %s\n", output_y); - } - - if (0 != strcmp(output_y, rand_a)) { + if (0 != memcmp(output_y, rand_a, out_len_w)) { printf("*** _test_imprison: fail-3\n"); } u3_noun b2 = u3h(c); - bzero(output_y, out_len_w + 1); + memset(output_y, 0, out_len_w + 1); u3r_bytes(0, out_len_w, output_y, b); - if (verbose_w){ - printf("b_rand_out = %s\n", output_y); - } - - if (0 != strcmp(output_y, rand_b)) { + if (0 != memcmp(output_y, rand_b, out_len_w)) { printf("*** _test_imprison: fail-4\n"); } - free(rand_a); - free(rand_b); + c3_free(rand_a); + c3_free(rand_b); } // medium complicated cell @@ -302,7 +285,7 @@ _test_cells() u3_noun b = (u3_noun) 0x2; u3_noun c = (u3_noun) 0x3; u3_noun d = (u3_noun) 0x4; - + u3_noun s = u3i_cell(c, d); u3_noun r = u3i_cell(b, s); u3_noun q = u3i_cell(a, r); @@ -335,7 +318,6 @@ _test_cells() if (a2 != a){ printf("*** _test_cells: complicated (via u3r_mean) a\n"); } - } // trel @@ -345,7 +327,7 @@ _test_cells() // a ? // / \ // b c - + // Produce the triple `[a b c]`. u3_noun a = (u3_noun) 0x1; u3_noun b = (u3_noun) 0x2; @@ -366,8 +348,6 @@ _test_cells() if (c2 != c){ printf("*** trel: 3 a\n"); } - - } // qual @@ -379,8 +359,8 @@ _test_cells() // b ? // / \ // c d - // - + // + // Produce the triple `[a b c]`. u3_noun a = (u3_noun) 0x1; u3_noun b = (u3_noun) 0x2; @@ -407,16 +387,13 @@ _test_cells() printf("*** qual: 4 \n"); } } - - - - - } +/* _test_cells_complex(): build cells with more complex methods +*/ static void _test_cells_complex() -{ +{ // trel { // q @@ -424,7 +401,7 @@ _test_cells_complex() // a ? // / \ // b c - + // Produce the triple `[a b c]`. u3_noun a = (u3_noun) 0x1; u3_noun b = (u3_noun) 0x2; @@ -458,7 +435,7 @@ _test_cells_complex() // b z // / \ // c d - + // Produce the qual `[a b c d]`. u3_noun a = (u3_noun) 0x1; u3_noun b = (u3_noun) 0x2; @@ -500,7 +477,7 @@ _test_cells_complex() // c ? // / \ // d e - + // Produce `[a b c d e]`. u3_noun a = (u3_noun) 0x1; u3_noun b = (u3_noun) 0x2; @@ -589,16 +566,13 @@ _test_cells_complex() printf("*** _test_cells_complex: hext() f - f2 = %i\n", f2); } } - - } - -// test functions from imprison.h / retrieve.h +/* _test_imprison_complex(): more complicated into/out-of nouns +*/ static void _test_imprison_complex() { - // vint { u3_noun a = 1; @@ -608,26 +582,31 @@ _test_imprison_complex() printf("*** vint 1\n"); } - u3_noun c= u3i_vint(b); + u3_noun c = u3i_vint(b); if (3 != c){ printf("*** vint 2\n"); } - a = 1ull << 50; - b= u3i_vint(a); - - if ((a + 1) != b){ - printf("*** vint 3\n"); - } + // XX disabled, 64-bit + // +#if 0 + { + c3_d d = 1ULL << 50; + a = u3i_chubs(1, &d); + b = u3i_vint(a); + if ((a + 1) != b){ + printf("*** vint 3\n"); + } + } +#endif } - // bytes { - c3_y in_y[10] = { 10, 20, c3_y_MAX}; + c3_y in_y[10] = { 10, 20, 0xff}; u3_noun a = u3i_bytes(3, in_y); - + c3_w out_a = u3r_byte(0, a); if (10 != out_a ){ printf("*** u3r_byte 1\n"); @@ -639,17 +618,17 @@ _test_imprison_complex() } c3_w out_c = u3r_byte(2, a); - if (c3_y_MAX != out_c ){ + if (0xff != out_c ){ printf("*** u3r_byte 3\n"); } c3_y out_y[10]; - bzero((void *) out_y, 10 * sizeof(c3_y)); + memset(out_y, 0, 10 * sizeof(c3_y)); u3r_bytes(0, 3, out_y, a); if (10 != out_y[0] || 20 != out_y[1] || - c3_y_MAX != out_y[2] || + 0xff != out_y[2] || 0 != out_y[3] ){ printf("*** u3r_byte 4\n"); @@ -658,9 +637,9 @@ _test_imprison_complex() // words { - c3_w in_w[10] = {10, 20, c3_w_MAX}; + c3_w in_w[10] = {10, 20, 0xffffffff}; u3_noun noun = u3i_words(3, in_w); - + c3_w out_a = u3r_word(0, noun); if (10 != out_a ){ @@ -672,18 +651,18 @@ _test_imprison_complex() printf("*** u3r_word 2\n"); } - c3_w out_c = u3r_word(2, noun); - if (c3_w_MAX != out_c ){ + c3_w out_c = u3r_word(2, noun); + if (0xffffffff != out_c ){ printf("*** u3r_word 3\n"); } c3_w out_w[10]; - bzero((void *) out_w, 10 * sizeof(c3_w)); + memset(out_w, 0, 10 * sizeof(c3_w)); u3r_words(0, 3, out_w, noun); if (10 != out_w[0] || 20 != out_w[1] || - c3_w_MAX != out_w[2] || + 0xffffffff != out_w[2] || 0 != out_w[3] ){ printf("*** u3r_word 4\n"); @@ -692,34 +671,34 @@ _test_imprison_complex() // chubs { - c3_d in_d[10] = {1, 2, c3_d_MAX}; + c3_d in_d[10] = {1, 2, 0xffffffffffffffffULL}; c3_d out_d[10]; u3_noun a = u3i_chubs(1, & in_d[0]); - bzero(out_d, sizeof(c3_d) * 10); + memset(out_d, 0, sizeof(c3_d) * 10); u3r_chubs(0, 1, out_d, a); if (1 != out_d[0] ){ printf("*** u3r_chubs 1\n"); } - + u3_noun b = u3i_chubs(1, & in_d[1]); - bzero(out_d, sizeof(c3_d) * 10); + memset(out_d, 0, sizeof(c3_d) * 10); u3r_chubs(0, 1, out_d, b); if (2 != out_d[0] ){ printf("*** u3r_chubs 2\n"); } u3_noun c = u3i_chubs(1, & in_d[2]); - bzero(out_d, sizeof(c3_d) * 10); + memset(out_d, 0, sizeof(c3_d) * 10); u3r_chubs(0, 1, out_d, c); - if (c3_d_MAX != out_d[0] ){ + if (0xffffffffffffffffULL != out_d[0] ){ printf("*** u3r_chubs 3\n"); } u3_noun d = u3i_chubs(3, in_d); - bzero(out_d, sizeof(c3_d) * 10); + memset(out_d, 0, sizeof(c3_d) * 10); u3r_chubs(0, 3, out_d, d); if (1 != out_d[0] ){ printf("*** u3r_chubs 4-a\n"); @@ -727,15 +706,13 @@ _test_imprison_complex() if (2 != out_d[1] ){ printf("*** u3r_chubs 4-b\n"); } - if (c3_d_MAX != out_d[2] ){ + if (0xffffffffffffffffULL != out_d[2] ){ printf("*** u3r_chubs 4-c\n"); } - } - + // string { - c3_c * in_c = "a"; u3_noun noun = u3i_string(in_c); c3_c* out_c = u3r_string(noun); @@ -767,32 +744,28 @@ _test_imprison_complex() if (0 != strcmp(in_c, out_c)){ printf("*** u3r_string: in '%s'; out '%s'\n", in_c, out_c); } - - } // tape { - - c3_c * in_c = "this is a test"; + c3_c* in_c = "this is a test"; u3_noun noun = u3i_tape(in_c); - c3_c* out_c = u3r_tape(noun); + c3_y* out_y = u3r_tape(noun); - if (0 != strcmp(in_c, out_c)){ + if (0 != memcmp(in_c, out_y, strlen(in_c))){ printf("*** u3r_tape 1\n"); } // tape stores each byte in the string as one atom in the tree u3_noun lent = u3qb_lent(noun); - if (u3a_noun_to_w(lent) != strlen(in_c)){ + if ( (c3_w)lent != strlen(in_c) ){ printf("*** u3r_tape 2\n"); } - } // edit - { + { // q // / \ @@ -806,7 +779,7 @@ _test_imprison_complex() u3_noun b = (u3_noun) 0x2; u3_noun c = (u3_noun) 0x3; u3_noun d = (u3_noun) 0x4; - + u3_noun s = u3i_cell(c, d); u3_noun r = u3i_cell(b, s); u3_noun q = u3i_cell(a, r); @@ -824,7 +797,7 @@ _test_imprison_complex() } // molt - { + { // q // / \ @@ -838,7 +811,7 @@ _test_imprison_complex() u3_noun b = (u3_noun) 0x2; u3_noun c = (u3_noun) 0x3; u3_noun d = (u3_noun) 0x4; - + u3_noun s = u3i_cell(c, d); u3_noun r = u3i_cell(b, s); u3_noun q = u3i_cell(a, r); @@ -848,7 +821,7 @@ _test_imprison_complex() u3_noun axis_2 = 6; u3_noun newval_2 = 777; - + u3_noun hacked = u3i_molt(q, axis_1, newval_1, axis_2, newval_2, 0); u3_noun read_1; @@ -865,8 +838,10 @@ _test_imprison_complex() } } -// sing - Yes iff (a) and (b) are the same noun. -void _test_sing() +/* _test_sing(): Yes iff (a) and (b) are the same noun. +*/ +static void +_test_sing() { // direct noun // @@ -891,13 +866,13 @@ void _test_sing() // indirect // { - c3_y * in_alpha_y = "abcdefghijklmnopqrstuvwxyz"; - c3_y * in_numer_y = "0123456789001234567890"; + c3_c* in_alpha_c = "abcdefghijklmnopqrstuvwxyz"; + c3_c* in_numer_c = "0123456789001234567890"; - - u3_noun a = u3i_string(in_alpha_y); - u3_noun b = u3i_string(in_alpha_y); - u3_noun c = u3i_string(in_numer_y); + + u3_noun a = u3i_string(in_alpha_c); + u3_noun b = u3i_string(in_alpha_c); + u3_noun c = u3i_string(in_numer_c); if (c3y != u3r_sing(a, a)) { printf("*** sing indirect: 1 \n"); @@ -911,13 +886,12 @@ void _test_sing() printf("*** sing indirect: \n"); } } - } - - -// fing - same copy of the same noun. -void _test_fing() +/* _test_fing(): yes same copy of the same noun (ie, pointer equality) +*/ +static void +_test_fing() { // direct noun // @@ -942,13 +916,13 @@ void _test_fing() // indirect // { - c3_y * in_alpha_y = "abcdefghijklmnopqrstuvwxyz"; - c3_y * in_numer_y = "0123456789001234567890"; + c3_c* in_alpha_c = "abcdefghijklmnopqrstuvwxyz"; + c3_c* in_numer_c = "0123456789001234567890"; - - u3_noun a = u3i_string(in_alpha_y); - u3_noun b = u3i_string(in_alpha_y); - u3_noun c = u3i_string(in_numer_y); + + u3_noun a = u3i_string(in_alpha_c); + u3_noun b = u3i_string(in_alpha_c); + u3_noun c = u3i_string(in_numer_c); if (c3y != u3r_fing(a, a)) { printf("*** fing indirect: 1 \n"); @@ -962,10 +936,12 @@ void _test_fing() printf("*** fing indirect: \n"); } } - } -void _test_met() +/* _test_met(): 'met' = measure / take size +*/ +static void +_test_met() { c3_w ret_w; u3_atom atom; @@ -973,7 +949,7 @@ void _test_met() // 1 { atom = 1; - + ret_w = u3r_met(0, atom); if (1 != ret_w){ printf("*** _test_met bit of 1 = %d \n", ret_w); @@ -988,7 +964,7 @@ void _test_met() if (1 != ret_w){ printf("*** _test_met _w of 1 = %d \n", ret_w); } - + ret_w = u3r_met(5, atom); if (1 != ret_w){ printf("*** _test_met _d of 1 = %d \n", ret_w); @@ -998,7 +974,7 @@ void _test_met() // 2 = 0b10 { atom = 2; - + ret_w = u3r_met(0, atom); if (2 != ret_w){ printf("*** _test_met bit of 1 = %d \n", ret_w); @@ -1013,7 +989,7 @@ void _test_met() if (1 != ret_w){ printf("*** _test_met _w of 1 = %d \n", ret_w); } - + ret_w = u3r_met(6, atom); if (1 != ret_w){ printf("*** _test_met _d of 1 = %d \n", ret_w); @@ -1023,7 +999,7 @@ void _test_met() // 8=0b1000 { atom = 8; - + ret_w = u3r_met(0, atom); if (4 != ret_w){ printf("*** _test_met bit of 1 = %d \n", ret_w); @@ -1038,7 +1014,7 @@ void _test_met() if (1 != ret_w){ printf("*** _test_met _w of 1 = %d \n", ret_w); } - + ret_w = u3r_met(6, atom); if (1 != ret_w){ printf("*** _test_met _d of 1 = %d \n", ret_w); @@ -1048,7 +1024,7 @@ void _test_met() // 0xff = 255 =0b 1111 1111 { atom = 0xff; - + ret_w = u3r_met(0, atom); if (8 != ret_w){ printf("*** _test_met bit of 1 = %d \n", ret_w); @@ -1063,7 +1039,7 @@ void _test_met() if (1 != ret_w){ printf("*** _test_met _w of 1 = %d \n", ret_w); } - + ret_w = u3r_met(6, atom); if (1 != ret_w){ printf("*** _test_met _d of 1 = %d \n", ret_w); @@ -1073,7 +1049,7 @@ void _test_met() // 0x100 = 256 =0b 0001 1111 1111 { atom = 0x100; - + ret_w = u3r_met(0, atom); if (9 != ret_w){ printf("*** _test_met bit of 1 = %d \n", ret_w); @@ -1088,18 +1064,21 @@ void _test_met() if (1 != ret_w){ printf("*** _test_met _w of 1 = %d \n", ret_w); } - + ret_w = u3r_met(6, atom); if (1 != ret_w){ printf("*** _test_met _d of 1 = %d \n", ret_w); } } + // XX disabled, 64-bit + // +#if 0 // 32 bit direct - // 0x ff ff ff ff - { + // 0x ff ff ff ff + { atom = 0xffffffffULL; - + ret_w = u3r_met(0, atom); if (32 != ret_w){ printf("*** _test_met bit of 1 = %d \n", ret_w); @@ -1114,22 +1093,20 @@ void _test_met() if (1 != ret_w){ printf("*** _test_met _w of 1 = %d \n", ret_w); } - + ret_w = u3r_met(6, atom); if (1 != ret_w){ printf("*** _test_met _d of 1 = %d \n", ret_w); } } +#endif // 4 words x 32 bits each = 128 bits = 16 bytes = 4 words = 2 doubles - // - if (1) { - - c3_w data_w[4] = { c3_w_MAX, c3_w_MAX, c3_w_MAX, c3_w_MAX }; - + // + { + c3_w data_w[4] = { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }; atom = u3i_words(4, data_w); - ret_w = u3r_met(0, atom); if (128 != ret_w){ printf("*** _test_met bit of 1 = %d \n", ret_w); @@ -1144,7 +1121,7 @@ void _test_met() if (4 != ret_w){ printf("*** _test_met _w of 1 = %d \n", ret_w); } - + ret_w = u3r_met(6, atom); if (2 != ret_w){ printf("*** _test_met _d of 1 = %d \n", ret_w); @@ -1152,14 +1129,11 @@ void _test_met() } // 4 words (top word is '1' ) - // - { - - c3_w data_w[4] = { c3_w_MAX, c3_w_MAX, c3_w_MAX, 1 }; - + // + { + c3_w data_w[4] = { 0xffffffff, 0xffffffff, 0xffffffff, 1 }; atom = u3i_words(4, data_w); - ret_w = u3r_met(0, atom); if (97 != ret_w){ printf("*** _test_met bit of 1 = %d \n", ret_w); @@ -1174,226 +1148,24 @@ void _test_met() if (4 != ret_w){ printf("*** _test_met _w of 1 = %d \n", ret_w); } - + ret_w = u3r_met(6, atom); if (2 != ret_w){ printf("*** _test_met _d of 1 = %d \n", ret_w); } } - - - } -void _test_cue_jam() -{ - - // the boot msg from the worker - { - u3_noun dat = u3_nul; - u3_noun in_1 = u3nc(c3__play, dat); - u3_atom jam_1 = u3ke_jam(in_1); - - u3_noun out_1 = u3ke_cue(jam_1); - u3_noun head_out = u3h(out_1); - u3_noun tail_out = u3t(out_1); - - if (c3__play != head_out){ - printf("*** cue_jam 0 out head \n"); - } - - if (u3_nul != tail_out){ - printf("*** cue_jam 0 out tail \n"); - } - - } - - // the boot msg from the worker, again, but this time torn apart into bytes and rebuilt - { - u3_noun dat = u3_nul; - u3_noun in_1 = u3nc(c3__play, dat); - u3_atom jam_1 = u3ke_jam(in_1); - - c3_y buf_y[1024]; - bzero(buf_y, 1024); - c3_w len_w = u3r_met(3, jam_1); - - u3r_bytes(0, // start byte - len_w, // len - buf_y, // buffer - jam_1 ); // input noun - - /// zip ....zap ... communicate between serf and king - - u3_noun jam_2 = u3i_bytes(len_w, buf_y); - - if (jam_1 != jam_2){ - printf("*** error in 6 byte message ; is u3ke_jam() building an indirect atom?? \n"); - } - - - u3_noun out_1 = u3ke_cue(jam_2); - - u3_noun head_out = u3h(out_1); - u3_noun tail_out = u3t(out_1); - - if (c3__play != head_out){ - printf("*** cue_jam 0 out head \n"); - } - - if (u3_nul != tail_out){ - printf("*** cue_jam 0 out tail \n"); - } - - } - - return; - - // 1 - { - - u3_atom in_1 = 1; - u3_atom jam_1 = u3ke_jam(in_1); - - if (12 != jam_1){ - printf("*** cue_jam 1a \n"); - } - - u3_noun out_1 = u3ke_cue(jam_1); - - if (1 != out_1){ - printf("*** cue_jam 1b \n"); - } - - } - - // [ 1 1 ] - { - - u3_noun in_1 = u3i_cell(1, 1); - u3_atom jam_1 = u3ke_jam(in_1); - - if (817 != jam_1){ - printf("*** cue_jam 2 in \n"); - } - - u3_noun out_1 = u3ke_cue(jam_1); - - - u3_noun head_out = u3h(out_1); - u3_noun tail_out = u3t(out_1); - - if (1 != head_out){ - printf("*** cue_jam 2 out head \n"); - } - - if (1 != tail_out){ - printf("*** cue_jam 2 out tail \n"); - } - - } - - // [ 1 2 ] - { - - u3_noun in_1 = u3i_cell(1, 2); - u3_atom jam_1 = u3ke_jam(in_1); - - if (4657 != jam_1){ - printf("*** cue_jam 2 in \n"); - } - - u3_noun out_1 = u3ke_cue(jam_1); - - u3_noun head_out = u3h(out_1); - u3_noun tail_out = u3t(out_1); - - if (1 != head_out){ - printf("*** cue_jam 2 out head \n"); - } - - if (2 != tail_out){ - printf("*** cue_jam 2 out tail \n"); - } - } - - - - // medium complicated cell - // q - // / \ - // a1 r - // / \ - // b2 s - // / \ - // c3 d4 - { - u3_noun a = (u3_noun) 0x1; - u3_noun b = (u3_noun) 0x2; - u3_noun c = (u3_noun) 0x3; - u3_noun d = (u3_noun) 0x4; - - u3_noun s = u3i_cell(c, d); - u3_noun r = u3i_cell(b, s); - u3_noun q = u3i_cell(a, r); - - u3_atom jam_1 = u3ke_jam(q); - - u3_noun out_1 = u3ke_cue(jam_1); - - - u3_noun a2 = u3h(out_1); - u3_noun r2 = u3t(out_1); - if (a2 != a){ - printf("*** _cue_jam: complicated a\n"); - } - - u3_noun b2 = u3h(r2); - u3_noun s2 = u3t(r2); - if (b2 != b){ - printf("*** _cue_jam: complicated b\n"); - } - - - u3_noun c2 = u3h(s2); - u3_noun d2 = u3t(s2); - if (c2 != c){ - printf("*** _cue_jam: complicated c\n"); - } - - if (d2 != d){ - printf("*** _cue_jam: complicated d\n"); - } - - } - -} - -void _test_into_outa() -{ - printf("we should really test into() / outa() here\n"); - -} - -void _test_cue_pil() -{ - extern c3_w u3_Ivory_length_w; - extern c3_y u3_Ivory_pill_y[]; - - u3_noun pil = u3i_bytes(u3_Ivory_length_w, u3_Ivory_pill_y); - - u3_noun arv = u3ke_cue(pil); // 'pil' is a simple bignum ; turn it into a tree 'arv' by cue-ing -} - - +/* _test_u3r_at(): inspect cells at arbitrary axis locations +** [ and utility function u3x_dep() ] +*/ static void _test_u3r_at() { + c3_w a_w = u3x_dep(0); - c3_w a_w; - a_w = u3x_dep(0); if (0xffffffff != a_w) { printf("*** u3x_dep() \n"); } - + a_w = u3x_dep(1); if (0 != a_w) { printf("*** u3x_dep() \n"); } @@ -1402,7 +1174,7 @@ _test_u3r_at() a_w = u3x_dep(0b11); if (1 != a_w) { printf("*** u3x_dep() \n"); } - + a_w = u3x_dep(0b100); if (2 != a_w) { printf("*** u3x_dep() \n"); } @@ -1411,11 +1183,13 @@ _test_u3r_at() a_w = u3x_dep(0b111); if (2 != a_w) { printf("*** u3x_dep() \n"); } - + a_w = u3x_dep( ((c3_w) (((c3_d) 1 << 32) - 1)) ); if (31 != a_w) { printf("*** u3x_dep() \n"); } + // XX disabled, 64-bit + // #if 0 a_w = u3x_dep_d(0); a_w = u3x_dep_d(1); @@ -1426,7 +1200,7 @@ _test_u3r_at() a_w = u3x_dep_d( ((c3_w) (((c3_d) 1 << 33) - 1)) ); a_w = u3x_dep_d( ((c3_d) (((c3_d) 1 << 64) - 1)) ); #endif - + u3_weak ret; // addr 1 in atom == atom value @@ -1448,14 +1222,14 @@ _test_u3r_at() tree = u3i_cell(10, 20); ret = u3r_at( 1, tree); if (tree != ret) { printf("*** u3r_at \n"); } - + ret = u3r_at( 2, tree); if (10 != ret) { printf("*** u3r_at \n"); } ret = u3r_at( 3, tree); if (20 != ret) { printf("*** u3r_at \n"); } // simple tree [ 1 ] - c3_w in_w[10] = {10, 20, c3_w_MAX}; + c3_w in_w[10] = {10, 20, 0xffffffff}; u3_noun bignum = u3i_words(3, in_w); tree = u3i_cell(99, bignum); @@ -1463,15 +1237,15 @@ _test_u3r_at() if (99 != ret) { printf("*** u3r_at \n"); } ret = u3r_at( 3, tree); if (bignum != ret) { printf("*** u3r_at \n"); } - - } -void _test_u3r_chop() +/* _test_u3r_chop: "extract bit slices from atom" +*/ +static void +_test_u3r_chop() { c3_w dst_w = 0; - // read 1 bit bloq { // read 1 bit from pos=0 (far right) @@ -1479,7 +1253,7 @@ void _test_u3r_chop() c3_g bloqsize_g = 0; - + dst_w = 0; u3r_chop(bloqsize_g, /// bloq size 0, // start index @@ -1537,7 +1311,7 @@ void _test_u3r_chop() if (0b10110 != dst_w) { printf("*** test_u3r_chop 5\n"); } - + } // read 2 bit bloq @@ -1547,7 +1321,7 @@ void _test_u3r_chop() c3_g bloqsize_g = 1; // read 2 bit from pos=0 (far right) - + dst_w = 0; u3r_chop(bloqsize_g, /// bloq size 0, // start index @@ -1590,7 +1364,7 @@ void _test_u3r_chop() c3_g bloqsize_g = 3; // 2^3 = 8 bits // pos=0 (far right) - + dst_w = 0; u3r_chop(bloqsize_g, /// bloq size 0, // start index @@ -1605,15 +1379,14 @@ void _test_u3r_chop() // read 1,8,16 bit bloqs from an indirect atom { // build an indirect noun 'src' - - c3_y * input_y = "abcdefghij"; - u3_noun src = u3i_bytes(10, input_y); - + c3_c* input_c = "abcdefghij"; + u3_noun src = u3i_bytes(10, (c3_y*)input_c); + + c3_g bloqsize_g = 0; // 2^0 = 1 bit // 1 x 1 bit pos=0 (far right) - // - because data is stored LSB first, this pulls the lowest bit of the 'a' out dst_w = 0; u3r_chop(bloqsize_g, /// bloq size 0, // start index @@ -1622,9 +1395,11 @@ void _test_u3r_chop() & dst_w, // where bytes go to src); // where bytes come from - if (0b1 != dst_w) { printf("*** test_u3r_chop indirect.1\n"); } + if (0b1 != dst_w) { + printf("*** test_u3r_chop indirect.1\n"); + } - // 8 x 1 bit pos=0 (far right), because data is stored LSB first, this pulls the 'a' out + // 8 x 1 bit pos=0 (far right) dst_w = 0; u3r_chop(bloqsize_g, /// bloq size 0, // start index @@ -1633,9 +1408,11 @@ void _test_u3r_chop() & dst_w, // where bytes go to src); // where bytes come from - if (0b1100001 != dst_w) { printf("*** test_u3r_chop indirect.2\n"); } + if (0b1100001 != dst_w) { + printf("*** test_u3r_chop indirect.2\n"); + } - // 1 x 1 byte = 8 bit, pos=0 (far right), because data is stored LSB first, this pulls the 'a' out + // 1 x 1 byte = 8 bit, pos=0 (far right) bloqsize_g = 3; // 2^3 = 1 byte dst_w = 0; u3r_chop(bloqsize_g, /// bloq size @@ -1645,9 +1422,10 @@ void _test_u3r_chop() & dst_w, // where bytes go to src); // where bytes come from - if (0b1100001 != dst_w) { printf("*** test_u3r_chop indirect.3\n"); } + if (0b1100001 != dst_w) { + printf("*** test_u3r_chop indirect.3\n"); + } - // 1 x 16 bit bloq, pos = 0 bloqsize_g = 4; // 2^4 = 2 bytes @@ -1659,25 +1437,24 @@ void _test_u3r_chop() & dst_w, // where bytes go to src); // where bytes come from - if (0b0110001001100001 != dst_w) { printf("*** test_u3r_chop indirect.4\n"); } - - + if (0b0110001001100001 != dst_w) { + printf("*** test_u3r_chop indirect.4\n"); + } } - // read lots of bits from a direct noun which holds 64 bits of data // makes sure that we handle top 32 / bottom 32 correctly { // build an indirect noun 'src' - - c3_y input_y[8] = { 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7 }; - u3_noun src = u3i_bytes(8, input_y); - + + c3_c input_c[8] = { 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7 }; + u3_noun src = u3i_bytes(8, (c3_y*)input_c); + c3_g bloqsize_g = 0; // 2^0 = 1 bit c3_w dst_w[2]; - bzero(dst_w, 2 * sizeof(c3_w)); - + memset(dst_w, 0, 2 * sizeof(c3_w)); + u3r_chop(bloqsize_g, /// bloq size 0, // start index 63, // count of bloqs @@ -1691,16 +1468,14 @@ void _test_u3r_chop() // makes sure that we handle top 32 / bottom 32 correctly) // but with a bit more nuance { - - // least significant most - c3_y input_y[8] = { 0x0, 0x0, 0x0, 0xaa, 0xff, 0x0, 0x0, 0x0 }; - u3_noun src = u3i_bytes(8, input_y); - + c3_c input_c[8] = { 0x0, 0x0, 0x0, 0xaa, 0xff, 0x0, 0x0, 0x0 }; + u3_noun src = u3i_bytes(8, (c3_y*)input_c); + c3_g bloqsize_g = 0; // 2^0 = 1 bit c3_w dst_w = 0; - + u3r_chop(bloqsize_g, /// bloq size 24, // start index 16, // count of bloqs @@ -1708,13 +1483,15 @@ void _test_u3r_chop() & dst_w, // where bytes go to src); // where bytes come from - if (0b1111111110101010 != dst_w) { printf("*** test_u3r_chop indirect. 6\n"); } - + if (0b1111111110101010 != dst_w) { + printf("*** test_u3r_chop indirect. 6\n"); + } } - } - +// XX disabled, static functions +// +#if 0 void _n_push(c3_ys mov, c3_ys off, u3_noun a); u3_noun * _n_peek(c3_ys off); u3_noun* _n_peet(c3_ys mov, c3_ys off); @@ -1723,14 +1500,13 @@ u3_noun _n_pep(c3_ys mov, c3_ys off); void _n_toss(c3_ys mov, c3_ys off); u3_noun* _n_swap(c3_ys mov, c3_ys off); - - - - -void _test_nvm_stack_inner(c3_ys mov, c3_ys off) +/* _test_nvm_stack_inner(): +*/ +void +_test_nvm_stack_inner(c3_ys mov, c3_ys off) { u3_noun * peek; - + // push 1, peek, pop if(1) { _n_push(mov, off, 0x1122334455667788); @@ -1738,7 +1514,7 @@ void _test_nvm_stack_inner(c3_ys mov, c3_ys off) if (0x1122334455667788 != *peek) { printf("*** test_nvm_stack 1\n"); } _n_pop(mov); } - + // push 2, peek, pop, peek, pop if(1) { _n_push(mov, off, 88); @@ -1759,11 +1535,11 @@ void _test_nvm_stack_inner(c3_ys mov, c3_ys off) } for (ii=100; ii >= 0; ii--){ peek = _n_peek(off); - if (ii != *peek) { printf("*** test_nvm_stack 4\n"); } + if (ii != *peek) { printf("*** test_nvm_stack 4\n"); } _n_pop(mov); } } - + // peet() { _n_push(mov, off, 333); @@ -1814,37 +1590,42 @@ void _test_nvm_stack_inner(c3_ys mov, c3_ys off) if (3003 != ret) { printf("*** test_nvm_stack 12\n"); } } - - - } - -u3_noun _test_nvm_stack_south(u3_noun arg) +/* _test_nvm_stack_south(): test the stack usage in an inner, south road +*/ +u3_noun +_test_nvm_stack_south(u3_noun arg) { c3_ys mov = 2; c3_ys off = -2; - + _test_nvm_stack_inner(mov, off); + return u3_nul; } +#endif -void _test_nvm_stack() +/* _test_nvm_stack(): test the stack usage of the bytecode interpreter +** (growing in both directions: N and S) +*/ +static void +_test_nvm_stack() { + // XX disabled, static functions + // XX rewrite to use u3a_push/u3a_pop? + // +#if 0 // north road c3_ys mov = -2; c3_ys off = 0; _test_nvm_stack_inner(mov, off); // south road - u3_noun ret = u3m_soft(100, // c3_w sec_w - & _test_nvm_stack_south, // u3_funk fun_f - 0); // u3_noun arg - - + u3m_soft(100, &_test_nvm_stack_south, 0); +#endif } - /* main(): run all test cases. */ int @@ -1852,57 +1633,20 @@ main(int argc, char* argv[]) { _setup(); - // allocate.h level 1 - _test_noun_bits_read(); - - // allocate.h level 1a _test_noun_bits_set(); - - - // test the "extract bit slices from atom" function u3r_chop() + _test_noun_bits_read(); _test_u3r_chop(); - - - // 'jam' = marshall / compress /serialize ; 'cue' = unpack - _test_cue_jam(); - - // test basic data into / out of nouns _test_imprison(); - - // test more complicated data into / out of nouns _test_imprison_complex(); - - - // 'sing' = equality _test_sing(); - - // 'fing' = equality _test_fing(); - - // 'met' = measure / take size _test_met(); - - - // cue the entire ivory pill, to really exercise 'cue' - _test_cue_pil(); - - // take loom numbers and convert them into pointers to loom memory - _test_into_outa(); - - // build and inspect cells: u3i_cell(), u3h(), u3t() _test_cells(); - - // build cells with more complex methods _test_cells_complex(); - - // inspect cells at arbitrary axis locations u3r_at() [ and utility function u3x_dep() ] _test_u3r_at(); - - // test the stack functions used inside the Nock Virtual Machine (growing in both directions: N and S) _test_nvm_stack(); - - printf("all tests done\n"); - + fprintf(stderr, "test_noun: ok\n"); + return 0; }