flan/web/examples/quotes.sh
Joseph Ferano 4d1a0c7807 Build sand for wasm32 and compare the hash, rather than repeat the number
It is the project's headline cross-target claim and the page was asserting it
second-hand. Both targets print 2256461126764447066 on this machine, so the
transcript is now what the page shows.
2026-09-12 03:53:38 +07:00

81 lines
3.5 KiB
Bash

#!/bin/sh
# The blocks on index.html that are not programs in this directory are quoted
# from somewhere: a repository file, or the output of a command. Each one is
# re-derived here and looked for in the page, so a quote cannot go stale
# quietly. check.sh covers the runnable blocks; this covers the rest.
#
# $ dune build && sh web/examples/quotes.sh
here=$(cd "$(dirname "$0")" && pwd)
root=$(cd "$here/../.." && pwd)
FLAN=${FLAN:-$root/_build/default/bin/main.exe}
page=$here/../index.html
fail=0
# The page is compared with its whitespace collapsed, so that a long compiler
# message may be wrapped in the HTML and still be recognised as the same text.
flat=$(sed -e 's/&lt;/</g' -e 's/&gt;/>/g' -e 's/&amp;/\&/g' "$page" | tr '\n' ' ' | tr -s ' ')
want() {
needle=$(printf '%s' "$2" | tr '\n' ' ' | tr -s ' ')
case $flat in
*"$needle"*) echo "ok $1" ;;
*) echo "FAIL $1"; echo " not on the page: $2"; fail=1 ;;
esac
}
# The usage text, from the binary itself.
want "flan usage" "$("$FLAN" 2>&1 | sed -n 2p)"
# calc-me, the first acceptance program, still answers what the page says.
want "calc-me" "$("$FLAN" run "$root/calc-me.flan" '1 + 2 * (3 - 0.5) / 2')"
# The sand hash. The page shows it twice — native and wasm32 — and the claim is
# that the two agree; only the native half is cheap enough to check here.
want "sand hash" "$("$FLAN" run "$root/test/programs/sand-headless.flan")"
# The two cross-target refusals, in the compiler's own words.
want "run --target" "$("$FLAN" run "$here/hello.flan" --target=wasm32-wasi 2>&1)"
# The refusal and diagnostic messages quoted in the prose and in the
# "Not implemented yet" table.
for pair in \
'vec:(defvar xs (Vec i32))' \
'map:(defvar m (Map string i32))' \
'result:(defn f [] (Result i32 i32) None)' \
'handle:(defvar h (Handle i32))' \
'fnty:(defn f [g (Fn [i32] i32)] i32 (g 1))' \
'quoted:(defn f [] i32 (quote a))' \
'deferblock:(defn f [] i32 (let [x 1] (defer (print-line "a")) x))' \
'i64index:(defconst xs [3 i32] [1 2 3]) (defn main [] i32 (let [i (i64 1)] (at xs i)))'
do
name=${pair%%:*}; src=${pair#*:}
printf '%s\n' "$src" > "$here/.q.flan"
msg=$("$FLAN" check "$here/.q.flan" 2>&1 | sed 's/^[^ ]*: //')
want "message: $name" "$msg"
done
rm -f "$here/.q.flan"
# The cell and the transfer channel, from a real --dev emit of hello.flan.
ir=$("$FLAN" emit --dev "$here/hello.flan" 2>/dev/null)
want "cell global" "$(printf '%s\n' "$ir" | grep '^@"flan.cell.print-line"')"
want "cell load" "$(printf '%s\n' "$ir" | grep 'load ptr, ptr @"flan.cell.print-line"')"
want "xfer channel" "$(printf '%s\n' "$ir" | grep 'define {} @"flan.main"')"
# The generated C, from flan shim.
want "shim wrapper" "$("$FLAN" shim "$here/shimdemo.flan" | grep 'GetMousePosition();')"
# Lines quoted verbatim from repository files.
want "raylib binding" "$(grep -F 'unload-texture' "$root/vendor/raylib/raylib.flan")"
want "agent declare" "$(grep -F 'flan_agent_poll' "$root/vendor/agent/agent.flan" | head -1)"
want "conditions.org" "$(grep -F 'Innermost frame offering the name wins' "$root/conditions.org")"
want "renderer" "$(grep -F ':r 17 :g 34 :b 51 :a 68' "$root/NEXT.md")"
# The Emacs bindings, from the keymap rather than from any prose about it.
for k in "C-c C-c" "C-c C-k" "C-x C-e" "C-c C-b" "C-c C-v" "C-c C-x"; do
grep -qF "(kbd \"$k\")" "$root/emacs/flan-mode.el" || {
echo "FAIL keybinding $k is not in flan-mode.el"; fail=1; continue; }
want "keybinding $k" "<kbd>$k</kbd>"
done
exit $fail