diff options
Diffstat (limited to 'ocaml/test/test_ivory_structure.ml')
-rw-r--r-- | ocaml/test/test_ivory_structure.ml | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/ocaml/test/test_ivory_structure.ml b/ocaml/test/test_ivory_structure.ml new file mode 100644 index 0000000..2ed76a9 --- /dev/null +++ b/ocaml/test/test_ivory_structure.ml @@ -0,0 +1,105 @@ +(* Examine Ivory Pill Structure *) + +open Nock_lib + +let test_ivory_structure env = + Printf.printf "🔍 Examining Ivory Pill Structure\n\n"; + + Eio.Switch.run @@ fun _sw -> + let fs = Eio.Stdenv.fs env in + + (* Load ivory pill *) + let file_path = Eio.Path.(fs / "ivory.pill") in + let pill_bytes = Eio.Path.load file_path |> Bytes.of_string in + + Printf.printf "Loading ivory pill (%d bytes)...\n" (Bytes.length pill_bytes); + let start = Unix.gettimeofday () in + let pill = Serial.cue pill_bytes in + let elapsed = Unix.gettimeofday () -. start in + + Printf.printf "Cued in %.2fs\n\n" elapsed; + + Printf.printf "Top-level structure:\n"; + if Noun.is_cell pill then begin + Printf.printf " ✓ Is cell\n"; + let head = Noun.head pill in + let tail = Noun.tail pill in + + Printf.printf "\nHead:\n"; + (match head with + | Noun.Atom z -> + Printf.printf " Atom: %s\n" (Z.to_string z); + Printf.printf " Hex: 0x%s\n" (Z.format "x" z); + Printf.printf " Bits: %d\n" (Z.numbits z); + + (* Try to decode as ASCII cord *) + if Z.numbits z <= 64 then begin + let bytes = Z.to_bits z in + Printf.printf " ASCII (reversed): "; + for i = 0 to String.length bytes - 1 do + let c = bytes.[i] in + if c >= ' ' && c <= '~' then + Printf.printf "%c" c + else + Printf.printf "\\x%02x" (Char.code c) + done; + Printf.printf "\n" + end; + + (* Check specific values *) + if Z.equal z (Z.of_string "129293697897") then + Printf.printf " ✓ This is 'ivory' tag!\n" + + | Noun.Cell _ -> + Printf.printf " Cell\n"); + + Printf.printf "\nTail (the ivory core):\n"; + Printf.printf " %s\n" (if Noun.is_cell tail then "Cell" else "Atom"); + + if Noun.is_cell tail then begin + Printf.printf " Head of tail: %s\n" + (if Noun.is_cell (Noun.head tail) then "Cell (battery?)" else "Atom"); + Printf.printf " Tail of tail: %s\n" + (if Noun.is_cell (Noun.tail tail) then "Cell (payload?)" else "Atom"); + + (* Test which slots exist on the core *) + Printf.printf "\nTesting slots 2-10 on ivory core:\n"; + for slot = 2 to 10 do + try + let value = Noun.slot (Z.of_int slot) tail in + Printf.printf " Slot %2d: exists (%s)\n" slot + (if Noun.is_cell value then "cell" else "atom") + with _ -> + Printf.printf " Slot %2d: does not exist\n" slot + done; + + (* Check if it's actually a gate [battery sample context] *) + Printf.printf "\nGate structure analysis:\n"; + if Noun.is_cell tail then begin + let battery = Noun.head tail in + let rest = Noun.tail tail in + Printf.printf " Battery (slot 2): %s\n" + (if Noun.is_cell battery then "Cell (contains formulas)" else "Atom"); + + if Noun.is_cell rest then begin + let sample = Noun.head rest in + let context = Noun.tail rest in + Printf.printf " Sample (slot 6): %s\n" + (if Noun.is_cell sample then "Cell" else "Atom"); + Printf.printf " Context (slot 7): %s\n" + (if Noun.is_cell context then "Cell" else "Atom") + end + end + end + + end else + Printf.printf " Atom (unexpected)\n" + +let () = + Printf.printf "\n"; + Printf.printf "═══════════════════════════════════════════════════════════\n"; + Printf.printf " Examining Ivory Pill Structure\n"; + Printf.printf "═══════════════════════════════════════════════════════════\n"; + Printf.printf "\n"; + + Eio_main.run test_ivory_structure |