diff options
author | polwex <polwex@sortug.com> | 2025-10-05 22:57:55 +0700 |
---|---|---|
committer | polwex <polwex@sortug.com> | 2025-10-05 22:57:55 +0700 |
commit | c4b71435d9afdb67450f320f54fb7aa99dcae85e (patch) | |
tree | a08c4c2f7965a95fcfe6dda09629d3f103d25a0b /ocaml/tmp | |
parent | fcedfddf00b3f994e4f4e40332ac7fc192c63244 (diff) |
fixed jamcue
Diffstat (limited to 'ocaml/tmp')
-rw-r--r-- | ocaml/tmp/get_jam_vectors.ml | 10 | ||||
-rw-r--r-- | ocaml/tmp/quick_test.ml | 6 | ||||
-rw-r--r-- | ocaml/tmp/test_hex.ml | 9 | ||||
-rw-r--r-- | ocaml/tmp/test_jam.ml | 17 | ||||
-rw-r--r-- | ocaml/tmp/test_prec.ml | 5 | ||||
-rw-r--r-- | ocaml/tmp/test_ref.ml | 7 |
6 files changed, 54 insertions, 0 deletions
diff --git a/ocaml/tmp/get_jam_vectors.ml b/ocaml/tmp/get_jam_vectors.ml new file mode 100644 index 0000000..1266f21 --- /dev/null +++ b/ocaml/tmp/get_jam_vectors.ml @@ -0,0 +1,10 @@ +(* Quick test to see what our jam produces for small numbers *) +open Nock_lib.Noun +open Nock_lib.Serial + +let () = + for i = 0 to 10 do + let n = atom i in + let jammed = jam n in + Printf.printf "%d: %s\n" i (bytes_to_hex jammed) + done diff --git a/ocaml/tmp/quick_test.ml b/ocaml/tmp/quick_test.ml new file mode 100644 index 0000000..9ce168a --- /dev/null +++ b/ocaml/tmp/quick_test.ml @@ -0,0 +1,6 @@ +let () = + Printf.printf "Z.numbits 0 = %d\n" (Z.numbits Z.zero); + Printf.printf "Z.numbits 1 = %d\n" (Z.numbits Z.one); + Printf.printf "Z.numbits 2 = %d\n" (Z.numbits (Z.of_int 2)); + Printf.printf "Z.numbits 42 = %d\n" (Z.numbits (Z.of_int 42)); + Printf.printf "Z.numbits 6 = %d\n" (Z.numbits (Z.of_int 6)); diff --git a/ocaml/tmp/test_hex.ml b/ocaml/tmp/test_hex.ml new file mode 100644 index 0000000..6504640 --- /dev/null +++ b/ocaml/tmp/test_hex.ml @@ -0,0 +1,9 @@ +open Nock_lib.Noun +open Nock_lib.Serial + +let () = + for i = 0 to 10 do + let n = atom i in + let jammed = jam n in + Printf.printf "jam(%d) = %s (%d bytes)\n" i (bytes_to_hex jammed) (Bytes.length jammed) + done diff --git a/ocaml/tmp/test_jam.ml b/ocaml/tmp/test_jam.ml new file mode 100644 index 0000000..e616e3e --- /dev/null +++ b/ocaml/tmp/test_jam.ml @@ -0,0 +1,17 @@ +open Nock_lib.Noun +open Nock_lib.Serial + +let () = + let test n_int = + let n = atom n_int in + let jammed = jam n in + Printf.printf "jam(%d) = %s\n" n_int (bytes_to_hex jammed); + let cued = cue jammed in + match cued with + | Atom a -> Printf.printf "cue -> %s\n" (Z.to_string a) + | Cell _ -> Printf.printf "cue -> cell?!\n" + in + test 0; + test 1; + test 2; + test 42; diff --git a/ocaml/tmp/test_prec.ml b/ocaml/tmp/test_prec.ml new file mode 100644 index 0000000..2a9134c --- /dev/null +++ b/ocaml/tmp/test_prec.ml @@ -0,0 +1,5 @@ +type t = { x : int ref } +let r = { x = ref 42 } +let test () = + let y = !(r.x) in + y diff --git a/ocaml/tmp/test_ref.ml b/ocaml/tmp/test_ref.ml new file mode 100644 index 0000000..8bff6e7 --- /dev/null +++ b/ocaml/tmp/test_ref.ml @@ -0,0 +1,7 @@ +type writer = { + buf: bytes ref; + mutable bit_pos: int; +} + +let test w = + Bytes.length !(w.buf) |