summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ocaml/lib/nock.ml9
-rw-r--r--ocaml/test/check_formula.ml28
-rw-r--r--ocaml/test/check_lifecycle_formula.ml45
-rw-r--r--ocaml/test/check_slot2_opcode.ml28
-rw-r--r--ocaml/test/dune25
-rw-r--r--ocaml/test/examine_core_head.ml38
-rw-r--r--ocaml/test/test_slot3.ml30
-rw-r--r--vere/build.zig5
-rw-r--r--vere/pkg/vere/test_slots.c30
9 files changed, 237 insertions, 1 deletions
diff --git a/ocaml/lib/nock.ml b/ocaml/lib/nock.ml
index ee06eeb..5658ed7 100644
--- a/ocaml/lib/nock.ml
+++ b/ocaml/lib/nock.ml
@@ -44,7 +44,14 @@ let rec nock_on init_bus init_fol =
let rec loop () =
let my_call = !call_count in
- let should_log = my_call < max_calls in
+
+ (* Check if this is opcode 0 (slot lookup) - C doesn't log these *)
+ let is_slot = match !fol with
+ | Cell { h = Atom { z = op; _ }; _ } when Z.fits_int op && Z.to_int op = 0 -> true
+ | _ -> false
+ in
+
+ let should_log = my_call < max_calls && not is_slot in
(* Log entry *)
if should_log then begin
diff --git a/ocaml/test/check_formula.ml b/ocaml/test/check_formula.ml
new file mode 100644
index 0000000..2935650
--- /dev/null
+++ b/ocaml/test/check_formula.ml
@@ -0,0 +1,28 @@
+(* Check what opcode is in the formula at slot 3 *)
+
+open Nock_lib
+
+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
+
+ (* Get the formula at slot 3 *)
+ let formula = Noun.slot (Z.of_int 3) core in
+ Printf.printf "Formula (slot 3) mug: 0x%08lx\n" (Noun.mug formula);
+ Printf.printf "Formula is: %s\n" (if Noun.is_cell formula then "cell" else "atom");
+
+ if Noun.is_cell formula then begin
+ let h = Noun.head formula in
+ Printf.printf "Formula head is: %s\n" (if Noun.is_cell h then "cell" else "atom");
+ match h with
+ | Noun.Atom { z; _ } when Z.fits_int z ->
+ Printf.printf "Formula starts with opcode: %d\n" (Z.to_int z)
+ | Noun.Cell _ ->
+ Printf.printf "Formula starts with CELL (distribution)\n"
+ | _ ->
+ Printf.printf "Formula head is large atom\n"
+ end
+ )
diff --git a/ocaml/test/check_lifecycle_formula.ml b/ocaml/test/check_lifecycle_formula.ml
new file mode 100644
index 0000000..6e4e72d
--- /dev/null
+++ b/ocaml/test/check_lifecycle_formula.ml
@@ -0,0 +1,45 @@
+(* Check the actual lifecycle formula structure *)
+
+open Nock_lib
+
+let () =
+ let formula = 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 "Lifecycle formula: [2 [0 3] [0 2]]\n";
+ Printf.printf "Formula is cell: %b\n" (Noun.is_cell formula);
+
+ let h = Noun.head formula in
+ let t = Noun.tail formula in
+
+ Printf.printf "Head (opcode): ";
+ (match h with
+ | Noun.Atom { z; _ } -> Printf.printf "atom %s\n" (Z.to_string z)
+ | Noun.Cell _ -> Printf.printf "cell\n");
+
+ Printf.printf "Tail (gal): cell\n";
+
+ let b_gal = Noun.head t in (* [0 3] *)
+ let c_gal = Noun.tail t in (* [0 2] *)
+
+ Printf.printf "b_gal ([0 3]): ";
+ (match b_gal with
+ | Noun.Atom _ -> Printf.printf "atom\n"
+ | Noun.Cell { h; t; _ } ->
+ Printf.printf "cell [";
+ (match h with Noun.Atom { z; _ } -> Printf.printf "%s " (Z.to_string z) | _ -> ());
+ (match t with Noun.Atom { z; _ } -> Printf.printf "%s" (Z.to_string z) | _ -> ());
+ Printf.printf "]\n");
+
+ Printf.printf "c_gal ([0 2]): ";
+ (match c_gal with
+ | Noun.Atom _ -> Printf.printf "atom\n"
+ | Noun.Cell { h; t; _ } ->
+ Printf.printf "cell [";
+ (match h with Noun.Atom { z; _ } -> Printf.printf "%s " (Z.to_string z) | _ -> ());
+ (match t with Noun.Atom { z; _ } -> Printf.printf "%s" (Z.to_string z) | _ -> ());
+ Printf.printf "]\n")
diff --git a/ocaml/test/check_slot2_opcode.ml b/ocaml/test/check_slot2_opcode.ml
new file mode 100644
index 0000000..faca7e0
--- /dev/null
+++ b/ocaml/test/check_slot2_opcode.ml
@@ -0,0 +1,28 @@
+(* Check what opcode is in slot 2 (the formula after opcode 2) *)
+
+open Nock_lib
+
+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
+
+ (* Get slot 2 (this becomes the formula after opcode 2) *)
+ let formula = Noun.slot (Z.of_int 2) core in
+ Printf.printf "Slot 2 (becomes formula) mug: 0x%08lx\n" (Noun.mug formula);
+ Printf.printf "Slot 2 is: %s\n" (if Noun.is_cell formula then "cell" else "atom");
+
+ if Noun.is_cell formula then begin
+ let h = Noun.head formula in
+ Printf.printf "Slot 2 head is: %s\n" (if Noun.is_cell h then "cell" else "atom");
+ match h with
+ | Noun.Atom { z; _ } when Z.fits_int z ->
+ Printf.printf "Slot 2 starts with opcode: %d\n" (Z.to_int z)
+ | Noun.Cell _ ->
+ Printf.printf "Slot 2 starts with CELL (distribution)\n"
+ | _ ->
+ Printf.printf "Slot 2 head is large atom\n"
+ end
+ )
diff --git a/ocaml/test/dune b/ocaml/test/dune
index 330f064..84a47a3 100644
--- a/ocaml/test/dune
+++ b/ocaml/test/dune
@@ -277,6 +277,31 @@
(modules test_mug)
(libraries nock_lib))
+(executable
+ (name test_slot3)
+ (modules test_slot3)
+ (libraries nock_lib eio_main))
+
+(executable
+ (name check_formula)
+ (modules check_formula)
+ (libraries nock_lib eio_main))
+
+(executable
+ (name check_lifecycle_formula)
+ (modules check_lifecycle_formula)
+ (libraries nock_lib))
+
+(executable
+ (name check_slot2_opcode)
+ (modules check_slot2_opcode)
+ (libraries nock_lib eio_main))
+
+(executable
+ (name examine_core_head)
+ (modules examine_core_head)
+ (libraries nock_lib eio_main))
+
; (executable
; (name test_life_formula)
; (modules test_life_formula)
diff --git a/ocaml/test/examine_core_head.ml b/ocaml/test/examine_core_head.ml
new file mode 100644
index 0000000..397bfbe
--- /dev/null
+++ b/ocaml/test/examine_core_head.ml
@@ -0,0 +1,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"
+ | _ -> ())
+ | _ -> ()
+ )
diff --git a/ocaml/test/test_slot3.ml b/ocaml/test/test_slot3.ml
new file mode 100644
index 0000000..246cfc3
--- /dev/null
+++ b/ocaml/test/test_slot3.ml
@@ -0,0 +1,30 @@
+(* Test slot 3 extraction to compare with C *)
+
+open Nock_lib
+
+let () =
+ Printf.printf "Loading ivory.pill...\n%!";
+ 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
+
+ Printf.printf "Cuing...\n%!";
+ let pill = Serial.cue pill_bytes in
+ let pill_mug = Noun.mug pill in
+ Printf.printf "Pill mug: 0x%08lx\n%!" pill_mug;
+
+ (* Extract core (tail of pill) *)
+ let core = Noun.tail pill in
+ let core_mug = Noun.mug core in
+ Printf.printf "Core mug: 0x%08lx\n%!" core_mug;
+
+ (* Extract slot 2 (head) *)
+ let slot2 = Noun.slot (Z.of_int 2) core in
+ let slot2_mug = Noun.mug slot2 in
+ Printf.printf "Slot 2 (head) mug: 0x%08lx\n%!" slot2_mug;
+
+ (* Extract slot 3 (tail) *)
+ let slot3 = Noun.slot (Z.of_int 3) core in
+ let slot3_mug = Noun.mug slot3 in
+ Printf.printf "Slot 3 (tail) mug: 0x%08lx\n%!" slot3_mug;
+ )
diff --git a/vere/build.zig b/vere/build.zig
index e2a7590..eaf3b48 100644
--- a/vere/build.zig
+++ b/vere/build.zig
@@ -648,6 +648,11 @@ fn buildBinary(
.deps = vere_test_deps,
},
.{
+ .name = "slots-test",
+ .file = "pkg/vere/test_slots.c",
+ .deps = vere_test_deps,
+ },
+ .{
.name = "newt-test",
.file = "pkg/vere/newt_tests.c",
.deps = vere_test_deps,
diff --git a/vere/pkg/vere/test_slots.c b/vere/pkg/vere/test_slots.c
new file mode 100644
index 0000000..7f7ab2f
--- /dev/null
+++ b/vere/pkg/vere/test_slots.c
@@ -0,0 +1,30 @@
+/// Test slot extraction
+
+#include "noun.h"
+#include "vere.h"
+
+int main(int argc, char* argv[])
+{
+ u3C.wag_w |= u3o_hashless;
+ u3m_boot_lite(1 << 28);
+
+ printf("Loading ivory.pill...\n");
+ u3_noun ivory_jammed = u3m_file("/home/y/code/urbit/vere/ocaml/ivory.pill");
+ u3_noun pil = u3ke_cue(ivory_jammed);
+
+ printf("Pill mug: 0x%x\n", u3r_mug(pil));
+
+ // Extract core (tail of pill)
+ u3_noun core = u3t(pil);
+ printf("Core mug: 0x%x\n", u3r_mug(core));
+
+ // Extract slot 2 (head)
+ u3_noun slot2 = u3r_at(2, core);
+ printf("Slot 2 (head) mug: 0x%x\n", u3r_mug(slot2));
+
+ // Extract slot 3 (tail)
+ u3_noun slot3 = u3r_at(3, core);
+ printf("Slot 3 (tail) mug: 0x%x\n", u3r_mug(slot3));
+
+ return 0;
+}