summaryrefslogtreecommitdiff
path: root/ocaml/test/test_op9.ml
diff options
context:
space:
mode:
Diffstat (limited to 'ocaml/test/test_op9.ml')
-rw-r--r--ocaml/test/test_op9.ml45
1 files changed, 45 insertions, 0 deletions
diff --git a/ocaml/test/test_op9.ml b/ocaml/test/test_op9.ml
new file mode 100644
index 0000000..dc34c8a
--- /dev/null
+++ b/ocaml/test/test_op9.ml
@@ -0,0 +1,45 @@
+(* Test opcode 9 (invoke) *)
+
+open Nock_lib
+
+let () =
+ (* Build a simple core: [[formula] payload] *)
+ (* Formula at slot 2: [0 3] (returns payload) *)
+ (* Payload at slot 3: 42 *)
+ let core = Noun.cell
+ (Noun.cell (Noun.atom 0) (Noun.atom 3))
+ (Noun.atom 42)
+ in
+
+ (* Test: *[core [9 2 [0 1]]] *)
+ (* This should:
+ 1. Evaluate [0 1] on core → core
+ 2. Extract slot 2 from core → [0 3]
+ 3. Evaluate [0 3] on core → 42
+ *)
+
+ let subject = core in
+ let formula = Noun.cell
+ (Noun.atom 9)
+ (Noun.cell
+ (Noun.atom 2)
+ (Noun.cell (Noun.atom 0) (Noun.atom 1)))
+ in
+
+ Printf.printf "Subject (core): [[0 3] 42]\n";
+ Printf.printf "Subject mug: 0x%08lx\n" (Noun.mug subject);
+ Printf.printf "Formula: [9 2 [0 1]]\n";
+ Printf.printf "Formula mug: 0x%08lx\n\n" (Noun.mug formula);
+
+ Printf.printf "This should compute:\n";
+ Printf.printf " 1. Evaluate [0 1] on core → core\n";
+ Printf.printf " 2. Extract slot 2 from result → [0 3]\n";
+ Printf.printf " 3. Evaluate [0 3] on core → 42\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")