summaryrefslogtreecommitdiff
path: root/ocaml/test/test_boot_with_slam.ml
diff options
context:
space:
mode:
Diffstat (limited to 'ocaml/test/test_boot_with_slam.ml')
-rw-r--r--ocaml/test/test_boot_with_slam.ml202
1 files changed, 202 insertions, 0 deletions
diff --git a/ocaml/test/test_boot_with_slam.ml b/ocaml/test/test_boot_with_slam.ml
new file mode 100644
index 0000000..c87c5c8
--- /dev/null
+++ b/ocaml/test/test_boot_with_slam.ml
@@ -0,0 +1,202 @@
+(* Boot Arvo using slam on slot 23 *)
+
+open Nock_lib
+
+let slam_on gate event =
+ (* C Vere slam_on: [battery [new-sample context]] *)
+ let battery = Noun.head gate in
+ let context = Noun.tail (Noun.tail gate) in (* slot 7 *)
+ let new_core = Noun.cell battery (Noun.cell event context) in
+
+ (* Kick arm 2: [9 2 0 1] *)
+ let kick_formula = Noun.cell (Noun.atom 9)
+ (Noun.cell (Noun.atom 2)
+ (Noun.cell (Noun.atom 0) (Noun.atom 1))) in
+
+ Nock.nock_on new_core kick_formula
+
+let rec to_list acc noun =
+ match noun with
+ | Noun.Atom _ -> List.rev acc
+ | Noun.Cell (item, rest) -> to_list (item :: acc) rest
+
+let boot_arvo _env =
+ Printf.printf "šŸš€ Booting Arvo with Slot 23 Slam\n\n";
+
+ (* Load solid pill *)
+ Printf.printf "Loading solid pill...\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
+ Printf.printf "Found %d events\n\n" (List.length event_list);
+
+ (* Event 1 is the initial kernel *)
+ let kernel = ref None in
+
+ List.iteri (fun i event ->
+ Printf.printf "=== Event %d ===\n" i;
+
+ match event with
+ | Noun.Atom a ->
+ Printf.printf "Atom: %s\n\n" (Z.to_string a)
+
+ | Noun.Cell _ ->
+ if i = 1 then begin
+ (* Event 1: Initial larval kernel *)
+ Printf.printf "Initial larval kernel\n";
+ kernel := Some event;
+
+ (* Verify slot 23 exists *)
+ begin try
+ let _poke = Noun.slot (Z.of_int 23) event in
+ Printf.printf " āœ“ Has poke gate at slot 23\n\n"
+ with _ ->
+ Printf.printf " āœ— No poke at slot 23\n\n"
+ end
+
+ end else if i > 2 then begin
+ (* Events 3-4: Larval initialization events *)
+ Printf.printf "Boot event (ovum)\n";
+
+ match !kernel with
+ | None ->
+ Printf.printf " āœ— No kernel yet\n\n"
+
+ | Some k ->
+ begin try
+ let poke_gate = Noun.slot (Z.of_int 23) k in
+
+ (* Build poke args: [now ovum] *)
+ (* The event itself should be the ovum [wire card] *)
+ let now = Noun.atom 0 in
+ let ovum = event in
+ let poke_arg = Noun.cell now ovum in
+
+ Printf.printf " → Slamming poke at slot 23...\n";
+ let start = Unix.gettimeofday () in
+ let result = slam_on poke_gate poke_arg in
+ let elapsed = Unix.gettimeofday () -. start in
+
+ Printf.printf " āœ“ Poke succeeded in %.4fs!\n" elapsed;
+
+ (* Parse result: [effects new-kernel] *)
+ begin match result with
+ | Noun.Cell (_effects, new_kernel) ->
+ Printf.printf " Result: [effects new-kernel]\n";
+
+ (* Update kernel *)
+ kernel := Some new_kernel;
+ Printf.printf " āœ“ Kernel updated\n"
+
+ | Noun.Atom _ ->
+ Printf.printf " āœ— Result is atom (unexpected)\n"
+ end;
+
+ Printf.printf "\n"
+
+ with
+ | Noun.Exit ->
+ Printf.printf " āœ— Poke failed (Nock Exit)\n\n"
+ | e ->
+ Printf.printf " āœ— Error: %s\n\n" (Printexc.to_string e)
+ end
+ end else begin
+ Printf.printf "Separator/other\n\n"
+ end
+ ) event_list;
+
+ (* Test final kernel *)
+ Printf.printf "═══════════════════════════════════════\n\n";
+
+ begin match !kernel with
+ | None ->
+ Printf.printf "āœ— No final kernel\n"
+
+ | Some k ->
+ Printf.printf "šŸŽ‰ Boot Complete!\n\n";
+
+ (* Check which slots exist in final kernel *)
+ Printf.printf "Checking final kernel:\n";
+ begin try
+ let _poke23 = Noun.slot (Z.of_int 23) k in
+ Printf.printf " āœ“ Has slot 23 (larval poke)\n"
+ with _ ->
+ Printf.printf " āœ— No slot 23\n"
+ end;
+
+ begin try
+ let _poke42 = Noun.slot (Z.of_int 42) k in
+ Printf.printf " āœ“ Has slot 42 (adult poke)\n"
+ with _ ->
+ Printf.printf " āœ— No slot 42\n"
+ end;
+
+ Printf.printf "\nTrying test poke on slot 42...\n";
+
+ (* Try slot 42 (adult Arvo) *)
+ begin try
+ let poke_gate = Noun.slot (Z.of_int 42) k in
+ let wire = Noun.atom 0 in
+ let card = Noun.cell (Noun.atom 1953719668) (Noun.atom 42) in
+ let ovum = Noun.cell wire card in
+ let now = Noun.atom 0 in
+ let poke_arg = Noun.cell now ovum in
+
+ Printf.printf " Slamming slot 42...\n";
+ let result = slam_on poke_gate poke_arg in
+
+ begin match result with
+ | Noun.Cell _ ->
+ Printf.printf " šŸŽŠ SLOT 42 WORKS! ARVO IS RUNNING!\n"
+ | Noun.Atom _ ->
+ Printf.printf " Result is atom\n"
+ end
+
+ with
+ | Noun.Exit ->
+ Printf.printf " āœ— Slot 42 poke failed (Nock Exit)\n"
+ | e ->
+ Printf.printf " āœ— Error: %s\n" (Printexc.to_string e)
+ end;
+
+ Printf.printf "\nTrying test poke on slot 23...\n";
+
+ (* Also try slot 23 *)
+ begin try
+ let poke_gate = Noun.slot (Z.of_int 23) k in
+ let wire = Noun.atom 0 in
+ let card = Noun.cell (Noun.atom 1953719668) (Noun.atom 42) in
+ let ovum = Noun.cell wire card in
+ let now = Noun.atom 0 in
+ let poke_arg = Noun.cell now ovum in
+
+ Printf.printf " Slamming slot 23...\n";
+ let result = slam_on poke_gate poke_arg in
+
+ begin match result with
+ | Noun.Cell _ ->
+ Printf.printf " āœ“ Slot 23 also works!\n"
+ | Noun.Atom _ ->
+ Printf.printf " Result is atom\n"
+ end
+
+ with
+ | Noun.Exit ->
+ Printf.printf " āœ— Slot 23 poke failed (Nock Exit)\n"
+ | e ->
+ Printf.printf " āœ— Error: %s\n" (Printexc.to_string e)
+ end
+ end
+
+ | Noun.Atom _ ->
+ Printf.printf "āœ— Pill is atom\n"
+
+let () =
+ Printf.printf "\n═══════════════════════════════════════════\n";
+ Printf.printf " Boot Arvo with Slot 23 Slam\n";
+ Printf.printf "═══════════════════════════════════════════\n\n";
+ Eio_main.run boot_arvo