ocaml: phase 6 Hashtbl (+6 tests, 332 total)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 32s

Backing store is a one-element list cell holding a SX dict; keys
coerced to strings via str so int/string keys work uniformly. API:
create, add, replace, find, find_opt, mem, length.

_hashtbl_create / _hashtbl_add / _hashtbl_replace / _hashtbl_find_opt /
_hashtbl_mem / _hashtbl_length primitives wired in eval.sx; OCaml-side
Hashtbl module wraps them in lib/ocaml/runtime.sx.
This commit is contained in:
2026-05-08 12:57:22 +00:00
parent 6d7197182e
commit 812aa75d43
4 changed files with 66 additions and 1 deletions

View File

@@ -814,6 +814,20 @@ cat > "$TMPFILE" << 'EPOCHS'
(epoch 1506)
(eval "(ocaml-type-of \"[true; false]\")")
;; ── Hashtbl ────────────────────────────────────────────────────
(epoch 1600)
(eval "(ocaml-run-program \"let t = Hashtbl.create 10;; Hashtbl.add t \\\"x\\\" 42;; Hashtbl.find t \\\"x\\\"\")")
(epoch 1601)
(eval "(ocaml-run-program \"let t = Hashtbl.create 10;; Hashtbl.add t 1 \\\"a\\\";; Hashtbl.add t 2 \\\"b\\\";; Hashtbl.length t\")")
(epoch 1602)
(eval "(ocaml-run-program \"let t = Hashtbl.create 10;; Hashtbl.add t 1 100;; Hashtbl.find_opt t 99\")")
(epoch 1603)
(eval "(ocaml-run-program \"let t = Hashtbl.create 10;; Hashtbl.add t 1 100;; Hashtbl.mem t 1\")")
(epoch 1604)
(eval "(ocaml-run-program \"let t = Hashtbl.create 10;; Hashtbl.add t \\\"a\\\" 1;; Hashtbl.replace t \\\"a\\\" 2;; Hashtbl.find t \\\"a\\\"\")")
(epoch 1605)
(eval "(ocaml-run-program \"let t = Hashtbl.create 10;; Hashtbl.add t \\\"k\\\" 5;; Hashtbl.find_opt t \\\"k\\\"\")")
EPOCHS
OUTPUT=$(timeout 180 "$SX_SERVER" < "$TMPFILE" 2>/dev/null)
@@ -1288,6 +1302,14 @@ check 1504 "type fn -> list" 'list"'
check 1505 "type fn -> tuple" ' * '
check 1506 "type Bool list" '"Bool list"'
# ── Hashtbl ─────────────────────────────────────────────────────
check 1600 "Hashtbl find" '42'
check 1601 "Hashtbl length" '2'
check 1602 "Hashtbl find_opt missing" '("None")'
check 1603 "Hashtbl mem" 'true'
check 1604 "Hashtbl replace" '2'
check 1605 "Hashtbl find_opt found" '("Some" 5)'
TOTAL=$((PASS + FAIL))
if [ $FAIL -eq 0 ]; then
echo "ok $PASS/$TOTAL OCaml-on-SX tests passed"