phase29ab(p2): add seg trim fixture+smoke and docs
This commit is contained in:
28
apps/tests/phase29ab_pattern2_loopbodylocal_seg_min.hako
Normal file
28
apps/tests/phase29ab_pattern2_loopbodylocal_seg_min.hako
Normal file
@ -0,0 +1,28 @@
|
||||
// Phase 29ab P2: Pattern2 LoopBodyLocal Trim (seg) minimal case
|
||||
//
|
||||
// Goal:
|
||||
// - break condition uses LoopBodyLocal (seg) with Trim A-3 shape
|
||||
// - JoinIR -> merge path should handle promotion
|
||||
//
|
||||
// Expected (before fix): FAIL/out-of-scope
|
||||
// Expected (after fix): prints "2" and returns 2
|
||||
|
||||
static box Main {
|
||||
main() {
|
||||
local s = "ab "
|
||||
local i = 0
|
||||
|
||||
loop(i < s.length()) {
|
||||
local seg = s.substring(i, i + 1)
|
||||
|
||||
if seg == " " || seg == "\t" {
|
||||
break
|
||||
}
|
||||
|
||||
i = i + 1
|
||||
}
|
||||
|
||||
print(i)
|
||||
return i
|
||||
}
|
||||
}
|
||||
@ -10,6 +10,11 @@
|
||||
- Supported: A-3 Trim / A-4 DigitPos (promote LoopBodyLocal to carrier)
|
||||
- ConditionOnly carriers are recalculated per iteration (no host binding)
|
||||
|
||||
## Trim (seg) minimal shape
|
||||
- Example shape (A-3): `local seg = s.substring(i, i + 1)`
|
||||
- Break guard: `if seg == " " || seg == "\\t" { break }`
|
||||
- seg is read-only (no reassignment in the loop body)
|
||||
|
||||
## Carrier binding rules (Pattern2)
|
||||
- `CarrierInit::FromHost` -> host binding required
|
||||
- `CarrierInit::BoolConst(_)` / `CarrierInit::LoopLocalZero` -> host binding is skipped
|
||||
@ -19,6 +24,7 @@
|
||||
- multiple breaks / continue / return in the loop body
|
||||
- reassigned LoopBodyLocal or ReadOnlySlot contract violations
|
||||
- break conditions with unsupported AST shapes
|
||||
- seg reassignment or non-substring init (e.g., `seg = other_call()`)
|
||||
|
||||
## Fail-Fast policy
|
||||
- `PromoteDecision::Freeze` -> Err (missing implementation or contract violation)
|
||||
|
||||
@ -0,0 +1,34 @@
|
||||
#!/bin/bash
|
||||
# Phase 29ab P2: Pattern2 LoopBodyLocal Trim (seg) minimal (VM backend)
|
||||
# Tests: LoopBodyLocal seg in break condition promoted via Trim A-3
|
||||
|
||||
source "$(dirname "$0")/../../../lib/test_runner.sh"
|
||||
export SMOKES_USE_PYVM=0
|
||||
require_env || exit 2
|
||||
|
||||
INPUT="$NYASH_ROOT/apps/tests/phase29ab_pattern2_loopbodylocal_seg_min.hako"
|
||||
RUN_TIMEOUT_SECS=${RUN_TIMEOUT_SECS:-10}
|
||||
|
||||
set +e
|
||||
OUTPUT=$(timeout "$RUN_TIMEOUT_SECS" env NYASH_DISABLE_PLUGINS=1 HAKO_JOINIR_STRICT=1 "$NYASH_BIN" "$INPUT" 2>&1)
|
||||
EXIT_CODE=$?
|
||||
set -e
|
||||
|
||||
if [ "$EXIT_CODE" -eq 124 ]; then
|
||||
test_fail "phase29ab_pattern2_loopbodylocal_seg_min_vm: hakorune timed out (>${RUN_TIMEOUT_SECS}s)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
OUTPUT_CLEAN=$(echo "$OUTPUT" | filter_noise)
|
||||
|
||||
if echo "$OUTPUT_CLEAN" | grep -q "^2$" || echo "$OUTPUT" | grep -q "^RC: 2$"; then
|
||||
test_pass "phase29ab_pattern2_loopbodylocal_seg_min_vm: Pattern2 Trim promotion succeeded (output: 2)"
|
||||
exit 0
|
||||
else
|
||||
echo "[FAIL] Unexpected output (expected: 2)"
|
||||
echo "[INFO] Exit code: $EXIT_CODE"
|
||||
echo "[INFO] Output (clean):"
|
||||
echo "$OUTPUT_CLEAN" | tail -n 20 || true
|
||||
test_fail "phase29ab_pattern2_loopbodylocal_seg_min_vm: Unexpected output"
|
||||
exit 1
|
||||
fi
|
||||
Reference in New Issue
Block a user