diff --git a/PORTING.md b/PORTING.md index a65a4af..e1d3250 100644 --- a/PORTING.md +++ b/PORTING.md @@ -791,6 +791,14 @@ pointer-and-count apart itself, and uses a zeroed `defvar` as the null pointer t "the default ASCII set". It was written for this call before anything called it, and the call fit it exactly. +**`and` short-circuits, which `step-back` depends on.** The backward walk's loop condition +is `(and (> i 0) (continuation? (at b i)))`, and at the start of the text `i` is -1 — so if +`and` were a strict function rather than a form, the guard would not save the `(at b -1)` +beside it and the first press of LEFT would signal `BoundsError`. It is a form and it does +short-circuit; `test/programs/raylib-codepoints.flan` has a row for it, because the walk +itself never reaches that offset and the claim is about the language rather than about the +example. + **Fixed arrays were the right shape for both.** A codepoint table with a count, a `[9 Rectangle]` of toggle buttons, a `[9 string]` of labels. The §3 finding from the siam-farmer report — a global cannot hold a `Vec`, and fixed arrays with counts are usually diff --git a/examples/text-codepoints-loading.flan b/examples/text-codepoints-loading.flan index 9ad13ae..7d1f85c 100644 --- a/examples/text-codepoints-loading.flan +++ b/examples/text-codepoints-loading.flan @@ -173,6 +173,11 @@ (if (< i 0) 0 i))) (defvar font rl/Font) +;; Whether the TTF was there, asked once. A `defvar` and not the call itself +;; in the draw loop: path-file? is a stat, and a syscall per frame to answer a +;; question whose answer cannot change while the program runs is exactly what +;; the per-frame rule in PORTING.md is about. +(defvar font-present bool) (defvar show-font-atlas bool) (defvar cursor i32) (defvar codepoint-count i32) @@ -204,6 +209,7 @@ ;; nothing else in this program does. (rl/set-text-line-spacing 20) + (set font-present (rl/path-file? font-path)) (set show-font-atlas false) (set cursor 0) @@ -249,7 +255,7 @@ ;; The line the C does not have, and the reason it is here is in the ;; header comment: without the TTF this program draws boxes, and a ;; program that draws boxes without saying why reads as broken. - (when (not (rl/path-file? font-path)) + (when (not font-present) (d/draw-piece "No font at examples/resources/ — glyphs will be boxes." 10 (- screen-height 55) 20 rl/maroon)) diff --git a/test/programs/raylib-codepoints.flan b/test/programs/raylib-codepoints.flan index b5a9546..f9919b9 100644 --- a/test/programs/raylib-codepoints.flan +++ b/test/programs/raylib-codepoints.flan @@ -108,6 +108,14 @@ (set mirrored false))) (print "walks mirror ") (println (yes-no mirrored))) + ;; The one call walk-backward never makes: step-back at the very start. + ;; It is where the example goes the moment anybody presses LEFT before + ;; pressing RIGHT, and it is the one offset where the continuation-byte + ;; loop is asked to step off the front of the buffer. `and` short-circuits, + ;; so the (> i 0) guard is what keeps (at b -1) from being evaluated at + ;; all — which is a claim about the language and so is worth a row. + (show "back at start" (cp/step-back 0)) + ;; Item 3: and the forward walk is what raylib said the text contains. (let [agrees (= forward-n total) all (slice-from-ptr raw total)] diff --git a/test/test_acceptance.ml b/test/test_acceptance.ml index c96edb7..e81f6c0 100644 --- a/test/test_acceptance.ml +++ b/test/test_acceptance.ml @@ -1065,6 +1065,7 @@ let () = forward 54\n\ backward 54\n\ walks mirror yes\n\ + back at start 0\n\ walk matches raylib yes\n" in if Sys.command "ldconfig -p 2>/dev/null | grep -q libraylib" = 0 then begin