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
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:
@@ -1106,6 +1106,16 @@ cat > "$TMPFILE" << 'EPOCHS'
|
||||
(epoch 4002)
|
||||
(eval "(ocaml-run-program \"type point = { x : int; y : int };; let p = { x = 3; y = 4 };; p.x + p.y\")")
|
||||
|
||||
;; ── Mutable record fields (r.f <- v) ──────────────────────────
|
||||
(epoch 4100)
|
||||
(eval "(ocaml-run \"let r = { x = 1; y = 2 } in r.x <- 5; r.x\")")
|
||||
(epoch 4101)
|
||||
(eval "(ocaml-run \"let r = { x = 0 } in for i = 1 to 5 do r.x <- r.x + i done; r.x\")")
|
||||
(epoch 4102)
|
||||
(eval "(ocaml-run \"let r = { name = \\\"Bob\\\"; age = 30 } in r.name <- \\\"Alice\\\"; r.name\")")
|
||||
(epoch 4103)
|
||||
(eval "(ocaml-run \"let r = { x = 1; y = 2 } in r.x <- r.y * 10; r.x\")")
|
||||
|
||||
EPOCHS
|
||||
|
||||
OUTPUT=$(timeout 180 "$SX_SERVER" < "$TMPFILE" 2>/dev/null)
|
||||
@@ -1751,6 +1761,12 @@ check 4000 "record type decl" '("type-def-record" "point" () (("x")
|
||||
check 4001 "mutable field decl" '("mutable" "x")'
|
||||
check 4002 "record decl + use" '7'
|
||||
|
||||
# ── Mutable record fields ──────────────────────────────────────
|
||||
check 4100 "r.x <- 5; r.x" '5'
|
||||
check 4101 "for-loop accum r.x" '15'
|
||||
check 4102 "r.name <- str" '"Alice"'
|
||||
check 4103 "r.x <- r.y * 10" '20'
|
||||
|
||||
TOTAL=$((PASS + FAIL))
|
||||
if [ $FAIL -eq 0 ]; then
|
||||
echo "ok $PASS/$TOTAL OCaml-on-SX tests passed"
|
||||
|
||||
Reference in New Issue
Block a user