From a12407b3f152a3dbd716d640202b9613c61d6105 Mon Sep 17 00:00:00 2001 From: polwex Date: Tue, 7 Oct 2025 01:40:54 +0700 Subject: lmao turned down the bytecode interpreter in Vere and it started giving the same results as us smh --- ocaml/test/test_opcodes.ml | 75 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 ocaml/test/test_opcodes.ml (limited to 'ocaml/test/test_opcodes.ml') diff --git a/ocaml/test/test_opcodes.ml b/ocaml/test/test_opcodes.ml new file mode 100644 index 0000000..7ef7a48 --- /dev/null +++ b/ocaml/test/test_opcodes.ml @@ -0,0 +1,75 @@ +(* Consolidated opcode tests *) + +open Nock_lib + +let test_name name = + Printf.printf "\n=== %s ===\n" name + +let test_op2_simple () = + test_name "Opcode 2: Simple lifecycle [0 1] → 99"; + let formula_slot2 = Noun.cell (Noun.atom 0) (Noun.atom 1) in + let payload = Noun.atom 99 in + let subject = Noun.cell formula_slot2 payload in + 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 + + let result = Nock.nock_on subject formula in + Printf.printf "Result: %s, mug: 0x%08lx\n" + (match result with Noun.Atom { z; _ } -> Z.to_string z | _ -> "cell") + (Noun.mug result) + +let test_op7_compose () = + test_name "Opcode 7: Compose with [0 1]"; + 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 + 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 + + let result = Nock.nock_on subject formula in + Printf.printf "Result mug: 0x%08lx\n" (Noun.mug result) + +let test_op8_extend () = + test_name "Opcode 8: Extend subject"; + 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)) + (Noun.cell (Noun.atom 0) (Noun.atom 1))) in + + let result = Nock.nock_on subject formula in + Printf.printf "Result: %s, mug: 0x%08lx\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" + else "atom") + (Noun.mug result) + +let test_op9_invoke () = + test_name "Opcode 9: Invoke core arm"; + let core = Noun.cell + (Noun.cell (Noun.atom 0) (Noun.atom 3)) + (Noun.atom 42) in + let formula = Noun.cell (Noun.atom 9) + (Noun.cell (Noun.atom 2) + (Noun.cell (Noun.atom 0) (Noun.atom 1))) in + + let result = Nock.nock_on core formula in + Printf.printf "Result: %s, mug: 0x%08lx\n" + (match result with Noun.Atom { z; _ } -> Z.to_string z | _ -> "cell") + (Noun.mug result) + +let () = + Printf.printf "Testing Nock opcodes...\n"; + test_op2_simple (); + test_op7_compose (); + test_op8_extend (); + test_op9_invoke (); + Printf.printf "\nAll tests complete.\n" -- cgit v1.2.3