sx: step 6 — JS AdtValue + define-type + match

Mirror of OCaml Step 5 to the JavaScript host. Native ADT representation
for define-type instances, with the same dict-shaped shim approach so
spec-level match-pattern code in evaluator.sx works without changes.

- platform.py typeOf: recognize ._adtv tag, return ._type (so
  (type-of (Just 42)) returns "Maybe" not "dict").
- platform.py adds makeAdtValue/isAdtValue helpers and registers
  PRIMITIVES["adt?"], "make-adt-value", "adt-value?".
- platform.py inspect: format AdtValue as "(Ctor f1 f2 ...)" and
  register as a primitive (was missing entirely on JS).
- fixups_js: hand-written define-type override that constructs
  AdtValue via makeAdtValue, with arity check, type/ctor predicates,
  and field accessors. Re-registered via registerSpecialForm so the
  CEK dispatch routes through it.
- dict? unchanged: AdtValue still passes (no _adtv exclusion) so
  the existing (and (dict? v) (get v :_adt) ...) checks in spec
  predicates keep working.

Tests: 2578 pass (was 2575), zero regressions. All 43 ADT tests
pass on the JS host (was 40, the 3 new Step 5 tests for type-of /
adt? / inspect are now green).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-06 23:05:33 +00:00
parent d441807c8e
commit fc8a391656
3 changed files with 164 additions and 8 deletions

View File

@@ -190,7 +190,7 @@ these when operands are known numbers/lists.
| 3 — tokenizer :end/:line | [x] | 023bc2d8 |
| 4 — parser spans complete | [x] | b7ad5152 (subsumed by 023bc2d8) |
| 5 — OCaml AdtValue + define-type + match | [x] | 1f49242a |
| 6 — JS AdtValue + define-type + match | [ ] | |
| 6 — JS AdtValue + define-type + match | [x] | (pending) |
| 7 — nested patterns | [ ] | — |
| 8 — exhaustiveness warnings | [ ] | — |
| 9 — parser feature registry | [ ] | — |