Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 23s
Side-quests required to land caesar.ml:
1. Top-level 'let r = expr in body' is now an expression decl, not a
broken decl-let. ocaml-parse-program's dispatch now checks
has-matching-in? at every top-level let; if matched, slices via
skip-let-rhs-boundary (which already opens depth on a leading let
with matching in) and ocaml-parse on the slice, wrapping as :expr.
2. runtime.sx: added String.make / String.init / String.map. Used by
caesar.ml's encode = String.init n (fun i -> shift_char s.[i] k).
3. baseline run.sh per-program timeout 240->480s (system load on the
shared host frequently exceeds 240s for large baselines).
caesar.ml exercises:
* the new top-level let-in expression dispatch
* s.[i] string indexing
* Char.code / Char.chr round-trip math
* String.init with a closure that captures k
Test value: Char.code r.[0] + Char.code r.[4] after ROT13(ROT13('hello')) = 104 + 111 = 215.
65 lines
1.6 KiB
Bash
Executable File
65 lines
1.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# lib/ocaml/baseline/run.sh — run each baseline OCaml program through
|
|
# ocaml-run-program and compare to expected.json.
|
|
|
|
set -uo pipefail
|
|
cd "$(git rev-parse --show-toplevel)"
|
|
|
|
SX_SERVER="${SX_SERVER:-hosts/ocaml/_build/default/bin/sx_server.exe}"
|
|
if [ ! -x "$SX_SERVER" ]; then
|
|
SX_SERVER="/root/rose-ash/hosts/ocaml/_build/default/bin/sx_server.exe"
|
|
fi
|
|
|
|
PASS=0
|
|
FAIL=0
|
|
ERRORS=""
|
|
|
|
for f in lib/ocaml/baseline/*.ml; do
|
|
name=$(basename "$f")
|
|
expected=$(grep -oE "\"$name\"[[:space:]]*:[[:space:]]*[0-9-]+" lib/ocaml/baseline/expected.json | sed -E 's/.*:[[:space:]]*//')
|
|
if [ -z "$expected" ]; then
|
|
continue
|
|
fi
|
|
|
|
TMP=$(mktemp)
|
|
cat > "$TMP" << EOF
|
|
(epoch 1)
|
|
(load "lib/guest/lex.sx")
|
|
(load "lib/guest/prefix.sx")
|
|
(load "lib/guest/pratt.sx")
|
|
(load "lib/ocaml/tokenizer.sx")
|
|
(load "lib/ocaml/parser.sx")
|
|
(load "lib/ocaml/eval.sx")
|
|
(load "lib/ocaml/runtime.sx")
|
|
(eval "(ocaml-load-stdlib!)")
|
|
(epoch 2)
|
|
(eval "(ocaml-run-program (file-read \"$f\"))")
|
|
EOF
|
|
|
|
output=$(timeout 480 "$SX_SERVER" < "$TMP" 2>/dev/null)
|
|
rm -f "$TMP"
|
|
|
|
result=$(echo "$output" | awk '
|
|
/^\(ok-len 2 / { getline; print; exit }
|
|
/^\(ok 2 [^)]+\)$/ { sub(/^\(ok 2 /, ""); sub(/\)$/, ""); print; exit }
|
|
')
|
|
|
|
if [ "$result" = "$expected" ]; then
|
|
PASS=$((PASS + 1))
|
|
echo " ok $name → $result"
|
|
else
|
|
FAIL=$((FAIL + 1))
|
|
ERRORS+=" FAIL $name expected=$expected got=$result
|
|
"
|
|
fi
|
|
done
|
|
|
|
TOTAL=$((PASS + FAIL))
|
|
if [ $FAIL -eq 0 ]; then
|
|
echo "ok $PASS/$TOTAL baseline OCaml programs run correctly"
|
|
else
|
|
echo "FAIL $PASS/$TOTAL baseline programs"
|
|
echo "$ERRORS"
|
|
fi
|
|
[ $FAIL -eq 0 ]
|