#!/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 # Look for a literal string in the page, allowing for HTML escaping of < and >. want() { esc=$(printf '%s' "$2" | sed -e 's/&/\&/g' -e 's//\>/g') if grep -qF -- "$esc" "$page"; then echo "ok $1"; else echo "FAIL $1" echo " not on the page: $2" fail=1 fi } # 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 refusal messages quoted in "Not implemented yet" and under defer. 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))' do name=${pair%%:*}; src=${pair#*:} printf '%s\n' "$src" > "$here/.q.flan" msg=$("$FLAN" check "$here/.q.flan" 2>&1 | sed 's/^[^ ]*: //') want "refusal: $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")" exit $fail