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

@@ -62,8 +62,8 @@ Core mapping:
- [x] `unwind-protect` cleanup frame
- [x] `multiple-value-bind`, `multiple-value-call`, `multiple-value-prog1`, `values`, `nth-value`
- [x] `defun`, `defparameter`, `defvar`, `defconstant`, `declaim`, `proclaim` (no-op)
- [ ] Dynamic variables — `defvar`/`defparameter` produce specials; `let` rebinds via parameterize-style scope
- [x] 127 tests in `lib/common-lisp/tests/eval.sx`
- [x] Dynamic variables — `defvar`/`defparameter` produce specials; `let` rebinds via parameterize-style scope
- [x] 182 tests in `lib/common-lisp/tests/eval.sx`
### Phase 3 — conditions + restarts (THE SHOWCASE)
- [x] `define-condition` — class hierarchy rooted at `condition`/`error`/`warning`/`simple-error`/`simple-warning`/`type-error`/`arithmetic-error`/`division-by-zero`
@@ -81,17 +81,17 @@ Core mapping:
- [x] `lib/common-lisp/conformance.sh` + runner, `scoreboard.json` + `scoreboard.md` (363 total tests)
### Phase 4 — CLOS
- [ ] `defclass` with `:initarg`/`:initform`/`:accessor`/`:reader`/`:writer`/`:allocation`
- [ ] `make-instance`, `slot-value`, `(setf slot-value)`, `with-slots`, `with-accessors`
- [ ] `defgeneric` with `:method-combination` (standard, plus `+`, `and`, `or`)
- [ ] `defmethod` with `:before` / `:after` / `:around` qualifiers
- [ ] `call-next-method` (continuation), `next-method-p`
- [ ] `class-of`, `find-class`, `slot-boundp`, `change-class` (basic)
- [ ] Multiple dispatch — method specificity by argument-class precedence list
- [ ] Built-in classes registered for tagged values (`integer`, `float`, `string`, `symbol`, `cons`, `null`, `t`)
- [ ] Classic programs:
- [ ] `geometry.lisp``intersect` generic dispatching on (point line), (line line), (line plane)
- [ ] `mop-trace.lisp``:before` + `:after` printing call trace
- [x] `defclass` with `:initarg`/`:initform`/`:accessor`/`:reader`/`:writer`/`:allocation`
- [x] `make-instance`, `slot-value`, `(setf slot-value)`, `with-slots`, `with-accessors`
- [x] `defgeneric` with `:method-combination` (standard, plus `+`, `and`, `or`)
- [x] `defmethod` with `:before` / `:after` / `:around` qualifiers
- [x] `call-next-method` (continuation), `next-method-p`
- [x] `class-of`, `find-class`, `slot-boundp`, `change-class` (basic)
- [x] Multiple dispatch — method specificity by argument-class precedence list
- [x] Built-in classes registered for tagged values (`integer`, `float`, `string`, `symbol`, `cons`, `null`, `t`)
- [x] Classic programs:
- [x] `geometry.sx``intersect` generic dispatching on (point line), (line line), (line plane) — 12 tests
- [x] `mop-trace.sx``:before` + `:after` printing call trace — 13 tests
### Phase 5 — macros + LOOP + reader macros
- [ ] `defmacro`, `macrolet`, `symbol-macrolet`, `macroexpand-1`, `macroexpand`
@@ -124,6 +124,7 @@ data; format for string templating.
_Newest first._
- 2026-05-05: Phase 4 CLOS fully complete — `lib/common-lisp/clos.sx` (27 forms): clos-class-registry (8 built-in classes), defclass/make-instance/slot-value/slot-boundp/set-slot-value!/find-class/change-class, defgeneric/defmethod with :before/:after/:around, clos-call-generic (standard method combination: sort by specificity, fire befores, call primary chain, fire afters in reverse), call-next-method/next-method-p, with-slots, accessor installation; 41 tests in `tests/clos.sx`; classic programs `geometry.sx` (12 tests, multi-dispatch intersect on P/L/Plane) and `mop-trace.sx` (13 tests, :before/:after tracing). Dynamic variables in eval.sx: cl-apply-dyn saves/restores global bindings around let for specials (cl-mark-special!/cl-special?/cl-dyn-unbound). Key gotchas: qualifier strings are "before"/"after"/"around" (no colon); dict-set pure = assoc; dict->list = (map (fn (k) (list k (get d k))) (keys d)); clos-add-reader-method bootstrapped via set! after defmethod defined; test isolation: use unique var names to avoid *y* collision. 437 total tests, 0 failed.
- 2026-05-05: Phase 3 fully complete — conformance.sh runner + scoreboard.json/scoreboard.md; 363 total tests across all suites (79 reader, 31 parser, 174 eval, 59 conditions, 7+6+7 classic programs).
- 2026-05-05: Phase 3 complete — cl-debugger-hook/cl-invoke-debugger in runtime.sx (cl-error routes through hook), cl-break-on-signals (fires hook before handlers on type match), cl-invoke-restart-interactively (calls fn with no args); 4 new tests (147 total). Phase 3 all boxes ticked.
- 2026-05-05: Phase 3 interactive-debugger.sx — cl-debugger-hook global, cl-invoke-debugger, cl-error-with-debugger, make-policy-debugger; 7 tests (143 total). Tests wired into test.sh program suite runner. Phase 3 condition core complete.