cl: Phase 4 CLOS complete — generic functions, multi-dispatch, method qualifiers, 437/437 tests

- lib/common-lisp/clos.sx (27 forms): class registry (8 built-in classes),
  defclass/make-instance/slot-value/slot-boundp/change-class, defgeneric/defmethod
  with :before/:after/:around, clos-call-generic (standard combination: sort by
  specificity, fire befores, call primary chain, fire afters reversed),
  call-next-method/next-method-p, with-slots, deferred accessor installation
- lib/common-lisp/tests/clos.sx: 41 tests (class-of, subclass-of?, defclass,
  make-instance, slot ops, inheritance, method specificity, qualifiers, accessors,
  with-slots, change-class)
- lib/common-lisp/tests/programs/geometry.sx: 12 tests — intersect generic
  dispatching on geo-point×geo-point, geo-point×geo-line, geo-line×geo-line,
  geo-line×geo-plane (multi-dispatch by class precedence)
- lib/common-lisp/tests/programs/mop-trace.sx: 13 tests — :before/:after
  tracing on area and describe-shape generics, call-next-method in circle/rect
- eval.sx: dynamic variables — cl-apply-dyn saves/restores global slot for
  specials; cl-mark-special!/cl-special?/cl-dyn-unbound; defvar now marks
  specials; let/let* rebind via cl-apply-dyn; 8 new tests (182 eval total)
- conformance.sh + test.sh: Phase 4 suites wired in
- plans/common-lisp-on-sx.md: Phase 4 + dynamic variable boxes ticked

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-05 11:38:37 +00:00
parent 71c4b5e33f
commit 0e426cfea8
11 changed files with 1529 additions and 36 deletions

View File

@@ -366,6 +366,56 @@ run_program_suite \
"lib/common-lisp/tests/programs/interactive-debugger.sx" \
"debugger-passed" "debugger-failed" "debugger-failures"
# ── Phase 4: CLOS unit tests ─────────────────────────────────────────────────
CLOS_FILE=$(mktemp); trap "rm -f $CLOS_FILE" EXIT
printf '(epoch 1)\n(load "spec/stdlib.sx")\n(epoch 2)\n(load "lib/common-lisp/runtime.sx")\n(epoch 3)\n(load "lib/common-lisp/clos.sx")\n(epoch 4)\n(load "lib/common-lisp/tests/clos.sx")\n(epoch 5)\n(eval "passed")\n(epoch 6)\n(eval "failed")\n(epoch 7)\n(eval "failures")\n' > "$CLOS_FILE"
CLOS_OUT=$(timeout 30 "$SX_SERVER" < "$CLOS_FILE" 2>/dev/null)
rm -f "$CLOS_FILE"
CLOS_PASSED=$(echo "$CLOS_OUT" | grep -A1 "^(ok-len 5 " | tail -1 || true)
CLOS_FAILED=$(echo "$CLOS_OUT" | grep -A1 "^(ok-len 6 " | tail -1 || true)
[ -z "$CLOS_PASSED" ] && CLOS_PASSED=$(echo "$CLOS_OUT" | grep "^(ok 5 " | awk '{print $3}' | tr -d ')' || true)
[ -z "$CLOS_FAILED" ] && CLOS_FAILED=$(echo "$CLOS_OUT" | grep "^(ok 6 " | awk '{print $3}' | tr -d ')' || true)
[ -z "$CLOS_PASSED" ] && CLOS_PASSED=0; [ -z "$CLOS_FAILED" ] && CLOS_FAILED=0
if [ "$CLOS_FAILED" = "0" ] && [ "$CLOS_PASSED" -gt 0 ] 2>/dev/null; then
PASS=$((PASS + CLOS_PASSED))
[ "$VERBOSE" = "-v" ] && echo " ok CLOS unit tests ($CLOS_PASSED)"
else
FAIL=$((FAIL + 1))
ERRORS+=" FAIL [CLOS unit tests] (${CLOS_PASSED} passed, ${CLOS_FAILED} failed)
"
fi
# ── Phase 4: CLOS classic programs ───────────────────────────────────────────
run_clos_suite() {
local prog="$1" pass_var="$2" fail_var="$3" failures_var="$4"
local PROG_FILE=$(mktemp)
printf '(epoch 1)\n(load "spec/stdlib.sx")\n(epoch 2)\n(load "lib/common-lisp/runtime.sx")\n(epoch 3)\n(load "lib/common-lisp/clos.sx")\n(epoch 4)\n(load "%s")\n(epoch 5)\n(eval "%s")\n(epoch 6)\n(eval "%s")\n(epoch 7)\n(eval "%s")\n' \
"$prog" "$pass_var" "$fail_var" "$failures_var" > "$PROG_FILE"
local OUT; OUT=$(timeout 20 "$SX_SERVER" < "$PROG_FILE" 2>/dev/null)
rm -f "$PROG_FILE"
local P F
P=$(echo "$OUT" | grep -A1 "^(ok-len 5 " | tail -1 || true)
F=$(echo "$OUT" | grep -A1 "^(ok-len 6 " | tail -1 || true)
local ERRS; ERRS=$(echo "$OUT" | grep -A1 "^(ok-len 7 " | tail -1 || true)
[ -z "$P" ] && P=0; [ -z "$F" ] && F=0
if [ "$F" = "0" ] && [ "$P" -gt 0 ] 2>/dev/null; then
PASS=$((PASS + P))
[ "$VERBOSE" = "-v" ] && echo " ok $prog ($P)"
else
FAIL=$((FAIL + 1))
ERRORS+=" FAIL [$prog] (${P} passed, ${F} failed) ${ERRS}
"
fi
}
run_clos_suite \
"lib/common-lisp/tests/programs/geometry.sx" \
"geo-passed" "geo-failed" "geo-failures"
run_clos_suite \
"lib/common-lisp/tests/programs/mop-trace.sx" \
"mop-passed" "mop-failed" "mop-failures"
TOTAL=$((PASS+FAIL))
if [ $FAIL -eq 0 ]; then
echo "ok $PASS/$TOTAL lib/common-lisp tests passed"