ocaml: phase 3 exception declarations (+4 tests, 304 total)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 50s

exception NAME [of TYPE] parses to (:exception-def NAME [ARG-SRC]).
Runtime is a no-op: raise/match already work on tagged ctor values, so
'exception E of int;; try raise (E 5) with | E n -> n' end-to-end with
zero new eval logic.
This commit is contained in:
2026-05-08 12:37:58 +00:00
parent d8f6250962
commit bc557a5ad2
4 changed files with 62 additions and 2 deletions

View File

@@ -178,8 +178,10 @@ SX CEK evaluator (both JS and OCaml hosts)
- [x] Exhaustiveness: runtime error on incomplete match (no compile-time check yet).
- [ ] Built-in types: `option` (`None`/`Some`), `result` (`Ok`/`Error`),
`list` (nil/cons), `bool`, `unit`, `exn`.
- [ ] `exception` declarations; built-in: `Not_found`, `Invalid_argument`,
`Failure`, `Match_failure`.
- [x] `exception` declarations: `exception NAME [of TYPE]`. Parser emits
`(:exception-def NAME [ARG-TYPE-SRC])`. Runtime no-op since
raise/match work on tagged ctor values. Built-ins:
`Failure`/`Invalid_argument` via `failwith`/`invalid_arg`.
- [ ] Polymorphic variants (surface syntax `\`Tag value`; runtime same tagged list).
- [ ] Tests in `lib/ocaml/tests/adt.sx` — 40+ tests: ADTs, match, option/result.
@@ -358,6 +360,11 @@ the "mother tongue" closure: OCaml → SX → OCaml. This means:
_Newest first._
- 2026-05-08 Phase 3 — `exception` declarations (+4 tests, 304 total).
`exception NAME [of TYPE]` parses to `(:exception-def NAME [ARG-SRC])`.
Runtime is a no-op: exception values are just tagged ctor values, so
the existing `raise`/`try`/`with` machinery works without any extra
wiring.
- 2026-05-08 Phase 3 — `type` declarations (+5 tests, 300 total). Parser
handles `type [PARAMS] NAME = | Ctor [of T1 [* T2]*] | ...`, with
optional `'a` or `('a, 'b)` type parameters. Argument types are