summaryrefslogtreecommitdiff
path: root/ocaml/lib/nock.ml
diff options
context:
space:
mode:
Diffstat (limited to 'ocaml/lib/nock.ml')
-rw-r--r--ocaml/lib/nock.ml110
1 files changed, 52 insertions, 58 deletions
diff --git a/ocaml/lib/nock.ml b/ocaml/lib/nock.ml
index 5658ed7..64daa91 100644
--- a/ocaml/lib/nock.ml
+++ b/ocaml/lib/nock.ml
@@ -41,40 +41,41 @@ let opcode_name op =
let rec nock_on init_bus init_fol =
let bus = ref init_bus in
let fol = ref init_fol in
+ let my_call = !call_count in
- let rec loop () =
- let my_call = !call_count in
-
- (* Check if this is opcode 0 (slot lookup) - C doesn't log these *)
- let is_slot = match !fol with
- | Cell { h = Atom { z = op; _ }; _ } when Z.fits_int op && Z.to_int op = 0 -> true
- | _ -> false
- in
+ (* Check if this is opcode 0 (slot lookup) - C doesn't log these *)
+ let is_slot = match init_fol with
+ | Cell { h = Atom { z = op; _ }; _ } when Z.fits_int op && Z.to_int op = 0 -> true
+ | _ -> false
+ in
- let should_log = my_call < max_calls && not is_slot in
+ let should_log = my_call < max_calls && not is_slot in
- (* Log entry *)
- if should_log then begin
- let opcode_str = match !fol with
- | Cell { h = Atom { z = op; _ }; _ } when Z.fits_int op -> opcode_name (Z.to_int op)
- | Cell { h = Cell _; _ } -> "CELL(dist)"
- | _ -> "?"
- in
- 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
- (if is_cell !bus then "cell" else "atom")
- bus_mug
- end else begin
- Printf.eprintf "%s>>> ENTER call #%d depth=%d opcode=%s bus=%s\n%!"
- (indent ()) my_call !depth opcode_str
- (if is_cell !bus then "cell" else "atom")
- end;
- incr call_count
+ (* Log entry ONCE at function entry *)
+ if should_log then begin
+ let opcode_str = match init_fol with
+ | Cell { h = Atom { z = op; _ }; _ } when Z.fits_int op -> opcode_name (Z.to_int op)
+ | Cell { h = Cell _; _ } -> "CELL(dist)"
+ | _ -> "?"
+ in
+ if !show_mugs || !depth <= !max_mug_depth then begin
+ let bus_mug = mug init_bus in
+ Printf.eprintf "%s>>> ENTER call #%d depth=%d opcode=%s bus=%s[mug=0x%lx]\n%!"
+ (indent ()) my_call !depth opcode_str
+ (if is_cell init_bus then "cell" else "atom")
+ bus_mug
+ end else begin
+ Printf.eprintf "%s>>> ENTER call #%d depth=%d opcode=%s bus=%s\n%!"
+ (indent ()) my_call !depth opcode_str
+ (if is_cell init_bus then "cell" else "atom")
end;
+ incr call_count
+ end;
+
+ (* Increment depth ONCE at function entry *)
+ incr depth;
- incr depth;
+ let rec loop () =
try
let result = match !fol with
@@ -101,18 +102,29 @@ let rec nock_on init_bus init_fol =
if not (is_cell gal) then raise Exit;
let c_gal = tail gal in
let b_gal = head gal in
+
+ (* Debug first call *)
+ if my_call = 0 then begin
+ Printf.eprintf "[Op2 Debug] Computing formula (tail gal):\n%!";
+ Printf.eprintf " c_gal mug: 0x%lx\n%!" (mug c_gal);
+ end;
+
let nex = nock_on !bus c_gal in
+
+ if my_call = 0 then begin
+ Printf.eprintf " nex mug: 0x%lx\n%!" (mug nex);
+ Printf.eprintf "[Op2 Debug] Computing subject (head gal):\n%!";
+ Printf.eprintf " b_gal mug: 0x%lx\n%!" (mug b_gal);
+ end;
+
let seb = nock_on !bus b_gal in
+
+ if my_call = 0 then begin
+ Printf.eprintf " seb mug: 0x%lx\n%!" (mug seb);
+ end;
+
bus := seb;
fol := nex;
- decr depth;
- if should_log then begin
- if !show_mugs || !depth <= !max_mug_depth then begin
- let result_mug = mug !bus in
- Printf.eprintf "%s<<< CONTINUE call #%d depth=%d with bus[mug=0x%lx]\n%!"
- (indent ()) my_call !depth result_mug
- end
- end;
loop ()
| 3 ->
@@ -145,11 +157,7 @@ let rec nock_on init_bus init_fol =
| _ -> raise Exit
in
fol := nex;
- decr depth;
- if should_log then begin
- Printf.eprintf "%s<<< CONTINUE call #%d depth=%d (if-branch)\n%!"
- (indent ()) my_call !depth
- end;
+ (* Don't decr depth for tail calls *)
loop ()
| 7 ->
@@ -160,14 +168,7 @@ let rec nock_on init_bus init_fol =
let bod = nock_on !bus b_gal in
bus := bod;
fol := c_gal;
- decr depth;
- if should_log then begin
- if !show_mugs || !depth <= !max_mug_depth then begin
- let result_mug = mug !bus in
- Printf.eprintf "%s<<< CONTINUE call #%d depth=%d with bus[mug=0x%lx]\n%!"
- (indent ()) my_call !depth result_mug
- end
- end;
+ (* Don't decr depth for tail calls *)
loop ()
| 8 ->
@@ -179,14 +180,7 @@ let rec nock_on init_bus init_fol =
let bod = cell heb !bus in
bus := bod;
fol := c_gal;
- decr depth;
- if should_log then begin
- if !show_mugs || !depth <= !max_mug_depth then begin
- let result_mug = mug !bus in
- Printf.eprintf "%s<<< CONTINUE call #%d depth=%d with bus[mug=0x%lx]\n%!"
- (indent ()) my_call !depth result_mug
- end
- end;
+ (* Don't decr depth for tail calls *)
loop ()
| 9 ->