summaryrefslogtreecommitdiff
path: root/ocaml/test/old/test_poke_formulas.ml
diff options
context:
space:
mode:
authorpolwex <polwex@sortug.com>2025-10-06 23:18:59 +0700
committerpolwex <polwex@sortug.com>2025-10-06 23:18:59 +0700
commit5de3f7a3ad7b0cf63b4a6cbddfc1e26359dea161 (patch)
treeb55b2258123149bed40bd89bbaa58e7da54f3a26 /ocaml/test/old/test_poke_formulas.ml
parentfdab65f6dac4ba85ed4749f61970660d1132d453 (diff)
cleaned up tests
Diffstat (limited to 'ocaml/test/old/test_poke_formulas.ml')
-rw-r--r--ocaml/test/old/test_poke_formulas.ml85
1 files changed, 85 insertions, 0 deletions
diff --git a/ocaml/test/old/test_poke_formulas.ml b/ocaml/test/old/test_poke_formulas.ml
new file mode 100644
index 0000000..54c08ff
--- /dev/null
+++ b/ocaml/test/old/test_poke_formulas.ml
@@ -0,0 +1,85 @@
+(* Test Different Poke Formulas
+ *
+ * Try various Nock formulas to figure out how to call Arvo
+ *)
+
+open Nock_lib
+
+let test_formula name formula kernel event =
+ Printf.printf "Testing: %s\n" name;
+ Printf.printf " Formula: %s\n" formula;
+
+ let subject = Noun.cell event kernel in
+
+ try
+ let start = Unix.gettimeofday () in
+ let result = Nock.nock_on subject
+ (match name with
+ | "Slot 3" -> Noun.cell (Noun.atom 0) (Noun.atom 3)
+ | "Call slot 3 arm 2" ->
+ Noun.cell (Noun.atom 9)
+ (Noun.cell (Noun.atom 2)
+ (Noun.cell (Noun.atom 0) (Noun.atom 3)))
+ | "Compose [event kernel] then call" ->
+ (* [7 formula-a formula-b]: compute a, use as subject for b *)
+ Noun.cell (Noun.atom 7)
+ (Noun.cell
+ (Noun.cell (Noun.atom 0) (Noun.atom 2)) (* formula-a: get event *)
+ (Noun.cell (Noun.atom 9) (* formula-b: call arm 2 *)
+ (Noun.cell (Noun.atom 2)
+ (Noun.cell (Noun.atom 0) (Noun.atom 3))))) (* of kernel *)
+ | _ -> Noun.cell (Noun.atom 0) (Noun.atom 1)) in
+ let elapsed = Unix.gettimeofday () -. start in
+
+ Printf.printf " โœ“ Success in %.4fs\n" elapsed;
+ (match result with
+ | Noun.Atom z ->
+ if Z.numbits z < 20 then
+ Printf.printf " Result: Atom(%s)\n" (Z.to_string z)
+ else
+ Printf.printf " Result: Atom(large: %d bits)\n" (Z.numbits z)
+ | Noun.Cell _ -> Printf.printf " Result: Cell(...)\n");
+ Printf.printf "\n";
+ true
+
+ with e ->
+ Printf.printf " โœ— Failed: %s\n\n" (Printexc.to_string e);
+ false
+
+let test_poke_formulas env =
+ Printf.printf "๐Ÿงช Testing Different Poke Formulas\n\n";
+
+ Eio.Switch.run @@ fun _sw ->
+ let fs = Eio.Stdenv.fs env in
+
+ (* Load ivory pill *)
+ let state = State.create () in
+ match Boot.boot_from_file ~fs state "ivory.pill" with
+ | Error msg ->
+ Printf.printf "โœ— Failed to load pill: %s\n%!" msg
+ | Ok () ->
+ let kernel = State.get_arvo state in
+ let event = Noun.cell (Noun.atom 0) (Noun.atom 42) in
+
+ Printf.printf "Kernel loaded, trying different formulas...\n\n";
+
+ let formulas = [
+ ("Slot 3", "[0 3] - just return kernel");
+ ("Call slot 3 arm 2", "[9 2 0 3] - call arm 2 of kernel");
+ ("Compose [event kernel] then call", "[7 [0 2] [0 3] [9 2 0 1]]");
+ ] in
+
+ let _ = List.map (fun (name, desc) ->
+ test_formula name desc kernel event
+ ) formulas in
+
+ ()
+
+let () =
+ Printf.printf "\n";
+ Printf.printf "โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•\n";
+ Printf.printf " Testing Different Poke Formulas on Arvo\n";
+ Printf.printf "โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•\n";
+ Printf.printf "\n";
+
+ Eio_main.run test_poke_formulas