ocaml: phase 6 stdlib slice (List/Option/Result, +23 tests, 248 total)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 45s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 45s
lib/ocaml/runtime.sx defines the stdlib in OCaml syntax (not SX): every function exercises the parser, evaluator, match engine, and module machinery built in earlier phases. Loaded once via ocaml-load-stdlib!, cached in ocaml-stdlib-env, layered under user code via ocaml-base-env. List: length, rev, rev_append, map, filter, fold_left/right, append, iter, mem, for_all, exists, hd, tl, nth. Option: map, bind, value, get, is_none, is_some. Result: map, bind, is_ok, is_error. Substrate validation: this stdlib is a nontrivial OCaml program — its mere existence proves the substrate works.
This commit is contained in:
@@ -33,7 +33,9 @@ cat > "$TMPFILE" << 'EPOCHS'
|
||||
(load "lib/ocaml/tokenizer.sx")
|
||||
(load "lib/ocaml/parser.sx")
|
||||
(load "lib/ocaml/eval.sx")
|
||||
(load "lib/ocaml/runtime.sx")
|
||||
(load "lib/ocaml/tests/tokenize.sx")
|
||||
(eval "(ocaml-load-stdlib!)")
|
||||
|
||||
;; ── empty / eof ────────────────────────────────────────────────
|
||||
(epoch 100)
|
||||
@@ -579,6 +581,56 @@ cat > "$TMPFILE" << 'EPOCHS'
|
||||
(epoch 754)
|
||||
(eval "(ocaml-run-program \"module Identity (M) = struct include M end ;; module Base = struct let v = 99 end ;; module Same = Identity(Base) ;; Same.v\")")
|
||||
|
||||
;; ── Phase 6: stdlib slice (List, Option, Result) ───────────────
|
||||
(epoch 800)
|
||||
(eval "(ocaml-run \"List.length [1; 2; 3; 4]\")")
|
||||
(epoch 801)
|
||||
(eval "(ocaml-run \"List.length []\")")
|
||||
(epoch 802)
|
||||
(eval "(ocaml-run \"List.map (fun x -> x * 2) [1; 2; 3]\")")
|
||||
(epoch 803)
|
||||
(eval "(ocaml-run \"List.filter (fun x -> x > 2) [1; 2; 3; 4; 5]\")")
|
||||
(epoch 804)
|
||||
(eval "(ocaml-run \"List.fold_left (fun a b -> a + b) 0 [1; 2; 3; 4; 5]\")")
|
||||
(epoch 805)
|
||||
(eval "(ocaml-run \"List.fold_right (fun x acc -> x :: acc) [1; 2; 3] []\")")
|
||||
(epoch 806)
|
||||
(eval "(ocaml-run \"List.rev [1; 2; 3]\")")
|
||||
(epoch 807)
|
||||
(eval "(ocaml-run \"List.append [1; 2] [3; 4]\")")
|
||||
(epoch 808)
|
||||
(eval "(ocaml-run \"List.mem 3 [1; 2; 3]\")")
|
||||
(epoch 809)
|
||||
(eval "(ocaml-run \"List.mem 99 [1; 2; 3]\")")
|
||||
(epoch 810)
|
||||
(eval "(ocaml-run \"List.for_all (fun x -> x > 0) [1; 2; 3]\")")
|
||||
(epoch 811)
|
||||
(eval "(ocaml-run \"List.exists (fun x -> x > 2) [1; 2; 3]\")")
|
||||
(epoch 812)
|
||||
(eval "(ocaml-run \"List.hd [10; 20; 30]\")")
|
||||
(epoch 813)
|
||||
(eval "(ocaml-run \"List.nth [10; 20; 30] 1\")")
|
||||
|
||||
(epoch 820)
|
||||
(eval "(ocaml-run \"Option.map (fun x -> x + 1) (Some 41)\")")
|
||||
(epoch 821)
|
||||
(eval "(ocaml-run \"Option.map (fun x -> x + 1) None\")")
|
||||
(epoch 822)
|
||||
(eval "(ocaml-run \"Option.value (Some 7) 0\")")
|
||||
(epoch 823)
|
||||
(eval "(ocaml-run \"Option.value None 42\")")
|
||||
(epoch 824)
|
||||
(eval "(ocaml-run \"Option.is_some (Some 1)\")")
|
||||
(epoch 825)
|
||||
(eval "(ocaml-run \"Option.is_none None\")")
|
||||
|
||||
(epoch 830)
|
||||
(eval "(ocaml-run \"Result.map (fun x -> x + 1) (Ok 5)\")")
|
||||
(epoch 831)
|
||||
(eval "(ocaml-run \"Result.is_ok (Ok 1)\")")
|
||||
(epoch 832)
|
||||
(eval "(ocaml-run \"Result.is_error (Error \\\"oops\\\")\")")
|
||||
|
||||
EPOCHS
|
||||
|
||||
OUTPUT=$(timeout 60 "$SX_SERVER" < "$TMPFILE" 2>/dev/null)
|
||||
@@ -921,6 +973,36 @@ check 752 "submodule alias" '42'
|
||||
check 753 "multi-param functor" '("tuple" 1 2)'
|
||||
check 754 "Identity functor + include" '99'
|
||||
|
||||
# ── Phase 6: stdlib slice ───────────────────────────────────────
|
||||
# List
|
||||
check 800 "List.length [1..4]" '4'
|
||||
check 801 "List.length []" '0'
|
||||
check 802 "List.map x*2 [1;2;3]" '(2 4 6)'
|
||||
check 803 "List.filter > 2" '(3 4 5)'
|
||||
check 804 "List.fold_left + 0 [1..5]" '15'
|
||||
check 805 "List.fold_right ::" '(1 2 3)'
|
||||
check 806 "List.rev" '(3 2 1)'
|
||||
check 807 "List.append" '(1 2 3 4)'
|
||||
check 808 "List.mem 3" 'true'
|
||||
check 809 "List.mem 99" 'false'
|
||||
check 810 "List.for_all >0" 'true'
|
||||
check 811 "List.exists >2" 'true'
|
||||
check 812 "List.hd" '10'
|
||||
check 813 "List.nth idx 1" '20'
|
||||
|
||||
# Option
|
||||
check 820 "Option.map Some" '("Some" 42)'
|
||||
check 821 "Option.map None" '("None")'
|
||||
check 822 "Option.value Some" '7'
|
||||
check 823 "Option.value None" '42'
|
||||
check 824 "Option.is_some" 'true'
|
||||
check 825 "Option.is_none" 'true'
|
||||
|
||||
# Result
|
||||
check 830 "Result.map Ok" '("Ok" 6)'
|
||||
check 831 "Result.is_ok" 'true'
|
||||
check 832 "Result.is_error" 'true'
|
||||
|
||||
TOTAL=$((PASS + FAIL))
|
||||
if [ $FAIL -eq 0 ]; then
|
||||
echo "ok $PASS/$TOTAL OCaml-on-SX tests passed"
|
||||
|
||||
Reference in New Issue
Block a user