blob: 2ed76a9ad6d99426c8c07accf3e780ce02919a9e (
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
99
100
101
102
103
104
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
|