ocaml: phase 2 try/with + raise (+6 tests, 204 total)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 57s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 57s
Parser: try EXPR with | pat -> handler | ... -> (:try EXPR CLAUSES).
Eval delegates to SX guard with else matching the raised value against
clause patterns; re-raises on no-match. raise/failwith/invalid_arg
shipped as builtins. failwith "msg" raises ("Failure" msg) so
| Failure msg -> ... patterns match.
This commit is contained in:
@@ -156,7 +156,8 @@ SX CEK evaluator (both JS and OCaml hosts)
|
||||
- [ ] Mutable record fields.
|
||||
- [x] `for i = lo to hi do ... done` loop; `while cond do ... done` (incl.
|
||||
`downto` direction).
|
||||
- [ ] `try`/`with` — maps to SX `guard`; `raise` via perform.
|
||||
- [x] `try`/`with` — maps to SX `guard`; `raise` is a builtin that calls
|
||||
host SX `raise`. `failwith` and `invalid_arg` ship as builtins.
|
||||
- [ ] Tests in `lib/ocaml/tests/eval.sx` — 50+ tests, pure + imperative.
|
||||
|
||||
### Phase 3 — ADTs + pattern matching
|
||||
@@ -320,6 +321,12 @@ the "mother tongue" closure: OCaml → SX → OCaml. This means:
|
||||
|
||||
_Newest first._
|
||||
|
||||
- 2026-05-08 Phase 2 — `try`/`with` + `raise` builtin. Parser produces
|
||||
`(:try EXPR CLAUSES)`; eval delegates to SX `guard` with `else`
|
||||
matching the raised value against clause patterns and re-raising on
|
||||
no-match. `raise`/`failwith`/`invalid_arg` exposed as builtins;
|
||||
failwith builds `("Failure" msg)` so `Failure msg -> ...` patterns
|
||||
match. 204/204 (+6).
|
||||
- 2026-05-08 Phase 2 — `function | pat -> body | …` parser + eval.
|
||||
Sugar for `fun x -> match x with | …`. AST: `(:function CLAUSES)`
|
||||
evaluated to a unary closure that runs `ocaml-match-clauses` on the
|
||||
|
||||
Reference in New Issue
Block a user