From acf0d9d90795db6b028d7404a5cdc0a20d0225d9 Mon Sep 17 00:00:00 2001 From: polwex Date: Tue, 7 Oct 2025 00:19:53 +0700 Subject: added mugs to nock logs --- ocaml/lib/nock.ml | 13 +++++++------ ocaml/test/test_two_stage_boot.ml | 4 ++++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/ocaml/lib/nock.ml b/ocaml/lib/nock.ml index 2d106b6..73e5407 100644 --- a/ocaml/lib/nock.ml +++ b/ocaml/lib/nock.ml @@ -24,12 +24,13 @@ open Noun - depth: current recursion depth - max_calls: how many calls to log (like C's limit) - max_mug_depth: only compute mugs at shallow depths (expensive!) + - show_mugs: global flag to enable/disable mug logging *) let call_count = ref 0 let depth = ref 0 let max_calls = 100 -let max_mug_depth = -1 (* Disabled: even cached, initial mug of huge ivory pill is slow *) -(* TODO: Enable selectively after verifying structural correctness *) +let max_mug_depth = ref (-1) (* Can be set from outside *) +let show_mugs = ref false (* Enable from test code to show mugs at every step *) (* Helper to generate indentation based on depth *) let indent () = @@ -77,8 +78,8 @@ let rec nock_on bus fol = | Cell { h = Cell _; _ } -> "CELL(dist)" | _ -> "?" in - (* Only compute mugs at shallow depths to avoid performance penalty *) - if !depth <= max_mug_depth then begin + (* Only compute mugs at shallow depths to avoid performance penalty, or if show_mugs is enabled *) + if !show_mugs || !depth <= !max_mug_depth then begin let bus_mug = mug bus in Printf.eprintf "%s>>> ENTER call #%d depth=%d opcode=%s bus=%s[mug=0x%lx]\n%!" (indent ()) my_call !depth opcode_str @@ -239,8 +240,8 @@ let rec nock_on bus fol = (* Restore depth and log exit before returning *) decr depth; if should_log then begin - (* Only compute mugs at shallow depths to avoid performance penalty *) - if !depth <= max_mug_depth then begin + (* Only compute mugs at shallow depths to avoid performance penalty, or if show_mugs is enabled *) + if !show_mugs || !depth <= !max_mug_depth then begin let result_mug = mug result in Printf.eprintf "%s<<< EXIT call #%d depth=%d returns=%s[mug=0x%lx]\n%!" (indent ()) my_call !depth diff --git a/ocaml/test/test_two_stage_boot.ml b/ocaml/test/test_two_stage_boot.ml index 17c72a8..863c3a1 100644 --- a/ocaml/test/test_two_stage_boot.ml +++ b/ocaml/test/test_two_stage_boot.ml @@ -54,6 +54,10 @@ let stage1_ivory_boot env = Printf.printf "[5] Running u3v_life() on Arvo core...\n%!"; Printf.printf " Formula: [2 [0 3] [0 2]]\n"; Printf.printf " Subject: Arvo core (cell, mug: 0x%08lx)\n%!" core_mug; + Printf.printf " Enabling mug logging for all nock steps...\n%!"; + + (* Enable mug logging at every step *) + Nock.show_mugs := true; begin try let start = Unix.gettimeofday () in -- cgit v1.2.3