ocaml: phase 2 mutable record fields r.f <- v (+4 tests, 451 total)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 27s

<- added to op-table at level 1 (same as :=). Eval short-circuits on
<- to mutate the lhs's field via host SX dict-set!. The lhs must be a
:field expression; otherwise raises.

Tested:
  let r = { x = 1; y = 2 } in r.x <- 5; r.x       (5)
  let r = { x = 0 } in for i = 1 to 5 do r.x <- r.x + i done; r.x  (15)
  let r = { name = ...; age = 30 } in r.name <- "Alice"; r.name

The 'mutable' keyword in record type decls is parsed-and-discarded;
runtime semantics: every field is mutable. Phase 2 closes this gap
without changing the dict-based record representation.
This commit is contained in:
2026-05-08 18:35:31 +00:00
parent 66da0e5b84
commit d9979eaf6c
4 changed files with 40 additions and 0 deletions

View File

@@ -157,6 +157,10 @@ SX CEK evaluator (both JS and OCaml hosts)
- [x] Arithmetic, comparison, boolean ops, string `^`, `mod`.
- [x] Unit `()` value; `ignore`.
- [x] References: `ref`, `!`, `:=`.
- [x] Mutable record fields via `r.f <- v` — uses host SX `dict-set!`
to mutate the underlying record dict in place. All record fields
are de-facto mutable (the `mutable` keyword in type-decls is
currently parsed-and-discarded).
- [ ] Mutable record fields.
- [x] `for i = lo to hi do ... done` loop; `while cond do ... done` (incl.
`downto` direction).
@@ -403,6 +407,13 @@ _Newest first._
binary search tree (`type 'a tree = Leaf | Node of 'a * 'a tree *
'a tree`) with insert + in-order traversal. Tests parametric ADT,
recursive match, List.append, List.fold_left.
- 2026-05-08 Phase 2 — mutable record fields `r.f <- v` (+4 tests, 451
total). `<-` added to op-table at level 1 (same as `:=`). Eval
short-circuits on `<-` to mutate the lhs's field via host SX
`dict-set!`. Tested with for-loop accumulator (`for i = 1 to 5 do
r.x <- r.x + i done`) and string-field reassignment. The `mutable`
keyword in record-type decls is parsed-and-discarded; runtime
semantics: every field is mutable.
- 2026-05-08 Phase 1+3 — record type declarations `type r = { x : int;
mutable y : string }` (+3 tests, 447 total). Parser dispatches on
`{` after `=` to parse field list (`mutable` keyword tracked).