diff options
Diffstat (limited to 'ocaml/test')
-rw-r--r-- | ocaml/test/dune | 8 | ||||
-rw-r--r-- | ocaml/test/test_nock_iter.ml | 59 | ||||
-rw-r--r-- | ocaml/test/test_two_stage_boot.ml | 6 |
3 files changed, 72 insertions, 1 deletions
diff --git a/ocaml/test/dune b/ocaml/test/dune index d23fc4d..abe712a 100644 --- a/ocaml/test/dune +++ b/ocaml/test/dune @@ -271,6 +271,14 @@ (name test_two_stage_boot) (modules test_two_stage_boot) (libraries nock_lib eio_main unix)) +; NOTE: Run with increased stack size for solid pill: +; OCAMLRUNPARAM='l=100M' dune exec test/test_two_stage_boot.exe + +(executable + (name test_nock_iter) + (modules test_nock_iter) + (libraries nock_lib eio_main unix)) +; NOTE: This uses the iterative Nock interpreter - no stack limit needed! (executable (name test_mug) diff --git a/ocaml/test/test_nock_iter.ml b/ocaml/test/test_nock_iter.ml new file mode 100644 index 0000000..05a03ce --- /dev/null +++ b/ocaml/test/test_nock_iter.ml @@ -0,0 +1,59 @@ +(** Test the fully iterative Nock interpreter - no stack overflow! *) + +open Nock_lib + +let () = + Printf.printf "Testing iterative Nock interpreter (no stack limit needed)...\n\n"; + + (* Test 1: Simple increment *) + Printf.printf "[1] Testing simple increment: *[42 [4 0 1]]\n"; + let result = Nock_iter.nock_on (Noun.atom 42) (Noun.cell (Noun.atom 4) (Noun.cell (Noun.atom 0) (Noun.atom 1))) in + Printf.printf " Result: %s\n" (Z.to_string (match result with Noun.Atom { z; _ } -> z | _ -> Z.zero)); + Printf.printf " Expected: 43\n\n"; + + (* Test 2: Distribution *) + Printf.printf "[2] Testing distribution: *[42 [[4 0 1] [4 0 1]]]\n"; + let inc_fol = Noun.cell (Noun.atom 4) (Noun.cell (Noun.atom 0) (Noun.atom 1)) in + let dist = Noun.cell inc_fol inc_fol in + let result = Nock_iter.nock_on (Noun.atom 42) dist in + Printf.printf " Result: [%s %s]\n" + (Z.to_string (match Noun.head result with Noun.Atom { z; _ } -> z | _ -> Z.zero)) + (Z.to_string (match Noun.tail result with Noun.Atom { z; _ } -> z | _ -> Z.zero)); + Printf.printf " Expected: [43 43]\n\n"; + + (* Test 3: Small pill to verify no recursion issues *) + Printf.printf "[3] Loading ivory pill (this would stack overflow with recursive version)...\n"; + Eio_main.run (fun env -> + let fs = Eio.Stdenv.fs env in + let bytes = Eio.Path.(load (fs / "ivory.pill")) |> Bytes.of_string in + Printf.printf " Pill size: %d bytes\n" (Bytes.length bytes); + + let pill = Serial.cue bytes in + Printf.printf " Cued successfully\n"; + + match pill with + | Noun.Cell { h = _tag; t = core; _ } -> + Printf.printf " Structure: [tag core]\n"; + Printf.printf " Core mug: 0x%08lx\n" (Noun.mug core); + + Printf.printf "\n Running lifecycle formula with ITERATIVE interpreter...\n"; + Printf.printf " (No OCAMLRUNPARAM needed!)\n"; + + 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 start = Unix.gettimeofday () in + let kernel = Nock_iter.nock_on core formula in + let elapsed = Unix.gettimeofday () -. start in + + Printf.printf " ā SUCCESS in %.2fs\n" elapsed; + Printf.printf " Kernel mug: 0x%08lx\n" (Noun.mug kernel); + Printf.printf "\nā
Iterative Nock interpreter works perfectly!\n"; + Printf.printf " No stack overflow, no OCAMLRUNPARAM needed.\n"; + + | _ -> + Printf.printf " Unexpected pill structure\n" + ) diff --git a/ocaml/test/test_two_stage_boot.ml b/ocaml/test/test_two_stage_boot.ml index c18ea58..0e4da5f 100644 --- a/ocaml/test/test_two_stage_boot.ml +++ b/ocaml/test/test_two_stage_boot.ml @@ -1,4 +1,8 @@ -(* Two-Stage Boot Test - Exactly like C Vere *) +(* Two-Stage Boot Test - Exactly like C Vere + * + * NOTE: This test requires increased stack size due to deep recursion in solid pill: + * OCAMLRUNPARAM='l=100M' dune exec test/test_two_stage_boot.exe + *) open Nock_lib |