summaryrefslogtreecommitdiff
path: root/ocaml/test/examine_core_head.ml
blob: 397bfbed108ca6b8ffc38da0e9024be808a853e9 (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
(* Examine the actual structure of the Arvo core *)

open Nock_lib

let rec show_structure depth max_depth noun =
  if depth >= max_depth then "..." else
  match noun with
  | Noun.Atom { z; _ } ->
      if Z.fits_int z then string_of_int (Z.to_int z)
      else Z.to_string z
  | Noun.Cell { h; t; _ } ->
      "[" ^ show_structure (depth+1) max_depth h ^ " " ^
      show_structure (depth+1) max_depth t ^ "]"

let () =
  Eio_main.run (fun env ->
    let fs = Eio.Stdenv.fs env in
    let pill_bytes = Eio.Path.(load (fs / "ivory.pill")) |> Bytes.of_string in
    let pill = Serial.cue pill_bytes in
    let core = Noun.tail pill in

    Printf.printf "Core structure (head, depth 3):\n";
    let core_head = Noun.head core in
    Printf.printf "%s\n" (show_structure 0 3 core_head);

    Printf.printf "\nCore head mug: 0x%08lx\n" (Noun.mug core_head);

    (* Check if it's [7 ...] *)
    match core_head with
    | Noun.Cell { h; _ } ->
        (match h with
        | Noun.Atom { z; _ } when Z.fits_int z ->
            Printf.printf "Core head starts with atom: %d\n" (Z.to_int z)
        | Noun.Cell _ ->
            Printf.printf "Core head starts with cell\n"
        | _ -> ())
    | _ -> ()
  )