summaryrefslogtreecommitdiff
path: root/ocaml/test/test_pill_depth.ml
blob: 329465b346f5b75fa692e9bef142b0e21d92abc6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
(* 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