diff options
author | polwex <polwex@sortug.com> | 2025-10-06 23:18:59 +0700 |
---|---|---|
committer | polwex <polwex@sortug.com> | 2025-10-06 23:18:59 +0700 |
commit | 5de3f7a3ad7b0cf63b4a6cbddfc1e26359dea161 (patch) | |
tree | b55b2258123149bed40bd89bbaa58e7da54f3a26 /ocaml/test/old/test_boot_with_slam.ml | |
parent | fdab65f6dac4ba85ed4749f61970660d1132d453 (diff) |
cleaned up tests
Diffstat (limited to 'ocaml/test/old/test_boot_with_slam.ml')
-rw-r--r-- | ocaml/test/old/test_boot_with_slam.ml | 202 |
1 files changed, 202 insertions, 0 deletions
diff --git a/ocaml/test/old/test_boot_with_slam.ml b/ocaml/test/old/test_boot_with_slam.ml new file mode 100644 index 0000000..c87c5c8 --- /dev/null +++ b/ocaml/test/old/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 |