summaryrefslogtreecommitdiff
path: root/ocaml/test/test_op8.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_op8.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_op8.ml')
-rw-r--r--ocaml/test/test_op8.ml38
1 files changed, 38 insertions, 0 deletions
diff --git a/ocaml/test/test_op8.ml b/ocaml/test/test_op8.ml
new file mode 100644
index 0000000..5c63926
--- /dev/null
+++ b/ocaml/test/test_op8.ml
@@ -0,0 +1,38 @@
+(* Test opcode 8 (extend) *)
+
+open Nock_lib
+
+let () =
+ (* Test: *[[42 99] [8 [1 123] [0 1]]] *)
+ (* This should compute: *[[123 [42 99]] [0 1]] = [123 [42 99]] *)
+
+ let subject = Noun.cell (Noun.atom 42) (Noun.atom 99) in
+ let formula = Noun.cell
+ (Noun.atom 8)
+ (Noun.cell
+ (Noun.cell (Noun.atom 1) (Noun.atom 123)) (* [1 123] produces 123 *)
+ (Noun.cell (Noun.atom 0) (Noun.atom 1))) (* [0 1] returns whole subject *)
+ in
+
+ Printf.printf "Subject: [42 99]\n";
+ Printf.printf "Subject mug: 0x%08lx\n" (Noun.mug subject);
+ Printf.printf "Formula: [8 [1 123] [0 1]]\n";
+ Printf.printf "Formula mug: 0x%08lx\n\n" (Noun.mug formula);
+
+ Printf.printf "This should compute:\n";
+ Printf.printf " 1. Evaluate [1 123] on [42 99] → 123\n";
+ Printf.printf " 2. Extend subject: [123 [42 99]]\n";
+ Printf.printf " 3. Evaluate [0 1] on [123 [42 99]] → [123 [42 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"
+ (if Noun.is_cell result then
+ let h = Noun.head result in
+ let t = Noun.tail result in
+ match (h, t) with
+ | (Noun.Atom { z = zh; _ }, Noun.Cell { h = Noun.Atom { z = zth; _ }; t = Noun.Atom { z = ztt; _ }; _ }) ->
+ Printf.sprintf "[%s [%s %s]]" (Z.to_string zh) (Z.to_string zth) (Z.to_string ztt)
+ | _ -> "cell (unexpected structure)"
+ else "atom")