diff options
author | polwex <polwex@sortug.com> | 2025-10-06 22:16:33 +0700 |
---|---|---|
committer | polwex <polwex@sortug.com> | 2025-10-06 22:16:33 +0700 |
commit | da03400d5857aab4c809c34f0416d1c09c4fed12 (patch) | |
tree | e44d94e3ceeafc108e1290a1de2e5c9c12012d48 /vere/pkg/noun/nock.c | |
parent | 64b132efc5ad870677ac974334b30fdbc4afafd3 (diff) |
pretty good pretty good
Diffstat (limited to 'vere/pkg/noun/nock.c')
-rw-r--r-- | vere/pkg/noun/nock.c | 83 |
1 files changed, 58 insertions, 25 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; } |