diff options
Diffstat (limited to 'ocaml/test/test_event4_slot42.ml')
-rw-r--r-- | ocaml/test/test_event4_slot42.ml | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/ocaml/test/test_event4_slot42.ml b/ocaml/test/test_event4_slot42.ml new file mode 100644 index 0000000..ce98863 --- /dev/null +++ b/ocaml/test/test_event4_slot42.ml @@ -0,0 +1,104 @@ +(* Test Event 4 using slot 42 instead of slot 23 *) + +open Nock_lib + +let slam_on gate event = + let battery = Noun.head gate in + let context = Noun.tail (Noun.tail gate) in + let new_core = Noun.cell battery (Noun.cell event context) in + 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 test _env = + Printf.printf "š Testing Event 4 with Slot 42\n\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 + + let kernel1 = List.nth event_list 1 in + let event3 = List.nth event_list 3 in + let event4 = List.nth event_list 4 in + + (* Slam Event 3 with slot 23 *) + Printf.printf "=== Event 3 (slot 23) ===\n"; + let poke_gate3 = Noun.slot (Z.of_int 23) kernel1 in + let result3 = slam_on poke_gate3 (Noun.cell (Noun.atom 0) event3) in + + let kernel_after_3 = match result3 with + | Noun.Cell (_effects, new_kernel) -> + Printf.printf "ā Succeeded\n\n"; + new_kernel + | _ -> kernel1 + in + + (* Try Event 4 with SLOT 42 *) + Printf.printf "=== Event 4 (slot 42) ===\n"; + begin try + let poke_gate4 = Noun.slot (Z.of_int 42) kernel_after_3 in + Printf.printf "ā Found poke gate at slot 42\n"; + + (* Check gate structure *) + begin match poke_gate4 with + | Noun.Cell (battery, payload) -> + Printf.printf " Battery: %s\n" (match battery with Noun.Atom _ -> "atom" | Noun.Cell _ -> "cell"); + begin match payload with + | Noun.Cell (_sample, _context) -> + Printf.printf " Payload: cell [sample context] ā\n\n" + | _ -> + Printf.printf " Payload: atom ā\n\n" + end + | _ -> () + end; + + Printf.printf "Slamming Event 4...\n"; + let start = Unix.gettimeofday () in + let result4 = slam_on poke_gate4 (Noun.cell (Noun.atom 0) event4) in + let elapsed = Unix.gettimeofday () -. start in + + begin match result4 with + | Noun.Cell (_effects, _new_kernel) -> + Printf.printf "ā Event 4 succeeded in %.4fs!\n\n" elapsed; + Printf.printf "āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā\n"; + Printf.printf " ššš FULL BOOT SUCCESS! ššš\n"; + Printf.printf "āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā\n\n"; + Printf.printf "Boot sequence:\n"; + Printf.printf " 1. Event 1: Initial larval kernel\n"; + Printf.printf " 2. Event 3: Poked with slot 23 (larval)\n"; + Printf.printf " 3. Kernel metamorphosed!\n"; + Printf.printf " 4. Event 4: Poked with slot 42 (adult)\n\n"; + Printf.printf "The kernel has metamorphosed from larval to adult!\n"; + Printf.printf " - Larval poke: slot 23\n"; + Printf.printf " - Adult poke: slot 42\n" + | Noun.Atom _ -> + Printf.printf "Result is atom\n" + end + + with + | Noun.Exit -> + Printf.printf "ā Still failed with slot 42\n" + | Not_found -> + Printf.printf "ā No slot 42 found\n" + | e -> + Printf.printf "ā Error: %s\n" (Printexc.to_string e) + end + + | Noun.Atom _ -> + Printf.printf "Pill is atom\n" + +let () = + Printf.printf "\nāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā\n"; + Printf.printf " Test Event 4 with Slot 42\n"; + Printf.printf "āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā\n\n"; + Eio_main.run test |