summaryrefslogtreecommitdiff
path: root/ocaml/test/test_simple_lifecycle.ml
diff options
context:
space:
mode:
authorpolwex <polwex@sortug.com>2025-10-07 01:40:54 +0700
committerpolwex <polwex@sortug.com>2025-10-07 01:40:54 +0700
commita12407b3f152a3dbd716d640202b9613c61d6105 (patch)
tree411c630824b992d3a7f5e3d17c83a8546577bad7 /ocaml/test/test_simple_lifecycle.ml
parentd0064c2f577c56a9e5b3fc00b45f71a73f3574c9 (diff)
lmao turned down the bytecode interpreter in Vere and it started giving the same results as us smh
Diffstat (limited to 'ocaml/test/test_simple_lifecycle.ml')
-rw-r--r--ocaml/test/test_simple_lifecycle.ml47
1 files changed, 47 insertions, 0 deletions
diff --git a/ocaml/test/test_simple_lifecycle.ml b/ocaml/test/test_simple_lifecycle.ml
new file mode 100644
index 0000000..96e0603
--- /dev/null
+++ b/ocaml/test/test_simple_lifecycle.ml
@@ -0,0 +1,47 @@
+(* Simple test of lifecycle formula on small noun *)
+
+open Nock_lib
+
+let () =
+ (* Test subject: [[formula] payload] *)
+ (* Formula: [7 [0 3] [0 1]] - compose: *[payload [0 1]] returns payload *)
+ (* Payload: [42 99] *)
+ let formula_slot2 = Noun.cell
+ (Noun.atom 7)
+ (Noun.cell
+ (Noun.cell (Noun.atom 0) (Noun.atom 3))
+ (Noun.cell (Noun.atom 0) (Noun.atom 1)))
+ in
+ let payload = Noun.cell (Noun.atom 42) (Noun.atom 99) in
+ let subject = Noun.cell formula_slot2 payload in
+
+ (* Lifecycle formula: [2 [0 3] [0 2]] *)
+ let formula = Noun.cell
+ (Noun.atom 2)
+ (Noun.cell
+ (Noun.cell (Noun.atom 0) (Noun.atom 3))
+ (Noun.cell (Noun.atom 0) (Noun.atom 2)))
+ in
+
+ Printf.printf "Subject: [[7 [0 3] [0 1]] [42 99]]\n";
+ Printf.printf "Subject mug: 0x%08lx\n" (Noun.mug subject);
+ Printf.printf "Formula: [2 [0 3] [0 2]]\n";
+ Printf.printf "Formula mug: 0x%08lx\n\n" (Noun.mug formula);
+
+ Printf.printf "Slot 2 of subject (formula): [7 [0 3] [0 1]] (mug=0x%08lx)\n"
+ (Noun.mug formula_slot2);
+
+ Printf.printf "Slot 3 of subject (payload): [42 99] (mug=0x%08lx)\n\n"
+ (Noun.mug payload);
+
+ Printf.printf "Running nock...\n";
+ Printf.printf "This should compute: *[[42 99] [7 [0 3] [0 1]]]\n";
+ Printf.printf "Which is: *[99 [0 1]] = 99\n\n";
+
+ let result = Nock.nock_on subject formula in
+
+ Printf.printf "Result mug: 0x%08lx\n" (Noun.mug result);
+ Printf.printf "Result: %s\n"
+ (match result with
+ | Noun.Atom { z; _ } -> Z.to_string z
+ | Noun.Cell _ -> "cell")