loopform(hints): detect up to 2 assigned vars in loop body (no break/continue) and emit LoopCarrier hint; add smoke for two-vars case

This commit is contained in:
Selfhosting Dev
2025-09-20 06:24:33 +09:00
parent 334b7e83af
commit f50f79994f
3 changed files with 62 additions and 0 deletions

View File

@ -0,0 +1,25 @@
#!/usr/bin/env bash
set -euo pipefail
root=$(cd "$(dirname "$0")"/../../../.. && pwd)
bin="$root/target/release/nyash"
src="apps/tests/macro/loopform/two_vars.nyash"
if [ ! -x "$bin" ]; then
echo "nyash binary not found at $bin; build first (cargo build --release)" >&2
exit 1
fi
export NYASH_MIR_TRACE_HINTS=1
out=$({ "$bin" --backend vm "$src" 1>/dev/null; } 2>&1 || true)
# Check the LoopCarrier hint contains both variable names (order-agnostic)
echo "$out" | rg -q "\[mir\]\[hint\] LoopCarrier\((i,sum|sum,i)\)" || {
echo "[FAIL] missing LoopCarrier(i,sum) hint" >&2
printf '%s\n' "$out" | tail -n 80 >&2
exit 2
}
echo "[OK] MIR hints LoopCarrier(two vars) trace smoke passed"