diff options
author | polwex <polwex@sortug.com> | 2025-10-06 14:35:41 +0700 |
---|---|---|
committer | polwex <polwex@sortug.com> | 2025-10-06 14:35:41 +0700 |
commit | 256376afffe66faa239a6a6aaebb8f68a9c6cbe4 (patch) | |
tree | 52f2ea2ba9da38e7edf64bb810708526cdeb14f5 /ocaml/test/explore_kernel_structure.ml | |
parent | 4a6067863d415e0334b4b61254fab2bd879a6964 (diff) |
very stuck
Diffstat (limited to 'ocaml/test/explore_kernel_structure.ml')
-rw-r--r-- | ocaml/test/explore_kernel_structure.ml | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/ocaml/test/explore_kernel_structure.ml b/ocaml/test/explore_kernel_structure.ml new file mode 100644 index 0000000..513d47f --- /dev/null +++ b/ocaml/test/explore_kernel_structure.ml @@ -0,0 +1,108 @@ +(* Explore the structure of Event 1 kernel *) + +open Nock_lib + +let check_slot noun slot = + try + let _val = Noun.slot (Z.of_int slot) noun in + "✓" + with _ -> "✗" + +let rec to_list acc noun = + match noun with + | Noun.Atom _ -> List.rev acc + | Noun.Cell (item, rest) -> to_list (item :: acc) rest + +let explore _env = + Printf.printf "Exploring Event 1 kernel structure...\n\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) -> + let event_list = to_list [] events in + + begin match List.nth_opt event_list 1 with + | Some kernel -> + Printf.printf "Event 1 (kernel) slot map:\n"; + Printf.printf " Slot 2 (head): %s\n" (check_slot kernel 2); + Printf.printf " Slot 3 (tail): %s\n" (check_slot kernel 3); + Printf.printf " Slot 4: %s\n" (check_slot kernel 4); + Printf.printf " Slot 5: %s\n" (check_slot kernel 5); + Printf.printf " Slot 6: %s\n" (check_slot kernel 6); + Printf.printf " Slot 7: %s\n" (check_slot kernel 7); + Printf.printf " Slot 20: %s\n" (check_slot kernel 20); + Printf.printf " Slot 23: %s\n" (check_slot kernel 23); + Printf.printf " Slot 42: %s\n" (check_slot kernel 42); + Printf.printf " Slot 87: %s\n" (check_slot kernel 87); + Printf.printf "\n"; + + (* Check if slots 23 and 42 are gates or formulas *) + Printf.printf "Checking slot 23:\n"; + begin try + let slot_23 = Noun.slot (Z.of_int 23) kernel in + match slot_23 with + | Noun.Atom a -> + Printf.printf " Atom: %s\n" (Z.to_string a) + | Noun.Cell (h, t) -> + Printf.printf " Cell (likely a formula or gate)\n"; + Printf.printf " Head: %s\n" (match h with Noun.Atom _ -> "atom" | Noun.Cell _ -> "cell"); + Printf.printf " Tail: %s\n" (match t with Noun.Atom _ -> "atom" | Noun.Cell _ -> "cell"); + + (* Check if it looks like a gate [battery payload] *) + (* Gate structure: [[formula] [sample context]] *) + begin try + let battery = Noun.head slot_23 in + let payload = Noun.tail slot_23 in + let sample = Noun.head payload in + let _context = Noun.tail payload in + Printf.printf " → Looks like a GATE (has battery/payload/sample/context)\n"; + Printf.printf " Battery: %s\n" (match battery with Noun.Atom _ -> "atom" | Noun.Cell _ -> "cell"); + Printf.printf " Sample: %s\n" (match sample with Noun.Atom _ -> "atom" | Noun.Cell _ -> "cell") + with _ -> + Printf.printf " → Looks like a FORMULA (not gate structure)\n" + end + with _ -> + Printf.printf " ✗ Error accessing slot 23\n" + end; + + Printf.printf "\nChecking slot 42:\n"; + begin try + let slot_42 = Noun.slot (Z.of_int 42) kernel in + match slot_42 with + | Noun.Atom a -> + Printf.printf " Atom: %s\n" (Z.to_string a) + | Noun.Cell (h, t) -> + Printf.printf " Cell\n"; + Printf.printf " Head: %s\n" (match h with Noun.Atom _ -> "atom" | Noun.Cell _ -> "cell"); + Printf.printf " Tail: %s\n" (match t with Noun.Atom _ -> "atom" | Noun.Cell _ -> "cell"); + + begin try + let battery = Noun.head slot_42 in + let payload = Noun.tail slot_42 in + let sample = Noun.head payload in + let _context = Noun.tail payload in + Printf.printf " → Looks like a GATE\n"; + Printf.printf " Battery: %s\n" (match battery with Noun.Atom _ -> "atom" | Noun.Cell _ -> "cell"); + Printf.printf " Sample: %s\n" (match sample with Noun.Atom _ -> "atom" | Noun.Cell _ -> "cell") + with _ -> + Printf.printf " → Looks like a FORMULA\n" + end + with _ -> + Printf.printf " ✗ Error accessing slot 42\n" + end + + | None -> + Printf.printf "No event 1\n" + end + + | Noun.Atom _ -> + Printf.printf "Pill is atom\n" + +let () = + Printf.printf "\n═══════════════════════════════════════════\n"; + Printf.printf " Explore Kernel Structure\n"; + Printf.printf "═══════════════════════════════════════════\n\n"; + Eio_main.run explore |