summaryrefslogtreecommitdiff
path: root/ocaml/test/examine_pill_events.ml
blob: 8a111171bca28bc0ccbdf865c8dd8ac4a0528255 (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
(* Examine what the bot/mod/use events actually contain *)

open Nock_lib

let describe_noun noun =
  match noun with
  | Noun.Atom a ->
      if Z.numbits a <= 64 then
        Printf.sprintf "Atom(%s)" (Z.to_string a)
      else
        Printf.sprintf "Atom(%d bits)" (Z.numbits a)
  | Noun.Cell _ -> "Cell"

let rec to_list acc noun =
  match noun with
  | Noun.Atom _ -> List.rev acc
  | Noun.Cell (item, rest) -> to_list (item :: acc) rest

let examine _env =
  Printf.printf "Loading solid.noun...\n";
  let in_channel = open_in_bin "solid.noun" in
  let pill = (Marshal.from_channel in_channel : Noun.noun) in
  close_in in_channel;

  match pill with
  | Noun.Cell (_tag, events) ->
      Printf.printf "\n=== solid.noun structure ===\n\n";

      let event_list = to_list [] events in
      Printf.printf "Total: %d items in list\n\n" (List.length event_list);

      List.iteri (fun i event ->
        Printf.printf "Item %d: %s\n" i (describe_noun event)
      ) event_list;

      (* Check if this matches what u3v_life expects *)
      Printf.printf "\n=== Testing u3v_life on this list ===\n\n";

      (* Functional BIOS formula: [2 [0 3] [0 2]] *)
      let lyf = Noun.cell (Noun.atom 2)
        (Noun.cell
          (Noun.cell (Noun.atom 0) (Noun.atom 3))
          (Noun.cell (Noun.atom 0) (Noun.atom 2))) in

      Printf.printf "Running [2 [0 3] [0 2]] on events...\n%!";

      begin try
        (* What does [0 2] get from events? *)
        let slot2 = Noun.slot (Z.of_int 2) events in
        Printf.printf "  Slot 2 of events: %s\n" (describe_noun slot2);

        (* What does [0 3] get from events? *)
        let slot3 = Noun.slot (Z.of_int 3) events in
        Printf.printf "  Slot 3 of events: %s\n\n" (describe_noun slot3);

        let start = Unix.gettimeofday () in
        let gat = Nock.nock_on events lyf in
        let elapsed = Unix.gettimeofday () -. start in

        Printf.printf "✓ Formula succeeded in %.4fs!\n\n" elapsed;

        (* Extract slot 7 *)
        let kernel = Noun.slot (Z.of_int 7) gat in
        Printf.printf "✓ Extracted kernel from slot 7\n\n";

        (* Check if kernel has slot 23 *)
        begin try
          let _poke = Noun.slot (Z.of_int 23) kernel in
          Printf.printf "✓ Kernel has poke at slot 23\n";
          Printf.printf "\n🎉 This is the correct event list format!\n"
        with _ ->
          Printf.printf "✗ No slot 23\n"
        end

      with
      | Not_found ->
          Printf.printf "✗ Slot not found\n"
      | Noun.Exit ->
          Printf.printf "✗ Nock Exit\n"
      | e ->
          Printf.printf "✗ Error: %s\n" (Printexc.to_string e)
      end

  | Noun.Atom _ ->
      Printf.printf "Pill is atom\n"

let () =
  Eio_main.run examine