ocaml: phase 2 for/while loops (+5 tests, 194 total)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 52s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 52s
Parser: for i = lo to|downto hi do body done, while cond do body done. AST: (:for NAME LO HI :ascend|:descend BODY) and (:while COND BODY). Eval re-binds the loop var per iteration; both forms evaluate to unit.
This commit is contained in:
@@ -495,6 +495,18 @@ cat > "$TMPFILE" << 'EPOCHS'
|
||||
(epoch 605)
|
||||
(eval "(ocaml-run \"let count = ref 0 in let rec loop n = if n = 0 then !count else (count := !count + n; loop (n - 1)) in loop 5\")")
|
||||
|
||||
;; ── for / while loops ──────────────────────────────────────────
|
||||
(epoch 620)
|
||||
(eval "(ocaml-run \"let s = ref 0 in for i = 1 to 5 do s := !s + i done; !s\")")
|
||||
(epoch 621)
|
||||
(eval "(ocaml-run \"let s = ref 0 in for i = 5 downto 1 do s := !s + i done; !s\")")
|
||||
(epoch 622)
|
||||
(eval "(ocaml-run \"let i = ref 0 in let s = ref 0 in while !i < 5 do i := !i + 1; s := !s + !i done; !s\")")
|
||||
(epoch 623)
|
||||
(eval "(ocaml-run \"let s = ref 0 in for i = 1 to 100 do s := !s + i done; !s\")")
|
||||
(epoch 624)
|
||||
(eval "(ocaml-run \"let p = ref 1 in for i = 1 to 5 do p := !p * i done; !p\")")
|
||||
|
||||
EPOCHS
|
||||
|
||||
OUTPUT=$(timeout 60 "$SX_SERVER" < "$TMPFILE" 2>/dev/null)
|
||||
@@ -789,6 +801,13 @@ check 603 "ref captured by closure" '115'
|
||||
check 604 "ref of string" '"b"'
|
||||
check 605 "ref + recursion" '15'
|
||||
|
||||
# ── for / while ─────────────────────────────────────────────────
|
||||
check 620 "for 1..5 sum" '15'
|
||||
check 621 "for 5 downto 1 sum" '15'
|
||||
check 622 "while loop" '15'
|
||||
check 623 "for 1..100 sum" '5050'
|
||||
check 624 "for 1..5 product = 120" '120'
|
||||
|
||||
TOTAL=$((PASS + FAIL))
|
||||
if [ $FAIL -eq 0 ]; then
|
||||
echo "ok $PASS/$TOTAL OCaml-on-SX tests passed"
|
||||
|
||||
Reference in New Issue
Block a user