diff options
Diffstat (limited to 'vere/pkg')
-rw-r--r-- | vere/pkg/noun/nock.c | 83 | ||||
-rw-r--r-- | vere/pkg/vere/ivory_boot_test.c | 72 | ||||
-rw-r--r-- | vere/pkg/vere/solid_boot_test.c | 19 |
3 files changed, 139 insertions, 35 deletions
diff --git a/vere/pkg/noun/nock.c b/vere/pkg/noun/nock.c index 959ec96..eef211b 100644 --- a/vere/pkg/noun/nock.c +++ b/vere/pkg/noun/nock.c @@ -2919,28 +2919,6 @@ u3n_burn(u3p(u3n_prog) pog_p, u3_noun bus) static u3_noun _n_burn_on(u3_noun bus, u3_noun fol) { - static c3_w burn_count = 0; - if ( burn_count < 500 ) { // Increased to 500 to capture solid pill boot - u3_noun hib = u3h(fol); - if ( c3y == u3du(hib) ) { - u3l_log("[C-Burn:%u] cell-cell formula", burn_count); - } else { - u3l_log("[C-Burn:%u] opcode %u", burn_count, hib); - // For call #1, dump more details - if ( burn_count == 1 ) { - u3_noun gal = u3t(fol); - u3l_log("[C-Burn:1-DEBUG] gal is %s", (c3y == u3du(gal)) ? "cell" : "atom"); - if ( c3y == u3du(gal) ) { - u3_noun gal_h = u3h(gal); - u3l_log("[C-Burn:1-DEBUG] head(gal) is %s, val=%u", - (c3y == u3du(gal_h)) ? "cell" : "atom", - (c3y == u3du(gal_h)) ? u3h(gal_h) : gal_h); - } - } - } - burn_count++; - } - u3n_prog* pog_u = _n_find(u3_nul, fol); u3z(fol); @@ -2954,12 +2932,46 @@ u3n_nock_on(u3_noun bus, u3_noun fol) { u3_noun pro; - static c3_w call_count = 0; - if ( call_count < 100 ) { // Increased to 100 - u3l_log(">>> u3n_nock_on call #%u <<<", call_count); + // Static variables persist across all calls; local variables are per-call + static c3_w call_count = 0; // Global counter incremented on each call + static c3_w depth = 0; // Current recursion depth + + // Capture current call_count in a local variable so it survives recursion. + // Without this, when we log EXIT, call_count will have been incremented + // by all the recursive calls that happened in between, giving wrong numbers. + c3_w my_call = call_count; + c3_o should_log = (call_count < 100) ? c3y : c3n; + + if ( c3y == should_log ) { + u3_noun hib = u3h(fol); // Get the opcode (head of formula) + + // Build indentation string based on recursion depth for readability + const char* indent = ""; + if ( depth == 0 ) indent = ""; + else if ( depth == 1 ) indent = " "; + else if ( depth == 2 ) indent = " "; + else if ( depth == 3 ) indent = " "; + else if ( depth == 4 ) indent = " "; + else if ( depth >= 5 ) indent = " "; + + // Log entry with opcode. CELL means distribution (implicit cons). + if ( c3y == u3du(hib) ) { + u3l_log("%s>>> ENTER call #%u depth=%u opcode=CELL bus=%s[mug=0x%x]", + indent, my_call, depth, + (c3y == u3du(bus)) ? "cell" : "atom", + u3r_mug(bus)); + } else { + // Opcodes 0-12 are the Nock rules (0=slot, 1=const, 2=eval, etc.) + u3l_log("%s>>> ENTER call #%u depth=%u opcode=%u bus=%s[mug=0x%x]", + indent, my_call, depth, hib, + (c3y == u3du(bus)) ? "cell" : "atom", + u3r_mug(bus)); + } call_count++; } + depth++; + u3t_on(noc_o); #if 0 pro = _n_nock_on(bus, fol); @@ -2968,6 +2980,27 @@ u3n_nock_on(u3_noun bus, u3_noun fol) #endif u3t_off(noc_o); + // Restore depth before logging exit (so depth matches the ENTER log) + depth--; + + if ( c3y == should_log ) { + // Rebuild indentation to match the ENTER log + const char* indent = ""; + if ( depth == 0 ) indent = ""; + else if ( depth == 1 ) indent = " "; + else if ( depth == 2 ) indent = " "; + else if ( depth == 3 ) indent = " "; + else if ( depth == 4 ) indent = " "; + else if ( depth >= 5 ) indent = " "; + + // Log exit with the result. Use my_call (not call_count) to match ENTER. + // The mug (hash) helps track if the same noun is returned multiple times. + u3l_log("%s<<< EXIT call #%u depth=%u returns=%s[mug=0x%x]", + indent, my_call, depth, + (c3y == u3du(pro)) ? "cell" : "atom", + u3r_mug(pro)); + } + return pro; } diff --git a/vere/pkg/vere/ivory_boot_test.c b/vere/pkg/vere/ivory_boot_test.c new file mode 100644 index 0000000..0bd968b --- /dev/null +++ b/vere/pkg/vere/ivory_boot_test.c @@ -0,0 +1,72 @@ +/// @file + +// #include "ivory.h" +#include "noun.h" +#include "ur/ur.h" +#include "vere.h" + +/* _setup(): prepare for tests. +*/ +static void +_setup(void) +{ + u3C.wag_w |= u3o_hashless; + u3m_boot_lite(1 << 28); // 256MB loom for solid pill + + // Load OCaml's ivory.pill file instead of embedded + u3l_log("Loading ivory.pill from OCaml directory..."); + u3_noun ivory_jammed = u3m_file("/home/y/code/urbit/vere/ocaml/ivory.pill"); + u3l_log("Cuing ivory.pill..."); + u3_noun pil = u3ke_cue(ivory_jammed); + // Don't free ivory_jammed - it's managed by u3m_file + + u3l_log("ivory_pil is_atom: %u", u3a_is_atom(pil)); + + // Boot with ivory pill + u3l_log("Booting with ivory.pill from OCaml..."); + if ( c3n == u3v_boot_lite(pil) ) { + printf("*** fail: ivory boot failed\n"); + exit(1); + } + u3l_log("✓ Ivory boot completed!"); +} + +/* _test_lily(): test small noun parsing. +*/ +static void +_test_lily() +{ + c3_l lit_l; + c3_w big_w[] = {0, 0, 1}; + u3_noun big = u3i_words(3, big_w); + u3_noun cod = u3dc("scot", c3__uv, big); + + if ( c3y == u3v_lily(c3__uv, cod, &lit_l) ) { + printf("*** fail _test_lily-1\n"); + exit(1); + } + cod = u3dc("scot", c3__ud, 0x7fffffff); + if ( (c3n == u3v_lily(c3__ud, cod, &lit_l)) || + (0x7fffffff != lit_l) ) { + printf("*** fail _test_lily-2a\n"); + exit(1); + } + cod = u3dc("scot", c3__ux, u3i_word(0x80000000)); + if ( c3y == u3v_lily(c3__ux, cod, &lit_l) ) { + printf("*** fail _test_lily-2b\n"); + exit(1); + } +} + +/* main(): run all test cases. +*/ +int +main(int argc, char* argv[]) +{ + _setup(); + + _test_lily(); + + fprintf(stderr, "test boot: ok\n"); + return 0; +} diff --git a/vere/pkg/vere/solid_boot_test.c b/vere/pkg/vere/solid_boot_test.c index 1d5c11d..26a0f07 100644 --- a/vere/pkg/vere/solid_boot_test.c +++ b/vere/pkg/vere/solid_boot_test.c @@ -258,22 +258,21 @@ _setup(void) u3C.wag_w |= u3o_hashless; u3m_boot_lite(1 << 28); // 256MB loom for solid pill - // Load OCaml's ivory.pill file instead of embedded - u3l_log("Loading ivory.pill from OCaml directory..."); - u3_noun ivory_jammed = u3m_file("/home/y/code/urbit/vere/ocaml/ivory.pill"); - u3l_log("Cuing ivory.pill..."); - u3_noun pil = u3ke_cue(ivory_jammed); + u3l_log("Loading solid.pill from OCaml directory..."); + u3_noun solid_jammed = u3m_file("/home/y/code/urbit/vere/ocaml/solid.pill"); + u3l_log("Cuing solid.pill..."); + u3_noun pil = u3ke_cue(solid_jammed); // Don't free ivory_jammed - it's managed by u3m_file - u3l_log("ivory_pil is_atom: %u", u3a_is_atom(pil)); + u3l_log("solid_pil is_atom: %u", u3a_is_atom(pil)); - // Boot with ivory pill - u3l_log("Booting with ivory.pill from OCaml..."); + // Boot with solid pill + u3l_log("Booting with solid.pill from OCaml..."); if ( c3n == u3v_boot_lite(pil) ) { - printf("*** fail: ivory boot failed\n"); + printf("*** fail: solid boot failed\n"); exit(1); } - u3l_log("✓ Ivory boot completed!"); + u3l_log("✓ solid boot completed!"); } /* _test_lily(): test small noun parsing. |