ocaml: phase 6 Printf %i/%u/%x/%X/%o + int_to_hex/octal host primitives (+5 tests, 533 total)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 41s

Three new host primitives in eval.sx:
  _int_to_hex_lower n  -> string of hex digits (lowercase)
  _int_to_hex_upper n  -> string of hex digits (uppercase)
  _int_to_octal    n   -> string of octal digits

Each builds the digit string by repeated floor(n / base) + mod,
prepending the digit at each step. Negative numbers prefix '-' so the
output round-trips through int_of_string with a sign.

Printf walker now fans out:
  %d, %i, %u  -> _string_of_int
  %f          -> _string_of_float
  %x          -> _int_to_hex_lower
  %X          -> _int_to_hex_upper
  %o          -> _int_to_octal
  %s, %c, %b  -> existing handling

  Printf.sprintf '%x' 255          = 'ff'
  Printf.sprintf '%X' 4096         = '1000'
  Printf.sprintf '%o' 8            = '10'
  Printf.sprintf '%x %X %o' 255 4096 8 = 'ff 1000 10'
This commit is contained in:
2026-05-09 03:12:28 +00:00
parent 8188a82a58
commit cb14a07413
4 changed files with 90 additions and 3 deletions

View File

@@ -1318,6 +1318,18 @@ cat > "$TMPFILE" << 'EPOCHS'
(epoch 5062)
(eval "(ocaml-run \"List.length (List.sort compare [9;8;7;6;5;4;3;2;1;0])\")")
;; ── Printf %i %x %X %o ─────────────────────────────────────────
(epoch 5070)
(eval "(ocaml-run \"Printf.sprintf \\\"%i\\\" 42\")")
(epoch 5071)
(eval "(ocaml-run \"Printf.sprintf \\\"%x\\\" 255\")")
(epoch 5072)
(eval "(ocaml-run \"Printf.sprintf \\\"%X\\\" 4096\")")
(epoch 5073)
(eval "(ocaml-run \"Printf.sprintf \\\"%o\\\" 8\")")
(epoch 5074)
(eval "(ocaml-run \"Printf.sprintf \\\"%x %X %o\\\" 255 4096 8\")")
EPOCHS
OUTPUT=$(timeout 360 "$SX_SERVER" < "$TMPFILE" 2>/dev/null)
@@ -2094,6 +2106,13 @@ check 5060 "sort 9-element list" '(1 2 3 4 5 6 7 8 9)'
check 5061 "sort with reverse cmp" '(5 4 3 1 1)'
check 5062 "sort 10 reversed -> length" '10'
# ── Printf %i %x %X %o ──────────────────────────────────────────
check 5070 "%i 42" '"42"'
check 5071 "%x 255" '"ff"'
check 5072 "%X 4096" '"1000"'
check 5073 "%o 8" '"10"'
check 5074 "%x %X %o multi" '"ff 1000 10"'
TOTAL=$((PASS + FAIL))
if [ $FAIL -eq 0 ]; then
echo "ok $PASS/$TOTAL OCaml-on-SX tests passed"