(* Examine Pill Structure at Depth * * Maybe Arvo is nested inside the pill structure *) open Nock_lib let rec find_gates noun depth max_depth path = if depth > max_depth then [] else match noun with | Noun.Atom _ -> [] | Noun.Cell (head, tail) -> let this_is_gate = (* A gate has: [battery sample context] where battery is a cell *) Noun.is_cell head && Noun.is_cell tail && Noun.is_cell (Noun.head tail) in (* tail = [sample context] *) let gates = if this_is_gate then [(depth, List.rev path, noun)] else [] in let head_gates = find_gates head (depth + 1) max_depth (2 :: path) in let tail_gates = find_gates tail (depth + 1) max_depth (3 :: path) in gates @ head_gates @ tail_gates let test_pill_depth env = Printf.printf "🔍 Searching for Gates in Pill Structure\n\n"; Eio.Switch.run @@ fun _sw -> let fs = Eio.Stdenv.fs env in (* Load ivory pill *) let state = State.create () in match Boot.boot_from_file ~fs state "ivory.pill" with | Error msg -> Printf.printf "✗ Failed to load pill: %s\n%!" msg | Ok () -> let kernel = State.get_arvo state in Printf.printf "Searching for gate structures (depth 0-8)...\n\n"; let gates = find_gates kernel 0 8 [] in if List.length gates = 0 then Printf.printf "No gate structures found!\n\n" else begin Printf.printf "Found %d potential gates:\n\n" (List.length gates); List.iteri (fun i (depth, path, gate) -> Printf.printf "%d. At depth %d, path: [%s]\n" (i + 1) depth (String.concat " " (List.map string_of_int path)); (* Try to call it *) try let formula = Noun.cell (Noun.atom 9) (Noun.cell (Noun.atom 2) (Noun.cell (Noun.atom 0) (Noun.atom 1))) in let _result = Nock.nock_on gate formula in Printf.printf " ✓ CALLABLE! Path to Arvo: [%s]\n\n" (String.concat " " (List.map string_of_int path)) with e -> Printf.printf " ✗ Not callable: %s\n\n" (Printexc.to_string e) ) gates end; (* Also check: maybe pill is [type data] *) Printf.printf "Checking if pill is a tagged pair...\n"; if Noun.is_cell kernel then begin let tag = Noun.head kernel in let payload = Noun.tail kernel in match tag with | Noun.Atom z when Z.numbits z < 32 -> Printf.printf " Tag: %s\n" (Z.to_string z); Printf.printf " Payload: %s\n" (if Noun.is_cell payload then "Cell" else "Atom"); (* Try calling payload *) if Noun.is_cell payload then begin Printf.printf "\n Trying to call payload...\n"; try let formula = Noun.cell (Noun.atom 9) (Noun.cell (Noun.atom 2) (Noun.cell (Noun.atom 0) (Noun.atom 1))) in let _result = Nock.nock_on payload formula in Printf.printf " ✓ Payload is callable!\n" with e -> Printf.printf " ✗ Payload not callable: %s\n" (Printexc.to_string e) end | _ -> Printf.printf " Not a simple tagged pair\n" end let () = Printf.printf "\n"; Printf.printf "═══════════════════════════════════════════════════════════\n"; Printf.printf " Searching for Arvo in Pill Structure\n"; Printf.printf "═══════════════════════════════════════════════════════════\n"; Printf.printf "\n"; Eio_main.run test_pill_depth