summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpolwex <polwex@sortug.com>2025-10-07 00:14:45 +0700
committerpolwex <polwex@sortug.com>2025-10-07 00:14:45 +0700
commit799007bbfee05ee706a9d24d399458c2229ad6af (patch)
tree8050c77f745cfdcbdd34aead8f41bcfc2053b118
parent5242ee845cdb3a7e9780443bf5d7e534f72c3f28 (diff)
and he fixed the mugs
-rw-r--r--ocaml/lib/noun.ml10
1 files changed, 8 insertions, 2 deletions
diff --git a/ocaml/lib/noun.ml b/ocaml/lib/noun.ml
index f4c4f87..382c79d 100644
--- a/ocaml/lib/noun.ml
+++ b/ocaml/lib/noun.ml
@@ -182,9 +182,15 @@ let rec mug noun =
end
and compute_mug_atom z =
- (* Convert to bytes (little-endian, strip trailing zeros) *)
+ (* Convert to bytes (little-endian) *)
let bytes = Z.to_bits z in
- mug_bytes_with_seed bytes 0xcafebabel
+ (* Strip trailing zeros like C's u3r_mug_words does *)
+ let len = ref (String.length bytes) in
+ while !len > 0 && bytes.[!len - 1] = '\x00' do
+ decr len
+ done;
+ let stripped = String.sub bytes 0 !len in
+ mug_bytes_with_seed stripped 0xcafebabel
(** Pretty-print a noun *)
let rec pp_noun fmt = function