ocaml: phase 2+6 print primitives wire to host display (+2 tests, 444 total)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 46s

print_string / print_endline / print_int / print_newline now route to
SX display primitive (not the non-existent print/println). print_endline
appends '\n'.

let _ = expr ;; at top level confirmed working via the
wildcard-param parser.
This commit is contained in:
2026-05-08 17:37:00 +00:00
parent cabf5dc9c3
commit 0bc6dbd233
3 changed files with 22 additions and 4 deletions

View File

@@ -72,10 +72,11 @@
(list "_string_of_float" (fn (f) (str f)))
(list "_char_code" (fn (c) (char-code c)))
(list "_char_chr" (fn (n) (char-from-code n)))
;; Print: prints to host stdout via println.
(list "print_string" (fn (s) (begin (print s) nil)))
(list "print_endline" (fn (s) (begin (println s) nil)))
(list "print_int" (fn (i) (begin (print (str i)) nil)))
;; Print: route to host SX `display` (no automatic newline).
(list "print_string" (fn (s) (begin (display s) nil)))
(list "print_endline" (fn (s) (begin (display s) (display "\n") nil)))
(list "print_int" (fn (i) (begin (display (str i)) nil)))
(list "print_newline" (fn (_) (begin (display "\n") nil)))
;; Float math primitives.
(list "_float_sqrt" (fn (x) (sqrt x)))
(list "_float_sin" (fn (x) (sin x)))

View File

@@ -1092,6 +1092,12 @@ cat > "$TMPFILE" << 'EPOCHS'
(epoch 3802)
(eval "(ocaml-type-of \"let f x = x + 1 and g x = x * 2 in f 1 + g 2\")")
;; ── let _ = expr top-level ─────────────────────────────────────
(epoch 3900)
(eval "(ocaml-run-program \"let _ = 1 + 2 ;; 42\")")
(epoch 3901)
(eval "(ocaml-run-program \"let x = 10 ;; let _ = x ;; x * 2\")")
EPOCHS
OUTPUT=$(timeout 180 "$SX_SERVER" < "$TMPFILE" 2>/dev/null)
@@ -1728,6 +1734,10 @@ check 3800 "let-mut x+y : Int" '"Int"'
check 3801 "let-rec-mut even" '"Int -> Bool"'
check 3802 "let-mut f and g" '"Int"'
# ── let _ = expr top-level ─────────────────────────────────────
check 3900 "let _ = 1+2;; 42" '42'
check 3901 "two top-level lets, _" '20'
TOTAL=$((PASS + FAIL))
if [ $FAIL -eq 0 ]; then
echo "ok $PASS/$TOTAL OCaml-on-SX tests passed"