diff options
Diffstat (limited to 'ocaml/test/old/test_correct_boot.ml')
-rw-r--r-- | ocaml/test/old/test_correct_boot.ml | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/ocaml/test/old/test_correct_boot.ml b/ocaml/test/old/test_correct_boot.ml new file mode 100644 index 0000000..c778d1b --- /dev/null +++ b/ocaml/test/old/test_correct_boot.ml @@ -0,0 +1,131 @@ +(* Boot using the CORRECT C Vere pattern: compute gates from formulas *) + +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 boot _env = + Printf.printf "š Booting Arvo with CORRECT C Vere Pattern\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 kernel = ref (List.nth event_list 1) in + + Printf.printf "Initial kernel loaded\n\n"; + + (* Process Events 3 and 4 *) + List.iteri (fun i event -> + if i >= 3 && i <= 4 then begin + Printf.printf "āāā Event %d āāā\n" i; + + (* Step 1: Get formula at slot 23 *) + Printf.printf "Step 1: Get formula at slot 23...\n"; + let slot_23_formula = Noun.slot (Z.of_int 23) !kernel in + Printf.printf " ā Got formula\n"; + + (* Step 2: Compute poke gate by running formula *) + Printf.printf "Step 2: Compute poke gate...\n"; + let start_compute = Unix.gettimeofday () in + let poke_gate = Nock.nock_on !kernel slot_23_formula in + let elapsed_compute = Unix.gettimeofday () -. start_compute in + Printf.printf " ā Computed in %.4fs\n" elapsed_compute; + + (* Step 3: Slam the computed gate *) + Printf.printf "Step 3: Slam poke gate...\n"; + let now = Noun.atom 0 in + let poke_arg = Noun.cell now event in + + let start_slam = Unix.gettimeofday () in + begin try + let result = slam_on poke_gate poke_arg in + let elapsed_slam = Unix.gettimeofday () -. start_slam in + + Printf.printf " ā Slam succeeded in %.4fs!\n" elapsed_slam; + + (* Parse result *) + begin match result with + | Noun.Cell (_effects, new_kernel) -> + Printf.printf " Result: [effects new-kernel]\n"; + kernel := new_kernel; + Printf.printf " ā Kernel updated\n\n" + | Noun.Atom _ -> + Printf.printf " ā Result is atom\n\n" + end + + with + | Noun.Exit -> + Printf.printf " ā Slam failed (Nock Exit)\n\n" + | e -> + Printf.printf " ā Error: %s\n\n" (Printexc.to_string e) + end + end + ) event_list; + + (* Test final kernel *) + Printf.printf "āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā\n"; + Printf.printf " Testing Final Kernel\n"; + Printf.printf "āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā\n\n"; + + Printf.printf "Computing poke gate from slot 23...\n"; + begin try + let slot_23_formula = Noun.slot (Z.of_int 23) !kernel in + let poke_gate = Nock.nock_on !kernel slot_23_formula in + Printf.printf "ā Computed poke gate\n\n"; + + Printf.printf "Testing with [0 [%%test 42]]...\n"; + 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 + + let result = slam_on poke_gate poke_arg in + + begin match result with + | Noun.Cell _ -> + Printf.printf "ā Test poke succeeded!\n\n"; + Printf.printf "āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā\n"; + Printf.printf " š ARVO IS FULLY BOOTED! š\n"; + Printf.printf "āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā\n\n"; + Printf.printf "Boot sequence complete:\n"; + Printf.printf " 1. Event 1: Initial kernel\n"; + Printf.printf " 2. Event 3: Boot initialization\n"; + Printf.printf " 3. Event 4: Final setup\n"; + Printf.printf " 4. Test poke: SUCCESS\n\n"; + Printf.printf "The kernel is ready to receive events!\n" + | Noun.Atom _ -> + Printf.printf "Result is atom\n" + end + + with + | Noun.Exit -> + Printf.printf "ā Test poke failed\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 " Boot with Correct C Vere Pattern\n"; + Printf.printf "āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā\n\n"; + Eio_main.run boot |